Import_3ds: Moved keyframe transform
[blender-addons.git] / ant_landscape / ant_noise.py
blobfee987e88e18f28fcfb0e46349749b5d8e23e255
1 # SPDX-FileCopyrightText: 2017-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # Another Noise Tool - Noise and Effects
6 # Jimmy Hazevoet
8 import bpy
9 from mathutils.noise import (
10 seed_set,
11 noise,
12 turbulence,
13 turbulence_vector,
14 fractal,
15 hybrid_multi_fractal,
16 multi_fractal,
17 ridged_multi_fractal,
18 hetero_terrain,
19 random_unit_vector,
20 variable_lacunarity,
21 voronoi,
23 from math import (
24 floor, sqrt,
25 sin, cos, pi,
28 noise_basis_default = "BLENDER"
29 noise_basis = [
30 ("BLENDER", "Blender", "Blender default noise", 0),
31 ("PERLIN_ORIGINAL", "Perlin", "Perlin noise", 1),
32 ("PERLIN_NEW", "New Perlin", "New Perlin noise", 2),
33 ("VORONOI_F1", "Voronoi F1", "Voronoi F1", 3),
34 ("VORONOI_F2", "Voronoi F2", "Voronoi F2", 4),
35 ("VORONOI_F3", "Voronoi F3", "Voronoi F3", 5),
36 ("VORONOI_F4", "Voronoi F4", "Voronoi F4", 6),
37 ("VORONOI_F2F1", "Voronoi F2-F1", "Voronoi F2-F1", 7),
38 ("VORONOI_CRACKLE", "Voronoi Crackle", "Voronoi Crackle", 8),
39 ("CELLNOISE", "Cell Noise", "Cell noise", 9)
42 # ------------------------------------------------------------
43 # Height scale:
46 def Height_Scale(input, iscale, offset, invert):
47 if invert != 0:
48 return (1.0 - input) * iscale + offset
49 else:
50 return input * iscale + offset
53 # Functions for marble_noise and effects:
55 def Dist(x, y):
56 return sqrt((x * x) + (y * y))
59 def sin_bias(a):
60 return 0.5 + 0.5 * sin(a)
63 def cos_bias(a):
64 return 0.5 + 0.5 * cos(a)
67 def tri_bias(a):
68 b = 2 * pi
69 a = 1 - 2 * abs(floor((a * (1 / b)) + 0.5) - (a * (1 / b)))
70 return a
73 def saw_bias(a):
74 b = 2 * pi
75 n = int(a / b)
76 a -= n * b
77 if a < 0:
78 a += b
79 return a / b
82 def soft(a):
83 return a
86 def sharp(a):
87 return a**0.5
90 def sharper(a):
91 return sharp(sharp(a))
94 def no_bias(a):
95 return a
98 def shapes(x, y, z, shape=0):
99 p = pi
100 if shape == 1:
101 # ring
102 x = x * p
103 y = y * p
104 s = cos(x**2 + y**2) / (x**2 + y**2 + 0.5)
105 elif shape == 2:
106 # swirl
107 x = x * p
108 y = y * p
109 s = ((x * sin(x * x + y * y) + y * cos(x * x + y * y)) / (x**2 + y**2 + 0.5))
110 elif shape == 3:
111 # bumps
112 x = x * p
113 y = y * p
114 z = z * p
115 s = 1 - ((cos(x * p) + cos(y * p) + cos(z * p)) - 0.5)
116 elif shape == 4:
117 # wave
118 x = x * p * 2
119 y = y * p * 2
120 s = sin(x + sin(y))
121 elif shape == 5:
122 # z grad.
123 s = (z * p)
124 elif shape == 6:
125 # y grad.
126 s = (y * p)
127 elif shape == 7:
128 # x grad.
129 s = (x * p)
130 else:
131 # marble default
132 s = ((x + y + z) * 5)
133 return s
136 # marble_noise
137 def marble_noise(x, y, z, origin, size, shape, bias, sharpnes, turb, depth, hard, basis, amp, freq):
139 s = shapes(x, y, z, shape)
140 x += origin[0]
141 y += origin[1]
142 z += origin[2]
143 value = s + turb * turbulence_vector((x, y, z), depth, hard, noise_basis=basis)[1]
145 if bias == 1:
146 value = cos_bias(value)
147 elif bias == 2:
148 value = tri_bias(value)
149 elif bias == 3:
150 value = saw_bias(value)
151 else:
152 value = sin_bias(value)
154 if sharpnes == 1:
155 value = 1.0 - sharp(value)
156 elif sharpnes == 2:
157 value = 1.0 - sharper(value)
158 elif sharpnes == 3:
159 value = soft(value)
160 elif sharpnes == 4:
161 value = sharp(value)
162 elif sharpnes == 5:
163 value = sharper(value)
164 else:
165 value = 1.0 - soft(value)
167 return value
170 # vl_noise_turbulence:
171 def vlnTurbMode(coords, distort, basis, vlbasis, hardnoise):
172 # hard noise
173 if hardnoise:
174 return (abs(-variable_lacunarity(coords, distort, noise_type1=basis, noise_type2=vlbasis)))
175 # soft noise
176 else:
177 return variable_lacunarity(coords, distort, noise_type1=basis, noise_type2=vlbasis)
180 def vl_noise_turbulence(coords, distort, depth, basis, vlbasis, hardnoise, amp, freq):
181 x, y, z = coords
182 value = vlnTurbMode(coords, distort, basis, vlbasis, hardnoise)
183 i = 0
184 for i in range(depth):
185 i += 1
186 value += vlnTurbMode((x * (freq * i), y * (freq * i), z * (freq * i)),
187 distort, basis, vlbasis, hardnoise) * (amp * 0.5 / i)
188 return value
191 # duo_multiFractal:
192 def double_multiFractal(coords, H, lacunarity, octaves, offset, gain, basis, vlbasis):
193 x, y, z = coords
194 n1 = multi_fractal((x * 1.5 + 1, y * 1.5 + 1, z * 1.5 + 1), 1.0, 1.0, 1.0, noise_basis=basis) * (offset * 0.5)
195 n2 = multi_fractal((x - 1, y - 1, z - 1), H, lacunarity, octaves, noise_basis=vlbasis) * (gain * 0.5)
196 return (n1 * n1 + n2 * n2) * 0.5
199 # distorted_heteroTerrain:
200 def distorted_heteroTerrain(coords, H, lacunarity, octaves, offset, distort, basis, vlbasis):
201 x, y, z = coords
202 h1 = (hetero_terrain((x, y, z), 1.0, 2.0, 1.0, 1.0, noise_basis=basis) * 0.5)
203 d = h1 * distort
204 h2 = (hetero_terrain((x + d, y + d, z + d), H, lacunarity, octaves, offset, noise_basis=vlbasis) * 0.25)
205 return (h1 * h1 + h2 * h2) * 0.5
208 # SlickRock:
209 def slick_rock(coords, H, lacunarity, octaves, offset, gain, distort, basis, vlbasis):
210 x, y, z = coords
211 n = multi_fractal((x, y, z), 1.0, 2.0, 2.0, noise_basis=basis) * distort * 0.25
212 r = ridged_multi_fractal((x + n, y + n, z + n), H, lacunarity, octaves, offset + 0.1, gain * 2, noise_basis=vlbasis)
213 return (n + (n * r)) * 0.5
216 # vlhTerrain
217 def vl_hTerrain(coords, H, lacunarity, octaves, offset, basis, vlbasis, distort):
218 x, y, z = coords
219 ht = hetero_terrain((x, y, z), H, lacunarity, octaves, offset, noise_basis=basis) * 0.25
220 vl = ht * variable_lacunarity((x, y, z), distort, noise_type1=basis, noise_type2=vlbasis) * 0.5 + 0.5
221 return vl * ht
224 # another turbulence
225 def ant_turbulence(coords, depth, hardnoise, nbasis, amp, freq, distortion):
226 x, y, z = coords
227 t = turbulence_vector((x / 2, y / 2, z / 2), depth, 0, noise_basis=nbasis,
228 amplitude_scale=amp, frequency_scale=freq) * 0.5 * distortion
229 return turbulence((t[0], t[1], t[2]), 2, hardnoise, noise_basis="VORONOI_F1") * 0.5 + 0.5
232 # rocks noise
233 def rocks_noise(coords, depth, hardnoise, nbasis, distortion):
234 x, y, z = coords
235 p = turbulence((x, y, z), 4, 0, noise_basis='BLENDER') * 0.125 * distortion
236 xx, yy, zz = x, y, z
237 a = turbulence((xx + p, yy + p, zz), 2, 0, noise_basis='VORONOI_F2F1')
238 pa = a * 0.1875 * distortion
239 b = turbulence((x, y, z + pa), depth, hardnoise, noise_basis=nbasis)
240 return ((a + 0.5 * (b - a)) * 0.5 + 0.5)
243 # shattered_hterrain:
244 def shattered_hterrain(coords, H, lacunarity, octaves, offset, distort, basis):
245 x, y, z = coords
246 d = (turbulence_vector(coords, 6, 0)[0] * 0.5 + 0.5) * distort * 0.5
247 t1 = (turbulence_vector((x + d, y + d, z + d), 0, 0, noise_basis='VORONOI_F2F1')[0] + 0.5)
248 t2 = (hetero_terrain((x * 2, y * 2, z * 2), H, lacunarity, octaves, offset, noise_basis=basis) * 0.5)
249 return ((t1 * t2) + t2 * 0.5) * 0.5
252 # strata_hterrain
253 def strata_hterrain(coords, H, lacunarity, octaves, offset, distort, basis):
254 x, y, z = coords
255 value = hetero_terrain((x, y, z), H, lacunarity, octaves, offset, noise_basis=basis) * 0.5
256 steps = (sin(value * (distort * 5) * pi) * (0.1 / (distort * 5) * pi))
257 return (value * (1.0 - 0.5) + steps * 0.5)
260 # Planet Noise by: Farsthary
261 # https://farsthary.com/2010/11/24/new-planet-procedural-texture/
262 def planet_noise(coords, oct=6, hard=0, noisebasis='PERLIN_ORIGINAL', nabla=0.001):
263 x, y, z = coords
264 d = 0.001
265 offset = nabla * 1000
266 x = turbulence((x, y, z), oct, hard, noise_basis=noisebasis)
267 y = turbulence((x + offset, y, z), oct, hard, noise_basis=noisebasis)
268 z = turbulence((x, y + offset, z), oct, hard, noise_basis=noisebasis)
269 xdy = x - turbulence((x, y + d, z), oct, hard, noise_basis=noisebasis)
270 xdz = x - turbulence((x, y, z + d), oct, hard, noise_basis=noisebasis)
271 ydx = y - turbulence((x + d, y, z), oct, hard, noise_basis=noisebasis)
272 ydz = y - turbulence((x, y, z + d), oct, hard, noise_basis=noisebasis)
273 zdx = z - turbulence((x + d, y, z), oct, hard, noise_basis=noisebasis)
274 zdy = z - turbulence((x, y + d, z), oct, hard, noise_basis=noisebasis)
275 return (zdy - ydz), (zdx - xdz), (ydx - xdy)
278 # ----------------------------------------------------------------------
279 # v.1.04 Effect functions:
281 def maximum(a, b):
282 if (a > b):
283 b = a
284 return b
287 def minimum(a, b):
288 if (a < b):
289 b = a
290 return b
293 def Mix_Modes(a, b, mixfactor, mode):
294 mode = int(mode)
295 a = a * (1.0 - mixfactor)
296 b = b * (1.0 + mixfactor)
297 # 1 mix
298 if mode == 0:
299 return (a * (1.0 - 0.5) + b * 0.5)
300 # 2 add
301 elif mode == 1:
302 return (a + b)
303 # 3 sub.
304 elif mode == 2:
305 return (a - b)
306 # 4 mult.
307 elif mode == 3:
308 return (a * b)
309 # 5 abs diff.
310 elif mode == 4:
311 return (abs(a - b))
312 # 6 screen
313 elif mode == 5:
314 return 1.0 - ((1.0 - a) * (1.0 - b) / 1.0)
315 # 7 addmodulo
316 elif mode == 6:
317 return (a + b) % 1.0
318 # 8 min.
319 elif mode == 7:
320 return minimum(a, b)
321 # 9 max.
322 elif mode == 8:
323 return maximum(a, b)
324 else:
325 return 0
328 Bias_Types = [sin_bias, cos_bias, tri_bias, saw_bias, no_bias]
329 Sharp_Types = [soft, sharp, sharper]
332 # Transpose effect coords:
333 def Trans_Effect(coords, size, loc):
334 x, y, z = coords
335 x = (x * 2.0 / size + loc[0])
336 y = (y * 2.0 / size + loc[1])
337 return x, y, z
340 # Effect_Basis_Function:
341 def Effect_Basis_Function(coords, type, bias):
342 bias = int(bias)
343 type = int(type)
344 x, y, z = coords
345 iscale = 1.0
346 offset = 0.0
348 # gradient:
349 if type == 1:
350 effect = offset + iscale * (Bias_Types[bias](x + y))
351 # waves / bumps:
352 elif type == 2:
353 effect = offset + iscale * 0.5 * (Bias_Types[bias](x * pi) + Bias_Types[bias](y * pi))
354 # zigzag:
355 elif type == 3:
356 effect = offset + iscale * Bias_Types[bias](offset + iscale * sin(x * pi + sin(y * pi)))
357 # wavy:
358 elif type == 4:
359 effect = offset + iscale * (Bias_Types[bias](cos(x) + sin(y) + cos(x * 2 + y * 2) - sin(-x * 4 + y * 4)))
360 # sine bump:
361 elif type == 5:
362 effect = offset + iscale * 1 - Bias_Types[bias]((sin(x * pi) + sin(y * pi)))
363 # dots:
364 elif type == 6:
365 effect = offset + iscale * (Bias_Types[bias](x * pi * 2) * Bias_Types[bias](y * pi * 2)) - 0.5
366 # rings:
367 elif type == 7:
368 effect = offset + iscale * (Bias_Types[bias](1.0 - (x * x + y * y)))
369 # spiral:
370 elif type == 8:
371 effect = offset + iscale * \
372 Bias_Types[bias]((x * sin(x * x + y * y) + y * cos(x * x + y * y)) / (x**2 + y**2 + 0.5)) * 2
373 # square / piramide:
374 elif type == 9:
375 effect = offset + iscale * Bias_Types[bias](1.0 - sqrt((x * x)**10 + (y * y)**10)**0.1)
376 # blocks:
377 elif type == 10:
378 effect = (0.5 - max(Bias_Types[bias](x * pi), Bias_Types[bias](y * pi)))
379 if effect > 0.0:
380 effect = 1.0
381 effect = offset + iscale * effect
382 # grid:
383 elif type == 11:
384 effect = (0.025 - min(Bias_Types[bias](x * pi), Bias_Types[bias](y * pi)))
385 if effect > 0.0:
386 effect = 1.0
387 effect = offset + iscale * effect
388 # tech:
389 elif type == 12:
390 a = max(Bias_Types[bias](x * pi), Bias_Types[bias](y * pi))
391 b = max(Bias_Types[bias](x * pi * 2 + 2), Bias_Types[bias](y * pi * 2 + 2))
392 effect = min(Bias_Types[bias](a), Bias_Types[bias](b)) * 3.0 - 2.0
393 if effect > 0.5:
394 effect = 1.0
395 effect = offset + iscale * effect
396 # crackle:
397 elif type == 13:
398 t = turbulence((x, y, 0), 6, 0, noise_basis="BLENDER") * 0.25
399 effect = variable_lacunarity((x, y, t), 0.25, noise_type2='VORONOI_CRACKLE')
400 if effect > 0.5:
401 effect = 0.5
402 effect = offset + iscale * effect
403 # sparse cracks noise:
404 elif type == 14:
405 effect = 2.5 * abs(noise((x, y, 0), noise_basis="PERLIN_ORIGINAL")) - 0.1
406 if effect > 0.25:
407 effect = 0.25
408 effect = offset + iscale * (effect * 2.5)
409 # shattered rock noise:
410 elif type == 15:
411 effect = 0.5 + noise((x, y, 0), noise_basis="VORONOI_F2F1")
412 if effect > 0.75:
413 effect = 0.75
414 effect = offset + iscale * effect
415 # lunar noise:
416 elif type == 16:
417 effect = 0.25 + 1.5 * voronoi((x, y, 0), distance_metric='DISTANCE_SQUARED')[0][0]
418 if effect > 0.5:
419 effect = 0.5
420 effect = offset + iscale * effect * 2
421 # cosine noise:
422 elif type == 17:
423 effect = cos(5 * noise((x, y, 0), noise_basis="BLENDER"))
424 effect = offset + iscale * (effect * 0.5)
425 # spikey noise:
426 elif type == 18:
427 n = 0.5 + 0.5 * turbulence((x * 5, y * 5, 0), 8, 0, noise_basis="BLENDER")
428 effect = ((n * n)**5)
429 effect = offset + iscale * effect
430 # stone noise:
431 elif type == 19:
432 effect = offset + iscale * (noise((x * 2, y * 2, 0), noise_basis="BLENDER") * 1.5 - 0.75)
433 # Flat Turb:
434 elif type == 20:
435 t = turbulence((x, y, 0), 6, 0, noise_basis="BLENDER")
436 effect = t * 2.0
437 if effect > 0.25:
438 effect = 0.25
439 effect = offset + iscale * effect
440 # Flat Voronoi:
441 elif type == 21:
442 t = 1 - voronoi((x, y, 0), distance_metric='DISTANCE_SQUARED')[0][0]
443 effect = t * 2 - 1.5
444 if effect > 0.25:
445 effect = 0.25
446 effect = offset + iscale * effect
447 else:
448 effect = 0.0
450 if effect < 0.0:
451 effect = 0.0
453 return effect
456 # fractalize Effect_Basis_Function: ------------------------------
457 def Effect_Function(coords, type, bias, turb, depth, frequency, amplitude):
459 x, y, z = coords
460 # turbulence:
461 if turb > 0.0:
462 t = turb * (0.5 + 0.5 * turbulence(coords, 6, 0, noise_basis="BLENDER"))
463 x = x + t
464 y = y + t
465 z = z + t
467 result = Effect_Basis_Function((x, y, z), type, bias) * amplitude
468 # fractalize:
469 if depth != 0:
470 i = 0
471 for i in range(depth):
472 i += 1
473 x *= frequency
474 y *= frequency
475 result += Effect_Basis_Function((x, y, z), type, bias) * amplitude / i
477 return result
480 # ------------------------------------------------------------
481 # landscape_gen
482 def noise_gen(coords, props):
484 terrain_name = props[0]
485 cursor = props[1]
486 smooth = props[2]
487 triface = props[3]
488 sphere = props[4]
489 land_mat = props[5]
490 water_mat = props[6]
491 texture_name = props[7]
492 subd_x = props[8]
493 subd_y = props[9]
494 meshsize_x = props[10]
495 meshsize_y = props[11]
496 meshsize = props[12]
497 rseed = props[13]
498 x_offset = props[14]
499 y_offset = props[15]
500 z_offset = props[16]
501 size_x = props[17]
502 size_y = props[18]
503 size_z = props[19]
504 nsize = props[20]
505 ntype = props[21]
506 nbasis = props[22]
507 vlbasis = props[23]
508 distortion = props[24]
509 hardnoise = int(props[25])
510 depth = props[26]
511 amp = props[27]
512 freq = props[28]
513 dimension = props[29]
514 lacunarity = props[30]
515 offset = props[31]
516 gain = props[32]
517 marblebias = int(props[33])
518 marblesharpnes = int(props[34])
519 marbleshape = int(props[35])
520 height = props[36]
521 height_invert = props[37]
522 height_offset = props[38]
523 maximum = props[39]
524 minimum = props[40]
525 falloff = int(props[41])
526 edge_level = props[42]
527 falloffsize_x = props[43]
528 falloffsize_y = props[44]
529 stratatype = props[45]
530 strata = props[46]
531 addwater = props[47]
532 waterlevel = props[48]
533 vert_group = props[49]
534 remove_double = props[50]
535 fx_mixfactor = props[51]
536 fx_mix_mode = props[52]
537 fx_type = props[53]
538 fx_bias = props[54]
539 fx_turb = props[55]
540 fx_depth = props[56]
541 fx_frequency = props[57]
542 fx_amplitude = props[58]
543 fx_size = props[59]
544 fx_loc_x = props[60]
545 fx_loc_y = props[61]
546 fx_height = props[62]
547 fx_offset = props[63]
548 fx_invert = props[64]
550 x, y, z = coords
552 # Origin
553 if rseed == 0:
554 origin = x_offset, y_offset, z_offset
555 origin_x = x_offset
556 origin_y = y_offset
557 origin_z = z_offset
558 o_range = 1.0
559 else:
560 # Randomise origin
561 o_range = 100
562 seed_set(rseed)
563 origin = random_unit_vector()
564 ox = (origin[0] * o_range)
565 oy = (origin[1] * o_range)
566 oz = 0
567 origin_x = (ox - (ox * 0.5)) + x_offset
568 origin_y = (oy - (oy * 0.5)) + y_offset
569 origin_z = oz + z_offset
571 ncoords = (x / (nsize * size_x) + origin_x, y / (nsize * size_y) + origin_y, z / (nsize * size_z) + origin_z)
573 # Noise type's
574 if ntype in [0, 'multi_fractal']:
575 value = multi_fractal(ncoords, dimension, lacunarity, depth, noise_basis=nbasis) * 0.5
577 elif ntype in [1, 'ridged_multi_fractal']:
578 value = ridged_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, noise_basis=nbasis) * 0.5
580 elif ntype in [2, 'hybrid_multi_fractal']:
581 value = hybrid_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, noise_basis=nbasis) * 0.5
583 elif ntype in [3, 'hetero_terrain']:
584 value = hetero_terrain(ncoords, dimension, lacunarity, depth, offset, noise_basis=nbasis) * 0.25
586 elif ntype in [4, 'fractal']:
587 value = fractal(ncoords, dimension, lacunarity, depth, noise_basis=nbasis)
589 elif ntype in [5, 'turbulence_vector']:
590 value = turbulence_vector(ncoords, depth, hardnoise, noise_basis=nbasis,
591 amplitude_scale=amp, frequency_scale=freq)[0]
593 elif ntype in [6, 'variable_lacunarity']:
594 value = variable_lacunarity(ncoords, distortion, noise_type1=nbasis, noise_type2=vlbasis)
596 elif ntype in [7, 'marble_noise']:
597 value = marble_noise(
598 (ncoords[0] - origin_x + x_offset),
599 (ncoords[1] - origin_y + y_offset),
600 (ncoords[2] - origin_z + z_offset),
601 (origin[0] + x_offset, origin[1] + y_offset, origin[2] + z_offset), nsize,
602 marbleshape, marblebias, marblesharpnes,
603 distortion, depth, hardnoise, nbasis, amp, freq
605 elif ntype in [8, 'shattered_hterrain']:
606 value = shattered_hterrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis)
608 elif ntype in [9, 'strata_hterrain']:
609 value = strata_hterrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis)
611 elif ntype in [10, 'ant_turbulence']:
612 value = ant_turbulence(ncoords, depth, hardnoise, nbasis, amp, freq, distortion)
614 elif ntype in [11, 'vl_noise_turbulence']:
615 value = vl_noise_turbulence(ncoords, distortion, depth, nbasis, vlbasis, hardnoise, amp, freq)
617 elif ntype in [12, 'vl_hTerrain']:
618 value = vl_hTerrain(ncoords, dimension, lacunarity, depth, offset, nbasis, vlbasis, distortion)
620 elif ntype in [13, 'distorted_heteroTerrain']:
621 value = distorted_heteroTerrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis, vlbasis)
623 elif ntype in [14, 'double_multiFractal']:
624 value = double_multiFractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis, vlbasis)
626 elif ntype in [15, 'rocks_noise']:
627 value = rocks_noise(ncoords, depth, hardnoise, nbasis, distortion)
629 elif ntype in [16, 'slick_rock']:
630 value = slick_rock(ncoords, dimension, lacunarity, depth, offset, gain, distortion, nbasis, vlbasis)
632 elif ntype in [17, 'planet_noise']:
633 value = planet_noise(ncoords, depth, hardnoise, nbasis)[2] * 0.5 + 0.5
635 elif ntype in [18, 'blender_texture']:
636 if texture_name != "" and texture_name in bpy.data.textures:
637 value = bpy.data.textures[texture_name].evaluate(ncoords)[3]
638 else:
639 value = 0.0
640 else:
641 value = 0.5
643 # Effect mix
644 val = value
645 if fx_type in [0, "0"]:
646 fx_mixfactor = -1.0
647 fxval = val
648 else:
649 fxcoords = Trans_Effect((x, y, z), fx_size, (fx_loc_x, fx_loc_y))
650 effect = Effect_Function(fxcoords, fx_type, fx_bias, fx_turb, fx_depth, fx_frequency, fx_amplitude)
651 effect = Height_Scale(effect, fx_height, fx_offset, fx_invert)
652 fxval = Mix_Modes(val, effect, fx_mixfactor, fx_mix_mode)
653 value = fxval
655 # Adjust height
656 value = Height_Scale(value, height, height_offset, height_invert)
658 # Edge falloff:
659 if not sphere:
660 if falloff:
661 ratio_x, ratio_y = abs(x) * 2 / meshsize_x, abs(y) * 2 / meshsize_y
662 fallofftypes = [
664 sqrt(ratio_y**falloffsize_y),
665 sqrt(ratio_x**falloffsize_x),
666 sqrt(ratio_x**falloffsize_x + ratio_y**falloffsize_y)
668 dist = fallofftypes[falloff]
669 value -= edge_level
670 if dist < 1.0:
671 dist = (dist * dist * (3 - 2 * dist))
672 value = (value - value * dist) + edge_level
673 else:
674 value = edge_level
676 # Strata / terrace / layers
677 if stratatype not in [0, "0"]:
678 if stratatype in [1, "1"]:
679 strata = strata / height
680 strata *= 2
681 steps = (sin(value * strata * pi) * (0.1 / strata * pi))
682 value = (value * 0.5 + steps * 0.5) * 2.0
684 elif stratatype in [2, "2"]:
685 strata = strata / height
686 steps = -abs(sin(value * strata * pi) * (0.1 / strata * pi))
687 value = (value * 0.5 + steps * 0.5) * 2.0
689 elif stratatype in [3, "3"]:
690 strata = strata / height
691 steps = abs(sin(value * strata * pi) * (0.1 / strata * pi))
692 value = (value * 0.5 + steps * 0.5) * 2.0
694 elif stratatype in [4, "4"]:
695 strata = strata / height
696 value = int(value * strata) * 1.0 / strata
698 elif stratatype in [5, "5"]:
699 strata = strata / height
700 steps = (int(value * strata) * 1.0 / strata)
701 value = (value * (1.0 - 0.5) + steps * 0.5)
703 # Clamp height min max
704 if (value < minimum):
705 value = minimum
706 if (value > maximum):
707 value = maximum
709 return value