1 # SPDX-FileCopyrightText: 2017-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # Another Noise Tool - Mesh Displace
8 # ------------------------------------------------------------
11 from bpy
.props
import (
19 from .ant_functions
import (
25 from .ant_noise
import noise_gen
26 from ant_landscape
import ant_noise
28 # ------------------------------------------------------------
29 # Do vert displacement
32 class AntMeshDisplace(bpy
.types
.Operator
):
33 bl_idname
= "mesh.ant_displace"
34 bl_label
= "Another Noise Tool - Displace"
35 bl_description
= "Displace mesh vertices"
36 bl_options
= {'REGISTER', 'UNDO', 'PRESET'}
38 ant_terrain_name
: StringProperty(
42 land_material
: StringProperty(
45 description
="Terrain material"
47 water_material
: StringProperty(
50 description
="Water plane material"
52 texture_block
: StringProperty(
56 at_cursor
: BoolProperty(
59 description
="Place at cursor location",
61 smooth_mesh
: BoolProperty(
64 description
="Shade smooth"
66 tri_face
: BoolProperty(
69 description
="Triangulate faces"
71 sphere_mesh
: BoolProperty(
74 description
="Generate uv sphere - remove doubles when ready"
76 subdivision_x
: IntProperty(
77 name
="Subdivisions X",
81 description
="Mesh X subdivisions"
83 subdivision_y
: IntProperty(
85 name
="Subdivisions Y",
88 description
="Mesh Y subdivisions"
90 mesh_size
: FloatProperty(
95 description
="Mesh size"
97 mesh_size_x
: FloatProperty(
101 description
="Mesh x size"
103 mesh_size_y
: FloatProperty(
107 description
="Mesh y size"
110 random_seed
: IntProperty(
114 description
="Randomize noise origin"
116 noise_offset_x
: FloatProperty(
119 description
="Noise X Offset"
121 noise_offset_y
: FloatProperty(
124 description
="Noise Y Offset"
126 noise_offset_z
: FloatProperty(
129 description
="Noise Z Offset"
131 noise_size_x
: FloatProperty(
136 description
="Noise x size"
138 noise_size_y
: FloatProperty(
143 description
="Noise y size"
145 noise_size_z
: FloatProperty(
150 description
="Noise Z size"
152 noise_size
: FloatProperty(
157 description
="Noise size"
159 noise_type
: EnumProperty(
161 default
='hetero_terrain',
162 description
="Noise type",
164 ('multi_fractal', "Multi Fractal", "Blender: Multi Fractal algorithm", 0),
165 ('ridged_multi_fractal', "Ridged MFractal", "Blender: Ridged Multi Fractal", 1),
166 ('hybrid_multi_fractal', "Hybrid MFractal", "Blender: Hybrid Multi Fractal", 2),
167 ('hetero_terrain', "Hetero Terrain", "Blender: Hetero Terrain", 3),
168 ('fractal', "fBm Fractal", "Blender: fBm - Fractional Browninian motion", 4),
169 ('turbulence_vector', "Turbulence", "Blender: Turbulence Vector", 5),
170 ('variable_lacunarity', "Distorted Noise", "Blender: Distorted Noise", 6),
171 ('marble_noise', "Marble", "A.N.T.: Marble Noise", 7),
172 ('shattered_hterrain', "Shattered hTerrain", "A.N.T.: Shattered hTerrain", 8),
173 ('strata_hterrain', "Strata hTerrain", "A.N.T: Strata hTerrain", 9),
174 ('ant_turbulence', "Another Noise", "A.N.T: Turbulence variation", 10),
175 ('vl_noise_turbulence', "vlNoise turbulence", "A.N.T: Real vlNoise turbulence", 11),
176 ('vl_hTerrain', "vlNoise hTerrain", "A.N.T: vlNoise hTerrain", 12),
177 ('distorted_heteroTerrain', "Distorted hTerrain", "A.N.T distorted hTerrain", 13),
178 ('double_multiFractal', "Double MultiFractal", "A.N.T: double multiFractal", 14),
179 ('rocks_noise', "Noise Rocks", "A.N.T: turbulence variation", 15),
180 ('slick_rock', "Slick Rock", "A.N.T: slick rock", 16),
181 ('planet_noise', "Planet Noise", "Planet Noise by: Farsthary", 17),
182 ('blender_texture', "Blender Texture - Texture Nodes", "Blender texture data block", 18)]
184 basis_type
: EnumProperty(
186 default
=ant_noise
.noise_basis_default
,
187 description
="Noise basis algorithms",
188 items
=ant_noise
.noise_basis
190 vl_basis_type
: EnumProperty(
191 name
="vlNoise Basis",
192 default
=ant_noise
.noise_basis_default
,
193 description
="VLNoise basis algorithms",
194 items
=ant_noise
.noise_basis
196 distortion
: FloatProperty(
201 description
="Distortion amount"
203 hard_noise
: EnumProperty(
206 description
="Soft Noise, Hard noise",
208 ("0", "Soft", "Soft Noise", 0),
209 ("1", "Hard", "Hard noise", 1)]
211 noise_depth
: IntProperty(
216 description
="Noise Depth - number of frequencies in the fBm"
218 amplitude
: FloatProperty(
223 description
="Amplitude"
225 frequency
: FloatProperty(
230 description
="Frequency"
232 dimension
: FloatProperty(
237 description
="H - fractal dimension of the roughest areas"
239 lacunarity
: FloatProperty(
244 description
="Lacunarity - gap between successive frequencies"
246 offset
: FloatProperty(
251 description
="Offset - raises the terrain from sea level"
258 description
="Gain - scale factor"
260 marble_bias
: EnumProperty(
263 description
="Marble bias",
265 ("0", "Sin", "Sin", 0),
266 ("1", "Cos", "Cos", 1),
267 ("2", "Tri", "Tri", 2),
268 ("3", "Saw", "Saw", 3)]
270 marble_sharp
: EnumProperty(
273 description
="Marble sharpness",
275 ("0", "Soft", "Soft", 0),
276 ("1", "Sharp", "Sharp", 1),
277 ("2", "Sharper", "Sharper", 2),
278 ("3", "Soft inv.", "Soft", 3),
279 ("4", "Sharp inv.", "Sharp", 4),
280 ("5", "Sharper inv.", "Sharper", 5)]
282 marble_shape
: EnumProperty(
285 description
="Marble shape",
287 ("0", "Default", "Default", 0),
288 ("1", "Ring", "Ring", 1),
289 ("2", "Swirl", "Swirl", 2),
290 ("3", "Bump", "Bump", 3),
291 ("4", "Wave", "Wave", 4),
296 height
: FloatProperty(
301 description
="Noise intensity scale"
303 height_invert
: BoolProperty(
306 description
="Height invert",
308 height_offset
: FloatProperty(
313 description
="Height offset"
316 fx_mixfactor
: FloatProperty(
321 description
="Effect mix factor: -1.0 = Noise, +1.0 = Effect"
323 fx_mix_mode
: EnumProperty(
326 description
="Effect mix mode",
328 ("0", "Mix", "Mix", 0),
329 ("1", "Add", "Add", 1),
330 ("2", "Sub", "Subtract", 2),
331 ("3", "Mul", "Multiply", 3),
332 ("4", "Abs", "Absolute", 4),
333 ("5", "Scr", "Screen", 5),
334 ("6", "Mod", "Modulo", 6),
335 ("7", "Min", "Minimum", 7),
336 ("8", "Max", "Maximum", 8)
339 fx_type
: EnumProperty(
342 description
="Effect type",
344 ("0", "None", "No effect", 0),
345 ("1", "Gradient", "Gradient", 1),
346 ("2", "Waves", "Waves - Bumps", 2),
347 ("3", "Zigzag", "Zigzag", 3),
348 ("4", "Wavy", "Wavy", 4),
349 ("5", "Bump", "Bump", 5),
350 ("6", "Dots", "Dots", 6),
351 ("7", "Rings", "Rings", 7),
352 ("8", "Spiral", "Spiral", 8),
353 ("9", "Square", "Square", 9),
354 ("10", "Blocks", "Blocks", 10),
355 ("11", "Grid", "Grid", 11),
356 ("12", "Tech", "Tech", 12),
357 ("13", "Crackle", "Crackle", 13),
358 ("14", "Cracks", "Cracks", 14),
359 ("15", "Rock", "Rock noise", 15),
360 ("16", "Lunar", "Craters", 16),
361 ("17", "Cosine", "Cosine", 17),
362 ("18", "Spikey", "Spikey", 18),
363 ("19", "Stone", "Stone", 19),
364 ("20", "Flat Turb", "Flat turbulence", 20),
365 ("21", "Flat Voronoi", "Flat voronoi", 21)
368 fx_bias
: EnumProperty(
371 description
="Effect bias type",
373 ("0", "Sin", "Sin", 0),
374 ("1", "Cos", "Cos", 1),
375 ("2", "Tri", "Tri", 2),
376 ("3", "Saw", "Saw", 3),
377 ("4", "None", "None", 4)
380 fx_turb
: FloatProperty(
385 description
="Effect turbulence distortion"
387 fx_depth
: IntProperty(
392 description
="Effect depth - number of frequencies"
394 fx_amplitude
: FloatProperty(
399 description
="Amplitude"
401 fx_frequency
: FloatProperty(
406 description
="Frequency"
408 fx_size
: FloatProperty(
413 description
="Effect size"
415 fx_loc_x
: FloatProperty(
418 description
="Effect x offset"
420 fx_loc_y
: FloatProperty(
423 description
="Effect y offset"
425 fx_height
: FloatProperty(
430 description
="Effect intensity scale"
432 fx_invert
: BoolProperty(
435 description
="Effect invert"
437 fx_offset
: FloatProperty(
442 description
="Effect height offset"
445 edge_falloff
: EnumProperty(
448 description
="Flatten edges",
450 ("0", "None", "None", 0),
451 ("1", "Y", "Y Falloff", 1),
452 ("2", "X", "X Falloff", 2),
453 ("3", "X Y", "X Y Falloff", 3)]
455 falloff_x
: FloatProperty(
460 description
="Falloff x scale"
462 falloff_y
: FloatProperty(
467 description
="Falloff y scale"
469 edge_level
: FloatProperty(
474 description
="Edge level, sealevel offset"
476 maximum
: FloatProperty(
481 description
="Maximum, flattens terrain at plateau level"
483 minimum
: FloatProperty(
488 description
="Minimum, flattens terrain at seabed level"
490 vert_group
: StringProperty(
494 strata
: FloatProperty(
499 description
="Strata layers / terraces"
501 strata_type
: EnumProperty(
504 description
="Strata types",
506 ("0", "None", "No strata", 0),
507 ("1", "Smooth", "Smooth transitions", 1),
508 ("2", "Sharp Sub", "Sharp subtract transitions", 2),
509 ("3", "Sharp Add", "Sharp add transitions", 3),
510 ("4", "Quantize", "Quantize", 4),
511 ("5", "Quantize Mix", "Quantize mixed", 5)]
513 water_plane
: BoolProperty(
516 description
="Add water plane"
518 water_level
: FloatProperty(
523 description
="Water level"
525 remove_double
: BoolProperty(
526 name
="Remove Doubles",
528 description
="Remove doubles"
530 direction
: EnumProperty(
533 description
="Displacement direction",
535 ("NORMAL", "Normal", "Displace along vertex normal direction", 0),
536 ("Z", "Z", "Displace in the Z direction", 1),
537 ("Y", "Y", "Displace in the Y direction", 2),
538 ("X", "X", "Displace in the X direction", 3)]
540 show_main_settings
: BoolProperty(
541 name
="Main Settings",
543 description
="Show settings"
545 show_noise_settings
: BoolProperty(
546 name
="Noise Settings",
548 description
="Show noise settings"
550 show_displace_settings
: BoolProperty(
551 name
="Displace Settings",
553 description
="Show terrain settings"
555 refresh
: BoolProperty(
558 description
="Refresh"
560 auto_refresh
: BoolProperty(
563 description
="Automatic refresh"
566 def draw(self
, context
):
567 draw_ant_refresh(self
, context
)
568 draw_ant_noise(self
, context
, generate
=False)
569 draw_ant_displace(self
, context
, generate
=False)
572 def poll(cls
, context
):
574 return (ob
and ob
.type == 'MESH')
576 def invoke(self
, context
, event
):
578 return self
.execute(context
)
580 def execute(self
, context
):
582 return {'PASS_THROUGH'}
588 self
.ant_terrain_name
,
658 if self
.vert_group
!= "" and self
.vert_group
in ob
.vertex_groups
:
659 vertex_group
= ob
.vertex_groups
[self
.vert_group
]
662 gi
= vertex_group
.index
663 if self
.direction
== "X":
664 for v
in mesh
.vertices
:
667 v
.co
[0] += vertex_group
.weight(v
.index
) * noise_gen(v
.co
, props
)
669 if self
.direction
== "Y":
670 for v
in mesh
.vertices
:
673 v
.co
[1] += vertex_group
.weight(v
.index
) * noise_gen(v
.co
, props
)
675 if self
.direction
== "Z":
676 for v
in mesh
.vertices
:
679 v
.co
[2] += vertex_group
.weight(v
.index
) * noise_gen(v
.co
, props
)
682 for v
in mesh
.vertices
:
685 v
.co
+= vertex_group
.weight(v
.index
) * v
.normal
* noise_gen(v
.co
, props
)
688 if self
.direction
== "X":
689 for v
in mesh
.vertices
:
690 v
.co
[0] += noise_gen(v
.co
, props
)
692 elif self
.direction
== "Y":
693 for v
in mesh
.vertices
:
694 v
.co
[1] += noise_gen(v
.co
, props
)
696 elif self
.direction
== "Z":
697 for v
in mesh
.vertices
:
698 v
.co
[2] += noise_gen(v
.co
, props
)
701 for v
in mesh
.vertices
:
702 v
.co
+= v
.normal
* noise_gen(v
.co
, props
)
706 if self
.auto_refresh
is False: