1 # SPDX-FileCopyrightText: 2017-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 # Another Noise Tool - Add Landscape
10 from bpy
.props
import (
19 from .ant_functions
import (
31 from ant_landscape
import ant_noise
33 # ------------------------------------------------------------
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(
47 land_material
: StringProperty(
50 description
="Terrain material"
52 water_material
: StringProperty(
55 description
="Water plane material"
57 texture_block
: StringProperty(
61 at_cursor
: BoolProperty(
64 description
="Place at cursor location",
66 smooth_mesh
: BoolProperty(
69 description
="Shade smooth"
71 tri_face
: BoolProperty(
74 description
="Triangulate faces"
76 sphere_mesh
: BoolProperty(
79 description
="Generate uv sphere - remove doubles when ready"
81 subdivision_x
: IntProperty(
82 name
="Subdivisions X",
86 description
="Mesh X subdivisions"
88 subdivision_y
: IntProperty(
90 name
="Subdivisions Y",
93 description
="Mesh Y subdivisions"
95 mesh_size
: FloatProperty(
100 description
="Mesh size"
102 mesh_size_x
: FloatProperty(
106 description
="Mesh x size"
108 mesh_size_y
: FloatProperty(
112 description
="Mesh y size"
115 random_seed
: IntProperty(
119 description
="Randomize noise origin"
121 noise_offset_x
: FloatProperty(
124 description
="Noise X Offset"
126 noise_offset_y
: FloatProperty(
129 description
="Noise Y Offset"
131 noise_offset_z
: FloatProperty(
134 description
="Noise Z Offset"
136 noise_size_x
: FloatProperty(
141 description
="Noise x size"
143 noise_size_y
: FloatProperty(
148 description
="Noise y size"
150 noise_size_z
: FloatProperty(
155 description
="Noise Z size"
157 noise_size
: FloatProperty(
162 description
="Noise size"
164 noise_type
: EnumProperty(
166 default
='hetero_terrain',
167 description
="Noise type",
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(
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(
206 description
="Distortion amount"
208 hard_noise
: EnumProperty(
211 description
="Soft Noise, Hard noise",
213 ("0", "Soft", "Soft Noise", 0),
214 ("1", "Hard", "Hard noise", 1)]
216 noise_depth
: IntProperty(
221 description
="Noise Depth - number of frequencies in the fBm"
223 amplitude
: FloatProperty(
228 description
="Amplitude"
230 frequency
: FloatProperty(
235 description
="Frequency"
237 dimension
: FloatProperty(
242 description
="H - fractal dimension of the roughest areas"
244 lacunarity
: FloatProperty(
249 description
="Lacunarity - gap between successive frequencies"
251 offset
: FloatProperty(
256 description
="Offset - raises the terrain from sea level"
263 description
="Gain - scale factor"
265 marble_bias
: EnumProperty(
268 description
="Marble bias",
270 ("0", "Sin", "Sin", 0),
271 ("1", "Cos", "Cos", 1),
272 ("2", "Tri", "Tri", 2),
273 ("3", "Saw", "Saw", 3)]
275 marble_sharp
: EnumProperty(
278 description
="Marble sharpness",
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(
290 description
="Marble shape",
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),
301 height
: FloatProperty(
306 description
="Noise intensity scale"
308 height_invert
: BoolProperty(
311 description
="Height invert",
313 height_offset
: FloatProperty(
318 description
="Height offset"
320 fx_mixfactor
: FloatProperty(
325 description
="Effect mix factor: -1.0 = Noise, +1.0 = Effect"
327 fx_mix_mode
: EnumProperty(
330 description
="Effect mix mode",
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(
346 description
="Effect type",
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(
375 description
="Effect bias type",
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(
388 description
="Effect turbulence distortion"
390 fx_depth
: IntProperty(
395 description
="Effect depth - number of frequencies"
397 fx_amplitude
: FloatProperty(
402 description
="Amplitude"
404 fx_frequency
: FloatProperty(
409 description
="Frequency"
411 fx_size
: FloatProperty(
416 description
="Effect size"
418 fx_loc_x
: FloatProperty(
421 description
="Effect x offset"
423 fx_loc_y
: FloatProperty(
426 description
="Effect y offset"
428 fx_height
: FloatProperty(
433 description
="Effect intensity scale"
435 fx_invert
: BoolProperty(
438 description
="Effect invert"
440 fx_offset
: FloatProperty(
445 description
="Effect height offset"
448 edge_falloff
: EnumProperty(
451 description
="Flatten edges",
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(
463 description
="Falloff x scale"
465 falloff_y
: FloatProperty(
470 description
="Falloff y scale"
472 edge_level
: FloatProperty(
477 description
="Edge level, sealevel offset"
479 maximum
: FloatProperty(
484 description
="Maximum, flattens terrain at plateau level"
486 minimum
: FloatProperty(
491 description
="Minimum, flattens terrain at seabed level"
493 vert_group
: StringProperty(
497 strata
: FloatProperty(
502 description
="Strata layers / terraces"
504 strata_type
: EnumProperty(
507 description
="Strata types",
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(
519 description
="Add water plane"
521 water_level
: FloatProperty(
526 description
="Water level"
528 remove_double
: BoolProperty(
529 name
="Remove Doubles",
531 description
="Remove doubles"
533 show_main_settings
: BoolProperty(
534 name
="Main Settings",
536 description
="Show settings"
538 show_noise_settings
: BoolProperty(
539 name
="Noise Settings",
541 description
="Show noise settings"
543 show_displace_settings
: BoolProperty(
544 name
="Displace Settings",
546 description
="Show displace settings"
548 refresh
: BoolProperty(
551 description
="Refresh"
553 auto_refresh
: BoolProperty(
556 description
="Automatic refresh"
560 def poll(self
, context
):
563 if ob
.mode
== 'EDIT':
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
):
576 return self
.execute(context
)
578 def execute(self
, context
):
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')
592 self
.ant_terrain_name
,
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
666 new_name
= "Landscape"
670 verts
, faces
= sphere_gen(
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')
687 verts
, faces
= grid_gen(
697 new_ob
= create_mesh_object(context
, verts
, [], faces
, new_name
)
699 new_ob
.select_set(True)
702 bpy
.ops
.object.shade_smooth()
704 bpy
.ops
.object.shade_flat()
706 if not self
.at_cursor
:
707 new_ob
.location
= (0.0, 0.0, 0.0)
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
)
718 verts
, faces
= sphere_gen(
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')
735 verts
, faces
= grid_gen(
745 wobj
= create_mesh_object(context
, verts
, [], faces
, new_name
+ "_plane")
747 wobj
.select_set(True)
750 bpy
.ops
.object.shade_smooth()
752 bpy
.ops
.object.shade_flat()
754 if not self
.at_cursor
:
755 wobj
.location
= (0.0, 0.0, 0.0)
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:
771 # restore pre operator state
772 bpy
.context
.preferences
.edit
.use_enter_edit_mode
= use_enter_edit_mode