Fix #105067: Node Wrangler: cannot preview multi-user material group
[blender-addons.git] / add_mesh_extra_objects / add_mesh_rocks / randomize_texture.py
blob47862b772578d14122798d761922174c2cb2b546
1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # This try block allows for the script to psudo-intelligently select the
6 # appropriate random to use. If Numpy's random is present it will use that.
7 # If Numpy's random is not present, it will through a "module not found"
8 # exception and instead use the slower built-in random that Python has.
9 try:
10 from numpy.random import random_integers as randint
11 from numpy.random import normal as gauss
12 from numpy.random import (
13 beta,
14 uniform,
16 except:
17 from random import (
18 randint,
19 gauss,
20 uniform,
22 from random import betavariate as beta
24 from .utils import skewedGauss
27 def randomizeTexture(texture, level=1):
28 '''
29 Set the values for a texture from parameters.
31 param: texture - bpy.data.texture to modify.
32 level - designated tweaked settings to use
33 -> Below 10 is a displacement texture
34 -> Between 10 and 20 is a base material texture
35 '''
36 noises = ['BLENDER_ORIGINAL', 'ORIGINAL_PERLIN', 'IMPROVED_PERLIN',
37 'VORONOI_F1', 'VORONOI_F2', 'VORONOI_F3', 'VORONOI_F4',
38 'VORONOI_F2_F1', 'VORONOI_CRACKLE']
39 if texture.type == 'CLOUDS':
40 if randint(0, 1) == 0:
41 texture.noise_type = 'SOFT_NOISE'
42 else:
43 texture.noise_type = 'HARD_NOISE'
44 if level != 11:
45 tempInt = randint(0, 6)
46 else:
47 tempInt = randint(0, 8)
48 texture.noise_basis = noises[tempInt]
49 texture.noise_depth = 8
51 if level == 0:
52 texture.noise_scale = gauss(0.625, 1 / 24)
53 elif level == 2:
54 texture.noise_scale = 0.15
55 elif level == 11:
56 texture.noise_scale = gauss(0.5, 1 / 24)
58 if texture.noise_basis in ['BLENDER_ORIGINAL', 'ORIGINAL_PERLIN',
59 'IMPROVED_PERLIN', 'VORONOI_F1']:
60 texture.intensity = gauss(1, 1 / 6)
61 texture.contrast = gauss(4, 1 / 3)
62 elif texture.noise_basis in ['VORONOI_F2', 'VORONOI_F3', 'VORONOI_F4']:
63 texture.intensity = gauss(0.25, 1 / 12)
64 texture.contrast = gauss(2, 1 / 6)
65 elif texture.noise_basis == 'VORONOI_F2_F1':
66 texture.intensity = gauss(0.5, 1 / 6)
67 texture.contrast = gauss(2, 1 / 6)
68 elif texture.noise_basis == 'VORONOI_CRACKLE':
69 texture.intensity = gauss(0.5, 1 / 6)
70 texture.contrast = gauss(2, 1 / 6)
71 elif texture.type == 'MUSGRAVE':
72 # musgraveType = ['MULTIFRACTAL', 'RIDGED_MULTIFRACTAL',
73 # 'HYBRID_MULTIFRACTAL', 'FBM', 'HETERO_TERRAIN']
74 texture.musgrave_type = 'MULTIFRACTAL'
75 texture.dimension_max = abs(gauss(0, 0.6)) + 0.2
76 texture.lacunarity = beta(3, 8) * 8.2 + 1.8
78 if level == 0:
79 texture.noise_scale = gauss(0.625, 1 / 24)
80 texture.noise_intensity = 0.2
81 texture.octaves = 1.0
82 elif level == 2:
83 texture.intensity = gauss(1, 1 / 6)
84 texture.contrast = 0.2
85 texture.noise_scale = 0.15
86 texture.octaves = 8.0
87 elif level == 10:
88 texture.intensity = gauss(0.25, 1 / 12)
89 texture.contrast = gauss(1.5, 1 / 6)
90 texture.noise_scale = 0.5
91 texture.octaves = 8.0
92 elif level == 12:
93 texture.octaves = uniform(1, 3)
94 elif level > 12:
95 texture.octaves = uniform(2, 8)
96 else:
97 texture.intensity = gauss(1, 1 / 6)
98 texture.contrast = 0.2
99 texture.octaves = 8.0
100 elif texture.type == 'DISTORTED_NOISE':
101 tempInt = randint(0, 8)
102 texture.noise_distortion = noises[tempInt]
103 tempInt = randint(0, 8)
104 texture.noise_basis = noises[tempInt]
105 texture.distortion = skewedGauss(2.0, 2.6666, (0.0, 10.0), False)
107 if level == 0:
108 texture.noise_scale = gauss(0.625, 1 / 24)
109 elif level == 2:
110 texture.noise_scale = 0.15
111 elif level >= 12:
112 texture.noise_scale = gauss(0.2, 1 / 48)
113 elif texture.type == 'STUCCI':
114 stucciTypes = ['PLASTIC', 'WALL_IN', 'WALL_OUT']
115 if randint(0, 1) == 0:
116 texture.noise_type = 'SOFT_NOISE'
117 else:
118 texture.noise_type = 'HARD_NOISE'
119 tempInt = randint(0, 2)
120 texture.stucci_type = stucciTypes[tempInt]
122 if level == 0:
123 tempInt = randint(0, 6)
124 texture.noise_basis = noises[tempInt]
125 texture.noise_scale = gauss(0.625, 1 / 24)
126 elif level == 2:
127 tempInt = randint(0, 6)
128 texture.noise_basis = noises[tempInt]
129 texture.noise_scale = 0.15
130 elif level >= 12:
131 tempInt = randint(0, 6)
132 texture.noise_basis = noises[tempInt]
133 texture.noise_scale = gauss(0.2, 1 / 30)
134 else:
135 tempInt = randint(0, 6)
136 texture.noise_basis = noises[tempInt]
137 elif texture.type == 'VORONOI':
138 metrics = ['DISTANCE', 'DISTANCE_SQUARED', 'MANHATTAN', 'CHEBYCHEV',
139 'MINKOVSKY_HALF', 'MINKOVSKY_FOUR', 'MINKOVSKY']
140 # Settings for first displacement level:
141 if level == 0:
142 tempInt = randint(0, 1)
143 texture.distance_metric = metrics[tempInt]
144 texture.noise_scale = gauss(0.625, 1 / 24)
145 texture.contrast = 0.5
146 texture.intensity = 0.7
147 elif level == 2:
148 texture.noise_scale = 0.15
149 tempInt = randint(0, 6)
150 texture.distance_metric = metrics[tempInt]
151 elif level >= 12:
152 tempInt = randint(0, 1)
153 texture.distance_metric = metrics[tempInt]
154 texture.noise_scale = gauss(0.125, 1 / 48)
155 texture.contrast = 0.5
156 texture.intensity = 0.7
157 else:
158 tempInt = randint(0, 6)
159 texture.distance_metric = metrics[tempInt]
161 return