1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 # Another Noise Tool - Add Landscape
24 from bpy
.props
import (
33 from .ant_functions
import (
45 # ------------------------------------------------------------
47 class AntAddLandscape(bpy
.types
.Operator
):
48 bl_idname
= "mesh.landscape_add"
49 bl_label
= "Another Noise Tool - Landscape"
50 bl_description
= "Add landscape mesh"
51 bl_options
= {'REGISTER', 'UNDO', 'PRESET'}
53 ant_terrain_name
= StringProperty(
57 land_material
= StringProperty(
60 description
="Terrain material"
62 water_material
= StringProperty(
65 description
="Water plane material"
67 texture_block
= StringProperty(
71 at_cursor
= BoolProperty(
74 description
="Place at cursor location",
76 smooth_mesh
= BoolProperty(
79 description
="Shade smooth"
81 tri_face
= BoolProperty(
84 description
="Triangulate faces"
86 sphere_mesh
= BoolProperty(
89 description
="Generate uv sphere - remove doubles when ready"
91 subdivision_x
= IntProperty(
92 name
="Subdivisions X",
96 description
="Mesh X subdivisions"
98 subdivision_y
= IntProperty(
100 name
="Subdivisions Y",
103 description
="Mesh Y subdivisions"
105 mesh_size
= FloatProperty(
110 description
="Mesh size"
112 mesh_size_x
= FloatProperty(
116 description
="Mesh x size"
118 mesh_size_y
= FloatProperty(
122 description
="Mesh y size"
125 random_seed
= IntProperty(
129 description
="Randomize noise origin"
131 noise_offset_x
= FloatProperty(
134 description
="Noise X Offset"
136 noise_offset_y
= FloatProperty(
139 description
="Noise Y Offset"
141 noise_offset_z
= FloatProperty(
144 description
="Noise Z Offset"
146 noise_size_x
= FloatProperty(
151 description
="Noise x size"
153 noise_size_y
= FloatProperty(
158 description
="Noise y size"
160 noise_size_z
= FloatProperty(
165 description
="Noise Z size"
167 noise_size
= FloatProperty(
172 description
="Noise size"
174 noise_type
= EnumProperty(
176 default
='hetero_terrain',
177 description
="Noise type",
179 ('multi_fractal', "Multi Fractal", "Blender: Multi Fractal algorithm", 0),
180 ('ridged_multi_fractal', "Ridged MFractal", "Blender: Ridged Multi Fractal", 1),
181 ('hybrid_multi_fractal', "Hybrid MFractal", "Blender: Hybrid Multi Fractal", 2),
182 ('hetero_terrain', "Hetero Terrain", "Blender: Hetero Terrain", 3),
183 ('fractal', "fBm Fractal", "Blender: fBm - Fractional Browninian motion", 4),
184 ('turbulence_vector', "Turbulence", "Blender: Turbulence Vector", 5),
185 ('variable_lacunarity', "Distorted Noise", "Blender: Distorted Noise", 6),
186 ('marble_noise', "Marble", "A.N.T.: Marble Noise", 7),
187 ('shattered_hterrain', "Shattered hTerrain", "A.N.T.: Shattered hTerrain", 8),
188 ('strata_hterrain', "Strata hTerrain", "A.N.T: Strata hTerrain", 9),
189 ('ant_turbulence', "Another Noise", "A.N.T: Turbulence variation", 10),
190 ('vl_noise_turbulence', "vlNoise turbulence", "A.N.T: Real vlNoise turbulence", 11),
191 ('vl_hTerrain', "vlNoise hTerrain", "A.N.T: vlNoise hTerrain", 12),
192 ('distorted_heteroTerrain', "Distorted hTerrain", "A.N.T distorted hTerrain", 13),
193 ('double_multiFractal', "Double MultiFractal", "A.N.T: double multiFractal", 14),
194 ('rocks_noise', "Noise Rocks", "A.N.T: turbulence variation", 15),
195 ('slick_rock', "Slick Rock", "A.N.T: slick rock", 16),
196 ('planet_noise', "Planet Noise", "Planet Noise by: Farsthary", 17),
197 ('blender_texture', "Blender Texture - Texture Nodes", "Blender texture data block", 18)]
199 basis_type
= EnumProperty(
202 description
="Noise basis algorithms",
204 ("0", "Blender", "Blender default noise", 0),
205 ("1", "Perlin", "Perlin noise", 1),
206 ("2", "New Perlin", "New Perlin noise", 2),
207 ("3", "Voronoi F1", "Voronoi F1", 3),
208 ("4", "Voronoi F2", "Voronoi F2", 4),
209 ("5", "Voronoi F3", "Voronoi F3", 5),
210 ("6", "Voronoi F4", "Voronoi F4", 6),
211 ("7", "Voronoi F2-F1", "Voronoi F2-F1", 7),
212 ("8", "Voronoi Crackle", "Voronoi Crackle", 8),
213 ("9", "Cell Noise", "Cell noise", 9)]
215 vl_basis_type
= EnumProperty(
216 name
="vlNoise Basis",
218 description
="VLNoise basis algorithms",
220 ("0", "Blender", "Blender default noise", 0),
221 ("1", "Perlin", "Perlin noise", 1),
222 ("2", "New Perlin", "New Perlin noise", 2),
223 ("3", "Voronoi F1", "Voronoi F1", 3),
224 ("4", "Voronoi F2", "Voronoi F2", 4),
225 ("5", "Voronoi F3", "Voronoi F3", 5),
226 ("6", "Voronoi F4", "Voronoi F4", 6),
227 ("7", "Voronoi F2-F1", "Voronoi F2-F1", 7),
228 ("8", "Voronoi Crackle", "Voronoi Crackle", 8),
229 ("9", "Cell Noise", "Cell noise", 9)]
231 distortion
= FloatProperty(
236 description
="Distortion amount"
238 hard_noise
= EnumProperty(
241 description
="Soft Noise, Hard noise",
243 ("0", "Soft", "Soft Noise", 0),
244 ("1", "Hard", "Hard noise", 1)]
246 noise_depth
= IntProperty(
251 description
="Noise Depth - number of frequencies in the fBm"
253 amplitude
= FloatProperty(
258 description
="Amplitude"
260 frequency
= FloatProperty(
265 description
="Frequency"
267 dimension
= FloatProperty(
272 description
="H - fractal dimension of the roughest areas"
274 lacunarity
= FloatProperty(
279 description
="Lacunarity - gap between successive frequencies"
281 offset
= FloatProperty(
286 description
="Offset - raises the terrain from sea level"
288 gain
= FloatProperty(
293 description
="Gain - scale factor"
295 marble_bias
= EnumProperty(
298 description
="Marble bias",
300 ("0", "Sin", "Sin", 0),
301 ("1", "Cos", "Cos", 1),
302 ("2", "Tri", "Tri", 2),
303 ("3", "Saw", "Saw", 3)]
305 marble_sharp
= EnumProperty(
308 description
="Marble sharpness",
310 ("0", "Soft", "Soft", 0),
311 ("1", "Sharp", "Sharp", 1),
312 ("2", "Sharper", "Sharper", 2),
313 ("3", "Soft inv.", "Soft", 3),
314 ("4", "Sharp inv.", "Sharp", 4),
315 ("5", "Sharper inv.", "Sharper", 5)]
317 marble_shape
= EnumProperty(
320 description
="Marble shape",
322 ("0", "Default", "Default", 0),
323 ("1", "Ring", "Ring", 1),
324 ("2", "Swirl", "Swirl", 2),
325 ("3", "Bump", "Bump", 3),
326 ("4", "Wave", "Wave", 4),
331 height
= FloatProperty(
336 description
="Noise intensity scale"
338 height_invert
= BoolProperty(
341 description
="Height invert",
343 height_offset
= FloatProperty(
348 description
="Height offset"
350 fx_mixfactor
= FloatProperty(
355 description
="Effect mix factor: -1.0 = Noise, +1.0 = Effect"
357 fx_mix_mode
= EnumProperty(
360 description
="Effect mix mode",
362 ("0", "Mix", "Mix", 0),
363 ("1", "Add", "Add", 1),
364 ("2", "Sub", "Subtract", 2),
365 ("3", "Mul", "Multiply", 3),
366 ("4", "Abs", "Absolute", 4),
367 ("5", "Scr", "Screen", 5),
368 ("6", "Mod", "Modulo", 6),
369 ("7", "Min", "Minimum", 7),
370 ("8", "Max", "Maximum", 8)
373 fx_type
= EnumProperty(
376 description
="Effect type",
378 ("0", "None", "No effect", 0),
379 ("1", "Gradient", "Gradient", 1),
380 ("2", "Waves", "Waves - Bumps", 2),
381 ("3", "Zigzag", "Zigzag", 3),
382 ("4", "Wavy", "Wavy", 4),
383 ("5", "Bump", "Bump", 5),
384 ("6", "Dots", "Dots", 6),
385 ("7", "Rings", "Rings", 7),
386 ("8", "Spiral", "Spiral", 8),
387 ("9", "Square", "Square", 9),
388 ("10", "Blocks", "Blocks", 10),
389 ("11", "Grid", "Grid", 11),
390 ("12", "Tech", "Tech", 12),
391 ("13", "Crackle", "Crackle", 13),
392 ("14", "Cracks", "Cracks", 14),
393 ("15", "Rock", "Rock noise", 15),
394 ("16", "Lunar", "Craters", 16),
395 ("17", "Cosine", "Cosine", 17),
396 ("18", "Spikey", "Spikey", 18),
397 ("19", "Stone", "Stone", 19),
398 ("20", "Flat Turb", "Flat turbulence", 20),
399 ("21", "Flat Voronoi", "Flat voronoi", 21)
402 fx_bias
= EnumProperty(
405 description
="Effect bias type",
407 ("0", "Sin", "Sin", 0),
408 ("1", "Cos", "Cos", 1),
409 ("2", "Tri", "Tri", 2),
410 ("3", "Saw", "Saw", 3),
411 ("4", "None", "None", 4)]
413 fx_turb
= FloatProperty(
418 description
="Effect turbulence distortion"
420 fx_depth
= IntProperty(
425 description
="Effect depth - number of frequencies"
427 fx_amplitude
= FloatProperty(
432 description
="Amplitude"
434 fx_frequency
= FloatProperty(
439 description
="Frequency"
441 fx_size
= FloatProperty(
446 description
="Effect size"
448 fx_loc_x
= FloatProperty(
451 description
="Effect x offset"
453 fx_loc_y
= FloatProperty(
456 description
="Effect y offset"
458 fx_height
= FloatProperty(
463 description
="Effect intensity scale"
465 fx_invert
= BoolProperty(
468 description
="Effect invert"
470 fx_offset
= FloatProperty(
475 description
="Effect height offset"
478 edge_falloff
= EnumProperty(
481 description
="Flatten edges",
483 ("0", "None", "None", 0),
484 ("1", "Y", "Y Falloff", 1),
485 ("2", "X", "X Falloff", 2),
486 ("3", "X Y", "X Y Falloff", 3)]
488 falloff_x
= FloatProperty(
493 description
="Falloff x scale"
495 falloff_y
= FloatProperty(
500 description
="Falloff y scale"
502 edge_level
= FloatProperty(
507 description
="Edge level, sealevel offset"
509 maximum
= FloatProperty(
514 description
="Maximum, flattens terrain at plateau level"
516 minimum
= FloatProperty(
521 description
="Minimum, flattens terrain at seabed level"
523 vert_group
= StringProperty(
527 strata
= FloatProperty(
532 description
="Strata layers / terraces"
534 strata_type
= EnumProperty(
537 description
="Strata types",
539 ("0", "None", "No strata", 0),
540 ("1", "Smooth", "Smooth transitions", 1),
541 ("2", "Sharp Sub", "Sharp substract transitions", 2),
542 ("3", "Sharp Add", "Sharp add transitions", 3),
543 ("4", "Quantize", "Quantize", 4),
544 ("5", "Quantize Mix", "Quantize mixed", 5)]
546 water_plane
= BoolProperty(
549 description
="Add water plane"
551 water_level
= FloatProperty(
556 description
="Water level"
558 remove_double
= BoolProperty(
559 name
="Remove Doubles",
561 description
="Remove doubles"
563 show_main_settings
= BoolProperty(
564 name
="Main Settings",
566 description
="Show settings"
568 show_noise_settings
= BoolProperty(
569 name
="Noise Settings",
571 description
="Show noise settings"
573 show_displace_settings
= BoolProperty(
574 name
="Displace Settings",
576 description
="Show displace settings"
578 refresh
= BoolProperty(
581 description
="Refresh"
583 auto_refresh
= BoolProperty(
586 description
="Automatic refresh"
590 def poll(self
, context
):
593 if ob
.mode
== 'EDIT':
597 def draw(self
, context
):
598 draw_ant_refresh(self
, context
)
599 draw_ant_main(self
, context
, generate
=True)
600 draw_ant_noise(self
, context
)
601 draw_ant_displace(self
, context
, generate
=True)
602 draw_ant_water(self
, context
)
605 def invoke(self
, context
, event
):
607 return self
.execute(context
)
610 def execute(self
, context
):
612 return {'PASS_THROUGH'}
615 undo
= bpy
.context
.user_preferences
.edit
.use_global_undo
616 bpy
.context
.user_preferences
.edit
.use_global_undo
= False
618 # deselect all objects when in object mode
619 if bpy
.ops
.object.select_all
.poll():
620 bpy
.ops
.object.select_all(action
='DESELECT')
624 self
.ant_terrain_name
,
691 scene
= context
.scene
693 # Main function, create landscape mesh object
694 if self
.ant_terrain_name
!= "":
695 new_name
= self
.ant_terrain_name
697 new_name
= "Landscape"
701 verts
, faces
= sphere_gen(
710 new_ob
= create_mesh_object(context
, verts
, [], faces
, new_name
)
711 if self
.remove_double
:
713 bpy
.ops
.object.mode_set(mode
= 'EDIT')
714 bpy
.ops
.mesh
.remove_doubles(threshold
=0.0001, use_unselected
=False)
715 bpy
.ops
.object.mode_set(mode
= 'OBJECT')
718 verts
, faces
= grid_gen(
728 new_ob
= create_mesh_object(context
, verts
, [], faces
, new_name
)
733 bpy
.ops
.object.shade_smooth()
735 if not self
.at_cursor
:
736 new_ob
.object.location
= (0.0, 0.0, 0.0)
739 if self
.land_material
!= "" and self
.land_material
in bpy
.data
.materials
:
740 mat
= bpy
.data
.materials
[self
.land_material
]
741 bpy
.context
.object.data
.materials
.append(mat
)
747 verts
, faces
= sphere_gen(
756 wobj
= create_mesh_object(context
, verts
, [], faces
, new_name
+"_plane")
757 if self
.remove_double
:
759 bpy
.ops
.object.mode_set(mode
= 'EDIT')
760 bpy
.ops
.mesh
.remove_doubles(threshold
=0.0001, use_unselected
=False)
761 bpy
.ops
.object.mode_set(mode
= 'OBJECT')
764 verts
, faces
= grid_gen(
774 wobj
= create_mesh_object(context
, verts
, [], faces
, new_name
+"_plane")
779 bpy
.ops
.object.shade_smooth()
781 if not self
.at_cursor
:
782 wobj
.object.location
= (0.0, 0.0, 0.0)
785 if self
.water_material
!= "" and self
.water_material
in bpy
.data
.materials
:
786 mat
= bpy
.data
.materials
[self
.water_material
]
787 bpy
.context
.object.data
.materials
.append(mat
)
789 # select landscape and make active
791 scene
.objects
.active
= new_ob
.object
793 new_ob
= store_properties(self
, new_ob
.object)
795 if self
.auto_refresh
is False:
798 # restore pre operator undo state
799 context
.user_preferences
.edit
.use_global_undo
= undo