Import_3ds: Moved keyframe transform
[blender-addons.git] / ant_landscape / mesh_ant_displace.py
blob7cfb9b576014774985f971b0a204e68fbb4a70fe
1 # SPDX-FileCopyrightText: 2017-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # Another Noise Tool - Mesh Displace
6 # Jimmy Hazevoet
8 # ------------------------------------------------------------
9 # import modules
10 import bpy
11 from bpy.props import (
12 BoolProperty,
13 EnumProperty,
14 FloatProperty,
15 IntProperty,
16 StringProperty,
17 FloatVectorProperty,
19 from .ant_functions import (
20 draw_ant_refresh,
21 draw_ant_main,
22 draw_ant_noise,
23 draw_ant_displace,
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(
39 name="Name",
40 default="Landscape"
42 land_material: StringProperty(
43 name='Material',
44 default="",
45 description="Terrain material"
47 water_material: StringProperty(
48 name='Material',
49 default="",
50 description="Water plane material"
52 texture_block: StringProperty(
53 name="Texture",
54 default=""
56 at_cursor: BoolProperty(
57 name="Cursor",
58 default=True,
59 description="Place at cursor location",
61 smooth_mesh: BoolProperty(
62 name="Smooth",
63 default=True,
64 description="Shade smooth"
66 tri_face: BoolProperty(
67 name="Triangulate",
68 default=False,
69 description="Triangulate faces"
71 sphere_mesh: BoolProperty(
72 name="Sphere",
73 default=False,
74 description="Generate uv sphere - remove doubles when ready"
76 subdivision_x: IntProperty(
77 name="Subdivisions X",
78 default=128,
79 min=4,
80 max=6400,
81 description="Mesh X subdivisions"
83 subdivision_y: IntProperty(
84 default=128,
85 name="Subdivisions Y",
86 min=4,
87 max=6400,
88 description="Mesh Y subdivisions"
90 mesh_size: FloatProperty(
91 default=2.0,
92 name="Mesh Size",
93 min=0.01,
94 max=100000.0,
95 description="Mesh size"
97 mesh_size_x: FloatProperty(
98 default=2.0,
99 name="Mesh Size X",
100 min=0.01,
101 description="Mesh x size"
103 mesh_size_y: FloatProperty(
104 name="Mesh Size Y",
105 default=2.0,
106 min=0.01,
107 description="Mesh y size"
110 random_seed: IntProperty(
111 name="Random Seed",
112 default=0,
113 min=0,
114 description="Randomize noise origin"
116 noise_offset_x: FloatProperty(
117 name="Offset X",
118 default=0.0,
119 description="Noise X Offset"
121 noise_offset_y: FloatProperty(
122 name="Offset Y",
123 default=0.0,
124 description="Noise Y Offset"
126 noise_offset_z: FloatProperty(
127 name="Offset Z",
128 default=0.0,
129 description="Noise Z Offset"
131 noise_size_x: FloatProperty(
132 default=1.0,
133 name="Size X",
134 min=0.01,
135 max=1000.0,
136 description="Noise x size"
138 noise_size_y: FloatProperty(
139 name="Size Y",
140 default=1.0,
141 min=0.01,
142 max=1000.0,
143 description="Noise y size"
145 noise_size_z: FloatProperty(
146 name="Size Z",
147 default=1.0,
148 min=0.01,
149 max=1000.0,
150 description="Noise Z size"
152 noise_size: FloatProperty(
153 name="Noise Size",
154 default=0.25,
155 min=0.01,
156 max=1000.0,
157 description="Noise size"
159 noise_type: EnumProperty(
160 name="Noise Type",
161 default='hetero_terrain',
162 description="Noise type",
163 items=[
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(
185 name="Noise Basis",
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(
197 name="Distortion",
198 default=1.0,
199 min=0.01,
200 max=100.0,
201 description="Distortion amount"
203 hard_noise: EnumProperty(
204 name="Soft Hard",
205 default="0",
206 description="Soft Noise, Hard noise",
207 items=[
208 ("0", "Soft", "Soft Noise", 0),
209 ("1", "Hard", "Hard noise", 1)]
211 noise_depth: IntProperty(
212 name="Depth",
213 default=8,
214 min=0,
215 max=16,
216 description="Noise Depth - number of frequencies in the fBm"
218 amplitude: FloatProperty(
219 name="Amp",
220 default=0.5,
221 min=0.01,
222 max=1.0,
223 description="Amplitude"
225 frequency: FloatProperty(
226 name="Freq",
227 default=2.0,
228 min=0.01,
229 max=5.0,
230 description="Frequency"
232 dimension: FloatProperty(
233 name="Dimension",
234 default=1.0,
235 min=0.01,
236 max=2.0,
237 description="H - fractal dimension of the roughest areas"
239 lacunarity: FloatProperty(
240 name="Lacunarity",
241 min=0.01,
242 max=6.0,
243 default=2.0,
244 description="Lacunarity - gap between successive frequencies"
246 offset: FloatProperty(
247 name="Offset",
248 default=1.0,
249 min=0.01,
250 max=6.0,
251 description="Offset - raises the terrain from sea level"
253 gain: FloatProperty(
254 name="Gain",
255 default=1.0,
256 min=0.01,
257 max=6.0,
258 description="Gain - scale factor"
260 marble_bias: EnumProperty(
261 name="Bias",
262 default="0",
263 description="Marble bias",
264 items=[
265 ("0", "Sin", "Sin", 0),
266 ("1", "Cos", "Cos", 1),
267 ("2", "Tri", "Tri", 2),
268 ("3", "Saw", "Saw", 3)]
270 marble_sharp: EnumProperty(
271 name="Sharp",
272 default="0",
273 description="Marble sharpness",
274 items=[
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(
283 name="Shape",
284 default="0",
285 description="Marble shape",
286 items=[
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),
292 ("5", "Z", "Z", 5),
293 ("6", "Y", "Y", 6),
294 ("7", "X", "X", 7)]
296 height: FloatProperty(
297 name="Height",
298 default=0.25,
299 min=-10000.0,
300 max=10000.0,
301 description="Noise intensity scale"
303 height_invert: BoolProperty(
304 name="Invert",
305 default=False,
306 description="Height invert",
308 height_offset: FloatProperty(
309 name="Offset",
310 default=0.0,
311 min=-10000.0,
312 max=10000.0,
313 description="Height offset"
316 fx_mixfactor: FloatProperty(
317 name="Mix Factor",
318 default=0.0,
319 min=-1.0,
320 max=1.0,
321 description="Effect mix factor: -1.0 = Noise, +1.0 = Effect"
323 fx_mix_mode: EnumProperty(
324 name="Effect Mix",
325 default="0",
326 description="Effect mix mode",
327 items=[
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(
340 name="Effect Type",
341 default="0",
342 description="Effect type",
343 items=[
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(
369 name="Effect Bias",
370 default="0",
371 description="Effect bias type",
372 items=[
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(
381 name="Distortion",
382 default=0.0,
383 min=0.0,
384 max=1000.0,
385 description="Effect turbulence distortion"
387 fx_depth: IntProperty(
388 name="Depth",
389 default=0,
390 min=0,
391 max=16,
392 description="Effect depth - number of frequencies"
394 fx_amplitude: FloatProperty(
395 name="Amp",
396 default=0.5,
397 min=0.01,
398 max=1.0,
399 description="Amplitude"
401 fx_frequency: FloatProperty(
402 name="Freq",
403 default=2.0,
404 min=0.01,
405 max=5.0,
406 description="Frequency"
408 fx_size: FloatProperty(
409 name="Effect Size",
410 default=1.0,
411 min=0.01,
412 max=1000.0,
413 description="Effect size"
415 fx_loc_x: FloatProperty(
416 name="Offset X",
417 default=0.0,
418 description="Effect x offset"
420 fx_loc_y: FloatProperty(
421 name="Offset Y",
422 default=0.0,
423 description="Effect y offset"
425 fx_height: FloatProperty(
426 name="Intensity",
427 default=1.0,
428 min=-1000.0,
429 max=1000.0,
430 description="Effect intensity scale"
432 fx_invert: BoolProperty(
433 name="Invert",
434 default=False,
435 description="Effect invert"
437 fx_offset: FloatProperty(
438 name="Offset",
439 default=0.0,
440 min=-1000.0,
441 max=1000.0,
442 description="Effect height offset"
445 edge_falloff: EnumProperty(
446 name="Falloff",
447 default="0",
448 description="Flatten edges",
449 items=[
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(
456 name="Falloff X",
457 default=4.0,
458 min=0.1,
459 max=100.0,
460 description="Falloff x scale"
462 falloff_y: FloatProperty(
463 name="Falloff Y",
464 default=4.0,
465 min=0.1,
466 max=100.0,
467 description="Falloff y scale"
469 edge_level: FloatProperty(
470 name="Edge Level",
471 default=0.0,
472 min=-10000.0,
473 max=10000.0,
474 description="Edge level, sealevel offset"
476 maximum: FloatProperty(
477 name="Maximum",
478 default=1.0,
479 min=-10000.0,
480 max=10000.0,
481 description="Maximum, flattens terrain at plateau level"
483 minimum: FloatProperty(
484 name="Minimum",
485 default=-1.0,
486 min=-10000.0,
487 max=10000.0,
488 description="Minimum, flattens terrain at seabed level"
490 vert_group: StringProperty(
491 name="Vertex Group",
492 default=""
494 strata: FloatProperty(
495 name="Amount",
496 default=5.0,
497 min=0.01,
498 max=1000.0,
499 description="Strata layers / terraces"
501 strata_type: EnumProperty(
502 name="Strata",
503 default="0",
504 description="Strata types",
505 items=[
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(
514 name="Water Plane",
515 default=False,
516 description="Add water plane"
518 water_level: FloatProperty(
519 name="Level",
520 default=0.01,
521 min=-10000.0,
522 max=10000.0,
523 description="Water level"
525 remove_double: BoolProperty(
526 name="Remove Doubles",
527 default=False,
528 description="Remove doubles"
530 direction: EnumProperty(
531 name="Direction",
532 default="NORMAL",
533 description="Displacement direction",
534 items=[
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",
542 default=True,
543 description="Show settings"
545 show_noise_settings: BoolProperty(
546 name="Noise Settings",
547 default=True,
548 description="Show noise settings"
550 show_displace_settings: BoolProperty(
551 name="Displace Settings",
552 default=True,
553 description="Show terrain settings"
555 refresh: BoolProperty(
556 name="Refresh",
557 default=False,
558 description="Refresh"
560 auto_refresh: BoolProperty(
561 name="Auto",
562 default=False,
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)
571 @classmethod
572 def poll(cls, context):
573 ob = context.object
574 return (ob and ob.type == 'MESH')
576 def invoke(self, context, event):
577 self.refresh = True
578 return self.execute(context)
580 def execute(self, context):
581 if not self.refresh:
582 return {'PASS_THROUGH'}
584 ob = context.object
586 # Properties:
587 props = [
588 self.ant_terrain_name,
589 self.at_cursor,
590 self.smooth_mesh,
591 self.tri_face,
592 self.sphere_mesh,
593 self.land_material,
594 self.water_material,
595 self.texture_block,
596 self.subdivision_x,
597 self.subdivision_y,
598 self.mesh_size_x,
599 self.mesh_size_y,
600 self.mesh_size,
601 self.random_seed,
602 self.noise_offset_x,
603 self.noise_offset_y,
604 self.noise_offset_z,
605 self.noise_size_x,
606 self.noise_size_y,
607 self.noise_size_z,
608 self.noise_size,
609 self.noise_type,
610 self.basis_type,
611 self.vl_basis_type,
612 self.distortion,
613 self.hard_noise,
614 self.noise_depth,
615 self.amplitude,
616 self.frequency,
617 self.dimension,
618 self.lacunarity,
619 self.offset,
620 self.gain,
621 self.marble_bias,
622 self.marble_sharp,
623 self.marble_shape,
624 self.height,
625 self.height_invert,
626 self.height_offset,
627 self.maximum,
628 self.minimum,
629 self.edge_falloff,
630 self.edge_level,
631 self.falloff_x,
632 self.falloff_y,
633 self.strata_type,
634 self.strata,
635 self.water_plane,
636 self.water_level,
637 self.vert_group,
638 self.remove_double,
639 self.fx_mixfactor,
640 self.fx_mix_mode,
641 self.fx_type,
642 self.fx_bias,
643 self.fx_turb,
644 self.fx_depth,
645 self.fx_frequency,
646 self.fx_amplitude,
647 self.fx_size,
648 self.fx_loc_x,
649 self.fx_loc_y,
650 self.fx_height,
651 self.fx_offset,
652 self.fx_invert
655 # do displace
656 mesh = ob.data
658 if self.vert_group != "" and self.vert_group in ob.vertex_groups:
659 vertex_group = ob.vertex_groups[self.vert_group]
661 if vertex_group:
662 gi = vertex_group.index
663 if self.direction == "X":
664 for v in mesh.vertices:
665 for g in v.groups:
666 if g.group == gi:
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:
671 for g in v.groups:
672 if g.group == gi:
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:
677 for g in v.groups:
678 if g.group == gi:
679 v.co[2] += vertex_group.weight(v.index) * noise_gen(v.co, props)
681 else:
682 for v in mesh.vertices:
683 for g in v.groups:
684 if g.group == gi:
685 v.co += vertex_group.weight(v.index) * v.normal * noise_gen(v.co, props)
687 else:
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)
700 else:
701 for v in mesh.vertices:
702 v.co += v.normal * noise_gen(v.co, props)
704 mesh.update()
706 if self.auto_refresh is False:
707 self.refresh = False
709 return {'FINISHED'}