1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 # Another Noise Tool - Mesh Displace
22 # ------------------------------------------------------------
25 from bpy
.props
import (
33 from .ant_functions
import (
39 from .ant_noise
import noise_gen
41 # ------------------------------------------------------------
42 # Do vert displacement
43 class AntMeshDisplace(bpy
.types
.Operator
):
44 bl_idname
= "mesh.ant_displace"
45 bl_label
= "Another Noise Tool - Displace"
46 bl_description
= "Displace mesh vertices"
47 bl_options
= {'REGISTER', 'UNDO', 'PRESET'}
49 ant_terrain_name
= StringProperty(
53 land_material
= StringProperty(
56 description
="Terrain material"
58 water_material
= StringProperty(
61 description
="Water plane material"
63 texture_block
= StringProperty(
67 at_cursor
= BoolProperty(
70 description
="Place at cursor location",
72 smooth_mesh
= BoolProperty(
75 description
="Shade smooth"
77 tri_face
= BoolProperty(
80 description
="Triangulate faces"
82 sphere_mesh
= BoolProperty(
85 description
="Generate uv sphere - remove doubles when ready"
87 subdivision_x
= IntProperty(
88 name
="Subdivisions X",
92 description
="Mesh X subdivisions"
94 subdivision_y
= IntProperty(
96 name
="Subdivisions Y",
99 description
="Mesh Y subdivisions"
101 mesh_size
= FloatProperty(
106 description
="Mesh size"
108 mesh_size_x
= FloatProperty(
112 description
="Mesh x size"
114 mesh_size_y
= FloatProperty(
118 description
="Mesh y size"
121 random_seed
= IntProperty(
125 description
="Randomize noise origin"
127 noise_offset_x
= FloatProperty(
130 description
="Noise X Offset"
132 noise_offset_y
= FloatProperty(
135 description
="Noise Y Offset"
137 noise_offset_z
= FloatProperty(
140 description
="Noise Z Offset"
142 noise_size_x
= FloatProperty(
147 description
="Noise x size"
149 noise_size_y
= FloatProperty(
154 description
="Noise y size"
156 noise_size_z
= FloatProperty(
161 description
="Noise Z size"
163 noise_size
= FloatProperty(
168 description
="Noise size"
170 noise_type
= EnumProperty(
172 default
='hetero_terrain',
173 description
="Noise type",
175 ('multi_fractal', "Multi Fractal", "Blender: Multi Fractal algorithm", 0),
176 ('ridged_multi_fractal', "Ridged MFractal", "Blender: Ridged Multi Fractal", 1),
177 ('hybrid_multi_fractal', "Hybrid MFractal", "Blender: Hybrid Multi Fractal", 2),
178 ('hetero_terrain', "Hetero Terrain", "Blender: Hetero Terrain", 3),
179 ('fractal', "fBm Fractal", "Blender: fBm - Fractional Browninian motion", 4),
180 ('turbulence_vector', "Turbulence", "Blender: Turbulence Vector", 5),
181 ('variable_lacunarity', "Distorted Noise", "Blender: Distorted Noise", 6),
182 ('marble_noise', "Marble", "A.N.T.: Marble Noise", 7),
183 ('shattered_hterrain', "Shattered hTerrain", "A.N.T.: Shattered hTerrain", 8),
184 ('strata_hterrain', "Strata hTerrain", "A.N.T: Strata hTerrain", 9),
185 ('ant_turbulence', "Another Noise", "A.N.T: Turbulence variation", 10),
186 ('vl_noise_turbulence', "vlNoise turbulence", "A.N.T: Real vlNoise turbulence", 11),
187 ('vl_hTerrain', "vlNoise hTerrain", "A.N.T: vlNoise hTerrain", 12),
188 ('distorted_heteroTerrain', "Distorted hTerrain", "A.N.T distorted hTerrain", 13),
189 ('double_multiFractal', "Double MultiFractal", "A.N.T: double multiFractal", 14),
190 ('rocks_noise', "Noise Rocks", "A.N.T: turbulence variation", 15),
191 ('slick_rock', "Slick Rock", "A.N.T: slick rock", 16),
192 ('planet_noise', "Planet Noise", "Planet Noise by: Farsthary", 17),
193 ('blender_texture', "Blender Texture - Texture Nodes", "Blender texture data block", 18)]
195 basis_type
= EnumProperty(
198 description
="Noise basis algorithms",
200 ("0", "Blender", "Blender default noise", 0),
201 ("1", "Perlin", "Perlin noise", 1),
202 ("2", "New Perlin", "New Perlin noise", 2),
203 ("3", "Voronoi F1", "Voronoi F1", 3),
204 ("4", "Voronoi F2", "Voronoi F2", 4),
205 ("5", "Voronoi F3", "Voronoi F3", 5),
206 ("6", "Voronoi F4", "Voronoi F4", 6),
207 ("7", "Voronoi F2-F1", "Voronoi F2-F1", 7),
208 ("8", "Voronoi Crackle", "Voronoi Crackle", 8),
209 ("9", "Cell Noise", "Cell noise", 9)]
211 vl_basis_type
= EnumProperty(
212 name
="vlNoise Basis",
214 description
="VLNoise basis algorithms",
216 ("0", "Blender", "Blender default noise", 0),
217 ("1", "Perlin", "Perlin noise", 1),
218 ("2", "New Perlin", "New Perlin noise", 2),
219 ("3", "Voronoi F1", "Voronoi F1", 3),
220 ("4", "Voronoi F2", "Voronoi F2", 4),
221 ("5", "Voronoi F3", "Voronoi F3", 5),
222 ("6", "Voronoi F4", "Voronoi F4", 6),
223 ("7", "Voronoi F2-F1", "Voronoi F2-F1", 7),
224 ("8", "Voronoi Crackle", "Voronoi Crackle", 8),
225 ("9", "Cell Noise", "Cell noise", 9)]
227 distortion
= FloatProperty(
232 description
="Distortion amount"
234 hard_noise
= EnumProperty(
237 description
="Soft Noise, Hard noise",
239 ("0", "Soft", "Soft Noise", 0),
240 ("1", "Hard", "Hard noise", 1)]
242 noise_depth
= IntProperty(
247 description
="Noise Depth - number of frequencies in the fBm"
249 amplitude
= FloatProperty(
254 description
="Amplitude"
256 frequency
= FloatProperty(
261 description
="Frequency"
263 dimension
= FloatProperty(
268 description
="H - fractal dimension of the roughest areas"
270 lacunarity
= FloatProperty(
275 description
="Lacunarity - gap between successive frequencies"
277 offset
= FloatProperty(
282 description
="Offset - raises the terrain from sea level"
284 gain
= FloatProperty(
289 description
="Gain - scale factor"
291 marble_bias
= EnumProperty(
294 description
="Marble bias",
296 ("0", "Sin", "Sin", 0),
297 ("1", "Cos", "Cos", 1),
298 ("2", "Tri", "Tri", 2),
299 ("3", "Saw", "Saw", 3)]
301 marble_sharp
= EnumProperty(
304 description
="Marble sharpness",
306 ("0", "Soft", "Soft", 0),
307 ("1", "Sharp", "Sharp", 1),
308 ("2", "Sharper", "Sharper", 2),
309 ("3", "Soft inv.", "Soft", 3),
310 ("4", "Sharp inv.", "Sharp", 4),
311 ("5", "Sharper inv.", "Sharper", 5)]
313 marble_shape
= EnumProperty(
316 description
="Marble shape",
318 ("0", "Default", "Default", 0),
319 ("1", "Ring", "Ring", 1),
320 ("2", "Swirl", "Swirl", 2),
321 ("3", "Bump", "Bump", 3),
322 ("4", "Wave", "Wave", 4),
327 height
= FloatProperty(
332 description
="Noise intensity scale"
334 height_invert
= BoolProperty(
337 description
="Height invert",
339 height_offset
= FloatProperty(
344 description
="Height offset"
347 fx_mixfactor
= FloatProperty(
352 description
="Effect mix factor: -1.0 = Noise, +1.0 = Effect"
354 fx_mix_mode
= EnumProperty(
357 description
="Effect mix mode",
359 ("0", "Mix", "Mix", 0),
360 ("1", "Add", "Add", 1),
361 ("2", "Sub", "Subtract", 2),
362 ("3", "Mul", "Multiply", 3),
363 ("4", "Abs", "Absolute", 4),
364 ("5", "Scr", "Screen", 5),
365 ("6", "Mod", "Modulo", 6),
366 ("7", "Min", "Minimum", 7),
367 ("8", "Max", "Maximum", 8)
370 fx_type
= EnumProperty(
373 description
="Effect type",
375 ("0", "None", "No effect", 0),
376 ("1", "Gradient", "Gradient", 1),
377 ("2", "Waves", "Waves - Bumps", 2),
378 ("3", "Zigzag", "Zigzag", 3),
379 ("4", "Wavy", "Wavy", 4),
380 ("5", "Bump", "Bump", 5),
381 ("6", "Dots", "Dots", 6),
382 ("7", "Rings", "Rings", 7),
383 ("8", "Spiral", "Spiral", 8),
384 ("9", "Square", "Square", 9),
385 ("10", "Blocks", "Blocks", 10),
386 ("11", "Grid", "Grid", 11),
387 ("12", "Tech", "Tech", 12),
388 ("13", "Crackle", "Crackle", 13),
389 ("14", "Cracks", "Cracks", 14),
390 ("15", "Rock", "Rock noise", 15),
391 ("16", "Lunar", "Craters", 16),
392 ("17", "Cosine", "Cosine", 17),
393 ("18", "Spikey", "Spikey", 18),
394 ("19", "Stone", "Stone", 19),
395 ("20", "Flat Turb", "Flat turbulence", 20),
396 ("21", "Flat Voronoi", "Flat voronoi", 21)
399 fx_bias
= EnumProperty(
402 description
="Effect bias type",
404 ("0", "Sin", "Sin", 0),
405 ("1", "Cos", "Cos", 1),
406 ("2", "Tri", "Tri", 2),
407 ("3", "Saw", "Saw", 3),
408 ("4", "None", "None", 4)
411 fx_turb
= FloatProperty(
416 description
="Effect turbulence distortion"
418 fx_depth
= IntProperty(
423 description
="Effect depth - number of frequencies"
425 fx_amplitude
= FloatProperty(
430 description
="Amplitude"
432 fx_frequency
= FloatProperty(
437 description
="Frequency"
439 fx_size
= FloatProperty(
444 description
="Effect size"
446 fx_loc_x
= FloatProperty(
449 description
="Effect x offset"
451 fx_loc_y
= FloatProperty(
454 description
="Effect y offset"
456 fx_height
= FloatProperty(
461 description
="Effect intensity scale"
463 fx_invert
= BoolProperty(
466 description
="Effect invert"
468 fx_offset
= FloatProperty(
473 description
="Effect height offset"
476 edge_falloff
= EnumProperty(
479 description
="Flatten edges",
481 ("0", "None", "None", 0),
482 ("1", "Y", "Y Falloff", 1),
483 ("2", "X", "X Falloff", 2),
484 ("3", "X Y", "X Y Falloff", 3)]
486 falloff_x
= FloatProperty(
491 description
="Falloff x scale"
493 falloff_y
= FloatProperty(
498 description
="Falloff y scale"
500 edge_level
= FloatProperty(
505 description
="Edge level, sealevel offset"
507 maximum
= FloatProperty(
512 description
="Maximum, flattens terrain at plateau level"
514 minimum
= FloatProperty(
519 description
="Minimum, flattens terrain at seabed level"
521 vert_group
= StringProperty(
525 strata
= FloatProperty(
530 description
="Strata layers / terraces"
532 strata_type
= EnumProperty(
535 description
="Strata types",
537 ("0", "None", "No strata", 0),
538 ("1", "Smooth", "Smooth transitions", 1),
539 ("2", "Sharp Sub", "Sharp substract transitions", 2),
540 ("3", "Sharp Add", "Sharp add transitions", 3),
541 ("4", "Quantize", "Quantize", 4),
542 ("5", "Quantize Mix", "Quantize mixed", 5)]
544 water_plane
= BoolProperty(
547 description
="Add water plane"
549 water_level
= FloatProperty(
554 description
="Water level"
556 remove_double
= BoolProperty(
557 name
="Remove Doubles",
559 description
="Remove doubles"
561 direction
= EnumProperty(
564 description
="Displacement direction",
566 ("NORMAL", "Normal", "Displace along vertex normal direction", 0),
567 ("Z", "Z", "Displace in the Z direction", 1),
568 ("Y", "Y", "Displace in the Y direction", 2),
569 ("X", "X", "Displace in the X direction", 3)]
571 show_main_settings
= BoolProperty(
572 name
="Main Settings",
574 description
="Show settings"
576 show_noise_settings
= BoolProperty(
577 name
="Noise Settings",
579 description
="Show noise settings"
581 show_displace_settings
= BoolProperty(
582 name
="Displace Settings",
584 description
="Show terrain settings"
586 refresh
= BoolProperty(
589 description
="Refresh"
591 auto_refresh
= BoolProperty(
594 description
="Automatic refresh"
597 def draw(self
, context
):
598 draw_ant_refresh(self
, context
)
599 draw_ant_noise(self
, context
, generate
=False)
600 draw_ant_displace(self
, context
, generate
=False)
604 def poll(cls
, context
):
606 return (ob
and ob
.type == 'MESH')
609 def invoke(self
, context
, event
):
611 return self
.execute(context
)
614 def execute(self
, context
):
616 return {'PASS_THROUGH'}
619 undo
= bpy
.context
.user_preferences
.edit
.use_global_undo
620 bpy
.context
.user_preferences
.edit
.use_global_undo
= False
626 self
.ant_terrain_name
,
696 if self
.vert_group
!= "" and self
.vert_group
in ob
.vertex_groups
:
697 vertex_group
= ob
.vertex_groups
[self
.vert_group
]
700 gi
= vertex_group
.index
701 if self
.direction
== "X":
702 for v
in mesh
.vertices
:
705 v
.co
[0] += vertex_group
.weight(v
.index
) * noise_gen(v
.co
, props
)
707 if self
.direction
== "Y":
708 for v
in mesh
.vertices
:
711 v
.co
[1] += vertex_group
.weight(v
.index
) * noise_gen(v
.co
, props
)
713 if self
.direction
== "Z":
714 for v
in mesh
.vertices
:
717 v
.co
[2] += vertex_group
.weight(v
.index
) * noise_gen(v
.co
, props
)
720 for v
in mesh
.vertices
:
723 v
.co
+= vertex_group
.weight(v
.index
) * v
.normal
* noise_gen(v
.co
, props
)
726 if self
.direction
== "X":
727 for v
in mesh
.vertices
:
728 v
.co
[0] += noise_gen(v
.co
, props
)
730 elif self
.direction
== "Y":
731 for v
in mesh
.vertices
:
732 v
.co
[1] += noise_gen(v
.co
, props
)
734 elif self
.direction
== "Z":
735 for v
in mesh
.vertices
:
736 v
.co
[2] += noise_gen(v
.co
, props
)
739 for v
in mesh
.vertices
:
740 v
.co
+= v
.normal
* noise_gen(v
.co
, props
)
744 if self
.auto_refresh
is False:
747 # restore pre operator undo state
748 context
.user_preferences
.edit
.use_global_undo
= undo