Import_3ds: Moved keyframe transform
[blender-addons.git] / ant_landscape / add_mesh_ant_landscape.py
blobc32393543398f543554d000fdf6b917367047ef3
1 # SPDX-FileCopyrightText: 2017-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # Another Noise Tool - Add Landscape
6 # Jimmy Hazevoet
8 # import modules
9 import bpy
10 from bpy.props import (
11 BoolProperty,
12 EnumProperty,
13 FloatProperty,
14 IntProperty,
15 StringProperty,
16 FloatVectorProperty,
19 from .ant_functions import (
20 grid_gen,
21 sphere_gen,
22 create_mesh_object,
23 store_properties,
24 draw_ant_refresh,
25 draw_ant_main,
26 draw_ant_noise,
27 draw_ant_displace,
28 draw_ant_water,
31 from ant_landscape import ant_noise
33 # ------------------------------------------------------------
34 # Add landscape
37 class AntAddLandscape(bpy.types.Operator):
38 bl_idname = "mesh.landscape_add"
39 bl_label = "Another Noise Tool - Landscape"
40 bl_description = "Add landscape mesh"
41 bl_options = {'REGISTER', 'UNDO', 'PRESET'}
43 ant_terrain_name: StringProperty(
44 name="Name",
45 default="Landscape"
47 land_material: StringProperty(
48 name='Material',
49 default="",
50 description="Terrain material"
52 water_material: StringProperty(
53 name='Material',
54 default="",
55 description="Water plane material"
57 texture_block: StringProperty(
58 name="Texture",
59 default=""
61 at_cursor: BoolProperty(
62 name="Cursor",
63 default=True,
64 description="Place at cursor location",
66 smooth_mesh: BoolProperty(
67 name="Smooth",
68 default=True,
69 description="Shade smooth"
71 tri_face: BoolProperty(
72 name="Triangulate",
73 default=False,
74 description="Triangulate faces"
76 sphere_mesh: BoolProperty(
77 name="Sphere",
78 default=False,
79 description="Generate uv sphere - remove doubles when ready"
81 subdivision_x: IntProperty(
82 name="Subdivisions X",
83 default=128,
84 min=4,
85 max=6400,
86 description="Mesh X subdivisions"
88 subdivision_y: IntProperty(
89 default=128,
90 name="Subdivisions Y",
91 min=4,
92 max=6400,
93 description="Mesh Y subdivisions"
95 mesh_size: FloatProperty(
96 default=2.0,
97 name="Mesh Size",
98 min=0.01,
99 max=100000.0,
100 description="Mesh size"
102 mesh_size_x: FloatProperty(
103 default=2.0,
104 name="Mesh Size X",
105 min=0.01,
106 description="Mesh x size"
108 mesh_size_y: FloatProperty(
109 name="Mesh Size Y",
110 default=2.0,
111 min=0.01,
112 description="Mesh y size"
115 random_seed: IntProperty(
116 name="Random Seed",
117 default=0,
118 min=0,
119 description="Randomize noise origin"
121 noise_offset_x: FloatProperty(
122 name="Offset X",
123 default=0.0,
124 description="Noise X Offset"
126 noise_offset_y: FloatProperty(
127 name="Offset Y",
128 default=0.0,
129 description="Noise Y Offset"
131 noise_offset_z: FloatProperty(
132 name="Offset Z",
133 default=0.0,
134 description="Noise Z Offset"
136 noise_size_x: FloatProperty(
137 default=1.0,
138 name="Size X",
139 min=0.01,
140 max=1000.0,
141 description="Noise x size"
143 noise_size_y: FloatProperty(
144 name="Size Y",
145 default=1.0,
146 min=0.01,
147 max=1000.0,
148 description="Noise y size"
150 noise_size_z: FloatProperty(
151 name="Size Z",
152 default=1.0,
153 min=0.01,
154 max=1000.0,
155 description="Noise Z size"
157 noise_size: FloatProperty(
158 name="Noise Size",
159 default=1.0,
160 min=0.01,
161 max=1000.0,
162 description="Noise size"
164 noise_type: EnumProperty(
165 name="Noise Type",
166 default='hetero_terrain',
167 description="Noise type",
168 items=[
169 ('multi_fractal', "Multi Fractal", "Blender: Multi Fractal algorithm", 0),
170 ('ridged_multi_fractal', "Ridged MFractal", "Blender: Ridged Multi Fractal", 1),
171 ('hybrid_multi_fractal', "Hybrid MFractal", "Blender: Hybrid Multi Fractal", 2),
172 ('hetero_terrain', "Hetero Terrain", "Blender: Hetero Terrain", 3),
173 ('fractal', "fBm Fractal", "Blender: fBm - Fractional Browninian motion", 4),
174 ('turbulence_vector', "Turbulence", "Blender: Turbulence Vector", 5),
175 ('variable_lacunarity', "Distorted Noise", "Blender: Distorted Noise", 6),
176 ('marble_noise', "Marble", "A.N.T.: Marble Noise", 7),
177 ('shattered_hterrain', "Shattered hTerrain", "A.N.T.: Shattered hTerrain", 8),
178 ('strata_hterrain', "Strata hTerrain", "A.N.T: Strata hTerrain", 9),
179 ('ant_turbulence', "Another Noise", "A.N.T: Turbulence variation", 10),
180 ('vl_noise_turbulence', "vlNoise turbulence", "A.N.T: Real vlNoise turbulence", 11),
181 ('vl_hTerrain', "vlNoise hTerrain", "A.N.T: vlNoise hTerrain", 12),
182 ('distorted_heteroTerrain', "Distorted hTerrain", "A.N.T distorted hTerrain", 13),
183 ('double_multiFractal', "Double MultiFractal", "A.N.T: double multiFractal", 14),
184 ('rocks_noise', "Noise Rocks", "A.N.T: turbulence variation", 15),
185 ('slick_rock', "Slick Rock", "A.N.T: slick rock", 16),
186 ('planet_noise', "Planet Noise", "Planet Noise by: Farsthary", 17),
187 ('blender_texture', "Blender Texture - Texture Nodes", "Blender texture data block", 18)]
189 basis_type: EnumProperty(
190 name="Noise Basis",
191 default=ant_noise.noise_basis_default,
192 description="Noise basis algorithms",
193 items=ant_noise.noise_basis
195 vl_basis_type: EnumProperty(
196 name="vlNoise Basis",
197 default=ant_noise.noise_basis_default,
198 description="VLNoise basis algorithms",
199 items=ant_noise.noise_basis
201 distortion: FloatProperty(
202 name="Distortion",
203 default=1.0,
204 min=0.01,
205 max=100.0,
206 description="Distortion amount"
208 hard_noise: EnumProperty(
209 name="Soft Hard",
210 default="0",
211 description="Soft Noise, Hard noise",
212 items=[
213 ("0", "Soft", "Soft Noise", 0),
214 ("1", "Hard", "Hard noise", 1)]
216 noise_depth: IntProperty(
217 name="Depth",
218 default=8,
219 min=0,
220 max=16,
221 description="Noise Depth - number of frequencies in the fBm"
223 amplitude: FloatProperty(
224 name="Amp",
225 default=0.5,
226 min=0.01,
227 max=1.0,
228 description="Amplitude"
230 frequency: FloatProperty(
231 name="Freq",
232 default=2.0,
233 min=0.01,
234 max=5.0,
235 description="Frequency"
237 dimension: FloatProperty(
238 name="Dimension",
239 default=1.0,
240 min=0.01,
241 max=2.0,
242 description="H - fractal dimension of the roughest areas"
244 lacunarity: FloatProperty(
245 name="Lacunarity",
246 min=0.01,
247 max=6.0,
248 default=2.0,
249 description="Lacunarity - gap between successive frequencies"
251 offset: FloatProperty(
252 name="Offset",
253 default=1.0,
254 min=0.01,
255 max=6.0,
256 description="Offset - raises the terrain from sea level"
258 gain: FloatProperty(
259 name="Gain",
260 default=1.0,
261 min=0.01,
262 max=6.0,
263 description="Gain - scale factor"
265 marble_bias: EnumProperty(
266 name="Bias",
267 default="0",
268 description="Marble bias",
269 items=[
270 ("0", "Sin", "Sin", 0),
271 ("1", "Cos", "Cos", 1),
272 ("2", "Tri", "Tri", 2),
273 ("3", "Saw", "Saw", 3)]
275 marble_sharp: EnumProperty(
276 name="Sharp",
277 default="0",
278 description="Marble sharpness",
279 items=[
280 ("0", "Soft", "Soft", 0),
281 ("1", "Sharp", "Sharp", 1),
282 ("2", "Sharper", "Sharper", 2),
283 ("3", "Soft inv.", "Soft", 3),
284 ("4", "Sharp inv.", "Sharp", 4),
285 ("5", "Sharper inv.", "Sharper", 5)]
287 marble_shape: EnumProperty(
288 name="Shape",
289 default="0",
290 description="Marble shape",
291 items=[
292 ("0", "Default", "Default", 0),
293 ("1", "Ring", "Ring", 1),
294 ("2", "Swirl", "Swirl", 2),
295 ("3", "Bump", "Bump", 3),
296 ("4", "Wave", "Wave", 4),
297 ("5", "Z", "Z", 5),
298 ("6", "Y", "Y", 6),
299 ("7", "X", "X", 7)]
301 height: FloatProperty(
302 name="Height",
303 default=0.5,
304 min=-10000.0,
305 max=10000.0,
306 description="Noise intensity scale"
308 height_invert: BoolProperty(
309 name="Invert",
310 default=False,
311 description="Height invert",
313 height_offset: FloatProperty(
314 name="Offset",
315 default=0.0,
316 min=-10000.0,
317 max=10000.0,
318 description="Height offset"
320 fx_mixfactor: FloatProperty(
321 name="Mix Factor",
322 default=0.0,
323 min=-1.0,
324 max=1.0,
325 description="Effect mix factor: -1.0 = Noise, +1.0 = Effect"
327 fx_mix_mode: EnumProperty(
328 name="Effect Mix",
329 default="0",
330 description="Effect mix mode",
331 items=[
332 ("0", "Mix", "Mix", 0),
333 ("1", "Add", "Add", 1),
334 ("2", "Sub", "Subtract", 2),
335 ("3", "Mul", "Multiply", 3),
336 ("4", "Abs", "Absolute", 4),
337 ("5", "Scr", "Screen", 5),
338 ("6", "Mod", "Modulo", 6),
339 ("7", "Min", "Minimum", 7),
340 ("8", "Max", "Maximum", 8)
343 fx_type: EnumProperty(
344 name="Effect Type",
345 default="0",
346 description="Effect type",
347 items=[
348 ("0", "None", "No effect", 0),
349 ("1", "Gradient", "Gradient", 1),
350 ("2", "Waves", "Waves - Bumps", 2),
351 ("3", "Zigzag", "Zigzag", 3),
352 ("4", "Wavy", "Wavy", 4),
353 ("5", "Bump", "Bump", 5),
354 ("6", "Dots", "Dots", 6),
355 ("7", "Rings", "Rings", 7),
356 ("8", "Spiral", "Spiral", 8),
357 ("9", "Square", "Square", 9),
358 ("10", "Blocks", "Blocks", 10),
359 ("11", "Grid", "Grid", 11),
360 ("12", "Tech", "Tech", 12),
361 ("13", "Crackle", "Crackle", 13),
362 ("14", "Cracks", "Cracks", 14),
363 ("15", "Rock", "Rock noise", 15),
364 ("16", "Lunar", "Craters", 16),
365 ("17", "Cosine", "Cosine", 17),
366 ("18", "Spikey", "Spikey", 18),
367 ("19", "Stone", "Stone", 19),
368 ("20", "Flat Turb", "Flat turbulence", 20),
369 ("21", "Flat Voronoi", "Flat voronoi", 21)
372 fx_bias: EnumProperty(
373 name="Effect Bias",
374 default="0",
375 description="Effect bias type",
376 items=[
377 ("0", "Sin", "Sin", 0),
378 ("1", "Cos", "Cos", 1),
379 ("2", "Tri", "Tri", 2),
380 ("3", "Saw", "Saw", 3),
381 ("4", "None", "None", 4)]
383 fx_turb: FloatProperty(
384 name="Distortion",
385 default=0.0,
386 min=0.0,
387 max=1000.0,
388 description="Effect turbulence distortion"
390 fx_depth: IntProperty(
391 name="Depth",
392 default=0,
393 min=0,
394 max=16,
395 description="Effect depth - number of frequencies"
397 fx_amplitude: FloatProperty(
398 name="Amp",
399 default=0.5,
400 min=0.01,
401 max=1.0,
402 description="Amplitude"
404 fx_frequency: FloatProperty(
405 name="Freq",
406 default=2.0,
407 min=0.01,
408 max=5.0,
409 description="Frequency"
411 fx_size: FloatProperty(
412 name="Effect Size",
413 default=1.0,
414 min=0.01,
415 max=1000.0,
416 description="Effect size"
418 fx_loc_x: FloatProperty(
419 name="Offset X",
420 default=0.0,
421 description="Effect x offset"
423 fx_loc_y: FloatProperty(
424 name="Offset Y",
425 default=0.0,
426 description="Effect y offset"
428 fx_height: FloatProperty(
429 name="Intensity",
430 default=1.0,
431 min=-1000.0,
432 max=1000.0,
433 description="Effect intensity scale"
435 fx_invert: BoolProperty(
436 name="Invert",
437 default=False,
438 description="Effect invert"
440 fx_offset: FloatProperty(
441 name="Offset",
442 default=0.0,
443 min=-1000.0,
444 max=1000.0,
445 description="Effect height offset"
448 edge_falloff: EnumProperty(
449 name="Falloff",
450 default="3",
451 description="Flatten edges",
452 items=[
453 ("0", "None", "None", 0),
454 ("1", "Y", "Y Falloff", 1),
455 ("2", "X", "X Falloff", 2),
456 ("3", "X Y", "X Y Falloff", 3)]
458 falloff_x: FloatProperty(
459 name="Falloff X",
460 default=4.0,
461 min=0.1,
462 max=100.0,
463 description="Falloff x scale"
465 falloff_y: FloatProperty(
466 name="Falloff Y",
467 default=4.0,
468 min=0.1,
469 max=100.0,
470 description="Falloff y scale"
472 edge_level: FloatProperty(
473 name="Edge Level",
474 default=0.0,
475 min=-10000.0,
476 max=10000.0,
477 description="Edge level, sealevel offset"
479 maximum: FloatProperty(
480 name="Maximum",
481 default=1.0,
482 min=-10000.0,
483 max=10000.0,
484 description="Maximum, flattens terrain at plateau level"
486 minimum: FloatProperty(
487 name="Minimum",
488 default=-1.0,
489 min=-10000.0,
490 max=10000.0,
491 description="Minimum, flattens terrain at seabed level"
493 vert_group: StringProperty(
494 name="Vertex Group",
495 default=""
497 strata: FloatProperty(
498 name="Amount",
499 default=5.0,
500 min=0.01,
501 max=1000.0,
502 description="Strata layers / terraces"
504 strata_type: EnumProperty(
505 name="Strata",
506 default="0",
507 description="Strata types",
508 items=[
509 ("0", "None", "No strata", 0),
510 ("1", "Smooth", "Smooth transitions", 1),
511 ("2", "Sharp Sub", "Sharp subtract transitions", 2),
512 ("3", "Sharp Add", "Sharp add transitions", 3),
513 ("4", "Quantize", "Quantize", 4),
514 ("5", "Quantize Mix", "Quantize mixed", 5)]
516 water_plane: BoolProperty(
517 name="Water Plane",
518 default=False,
519 description="Add water plane"
521 water_level: FloatProperty(
522 name="Level",
523 default=0.01,
524 min=-10000.0,
525 max=10000.0,
526 description="Water level"
528 remove_double: BoolProperty(
529 name="Remove Doubles",
530 default=False,
531 description="Remove doubles"
533 show_main_settings: BoolProperty(
534 name="Main Settings",
535 default=True,
536 description="Show settings"
538 show_noise_settings: BoolProperty(
539 name="Noise Settings",
540 default=True,
541 description="Show noise settings"
543 show_displace_settings: BoolProperty(
544 name="Displace Settings",
545 default=True,
546 description="Show displace settings"
548 refresh: BoolProperty(
549 name="Refresh",
550 default=False,
551 description="Refresh"
553 auto_refresh: BoolProperty(
554 name="Auto",
555 default=True,
556 description="Automatic refresh"
559 @classmethod
560 def poll(self, context):
561 ob = context.object
562 if ob is not None:
563 if ob.mode == 'EDIT':
564 return False
565 return True
567 def draw(self, context):
568 draw_ant_refresh(self, context)
569 draw_ant_main(self, context, generate=True)
570 draw_ant_noise(self, context)
571 draw_ant_displace(self, context, generate=True)
572 draw_ant_water(self, context)
574 def invoke(self, context, event):
575 self.refresh = True
576 return self.execute(context)
578 def execute(self, context):
579 if not self.refresh:
580 return {'PASS_THROUGH'}
582 # turn off 'Enter Edit Mode'
583 use_enter_edit_mode = bpy.context.preferences.edit.use_enter_edit_mode
584 bpy.context.preferences.edit.use_enter_edit_mode = False
586 # deselect all objects when in object mode
587 if bpy.ops.object.select_all.poll():
588 bpy.ops.object.select_all(action='DESELECT')
590 # Properties
591 ant_props = [
592 self.ant_terrain_name,
593 self.at_cursor,
594 self.smooth_mesh,
595 self.tri_face,
596 self.sphere_mesh,
597 self.land_material,
598 self.water_material,
599 self.texture_block,
600 self.subdivision_x,
601 self.subdivision_y,
602 self.mesh_size_x,
603 self.mesh_size_y,
604 self.mesh_size,
605 self.random_seed,
606 self.noise_offset_x,
607 self.noise_offset_y,
608 self.noise_offset_z,
609 self.noise_size_x,
610 self.noise_size_y,
611 self.noise_size_z,
612 self.noise_size,
613 self.noise_type,
614 self.basis_type,
615 self.vl_basis_type,
616 self.distortion,
617 self.hard_noise,
618 self.noise_depth,
619 self.amplitude,
620 self.frequency,
621 self.dimension,
622 self.lacunarity,
623 self.offset,
624 self.gain,
625 self.marble_bias,
626 self.marble_sharp,
627 self.marble_shape,
628 self.height,
629 self.height_invert,
630 self.height_offset,
631 self.maximum,
632 self.minimum,
633 self.edge_falloff,
634 self.edge_level,
635 self.falloff_x,
636 self.falloff_y,
637 self.strata_type,
638 self.strata,
639 self.water_plane,
640 self.water_level,
641 self.vert_group,
642 self.remove_double,
643 self.fx_mixfactor,
644 self.fx_mix_mode,
645 self.fx_type,
646 self.fx_bias,
647 self.fx_turb,
648 self.fx_depth,
649 self.fx_frequency,
650 self.fx_amplitude,
651 self.fx_size,
652 self.fx_loc_x,
653 self.fx_loc_y,
654 self.fx_height,
655 self.fx_offset,
656 self.fx_invert
659 scene = context.scene
660 vl = context.view_layer
662 # Main function, create landscape mesh object
663 if self.ant_terrain_name != "":
664 new_name = self.ant_terrain_name
665 else:
666 new_name = "Landscape"
668 if self.sphere_mesh:
669 # sphere
670 verts, faces = sphere_gen(
671 self.subdivision_y,
672 self.subdivision_x,
673 self.tri_face,
674 self.mesh_size,
675 ant_props,
676 False,
677 0.0,
679 new_ob = create_mesh_object(context, verts, [], faces, new_name)
680 if self.remove_double:
681 new_ob.select_set(True)
682 bpy.ops.object.mode_set(mode='EDIT')
683 bpy.ops.mesh.remove_doubles(threshold=0.0001, use_unselected=False)
684 bpy.ops.object.mode_set(mode='OBJECT')
685 else:
686 # grid
687 verts, faces = grid_gen(
688 self.subdivision_x,
689 self.subdivision_y,
690 self.tri_face,
691 self.mesh_size_x,
692 self.mesh_size_y,
693 ant_props,
694 False,
695 0.0,
697 new_ob = create_mesh_object(context, verts, [], faces, new_name)
699 new_ob.select_set(True)
701 if self.smooth_mesh:
702 bpy.ops.object.shade_smooth()
703 else:
704 bpy.ops.object.shade_flat()
706 if not self.at_cursor:
707 new_ob.location = (0.0, 0.0, 0.0)
709 # Landscape Material
710 if self.land_material != "" and self.land_material in bpy.data.materials:
711 mat = bpy.data.materials[self.land_material]
712 bpy.context.object.data.materials.append(mat)
714 # Water plane
715 if self.water_plane:
716 if self.sphere_mesh:
717 # sphere
718 verts, faces = sphere_gen(
719 self.subdivision_y,
720 self.subdivision_x,
721 self.tri_face,
722 self.mesh_size,
723 ant_props,
724 self.water_plane,
725 self.water_level,
727 wobj = create_mesh_object(context, verts, [], faces, new_name + "_plane")
728 if self.remove_double:
729 wobj.select_set(True)
730 bpy.ops.object.mode_set(mode='EDIT')
731 bpy.ops.mesh.remove_doubles(threshold=0.0001, use_unselected=False)
732 bpy.ops.object.mode_set(mode='OBJECT')
733 else:
734 # grid
735 verts, faces = grid_gen(
738 self.tri_face,
739 self.mesh_size_x,
740 self.mesh_size_y,
741 ant_props,
742 self.water_plane,
743 self.water_level,
745 wobj = create_mesh_object(context, verts, [], faces, new_name + "_plane")
747 wobj.select_set(True)
749 if self.smooth_mesh:
750 bpy.ops.object.shade_smooth()
751 else:
752 bpy.ops.object.shade_flat()
754 if not self.at_cursor:
755 wobj.location = (0.0, 0.0, 0.0)
757 # Water Material
758 if self.water_material != "" and self.water_material in bpy.data.materials:
759 mat = bpy.data.materials[self.water_material]
760 bpy.context.object.data.materials.append(mat)
762 # select landscape and make active
763 new_ob.select_set(True)
764 vl.objects.active = new_ob
766 new_ob = store_properties(self, new_ob)
768 if self.auto_refresh is False:
769 self.refresh = False
771 # restore pre operator state
772 bpy.context.preferences.edit.use_enter_edit_mode = use_enter_edit_mode
774 return {'FINISHED'}