Fix T58881: FBX error exporting tangent space
[blender-addons.git] / ant_landscape / add_mesh_ant_landscape.py
blobf103a6c0395fb2e6ab1955021d2f71acf3d65509
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
20 # Jimmy Hazevoet
22 # import modules
23 import bpy
24 from bpy.props import (
25 BoolProperty,
26 EnumProperty,
27 FloatProperty,
28 IntProperty,
29 StringProperty,
30 FloatVectorProperty,
33 from .ant_functions import (
34 grid_gen,
35 sphere_gen,
36 create_mesh_object,
37 store_properties,
38 draw_ant_refresh,
39 draw_ant_main,
40 draw_ant_noise,
41 draw_ant_displace,
42 draw_ant_water,
45 # ------------------------------------------------------------
46 # Add landscape
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(
54 name="Name",
55 default="Landscape"
57 land_material = StringProperty(
58 name='Material',
59 default="",
60 description="Terrain material"
62 water_material = StringProperty(
63 name='Material',
64 default="",
65 description="Water plane material"
67 texture_block = StringProperty(
68 name="Texture",
69 default=""
71 at_cursor = BoolProperty(
72 name="Cursor",
73 default=True,
74 description="Place at cursor location",
76 smooth_mesh = BoolProperty(
77 name="Smooth",
78 default=True,
79 description="Shade smooth"
81 tri_face = BoolProperty(
82 name="Triangulate",
83 default=False,
84 description="Triangulate faces"
86 sphere_mesh = BoolProperty(
87 name="Sphere",
88 default=False,
89 description="Generate uv sphere - remove doubles when ready"
91 subdivision_x = IntProperty(
92 name="Subdivisions X",
93 default=128,
94 min=4,
95 max=6400,
96 description="Mesh X subdivisions"
98 subdivision_y = IntProperty(
99 default=128,
100 name="Subdivisions Y",
101 min=4,
102 max=6400,
103 description="Mesh Y subdivisions"
105 mesh_size = FloatProperty(
106 default=2.0,
107 name="Mesh Size",
108 min=0.01,
109 max=100000.0,
110 description="Mesh size"
112 mesh_size_x = FloatProperty(
113 default=2.0,
114 name="Mesh Size X",
115 min=0.01,
116 description="Mesh x size"
118 mesh_size_y = FloatProperty(
119 name="Mesh Size Y",
120 default=2.0,
121 min=0.01,
122 description="Mesh y size"
125 random_seed = IntProperty(
126 name="Random Seed",
127 default=0,
128 min=0,
129 description="Randomize noise origin"
131 noise_offset_x = FloatProperty(
132 name="Offset X",
133 default=0.0,
134 description="Noise X Offset"
136 noise_offset_y = FloatProperty(
137 name="Offset Y",
138 default=0.0,
139 description="Noise Y Offset"
141 noise_offset_z = FloatProperty(
142 name="Offset Z",
143 default=0.0,
144 description="Noise Z Offset"
146 noise_size_x = FloatProperty(
147 default=1.0,
148 name="Size X",
149 min=0.01,
150 max=1000.0,
151 description="Noise x size"
153 noise_size_y = FloatProperty(
154 name="Size Y",
155 default=1.0,
156 min=0.01,
157 max=1000.0,
158 description="Noise y size"
160 noise_size_z = FloatProperty(
161 name="Size Z",
162 default=1.0,
163 min=0.01,
164 max=1000.0,
165 description="Noise Z size"
167 noise_size = FloatProperty(
168 name="Noise Size",
169 default=1.0,
170 min=0.01,
171 max=1000.0,
172 description="Noise size"
174 noise_type = EnumProperty(
175 name="Noise Type",
176 default='hetero_terrain',
177 description="Noise type",
178 items = [
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(
200 name="Noise Basis",
201 default="0",
202 description="Noise basis algorithms",
203 items = [
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",
217 default="0",
218 description="VLNoise basis algorithms",
219 items = [
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(
232 name="Distortion",
233 default=1.0,
234 min=0.01,
235 max=100.0,
236 description="Distortion amount"
238 hard_noise = EnumProperty(
239 name="Soft Hard",
240 default="0",
241 description="Soft Noise, Hard noise",
242 items = [
243 ("0", "Soft", "Soft Noise", 0),
244 ("1", "Hard", "Hard noise", 1)]
246 noise_depth = IntProperty(
247 name="Depth",
248 default=8,
249 min=0,
250 max=16,
251 description="Noise Depth - number of frequencies in the fBm"
253 amplitude = FloatProperty(
254 name="Amp",
255 default=0.5,
256 min=0.01,
257 max=1.0,
258 description="Amplitude"
260 frequency = FloatProperty(
261 name="Freq",
262 default=2.0,
263 min=0.01,
264 max=5.0,
265 description="Frequency"
267 dimension = FloatProperty(
268 name="Dimension",
269 default=1.0,
270 min=0.01,
271 max=2.0,
272 description="H - fractal dimension of the roughest areas"
274 lacunarity = FloatProperty(
275 name="Lacunarity",
276 min=0.01,
277 max=6.0,
278 default=2.0,
279 description="Lacunarity - gap between successive frequencies"
281 offset = FloatProperty(
282 name="Offset",
283 default=1.0,
284 min=0.01,
285 max=6.0,
286 description="Offset - raises the terrain from sea level"
288 gain = FloatProperty(
289 name="Gain",
290 default=1.0,
291 min=0.01,
292 max=6.0,
293 description="Gain - scale factor"
295 marble_bias = EnumProperty(
296 name="Bias",
297 default="0",
298 description="Marble bias",
299 items = [
300 ("0", "Sin", "Sin", 0),
301 ("1", "Cos", "Cos", 1),
302 ("2", "Tri", "Tri", 2),
303 ("3", "Saw", "Saw", 3)]
305 marble_sharp = EnumProperty(
306 name="Sharp",
307 default="0",
308 description="Marble sharpness",
309 items = [
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(
318 name="Shape",
319 default="0",
320 description="Marble shape",
321 items= [
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),
327 ("5", "Z", "Z", 5),
328 ("6", "Y", "Y", 6),
329 ("7", "X", "X", 7)]
331 height = FloatProperty(
332 name="Height",
333 default=0.5,
334 min=-10000.0,
335 max=10000.0,
336 description="Noise intensity scale"
338 height_invert = BoolProperty(
339 name="Invert",
340 default=False,
341 description="Height invert",
343 height_offset = FloatProperty(
344 name="Offset",
345 default=0.0,
346 min=-10000.0,
347 max=10000.0,
348 description="Height offset"
350 fx_mixfactor = FloatProperty(
351 name="Mix Factor",
352 default=0.0,
353 min=-1.0,
354 max=1.0,
355 description="Effect mix factor: -1.0 = Noise, +1.0 = Effect"
357 fx_mix_mode = EnumProperty(
358 name="Effect Mix",
359 default="0",
360 description="Effect mix mode",
361 items = [
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(
374 name="Effect Type",
375 default="0",
376 description="Effect type",
377 items = [
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(
403 name="Effect Bias",
404 default="0",
405 description="Effect bias type",
406 items = [
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(
414 name="Distortion",
415 default=0.0,
416 min=0.0,
417 max=1000.0,
418 description="Effect turbulence distortion"
420 fx_depth = IntProperty(
421 name="Depth",
422 default=0,
423 min=0,
424 max=16,
425 description="Effect depth - number of frequencies"
427 fx_amplitude = FloatProperty(
428 name="Amp",
429 default=0.5,
430 min=0.01,
431 max=1.0,
432 description="Amplitude"
434 fx_frequency = FloatProperty(
435 name="Freq",
436 default=2.0,
437 min=0.01,
438 max=5.0,
439 description="Frequency"
441 fx_size = FloatProperty(
442 name="Effect Size",
443 default=1.0,
444 min=0.01,
445 max=1000.0,
446 description="Effect size"
448 fx_loc_x = FloatProperty(
449 name="Offset X",
450 default=0.0,
451 description="Effect x offset"
453 fx_loc_y = FloatProperty(
454 name="Offset Y",
455 default=0.0,
456 description="Effect y offset"
458 fx_height = FloatProperty(
459 name="Intensity",
460 default=1.0,
461 min=-1000.0,
462 max=1000.0,
463 description="Effect intensity scale"
465 fx_invert = BoolProperty(
466 name="Invert",
467 default=False,
468 description="Effect invert"
470 fx_offset = FloatProperty(
471 name="Offset",
472 default=0.0,
473 min=-1000.0,
474 max=1000.0,
475 description="Effect height offset"
478 edge_falloff = EnumProperty(
479 name="Falloff",
480 default="3",
481 description="Flatten edges",
482 items = [
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(
489 name="Falloff X",
490 default=4.0,
491 min=0.1,
492 max=100.0,
493 description="Falloff x scale"
495 falloff_y = FloatProperty(
496 name="Falloff Y",
497 default=4.0,
498 min=0.1,
499 max=100.0,
500 description="Falloff y scale"
502 edge_level = FloatProperty(
503 name="Edge Level",
504 default=0.0,
505 min=-10000.0,
506 max=10000.0,
507 description="Edge level, sealevel offset"
509 maximum = FloatProperty(
510 name="Maximum",
511 default=1.0,
512 min=-10000.0,
513 max=10000.0,
514 description="Maximum, flattens terrain at plateau level"
516 minimum = FloatProperty(
517 name="Minimum",
518 default=-1.0,
519 min=-10000.0,
520 max=10000.0,
521 description="Minimum, flattens terrain at seabed level"
523 vert_group = StringProperty(
524 name="Vertex Group",
525 default=""
527 strata = FloatProperty(
528 name="Amount",
529 default=5.0,
530 min=0.01,
531 max=1000.0,
532 description="Strata layers / terraces"
534 strata_type = EnumProperty(
535 name="Strata",
536 default="0",
537 description="Strata types",
538 items = [
539 ("0", "None", "No strata", 0),
540 ("1", "Smooth", "Smooth transitions", 1),
541 ("2", "Sharp Sub", "Sharp subtract 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(
547 name="Water Plane",
548 default=False,
549 description="Add water plane"
551 water_level = FloatProperty(
552 name="Level",
553 default=0.01,
554 min=-10000.0,
555 max=10000.0,
556 description="Water level"
558 remove_double = BoolProperty(
559 name="Remove Doubles",
560 default=False,
561 description="Remove doubles"
563 show_main_settings = BoolProperty(
564 name="Main Settings",
565 default=True,
566 description="Show settings"
568 show_noise_settings = BoolProperty(
569 name="Noise Settings",
570 default=True,
571 description="Show noise settings"
573 show_displace_settings = BoolProperty(
574 name="Displace Settings",
575 default=True,
576 description="Show displace settings"
578 refresh = BoolProperty(
579 name="Refresh",
580 default=False,
581 description="Refresh"
583 auto_refresh = BoolProperty(
584 name="Auto",
585 default=True,
586 description="Automatic refresh"
589 @classmethod
590 def poll(self, context):
591 ob = context.object
592 if ob is not None:
593 if ob.mode == 'EDIT':
594 return False
595 return True
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):
606 self.refresh = True
607 return self.execute(context)
610 def execute(self, context):
611 if not self.refresh:
612 return {'PASS_THROUGH'}
614 # turn off undo
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')
622 # Properties
623 ant_props = [
624 self.ant_terrain_name,
625 self.at_cursor,
626 self.smooth_mesh,
627 self.tri_face,
628 self.sphere_mesh,
629 self.land_material,
630 self.water_material,
631 self.texture_block,
632 self.subdivision_x,
633 self.subdivision_y,
634 self.mesh_size_x,
635 self.mesh_size_y,
636 self.mesh_size,
637 self.random_seed,
638 self.noise_offset_x,
639 self.noise_offset_y,
640 self.noise_offset_z,
641 self.noise_size_x,
642 self.noise_size_y,
643 self.noise_size_z,
644 self.noise_size,
645 self.noise_type,
646 self.basis_type,
647 self.vl_basis_type,
648 self.distortion,
649 self.hard_noise,
650 self.noise_depth,
651 self.amplitude,
652 self.frequency,
653 self.dimension,
654 self.lacunarity,
655 self.offset,
656 self.gain,
657 self.marble_bias,
658 self.marble_sharp,
659 self.marble_shape,
660 self.height,
661 self.height_invert,
662 self.height_offset,
663 self.maximum,
664 self.minimum,
665 self.edge_falloff,
666 self.edge_level,
667 self.falloff_x,
668 self.falloff_y,
669 self.strata_type,
670 self.strata,
671 self.water_plane,
672 self.water_level,
673 self.vert_group,
674 self.remove_double,
675 self.fx_mixfactor,
676 self.fx_mix_mode,
677 self.fx_type,
678 self.fx_bias,
679 self.fx_turb,
680 self.fx_depth,
681 self.fx_frequency,
682 self.fx_amplitude,
683 self.fx_size,
684 self.fx_loc_x,
685 self.fx_loc_y,
686 self.fx_height,
687 self.fx_offset,
688 self.fx_invert
691 scene = context.scene
693 # Main function, create landscape mesh object
694 if self.ant_terrain_name != "":
695 new_name = self.ant_terrain_name
696 else:
697 new_name = "Landscape"
699 if self.sphere_mesh:
700 # sphere
701 verts, faces = sphere_gen(
702 self.subdivision_y,
703 self.subdivision_x,
704 self.tri_face,
705 self.mesh_size,
706 ant_props,
707 False,
710 new_ob = create_mesh_object(context, verts, [], faces, new_name)
711 if self.remove_double:
712 new_ob.select = True
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')
716 else:
717 # grid
718 verts, faces = grid_gen(
719 self.subdivision_x,
720 self.subdivision_y,
721 self.tri_face,
722 self.mesh_size_x,
723 self.mesh_size_y,
724 ant_props,
725 False,
728 new_ob = create_mesh_object(context, verts, [], faces, new_name)
730 new_ob.select = True
732 if self.smooth_mesh:
733 bpy.ops.object.shade_smooth()
735 if not self.at_cursor:
736 new_ob.object.location = (0.0, 0.0, 0.0)
738 # Landscape Material
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)
743 # Water plane
744 if self.water_plane:
745 if self.sphere_mesh:
746 # sphere
747 verts, faces = sphere_gen(
748 self.subdivision_y,
749 self.subdivision_x,
750 self.tri_face,
751 self.mesh_size,
752 ant_props,
753 self.water_plane,
754 self.water_level
756 wobj = create_mesh_object(context, verts, [], faces, new_name+"_plane")
757 if self.remove_double:
758 wobj.select = True
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')
762 else:
763 # grid
764 verts, faces = grid_gen(
767 self.tri_face,
768 self.mesh_size_x,
769 self.mesh_size_y,
770 ant_props,
771 self.water_plane,
772 self.water_level
774 wobj = create_mesh_object(context, verts, [], faces, new_name+"_plane")
776 wobj.select = True
778 if self.smooth_mesh:
779 bpy.ops.object.shade_smooth()
781 if not self.at_cursor:
782 wobj.object.location = (0.0, 0.0, 0.0)
784 # Water Material
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
790 new_ob.select = True
791 scene.objects.active = new_ob.object
793 new_ob = store_properties(self, new_ob.object)
795 if self.auto_refresh is False:
796 self.refresh = False
798 # restore pre operator undo state
799 context.user_preferences.edit.use_global_undo = undo
801 return {'FINISHED'}