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.
10 from numpy
.random
import random_integers
as randint
11 from numpy
.random
import normal
as gauss
12 from numpy
.random
import (
22 from random
import betavariate
as beta
24 from .utils
import skewedGauss
27 def randomizeTexture(texture
, level
=1):
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
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'
43 texture
.noise_type
= 'HARD_NOISE'
45 tempInt
= randint(0, 6)
47 tempInt
= randint(0, 8)
48 texture
.noise_basis
= noises
[tempInt
]
49 texture
.noise_depth
= 8
52 texture
.noise_scale
= gauss(0.625, 1 / 24)
54 texture
.noise_scale
= 0.15
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
79 texture
.noise_scale
= gauss(0.625, 1 / 24)
80 texture
.noise_intensity
= 0.2
83 texture
.intensity
= gauss(1, 1 / 6)
84 texture
.contrast
= 0.2
85 texture
.noise_scale
= 0.15
88 texture
.intensity
= gauss(0.25, 1 / 12)
89 texture
.contrast
= gauss(1.5, 1 / 6)
90 texture
.noise_scale
= 0.5
93 texture
.octaves
= uniform(1, 3)
95 texture
.octaves
= uniform(2, 8)
97 texture
.intensity
= gauss(1, 1 / 6)
98 texture
.contrast
= 0.2
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)
108 texture
.noise_scale
= gauss(0.625, 1 / 24)
110 texture
.noise_scale
= 0.15
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'
118 texture
.noise_type
= 'HARD_NOISE'
119 tempInt
= randint(0, 2)
120 texture
.stucci_type
= stucciTypes
[tempInt
]
123 tempInt
= randint(0, 6)
124 texture
.noise_basis
= noises
[tempInt
]
125 texture
.noise_scale
= gauss(0.625, 1 / 24)
127 tempInt
= randint(0, 6)
128 texture
.noise_basis
= noises
[tempInt
]
129 texture
.noise_scale
= 0.15
131 tempInt
= randint(0, 6)
132 texture
.noise_basis
= noises
[tempInt
]
133 texture
.noise_scale
= gauss(0.2, 1 / 30)
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:
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
148 texture
.noise_scale
= 0.15
149 tempInt
= randint(0, 6)
150 texture
.distance_metric
= metrics
[tempInt
]
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
158 tempInt
= randint(0, 6)
159 texture
.distance_metric
= metrics
[tempInt
]