1 # SPDX-License-Identifier: GPL-2.0-or-later
3 # This try block allows for the script to psudo-intelligently select the
4 # appropriate random to use. If Numpy's random is present it will use that.
5 # If Numpy's random is not present, it will through a "module not found"
6 # exception and instead use the slower built-in random that Python has.
8 from numpy
.random
import random_integers
as randint
9 from numpy
.random
import normal
as gauss
10 from numpy
.random
import (
20 from random
import betavariate
as beta
22 from .utils
import skewedGauss
25 def randomizeTexture(texture
, level
=1):
27 Set the values for a texture from parameters.
29 param: texture - bpy.data.texture to modify.
30 level - designated tweaked settings to use
31 -> Below 10 is a displacement texture
32 -> Between 10 and 20 is a base material texture
34 noises
= ['BLENDER_ORIGINAL', 'ORIGINAL_PERLIN', 'IMPROVED_PERLIN',
35 'VORONOI_F1', 'VORONOI_F2', 'VORONOI_F3', 'VORONOI_F4',
36 'VORONOI_F2_F1', 'VORONOI_CRACKLE']
37 if texture
.type == 'CLOUDS':
38 if randint(0, 1) == 0:
39 texture
.noise_type
= 'SOFT_NOISE'
41 texture
.noise_type
= 'HARD_NOISE'
43 tempInt
= randint(0, 6)
45 tempInt
= randint(0, 8)
46 texture
.noise_basis
= noises
[tempInt
]
47 texture
.noise_depth
= 8
50 texture
.noise_scale
= gauss(0.625, 1 / 24)
52 texture
.noise_scale
= 0.15
54 texture
.noise_scale
= gauss(0.5, 1 / 24)
56 if texture
.noise_basis
in ['BLENDER_ORIGINAL', 'ORIGINAL_PERLIN',
57 'IMPROVED_PERLIN', 'VORONOI_F1']:
58 texture
.intensity
= gauss(1, 1 / 6)
59 texture
.contrast
= gauss(4, 1 / 3)
60 elif texture
.noise_basis
in ['VORONOI_F2', 'VORONOI_F3', 'VORONOI_F4']:
61 texture
.intensity
= gauss(0.25, 1 / 12)
62 texture
.contrast
= gauss(2, 1 / 6)
63 elif texture
.noise_basis
== 'VORONOI_F2_F1':
64 texture
.intensity
= gauss(0.5, 1 / 6)
65 texture
.contrast
= gauss(2, 1 / 6)
66 elif texture
.noise_basis
== 'VORONOI_CRACKLE':
67 texture
.intensity
= gauss(0.5, 1 / 6)
68 texture
.contrast
= gauss(2, 1 / 6)
69 elif texture
.type == 'MUSGRAVE':
70 # musgraveType = ['MULTIFRACTAL', 'RIDGED_MULTIFRACTAL',
71 # 'HYBRID_MULTIFRACTAL', 'FBM', 'HETERO_TERRAIN']
72 texture
.musgrave_type
= 'MULTIFRACTAL'
73 texture
.dimension_max
= abs(gauss(0, 0.6)) + 0.2
74 texture
.lacunarity
= beta(3, 8) * 8.2 + 1.8
77 texture
.noise_scale
= gauss(0.625, 1 / 24)
78 texture
.noise_intensity
= 0.2
81 texture
.intensity
= gauss(1, 1 / 6)
82 texture
.contrast
= 0.2
83 texture
.noise_scale
= 0.15
86 texture
.intensity
= gauss(0.25, 1 / 12)
87 texture
.contrast
= gauss(1.5, 1 / 6)
88 texture
.noise_scale
= 0.5
91 texture
.octaves
= uniform(1, 3)
93 texture
.octaves
= uniform(2, 8)
95 texture
.intensity
= gauss(1, 1 / 6)
96 texture
.contrast
= 0.2
98 elif texture
.type == 'DISTORTED_NOISE':
99 tempInt
= randint(0, 8)
100 texture
.noise_distortion
= noises
[tempInt
]
101 tempInt
= randint(0, 8)
102 texture
.noise_basis
= noises
[tempInt
]
103 texture
.distortion
= skewedGauss(2.0, 2.6666, (0.0, 10.0), False)
106 texture
.noise_scale
= gauss(0.625, 1 / 24)
108 texture
.noise_scale
= 0.15
110 texture
.noise_scale
= gauss(0.2, 1 / 48)
111 elif texture
.type == 'STUCCI':
112 stucciTypes
= ['PLASTIC', 'WALL_IN', 'WALL_OUT']
113 if randint(0, 1) == 0:
114 texture
.noise_type
= 'SOFT_NOISE'
116 texture
.noise_type
= 'HARD_NOISE'
117 tempInt
= randint(0, 2)
118 texture
.stucci_type
= stucciTypes
[tempInt
]
121 tempInt
= randint(0, 6)
122 texture
.noise_basis
= noises
[tempInt
]
123 texture
.noise_scale
= gauss(0.625, 1 / 24)
125 tempInt
= randint(0, 6)
126 texture
.noise_basis
= noises
[tempInt
]
127 texture
.noise_scale
= 0.15
129 tempInt
= randint(0, 6)
130 texture
.noise_basis
= noises
[tempInt
]
131 texture
.noise_scale
= gauss(0.2, 1 / 30)
133 tempInt
= randint(0, 6)
134 texture
.noise_basis
= noises
[tempInt
]
135 elif texture
.type == 'VORONOI':
136 metrics
= ['DISTANCE', 'DISTANCE_SQUARED', 'MANHATTAN', 'CHEBYCHEV',
137 'MINKOVSKY_HALF', 'MINKOVSKY_FOUR', 'MINKOVSKY']
138 # Settings for first displacement level:
140 tempInt
= randint(0, 1)
141 texture
.distance_metric
= metrics
[tempInt
]
142 texture
.noise_scale
= gauss(0.625, 1 / 24)
143 texture
.contrast
= 0.5
144 texture
.intensity
= 0.7
146 texture
.noise_scale
= 0.15
147 tempInt
= randint(0, 6)
148 texture
.distance_metric
= metrics
[tempInt
]
150 tempInt
= randint(0, 1)
151 texture
.distance_metric
= metrics
[tempInt
]
152 texture
.noise_scale
= gauss(0.125, 1 / 48)
153 texture
.contrast
= 0.5
154 texture
.intensity
= 0.7
156 tempInt
= randint(0, 6)
157 texture
.distance_metric
= metrics
[tempInt
]