Sun Position: Fix crash when Blender was started in background
[blender-addons.git] / add_mesh_extra_objects / add_mesh_rocks / randomize_texture.py
blobb1dd99bdfff6d48a42ba2bad089be909cb905aa2
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.
7 try:
8 from numpy.random import random_integers as randint
9 from numpy.random import normal as gauss
10 from numpy.random import (
11 beta,
12 uniform,
14 except:
15 from random import (
16 randint,
17 gauss,
18 uniform,
20 from random import betavariate as beta
22 from .utils import skewedGauss
25 def randomizeTexture(texture, level=1):
26 '''
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
33 '''
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'
40 else:
41 texture.noise_type = 'HARD_NOISE'
42 if level != 11:
43 tempInt = randint(0, 6)
44 else:
45 tempInt = randint(0, 8)
46 texture.noise_basis = noises[tempInt]
47 texture.noise_depth = 8
49 if level == 0:
50 texture.noise_scale = gauss(0.625, 1 / 24)
51 elif level == 2:
52 texture.noise_scale = 0.15
53 elif level == 11:
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
76 if level == 0:
77 texture.noise_scale = gauss(0.625, 1 / 24)
78 texture.noise_intensity = 0.2
79 texture.octaves = 1.0
80 elif level == 2:
81 texture.intensity = gauss(1, 1 / 6)
82 texture.contrast = 0.2
83 texture.noise_scale = 0.15
84 texture.octaves = 8.0
85 elif level == 10:
86 texture.intensity = gauss(0.25, 1 / 12)
87 texture.contrast = gauss(1.5, 1 / 6)
88 texture.noise_scale = 0.5
89 texture.octaves = 8.0
90 elif level == 12:
91 texture.octaves = uniform(1, 3)
92 elif level > 12:
93 texture.octaves = uniform(2, 8)
94 else:
95 texture.intensity = gauss(1, 1 / 6)
96 texture.contrast = 0.2
97 texture.octaves = 8.0
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)
105 if level == 0:
106 texture.noise_scale = gauss(0.625, 1 / 24)
107 elif level == 2:
108 texture.noise_scale = 0.15
109 elif level >= 12:
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'
115 else:
116 texture.noise_type = 'HARD_NOISE'
117 tempInt = randint(0, 2)
118 texture.stucci_type = stucciTypes[tempInt]
120 if level == 0:
121 tempInt = randint(0, 6)
122 texture.noise_basis = noises[tempInt]
123 texture.noise_scale = gauss(0.625, 1 / 24)
124 elif level == 2:
125 tempInt = randint(0, 6)
126 texture.noise_basis = noises[tempInt]
127 texture.noise_scale = 0.15
128 elif level >= 12:
129 tempInt = randint(0, 6)
130 texture.noise_basis = noises[tempInt]
131 texture.noise_scale = gauss(0.2, 1 / 30)
132 else:
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:
139 if level == 0:
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
145 elif level == 2:
146 texture.noise_scale = 0.15
147 tempInt = randint(0, 6)
148 texture.distance_metric = metrics[tempInt]
149 elif level >= 12:
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
155 else:
156 tempInt = randint(0, 6)
157 texture.distance_metric = metrics[tempInt]
159 return