1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # Converts a formatted string to a float tuple:
6 # IN - '(0.5, 0.2)' -> CONVERT -> OUT - (0.5, 0.2)
8 sTemp
= str(stringIn
)[1:len(str(stringIn
)) - 1].split(', ')
11 fTemp
.append(float(i
))
15 # Converts a formatted string to a float tuple:
16 # IN - '[0.5, 0.2]' -> CONVERT -> OUT - [0.5, 0.2]
18 sTemp
= str(stringIn
)[1:len(str(stringIn
)) - 1].split(', ')
21 fTemp
.append(float(i
))
25 # Converts each item of a list into a float:
29 outList
.append(float(i
))
33 # Converts each item of a list into an integer:
37 outList
.append(int(i
))
41 # Sets all faces smooth. Done this way since I can't
42 # find a simple way without using bpy.ops:
53 # This try block allows for the script to psudo-intelligently select the
54 # appropriate random to use. If Numpy's random is present it will use that.
55 # If Numpy's random is not present, it will through a "module not found"
56 # exception and instead use the slower built-in random that Python has.
58 # from numpy.random import random_integers as randint
59 from numpy
.random
import normal
as gauss
60 # from numpy.random import (beta,
64 # print("Rock Generator: Numpy found.")
73 # from random import betavariate as beta
74 # from random import weibullvariate as weibull
75 print("Rock Generator: Numpy not found. Using Python's random.")
77 # Artificially skews a normal (gaussian) distribution. This will not create
78 # a continuous distribution curve but instead acts as a piecewise finction.
79 # This linearly scales the output on one side to fit the bounds.
81 # Example output histograms:
83 # Upper skewed: Lower skewed:
91 # | _█▄███████ | ███████
92 # | _██████████_ | ████████▄▄█_ _
93 # | _▄▄████████████ | ████████████▄█_
94 # | _▄_ ▄███████████████▄_ | _▄███████████████▄▄_
95 # ------------------------- -----------------------
97 # Histograms were generated in R (http://www.r-project.org/) based on the
98 # calculations below and manually duplicated here.
100 # param: mu - mu is the mean of the distribution.
101 # sigma - sigma is the standard deviation of the distribution.
102 # bounds - bounds[0] is the lower bound and bounds[1]
103 # is the upper bound.
104 # upperSkewed - if the distribution is upper skewed.
105 # return: out - Rondomly generated value from the skewed distribution.
107 # @todo: Because NumPy's random value generators are faster when called
108 # a bunch of times at once, maybe allow this to generate and return
109 # multiple values at once?
112 def skewedGauss(mu
, sigma
, bounds
, upperSkewed
=True):
113 raw
= gauss(mu
, sigma
)
115 # Quicker to check an extra condition than do unnecessary math. . . .
116 if raw
< mu
and not upperSkewed
:
117 out
= ((mu
- bounds
[0]) / (3 * sigma
)) * raw
+ ((mu
* (bounds
[0] - (mu
- 3 * sigma
))) / (3 * sigma
))
118 elif raw
> mu
and upperSkewed
:
119 out
= ((mu
- bounds
[1]) / (3 * -sigma
)) * raw
+ ((mu
* (bounds
[1] - (mu
+ 3 * sigma
))) / (3 * -sigma
))
126 # @todo create a def for generating an alpha and beta for a beta distribution
127 # given a mu, sigma, and an upper and lower bound. This proved faster in
128 # profiling in addition to providing a much better distribution curve
129 # provided multiple iterations happen within this function; otherwise it was
131 # This might be a scratch because of the bounds placed on mu and sigma:
133 # For alpha > 1 and beta > 1:
134 # mu^2 - mu^3 mu^3 - mu^2 + mu
135 # ----------- < sigma < ----------------
138 # def generateBeta(mu, sigma, scale, repitions=1):