glTF exporter: Export DEF bones only, without animation, is now possible
[blender-addons.git] / ant_landscape / mesh_ant_displace.py
blob5638d96a7d4feee8203fd67c63da27f9644f4565
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Another Noise Tool - Mesh Displace
4 # Jimmy Hazevoet
6 # ------------------------------------------------------------
7 # import modules
8 import bpy
9 from bpy.props import (
10 BoolProperty,
11 EnumProperty,
12 FloatProperty,
13 IntProperty,
14 StringProperty,
15 FloatVectorProperty,
17 from .ant_functions import (
18 draw_ant_refresh,
19 draw_ant_main,
20 draw_ant_noise,
21 draw_ant_displace,
23 from .ant_noise import noise_gen
24 from ant_landscape import ant_noise
26 # ------------------------------------------------------------
27 # Do vert displacement
28 class AntMeshDisplace(bpy.types.Operator):
29 bl_idname = "mesh.ant_displace"
30 bl_label = "Another Noise Tool - Displace"
31 bl_description = "Displace mesh vertices"
32 bl_options = {'REGISTER', 'UNDO', 'PRESET'}
34 ant_terrain_name: StringProperty(
35 name="Name",
36 default="Landscape"
38 land_material: StringProperty(
39 name='Material',
40 default="",
41 description="Terrain material"
43 water_material: StringProperty(
44 name='Material',
45 default="",
46 description="Water plane material"
48 texture_block: StringProperty(
49 name="Texture",
50 default=""
52 at_cursor: BoolProperty(
53 name="Cursor",
54 default=True,
55 description="Place at cursor location",
57 smooth_mesh: BoolProperty(
58 name="Smooth",
59 default=True,
60 description="Shade smooth"
62 tri_face: BoolProperty(
63 name="Triangulate",
64 default=False,
65 description="Triangulate faces"
67 sphere_mesh: BoolProperty(
68 name="Sphere",
69 default=False,
70 description="Generate uv sphere - remove doubles when ready"
72 subdivision_x: IntProperty(
73 name="Subdivisions X",
74 default=128,
75 min=4,
76 max=6400,
77 description="Mesh X subdivisions"
79 subdivision_y: IntProperty(
80 default=128,
81 name="Subdivisions Y",
82 min=4,
83 max=6400,
84 description="Mesh Y subdivisions"
86 mesh_size: FloatProperty(
87 default=2.0,
88 name="Mesh Size",
89 min=0.01,
90 max=100000.0,
91 description="Mesh size"
93 mesh_size_x: FloatProperty(
94 default=2.0,
95 name="Mesh Size X",
96 min=0.01,
97 description="Mesh x size"
99 mesh_size_y: FloatProperty(
100 name="Mesh Size Y",
101 default=2.0,
102 min=0.01,
103 description="Mesh y size"
106 random_seed: IntProperty(
107 name="Random Seed",
108 default=0,
109 min=0,
110 description="Randomize noise origin"
112 noise_offset_x: FloatProperty(
113 name="Offset X",
114 default=0.0,
115 description="Noise X Offset"
117 noise_offset_y: FloatProperty(
118 name="Offset Y",
119 default=0.0,
120 description="Noise Y Offset"
122 noise_offset_z: FloatProperty(
123 name="Offset Z",
124 default=0.0,
125 description="Noise Z Offset"
127 noise_size_x: FloatProperty(
128 default=1.0,
129 name="Size X",
130 min=0.01,
131 max=1000.0,
132 description="Noise x size"
134 noise_size_y: FloatProperty(
135 name="Size Y",
136 default=1.0,
137 min=0.01,
138 max=1000.0,
139 description="Noise y size"
141 noise_size_z: FloatProperty(
142 name="Size Z",
143 default=1.0,
144 min=0.01,
145 max=1000.0,
146 description="Noise Z size"
148 noise_size: FloatProperty(
149 name="Noise Size",
150 default=0.25,
151 min=0.01,
152 max=1000.0,
153 description="Noise size"
155 noise_type: EnumProperty(
156 name="Noise Type",
157 default='hetero_terrain',
158 description="Noise type",
159 items = [
160 ('multi_fractal', "Multi Fractal", "Blender: Multi Fractal algorithm", 0),
161 ('ridged_multi_fractal', "Ridged MFractal", "Blender: Ridged Multi Fractal", 1),
162 ('hybrid_multi_fractal', "Hybrid MFractal", "Blender: Hybrid Multi Fractal", 2),
163 ('hetero_terrain', "Hetero Terrain", "Blender: Hetero Terrain", 3),
164 ('fractal', "fBm Fractal", "Blender: fBm - Fractional Browninian motion", 4),
165 ('turbulence_vector', "Turbulence", "Blender: Turbulence Vector", 5),
166 ('variable_lacunarity', "Distorted Noise", "Blender: Distorted Noise", 6),
167 ('marble_noise', "Marble", "A.N.T.: Marble Noise", 7),
168 ('shattered_hterrain', "Shattered hTerrain", "A.N.T.: Shattered hTerrain", 8),
169 ('strata_hterrain', "Strata hTerrain", "A.N.T: Strata hTerrain", 9),
170 ('ant_turbulence', "Another Noise", "A.N.T: Turbulence variation", 10),
171 ('vl_noise_turbulence', "vlNoise turbulence", "A.N.T: Real vlNoise turbulence", 11),
172 ('vl_hTerrain', "vlNoise hTerrain", "A.N.T: vlNoise hTerrain", 12),
173 ('distorted_heteroTerrain', "Distorted hTerrain", "A.N.T distorted hTerrain", 13),
174 ('double_multiFractal', "Double MultiFractal", "A.N.T: double multiFractal", 14),
175 ('rocks_noise', "Noise Rocks", "A.N.T: turbulence variation", 15),
176 ('slick_rock', "Slick Rock", "A.N.T: slick rock", 16),
177 ('planet_noise', "Planet Noise", "Planet Noise by: Farsthary", 17),
178 ('blender_texture', "Blender Texture - Texture Nodes", "Blender texture data block", 18)]
180 basis_type: EnumProperty(
181 name="Noise Basis",
182 default=ant_noise.noise_basis_default,
183 description="Noise basis algorithms",
184 items = ant_noise.noise_basis
186 vl_basis_type: EnumProperty(
187 name="vlNoise Basis",
188 default=ant_noise.noise_basis_default,
189 description="VLNoise basis algorithms",
190 items = ant_noise.noise_basis
192 distortion: FloatProperty(
193 name="Distortion",
194 default=1.0,
195 min=0.01,
196 max=100.0,
197 description="Distortion amount"
199 hard_noise: EnumProperty(
200 name="Soft Hard",
201 default="0",
202 description="Soft Noise, Hard noise",
203 items = [
204 ("0", "Soft", "Soft Noise", 0),
205 ("1", "Hard", "Hard noise", 1)]
207 noise_depth: IntProperty(
208 name="Depth",
209 default=8,
210 min=0,
211 max=16,
212 description="Noise Depth - number of frequencies in the fBm"
214 amplitude: FloatProperty(
215 name="Amp",
216 default=0.5,
217 min=0.01,
218 max=1.0,
219 description="Amplitude"
221 frequency: FloatProperty(
222 name="Freq",
223 default=2.0,
224 min=0.01,
225 max=5.0,
226 description="Frequency"
228 dimension: FloatProperty(
229 name="Dimension",
230 default=1.0,
231 min=0.01,
232 max=2.0,
233 description="H - fractal dimension of the roughest areas"
235 lacunarity: FloatProperty(
236 name="Lacunarity",
237 min=0.01,
238 max=6.0,
239 default=2.0,
240 description="Lacunarity - gap between successive frequencies"
242 offset: FloatProperty(
243 name="Offset",
244 default=1.0,
245 min=0.01,
246 max=6.0,
247 description="Offset - raises the terrain from sea level"
249 gain: FloatProperty(
250 name="Gain",
251 default=1.0,
252 min=0.01,
253 max=6.0,
254 description="Gain - scale factor"
256 marble_bias: EnumProperty(
257 name="Bias",
258 default="0",
259 description="Marble bias",
260 items = [
261 ("0", "Sin", "Sin", 0),
262 ("1", "Cos", "Cos", 1),
263 ("2", "Tri", "Tri", 2),
264 ("3", "Saw", "Saw", 3)]
266 marble_sharp: EnumProperty(
267 name="Sharp",
268 default="0",
269 description="Marble sharpness",
270 items = [
271 ("0", "Soft", "Soft", 0),
272 ("1", "Sharp", "Sharp", 1),
273 ("2", "Sharper", "Sharper", 2),
274 ("3", "Soft inv.", "Soft", 3),
275 ("4", "Sharp inv.", "Sharp", 4),
276 ("5", "Sharper inv.", "Sharper", 5)]
278 marble_shape: EnumProperty(
279 name="Shape",
280 default="0",
281 description="Marble shape",
282 items= [
283 ("0", "Default", "Default", 0),
284 ("1", "Ring", "Ring", 1),
285 ("2", "Swirl", "Swirl", 2),
286 ("3", "Bump", "Bump", 3),
287 ("4", "Wave", "Wave", 4),
288 ("5", "Z", "Z", 5),
289 ("6", "Y", "Y", 6),
290 ("7", "X", "X", 7)]
292 height: FloatProperty(
293 name="Height",
294 default=0.25,
295 min=-10000.0,
296 max=10000.0,
297 description="Noise intensity scale"
299 height_invert: BoolProperty(
300 name="Invert",
301 default=False,
302 description="Height invert",
304 height_offset: FloatProperty(
305 name="Offset",
306 default=0.0,
307 min=-10000.0,
308 max=10000.0,
309 description="Height offset"
312 fx_mixfactor: FloatProperty(
313 name="Mix Factor",
314 default=0.0,
315 min=-1.0,
316 max=1.0,
317 description="Effect mix factor: -1.0 = Noise, +1.0 = Effect"
319 fx_mix_mode: EnumProperty(
320 name="Effect Mix",
321 default="0",
322 description="Effect mix mode",
323 items = [
324 ("0", "Mix", "Mix", 0),
325 ("1", "Add", "Add", 1),
326 ("2", "Sub", "Subtract", 2),
327 ("3", "Mul", "Multiply", 3),
328 ("4", "Abs", "Absolute", 4),
329 ("5", "Scr", "Screen", 5),
330 ("6", "Mod", "Modulo", 6),
331 ("7", "Min", "Minimum", 7),
332 ("8", "Max", "Maximum", 8)
335 fx_type: EnumProperty(
336 name="Effect Type",
337 default="0",
338 description="Effect type",
339 items = [
340 ("0", "None", "No effect", 0),
341 ("1", "Gradient", "Gradient", 1),
342 ("2", "Waves", "Waves - Bumps", 2),
343 ("3", "Zigzag", "Zigzag", 3),
344 ("4", "Wavy", "Wavy", 4),
345 ("5", "Bump", "Bump", 5),
346 ("6", "Dots", "Dots", 6),
347 ("7", "Rings", "Rings", 7),
348 ("8", "Spiral", "Spiral", 8),
349 ("9", "Square", "Square", 9),
350 ("10", "Blocks", "Blocks", 10),
351 ("11", "Grid", "Grid", 11),
352 ("12", "Tech", "Tech", 12),
353 ("13", "Crackle", "Crackle", 13),
354 ("14", "Cracks", "Cracks", 14),
355 ("15", "Rock", "Rock noise", 15),
356 ("16", "Lunar", "Craters", 16),
357 ("17", "Cosine", "Cosine", 17),
358 ("18", "Spikey", "Spikey", 18),
359 ("19", "Stone", "Stone", 19),
360 ("20", "Flat Turb", "Flat turbulence", 20),
361 ("21", "Flat Voronoi", "Flat voronoi", 21)
364 fx_bias: EnumProperty(
365 name="Effect Bias",
366 default="0",
367 description="Effect bias type",
368 items = [
369 ("0", "Sin", "Sin", 0),
370 ("1", "Cos", "Cos", 1),
371 ("2", "Tri", "Tri", 2),
372 ("3", "Saw", "Saw", 3),
373 ("4", "None", "None", 4)
376 fx_turb: FloatProperty(
377 name="Distortion",
378 default=0.0,
379 min=0.0,
380 max=1000.0,
381 description="Effect turbulence distortion"
383 fx_depth: IntProperty(
384 name="Depth",
385 default=0,
386 min=0,
387 max=16,
388 description="Effect depth - number of frequencies"
390 fx_amplitude: FloatProperty(
391 name="Amp",
392 default=0.5,
393 min=0.01,
394 max=1.0,
395 description="Amplitude"
397 fx_frequency: FloatProperty(
398 name="Freq",
399 default=2.0,
400 min=0.01,
401 max=5.0,
402 description="Frequency"
404 fx_size: FloatProperty(
405 name="Effect Size",
406 default=1.0,
407 min=0.01,
408 max=1000.0,
409 description="Effect size"
411 fx_loc_x: FloatProperty(
412 name="Offset X",
413 default=0.0,
414 description="Effect x offset"
416 fx_loc_y: FloatProperty(
417 name="Offset Y",
418 default=0.0,
419 description="Effect y offset"
421 fx_height: FloatProperty(
422 name="Intensity",
423 default=1.0,
424 min=-1000.0,
425 max=1000.0,
426 description="Effect intensity scale"
428 fx_invert: BoolProperty(
429 name="Invert",
430 default=False,
431 description="Effect invert"
433 fx_offset: FloatProperty(
434 name="Offset",
435 default=0.0,
436 min=-1000.0,
437 max=1000.0,
438 description="Effect height offset"
441 edge_falloff: EnumProperty(
442 name="Falloff",
443 default="0",
444 description="Flatten edges",
445 items = [
446 ("0", "None", "None", 0),
447 ("1", "Y", "Y Falloff", 1),
448 ("2", "X", "X Falloff", 2),
449 ("3", "X Y", "X Y Falloff", 3)]
451 falloff_x: FloatProperty(
452 name="Falloff X",
453 default=4.0,
454 min=0.1,
455 max=100.0,
456 description="Falloff x scale"
458 falloff_y: FloatProperty(
459 name="Falloff Y",
460 default=4.0,
461 min=0.1,
462 max=100.0,
463 description="Falloff y scale"
465 edge_level: FloatProperty(
466 name="Edge Level",
467 default=0.0,
468 min=-10000.0,
469 max=10000.0,
470 description="Edge level, sealevel offset"
472 maximum: FloatProperty(
473 name="Maximum",
474 default=1.0,
475 min=-10000.0,
476 max=10000.0,
477 description="Maximum, flattens terrain at plateau level"
479 minimum: FloatProperty(
480 name="Minimum",
481 default=-1.0,
482 min=-10000.0,
483 max=10000.0,
484 description="Minimum, flattens terrain at seabed level"
486 vert_group: StringProperty(
487 name="Vertex Group",
488 default=""
490 strata: FloatProperty(
491 name="Amount",
492 default=5.0,
493 min=0.01,
494 max=1000.0,
495 description="Strata layers / terraces"
497 strata_type: EnumProperty(
498 name="Strata",
499 default="0",
500 description="Strata types",
501 items = [
502 ("0", "None", "No strata", 0),
503 ("1", "Smooth", "Smooth transitions", 1),
504 ("2", "Sharp Sub", "Sharp subtract transitions", 2),
505 ("3", "Sharp Add", "Sharp add transitions", 3),
506 ("4", "Quantize", "Quantize", 4),
507 ("5", "Quantize Mix", "Quantize mixed", 5)]
509 water_plane: BoolProperty(
510 name="Water Plane",
511 default=False,
512 description="Add water plane"
514 water_level: FloatProperty(
515 name="Level",
516 default=0.01,
517 min=-10000.0,
518 max=10000.0,
519 description="Water level"
521 remove_double: BoolProperty(
522 name="Remove Doubles",
523 default=False,
524 description="Remove doubles"
526 direction: EnumProperty(
527 name="Direction",
528 default="NORMAL",
529 description="Displacement direction",
530 items = [
531 ("NORMAL", "Normal", "Displace along vertex normal direction", 0),
532 ("Z", "Z", "Displace in the Z direction", 1),
533 ("Y", "Y", "Displace in the Y direction", 2),
534 ("X", "X", "Displace in the X direction", 3)]
536 show_main_settings: BoolProperty(
537 name="Main Settings",
538 default=True,
539 description="Show settings"
541 show_noise_settings: BoolProperty(
542 name="Noise Settings",
543 default=True,
544 description="Show noise settings"
546 show_displace_settings: BoolProperty(
547 name="Displace Settings",
548 default=True,
549 description="Show terrain settings"
551 refresh: BoolProperty(
552 name="Refresh",
553 default=False,
554 description="Refresh"
556 auto_refresh: BoolProperty(
557 name="Auto",
558 default=False,
559 description="Automatic refresh"
562 def draw(self, context):
563 draw_ant_refresh(self, context)
564 draw_ant_noise(self, context, generate=False)
565 draw_ant_displace(self, context, generate=False)
568 @classmethod
569 def poll(cls, context):
570 ob = context.object
571 return (ob and ob.type == 'MESH')
574 def invoke(self, context, event):
575 self.refresh = True
576 return self.execute(context)
579 def execute(self, context):
580 if not self.refresh:
581 return {'PASS_THROUGH'}
583 ob = context.object
585 # Properties:
586 props = [
587 self.ant_terrain_name,
588 self.at_cursor,
589 self.smooth_mesh,
590 self.tri_face,
591 self.sphere_mesh,
592 self.land_material,
593 self.water_material,
594 self.texture_block,
595 self.subdivision_x,
596 self.subdivision_y,
597 self.mesh_size_x,
598 self.mesh_size_y,
599 self.mesh_size,
600 self.random_seed,
601 self.noise_offset_x,
602 self.noise_offset_y,
603 self.noise_offset_z,
604 self.noise_size_x,
605 self.noise_size_y,
606 self.noise_size_z,
607 self.noise_size,
608 self.noise_type,
609 self.basis_type,
610 self.vl_basis_type,
611 self.distortion,
612 self.hard_noise,
613 self.noise_depth,
614 self.amplitude,
615 self.frequency,
616 self.dimension,
617 self.lacunarity,
618 self.offset,
619 self.gain,
620 self.marble_bias,
621 self.marble_sharp,
622 self.marble_shape,
623 self.height,
624 self.height_invert,
625 self.height_offset,
626 self.maximum,
627 self.minimum,
628 self.edge_falloff,
629 self.edge_level,
630 self.falloff_x,
631 self.falloff_y,
632 self.strata_type,
633 self.strata,
634 self.water_plane,
635 self.water_level,
636 self.vert_group,
637 self.remove_double,
638 self.fx_mixfactor,
639 self.fx_mix_mode,
640 self.fx_type,
641 self.fx_bias,
642 self.fx_turb,
643 self.fx_depth,
644 self.fx_frequency,
645 self.fx_amplitude,
646 self.fx_size,
647 self.fx_loc_x,
648 self.fx_loc_y,
649 self.fx_height,
650 self.fx_offset,
651 self.fx_invert
654 # do displace
655 mesh = ob.data
657 if self.vert_group != "" and self.vert_group in ob.vertex_groups:
658 vertex_group = ob.vertex_groups[self.vert_group]
660 if vertex_group:
661 gi = vertex_group.index
662 if self.direction == "X":
663 for v in mesh.vertices:
664 for g in v.groups:
665 if g.group == gi:
666 v.co[0] += vertex_group.weight(v.index) * noise_gen(v.co, props)
668 if self.direction == "Y":
669 for v in mesh.vertices:
670 for g in v.groups:
671 if g.group == gi:
672 v.co[1] += vertex_group.weight(v.index) * noise_gen(v.co, props)
674 if self.direction == "Z":
675 for v in mesh.vertices:
676 for g in v.groups:
677 if g.group == gi:
678 v.co[2] += vertex_group.weight(v.index) * noise_gen(v.co, props)
680 else:
681 for v in mesh.vertices:
682 for g in v.groups:
683 if g.group == gi:
684 v.co += vertex_group.weight(v.index) * v.normal * noise_gen(v.co, props)
686 else:
687 if self.direction == "X":
688 for v in mesh.vertices:
689 v.co[0] += noise_gen(v.co, props)
691 elif self.direction == "Y":
692 for v in mesh.vertices:
693 v.co[1] += noise_gen(v.co, props)
695 elif self.direction == "Z":
696 for v in mesh.vertices:
697 v.co[2] += noise_gen(v.co, props)
699 else:
700 for v in mesh.vertices:
701 v.co += v.normal * noise_gen(v.co, props)
703 mesh.update()
705 if self.auto_refresh is False:
706 self.refresh = False
708 return {'FINISHED'}