1 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Another Noise Tool - Add Landscape
8 from bpy
.props
import (
17 from .ant_functions
import (
29 from ant_landscape
import ant_noise
31 # ------------------------------------------------------------
35 class AntAddLandscape(bpy
.types
.Operator
):
36 bl_idname
= "mesh.landscape_add"
37 bl_label
= "Another Noise Tool - Landscape"
38 bl_description
= "Add landscape mesh"
39 bl_options
= {'REGISTER', 'UNDO', 'PRESET'}
41 ant_terrain_name
: StringProperty(
45 land_material
: StringProperty(
48 description
="Terrain material"
50 water_material
: StringProperty(
53 description
="Water plane material"
55 texture_block
: StringProperty(
59 at_cursor
: BoolProperty(
62 description
="Place at cursor location",
64 smooth_mesh
: BoolProperty(
67 description
="Shade smooth"
69 tri_face
: BoolProperty(
72 description
="Triangulate faces"
74 sphere_mesh
: BoolProperty(
77 description
="Generate uv sphere - remove doubles when ready"
79 subdivision_x
: IntProperty(
80 name
="Subdivisions X",
84 description
="Mesh X subdivisions"
86 subdivision_y
: IntProperty(
88 name
="Subdivisions Y",
91 description
="Mesh Y subdivisions"
93 mesh_size
: FloatProperty(
98 description
="Mesh size"
100 mesh_size_x
: FloatProperty(
104 description
="Mesh x size"
106 mesh_size_y
: FloatProperty(
110 description
="Mesh y size"
113 random_seed
: IntProperty(
117 description
="Randomize noise origin"
119 noise_offset_x
: FloatProperty(
122 description
="Noise X Offset"
124 noise_offset_y
: FloatProperty(
127 description
="Noise Y Offset"
129 noise_offset_z
: FloatProperty(
132 description
="Noise Z Offset"
134 noise_size_x
: FloatProperty(
139 description
="Noise x size"
141 noise_size_y
: FloatProperty(
146 description
="Noise y size"
148 noise_size_z
: FloatProperty(
153 description
="Noise Z size"
155 noise_size
: FloatProperty(
160 description
="Noise size"
162 noise_type
: EnumProperty(
164 default
='hetero_terrain',
165 description
="Noise type",
167 ('multi_fractal', "Multi Fractal", "Blender: Multi Fractal algorithm", 0),
168 ('ridged_multi_fractal', "Ridged MFractal", "Blender: Ridged Multi Fractal", 1),
169 ('hybrid_multi_fractal', "Hybrid MFractal", "Blender: Hybrid Multi Fractal", 2),
170 ('hetero_terrain', "Hetero Terrain", "Blender: Hetero Terrain", 3),
171 ('fractal', "fBm Fractal", "Blender: fBm - Fractional Browninian motion", 4),
172 ('turbulence_vector', "Turbulence", "Blender: Turbulence Vector", 5),
173 ('variable_lacunarity', "Distorted Noise", "Blender: Distorted Noise", 6),
174 ('marble_noise', "Marble", "A.N.T.: Marble Noise", 7),
175 ('shattered_hterrain', "Shattered hTerrain", "A.N.T.: Shattered hTerrain", 8),
176 ('strata_hterrain', "Strata hTerrain", "A.N.T: Strata hTerrain", 9),
177 ('ant_turbulence', "Another Noise", "A.N.T: Turbulence variation", 10),
178 ('vl_noise_turbulence', "vlNoise turbulence", "A.N.T: Real vlNoise turbulence", 11),
179 ('vl_hTerrain', "vlNoise hTerrain", "A.N.T: vlNoise hTerrain", 12),
180 ('distorted_heteroTerrain', "Distorted hTerrain", "A.N.T distorted hTerrain", 13),
181 ('double_multiFractal', "Double MultiFractal", "A.N.T: double multiFractal", 14),
182 ('rocks_noise', "Noise Rocks", "A.N.T: turbulence variation", 15),
183 ('slick_rock', "Slick Rock", "A.N.T: slick rock", 16),
184 ('planet_noise', "Planet Noise", "Planet Noise by: Farsthary", 17),
185 ('blender_texture', "Blender Texture - Texture Nodes", "Blender texture data block", 18)]
187 basis_type
: EnumProperty(
189 default
=ant_noise
.noise_basis_default
,
190 description
="Noise basis algorithms",
191 items
=ant_noise
.noise_basis
193 vl_basis_type
: EnumProperty(
194 name
="vlNoise Basis",
195 default
=ant_noise
.noise_basis_default
,
196 description
="VLNoise basis algorithms",
197 items
=ant_noise
.noise_basis
199 distortion
: FloatProperty(
204 description
="Distortion amount"
206 hard_noise
: EnumProperty(
209 description
="Soft Noise, Hard noise",
211 ("0", "Soft", "Soft Noise", 0),
212 ("1", "Hard", "Hard noise", 1)]
214 noise_depth
: IntProperty(
219 description
="Noise Depth - number of frequencies in the fBm"
221 amplitude
: FloatProperty(
226 description
="Amplitude"
228 frequency
: FloatProperty(
233 description
="Frequency"
235 dimension
: FloatProperty(
240 description
="H - fractal dimension of the roughest areas"
242 lacunarity
: FloatProperty(
247 description
="Lacunarity - gap between successive frequencies"
249 offset
: FloatProperty(
254 description
="Offset - raises the terrain from sea level"
261 description
="Gain - scale factor"
263 marble_bias
: EnumProperty(
266 description
="Marble bias",
268 ("0", "Sin", "Sin", 0),
269 ("1", "Cos", "Cos", 1),
270 ("2", "Tri", "Tri", 2),
271 ("3", "Saw", "Saw", 3)]
273 marble_sharp
: EnumProperty(
276 description
="Marble sharpness",
278 ("0", "Soft", "Soft", 0),
279 ("1", "Sharp", "Sharp", 1),
280 ("2", "Sharper", "Sharper", 2),
281 ("3", "Soft inv.", "Soft", 3),
282 ("4", "Sharp inv.", "Sharp", 4),
283 ("5", "Sharper inv.", "Sharper", 5)]
285 marble_shape
: EnumProperty(
288 description
="Marble shape",
290 ("0", "Default", "Default", 0),
291 ("1", "Ring", "Ring", 1),
292 ("2", "Swirl", "Swirl", 2),
293 ("3", "Bump", "Bump", 3),
294 ("4", "Wave", "Wave", 4),
299 height
: FloatProperty(
304 description
="Noise intensity scale"
306 height_invert
: BoolProperty(
309 description
="Height invert",
311 height_offset
: FloatProperty(
316 description
="Height offset"
318 fx_mixfactor
: FloatProperty(
323 description
="Effect mix factor: -1.0 = Noise, +1.0 = Effect"
325 fx_mix_mode
: EnumProperty(
328 description
="Effect mix mode",
330 ("0", "Mix", "Mix", 0),
331 ("1", "Add", "Add", 1),
332 ("2", "Sub", "Subtract", 2),
333 ("3", "Mul", "Multiply", 3),
334 ("4", "Abs", "Absolute", 4),
335 ("5", "Scr", "Screen", 5),
336 ("6", "Mod", "Modulo", 6),
337 ("7", "Min", "Minimum", 7),
338 ("8", "Max", "Maximum", 8)
341 fx_type
: EnumProperty(
344 description
="Effect type",
346 ("0", "None", "No effect", 0),
347 ("1", "Gradient", "Gradient", 1),
348 ("2", "Waves", "Waves - Bumps", 2),
349 ("3", "Zigzag", "Zigzag", 3),
350 ("4", "Wavy", "Wavy", 4),
351 ("5", "Bump", "Bump", 5),
352 ("6", "Dots", "Dots", 6),
353 ("7", "Rings", "Rings", 7),
354 ("8", "Spiral", "Spiral", 8),
355 ("9", "Square", "Square", 9),
356 ("10", "Blocks", "Blocks", 10),
357 ("11", "Grid", "Grid", 11),
358 ("12", "Tech", "Tech", 12),
359 ("13", "Crackle", "Crackle", 13),
360 ("14", "Cracks", "Cracks", 14),
361 ("15", "Rock", "Rock noise", 15),
362 ("16", "Lunar", "Craters", 16),
363 ("17", "Cosine", "Cosine", 17),
364 ("18", "Spikey", "Spikey", 18),
365 ("19", "Stone", "Stone", 19),
366 ("20", "Flat Turb", "Flat turbulence", 20),
367 ("21", "Flat Voronoi", "Flat voronoi", 21)
370 fx_bias
: EnumProperty(
373 description
="Effect bias type",
375 ("0", "Sin", "Sin", 0),
376 ("1", "Cos", "Cos", 1),
377 ("2", "Tri", "Tri", 2),
378 ("3", "Saw", "Saw", 3),
379 ("4", "None", "None", 4)]
381 fx_turb
: FloatProperty(
386 description
="Effect turbulence distortion"
388 fx_depth
: IntProperty(
393 description
="Effect depth - number of frequencies"
395 fx_amplitude
: FloatProperty(
400 description
="Amplitude"
402 fx_frequency
: FloatProperty(
407 description
="Frequency"
409 fx_size
: FloatProperty(
414 description
="Effect size"
416 fx_loc_x
: FloatProperty(
419 description
="Effect x offset"
421 fx_loc_y
: FloatProperty(
424 description
="Effect y offset"
426 fx_height
: FloatProperty(
431 description
="Effect intensity scale"
433 fx_invert
: BoolProperty(
436 description
="Effect invert"
438 fx_offset
: FloatProperty(
443 description
="Effect height offset"
446 edge_falloff
: EnumProperty(
449 description
="Flatten edges",
451 ("0", "None", "None", 0),
452 ("1", "Y", "Y Falloff", 1),
453 ("2", "X", "X Falloff", 2),
454 ("3", "X Y", "X Y Falloff", 3)]
456 falloff_x
: FloatProperty(
461 description
="Falloff x scale"
463 falloff_y
: FloatProperty(
468 description
="Falloff y scale"
470 edge_level
: FloatProperty(
475 description
="Edge level, sealevel offset"
477 maximum
: FloatProperty(
482 description
="Maximum, flattens terrain at plateau level"
484 minimum
: FloatProperty(
489 description
="Minimum, flattens terrain at seabed level"
491 vert_group
: StringProperty(
495 strata
: FloatProperty(
500 description
="Strata layers / terraces"
502 strata_type
: EnumProperty(
505 description
="Strata types",
507 ("0", "None", "No strata", 0),
508 ("1", "Smooth", "Smooth transitions", 1),
509 ("2", "Sharp Sub", "Sharp subtract transitions", 2),
510 ("3", "Sharp Add", "Sharp add transitions", 3),
511 ("4", "Quantize", "Quantize", 4),
512 ("5", "Quantize Mix", "Quantize mixed", 5)]
514 water_plane
: BoolProperty(
517 description
="Add water plane"
519 water_level
: FloatProperty(
524 description
="Water level"
526 remove_double
: BoolProperty(
527 name
="Remove Doubles",
529 description
="Remove doubles"
531 show_main_settings
: BoolProperty(
532 name
="Main Settings",
534 description
="Show settings"
536 show_noise_settings
: BoolProperty(
537 name
="Noise Settings",
539 description
="Show noise settings"
541 show_displace_settings
: BoolProperty(
542 name
="Displace Settings",
544 description
="Show displace settings"
546 refresh
: BoolProperty(
549 description
="Refresh"
551 auto_refresh
: BoolProperty(
554 description
="Automatic refresh"
558 def poll(self
, context
):
561 if ob
.mode
== 'EDIT':
565 def draw(self
, context
):
566 draw_ant_refresh(self
, context
)
567 draw_ant_main(self
, context
, generate
=True)
568 draw_ant_noise(self
, context
)
569 draw_ant_displace(self
, context
, generate
=True)
570 draw_ant_water(self
, context
)
572 def invoke(self
, context
, event
):
574 return self
.execute(context
)
576 def execute(self
, context
):
578 return {'PASS_THROUGH'}
580 # turn off 'Enter Edit Mode'
581 use_enter_edit_mode
= bpy
.context
.preferences
.edit
.use_enter_edit_mode
582 bpy
.context
.preferences
.edit
.use_enter_edit_mode
= False
584 # deselect all objects when in object mode
585 if bpy
.ops
.object.select_all
.poll():
586 bpy
.ops
.object.select_all(action
='DESELECT')
590 self
.ant_terrain_name
,
657 scene
= context
.scene
658 vl
= context
.view_layer
660 # Main function, create landscape mesh object
661 if self
.ant_terrain_name
!= "":
662 new_name
= self
.ant_terrain_name
664 new_name
= "Landscape"
668 verts
, faces
= sphere_gen(
677 new_ob
= create_mesh_object(context
, verts
, [], faces
, new_name
)
678 if self
.remove_double
:
679 new_ob
.select_set(True)
680 bpy
.ops
.object.mode_set(mode
='EDIT')
681 bpy
.ops
.mesh
.remove_doubles(threshold
=0.0001, use_unselected
=False)
682 bpy
.ops
.object.mode_set(mode
='OBJECT')
685 verts
, faces
= grid_gen(
695 new_ob
= create_mesh_object(context
, verts
, [], faces
, new_name
)
697 new_ob
.select_set(True)
700 bpy
.ops
.object.shade_smooth()
702 if not self
.at_cursor
:
703 new_ob
.location
= (0.0, 0.0, 0.0)
706 if self
.land_material
!= "" and self
.land_material
in bpy
.data
.materials
:
707 mat
= bpy
.data
.materials
[self
.land_material
]
708 bpy
.context
.object.data
.materials
.append(mat
)
714 verts
, faces
= sphere_gen(
723 wobj
= create_mesh_object(context
, verts
, [], faces
, new_name
+ "_plane")
724 if self
.remove_double
:
725 wobj
.select_set(True)
726 bpy
.ops
.object.mode_set(mode
='EDIT')
727 bpy
.ops
.mesh
.remove_doubles(threshold
=0.0001, use_unselected
=False)
728 bpy
.ops
.object.mode_set(mode
='OBJECT')
731 verts
, faces
= grid_gen(
741 wobj
= create_mesh_object(context
, verts
, [], faces
, new_name
+ "_plane")
743 wobj
.select_set(True)
746 bpy
.ops
.object.shade_smooth()
748 if not self
.at_cursor
:
749 wobj
.location
= (0.0, 0.0, 0.0)
752 if self
.water_material
!= "" and self
.water_material
in bpy
.data
.materials
:
753 mat
= bpy
.data
.materials
[self
.water_material
]
754 bpy
.context
.object.data
.materials
.append(mat
)
756 # select landscape and make active
757 new_ob
.select_set(True)
758 vl
.objects
.active
= new_ob
760 new_ob
= store_properties(self
, new_ob
)
762 if self
.auto_refresh
is False:
765 # restore pre operator state
766 bpy
.context
.preferences
.edit
.use_enter_edit_mode
= use_enter_edit_mode