Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJimmy Hazevoet <jimhazevoet@gmail.com>2017-07-11 12:27:48 +0300
committermeta-androcto <meta.androcto1@gmail.com>2017-07-11 12:27:48 +0300
commit5de432942210e4b09d16bc9adbb612d0472183c4 (patch)
tree5c8a9f0f27b80d35b5535ba55a859b6eef7467ec /ant_landscape
parentdbb3c56b2c6816a0df3e9bc7417e21499c57c660 (diff)
ant landscape: fix noise types
Diffstat (limited to 'ant_landscape')
-rw-r--r--ant_landscape/__init__.py180
-rw-r--r--ant_landscape/add_mesh_ant_landscape.py147
-rw-r--r--ant_landscape/ant_functions.py715
-rw-r--r--ant_landscape/ant_landscape_refresh.py238
-rw-r--r--ant_landscape/ant_noise.py705
-rw-r--r--ant_landscape/mesh_ant_displace.py165
6 files changed, 1436 insertions, 714 deletions
diff --git a/ant_landscape/__init__.py b/ant_landscape/__init__.py
index 25d4be9b..c8e9fb92 100644
--- a/ant_landscape/__init__.py
+++ b/ant_landscape/__init__.py
@@ -35,14 +35,14 @@ bl_info = {
if "bpy" in locals():
import importlib
importlib.reload(add_mesh_ant_landscape)
- importlib.reload(ant_landscape_refresh)
importlib.reload(mesh_ant_displace)
importlib.reload(ant_functions)
+ importlib.reload(ant_noise)
else:
from ant_landscape import add_mesh_ant_landscape
- from ant_landscape import ant_landscape_refresh
from ant_landscape import mesh_ant_displace
from ant_landscape import ant_functions
+ from ant_landscape import ant_noise
import bpy
@@ -54,7 +54,6 @@ from bpy.props import (
PointerProperty,
EnumProperty,
)
-
from .ant_functions import (
draw_ant_refresh,
draw_ant_main,
@@ -62,7 +61,6 @@ from .ant_functions import (
draw_ant_displace,
)
-
# ------------------------------------------------------------
# Menu's and panels
@@ -114,7 +112,7 @@ class AntLandscapeToolsPanel(bpy.types.Panel):
col.operator('mesh.eroder', text="Landscape Eroder", icon='SMOOTHCURVE')
-# Landscape Settings / Properties:
+# Landscape Main Settings
class AntMainSettingsPanel(bpy.types.Panel):
bl_idname = "ANTMAIN_PT_layout"
bl_options = {'DEFAULT_CLOSED'}
@@ -156,7 +154,7 @@ class AntMainSettingsPanel(bpy.types.Panel):
col.prop(ant, "mesh_size_y")
-# Landscape Settings / Properties:
+# Landscape Noise Settings
class AntNoiseSettingsPanel(bpy.types.Panel):
bl_idname = "ANTNOISE_PT_layout"
bl_options = {'DEFAULT_CLOSED'}
@@ -194,7 +192,8 @@ class AntNoiseSettingsPanel(bpy.types.Panel):
col = box.column(align=True)
col.prop(ant, "noise_offset_x")
col.prop(ant, "noise_offset_y")
- col.prop(ant, "noise_offset_z")
+ if ant.sphere_mesh:
+ col.prop(ant, "noise_offset_z")
col.prop(ant, "noise_size_x")
col.prop(ant, "noise_size_y")
if ant.sphere_mesh:
@@ -274,7 +273,7 @@ class AntNoiseSettingsPanel(bpy.types.Panel):
col.prop(ant, "frequency")
col.prop(ant, "distortion")
col.separator()
- col.prop(ant, "vl_basis_type")
+ box.prop(ant, "vl_basis_type")
col.separator()
row = col.row(align=True)
row.prop(ant, "hard_noise", expand=True)
@@ -285,7 +284,7 @@ class AntNoiseSettingsPanel(bpy.types.Panel):
col.prop(ant, "offset")
col.prop(ant, "distortion")
col.separator()
- col.prop(ant, "vl_basis_type")
+ box.prop(ant, "vl_basis_type")
elif ant.noise_type == "distorted_heteroTerrain":
col.prop(ant, "noise_depth")
col.prop(ant, "dimension")
@@ -301,7 +300,7 @@ class AntNoiseSettingsPanel(bpy.types.Panel):
col.prop(ant, "offset")
col.prop(ant, "gain")
col.separator()
- col.prop(ant, "vl_basis_type")
+ box.prop(ant, "vl_basis_type")
elif ant.noise_type == "rocks_noise":
col.prop(ant, "noise_depth")
col.prop(ant, "distortion")
@@ -316,15 +315,44 @@ class AntNoiseSettingsPanel(bpy.types.Panel):
col.prop(ant, "offset")
col.prop(ant, "distortion")
col.separator()
- col.prop(ant, "vl_basis_type")
+ box.prop(ant, "vl_basis_type")
elif ant.noise_type == "planet_noise":
col.prop(ant, "noise_depth")
col.separator()
row = col.row(align=True)
row.prop(ant, "hard_noise", expand=True)
+ # Effects mix
+ col = box.column(align=False)
+ box.prop(ant, "fx_type")
+ if ant.fx_type != "0":
+ if int(ant.fx_type) <= 12:
+ box.prop(ant, "fx_bias")
+
+ box.prop(ant, "fx_mix_mode")
+ col = box.column(align=True)
+ col.prop(ant, "fx_mixfactor")
+
+ col = box.column(align=True)
+ col.prop(ant, "fx_loc_x")
+ col.prop(ant, "fx_loc_y")
+ col.prop(ant, "fx_size")
+
+ col = box.column(align=True)
+ col.prop(ant, "fx_depth")
+ if ant.fx_depth != 0:
+ col.prop(ant, "fx_frequency")
+ col.prop(ant, "fx_amplitude")
+ col.prop(ant, "fx_turb")
+
+ col = box.column(align=True)
+ row = col.row(align=True).split(0.92, align=True)
+ row.prop(ant, "fx_height")
+ row.prop(ant, "fx_invert", toggle=True, text="", icon='ARROW_LEFTRIGHT')
+ col.prop(ant, "fx_offset")
+
-# Landscape Settings / Properties:
+# Landscape Displace Settings
class AntDisplaceSettingsPanel(bpy.types.Panel):
bl_idname = "ANTDISP_PT_layout"
bl_options = {'DEFAULT_CLOSED'}
@@ -679,6 +707,134 @@ class AntLandscapePropertiesGroup(bpy.types.PropertyGroup):
max=10000.0,
description="Height offset"
)
+ fx_mixfactor = FloatProperty(
+ name="Mix Factor",
+ default=0.0,
+ min=-1.0,
+ max=1.0,
+ description="Effect mix factor: -1.0 = Noise, +1.0 = Effect"
+ )
+ fx_mix_mode = EnumProperty(
+ name="Effect Mix",
+ default="0",
+ description="Effect mix mode",
+ items = [
+ ("0", "Mix", "Mix", 0),
+ ("1", "Add", "Add", 1),
+ ("2", "Sub", "Subtract", 2),
+ ("3", "Mul", "Multiply", 3),
+ ("4", "Abs", "Absolute", 4),
+ ("5", "Scr", "Screen", 5),
+ ("6", "Mod", "Modulo", 6),
+ ("7", "Min", "Minimum", 7),
+ ("8", "Max", "Maximum", 8)
+ ]
+ )
+ fx_type = EnumProperty(
+ name="Effect Type",
+ default="0",
+ description="Effect type",
+ items = [
+ ("0", "None", "No effect", 0),
+ ("1", "Gradient", "Gradient", 1),
+ ("2", "Waves", "Waves - Bumps", 2),
+ ("3", "Zigzag", "Zigzag", 3),
+ ("4", "Wavy", "Wavy", 4),
+ ("5", "Bump", "Bump", 5),
+ ("6", "Dots", "Dots", 6),
+ ("7", "Rings", "Rings", 7),
+ ("8", "Spiral", "Spiral", 8),
+ ("9", "Square", "Square", 9),
+ ("10", "Blocks", "Blocks", 10),
+ ("11", "Grid", "Grid", 11),
+ ("12", "Tech", "Tech", 12),
+ ("13", "Crackle", "Crackle", 13),
+ ("14", "Cracks", "Cracks", 14),
+ ("15", "Rock", "Rock noise", 15),
+ ("16", "Lunar", "Craters", 16),
+ ("17", "Cosine", "Cosine", 17),
+ ("18", "Spikey", "Spikey", 18),
+ ("19", "Stone", "Stone", 19),
+ ("20", "Flat Turb", "Flat turbulence", 20),
+ ("21", "Flat Voronoi", "Flat voronoi", 21)
+ ]
+ )
+ fx_bias = EnumProperty(
+ name="Effect Bias",
+ default="0",
+ description="Effect bias type",
+ items = [
+ ("0", "Sin", "Sin", 0),
+ ("1", "Cos", "Cos", 1),
+ ("2", "Tri", "Tri", 2),
+ ("3", "Saw", "Saw", 3),
+ ("4", "None", "None", 4)]
+ )
+ fx_turb = FloatProperty(
+ name="Distortion",
+ default=0.0,
+ min=0.0,
+ max=1000.0,
+ description="Effect turbulence distortion"
+ )
+ fx_depth = IntProperty(
+ name="Depth",
+ default=0,
+ min=0,
+ max=16,
+ description="Effect depth - number of frequencies"
+ )
+ fx_amplitude = FloatProperty(
+ name="Amp",
+ default=0.5,
+ min=0.01,
+ max=1.0,
+ description="Amplitude"
+ )
+ fx_frequency = FloatProperty(
+ name="Freq",
+ default=2.0,
+ min=0.01,
+ max=5.0,
+ description="Frequency"
+ )
+ fx_size = FloatProperty(
+ name="Effect Size",
+ default=1.0,
+ min=0.01,
+ max=1000.0,
+ description="Effect size"
+ )
+ fx_loc_x = FloatProperty(
+ name="Offset X",
+ default=0.0,
+ description="Effect x offset"
+ )
+ fx_loc_y = FloatProperty(
+ name="Offset Y",
+ default=0.0,
+ description="Effect y offset"
+ )
+ fx_height = FloatProperty(
+ name="Intensity",
+ default=1.0,
+ min=-1000.0,
+ max=1000.0,
+ description="Effect intensity scale"
+ )
+ fx_invert = BoolProperty(
+ name="Invert",
+ default=False,
+ description="Effect invert"
+ )
+ fx_offset = FloatProperty(
+ name="Offset",
+ default=0.0,
+ min=-1000.0,
+ max=1000.0,
+ description="Effect height offset"
+ )
+
edge_falloff = EnumProperty(
name="Falloff",
default="3",
diff --git a/ant_landscape/add_mesh_ant_landscape.py b/ant_landscape/add_mesh_ant_landscape.py
index dee82a55..df941c4f 100644
--- a/ant_landscape/add_mesh_ant_landscape.py
+++ b/ant_landscape/add_mesh_ant_landscape.py
@@ -16,7 +16,7 @@
#
# ##### END GPL LICENSE BLOCK #####
-# Another Noise Tool - Landscape
+# Another Noise Tool - Add Landscape
# Jimmy Hazevoet
# import modules
@@ -347,6 +347,134 @@ class AntAddLandscape(bpy.types.Operator):
max=10000.0,
description="Height offset"
)
+ fx_mixfactor = FloatProperty(
+ name="Mix Factor",
+ default=0.0,
+ min=-1.0,
+ max=1.0,
+ description="Effect mix factor: -1.0 = Noise, +1.0 = Effect"
+ )
+ fx_mix_mode = EnumProperty(
+ name="Effect Mix",
+ default="0",
+ description="Effect mix mode",
+ items = [
+ ("0", "Mix", "Mix", 0),
+ ("1", "Add", "Add", 1),
+ ("2", "Sub", "Subtract", 2),
+ ("3", "Mul", "Multiply", 3),
+ ("4", "Abs", "Absolute", 4),
+ ("5", "Scr", "Screen", 5),
+ ("6", "Mod", "Modulo", 6),
+ ("7", "Min", "Minimum", 7),
+ ("8", "Max", "Maximum", 8)
+ ]
+ )
+ fx_type = EnumProperty(
+ name="Effect Type",
+ default="0",
+ description="Effect type",
+ items = [
+ ("0", "None", "No effect", 0),
+ ("1", "Gradient", "Gradient", 1),
+ ("2", "Waves", "Waves - Bumps", 2),
+ ("3", "Zigzag", "Zigzag", 3),
+ ("4", "Wavy", "Wavy", 4),
+ ("5", "Bump", "Bump", 5),
+ ("6", "Dots", "Dots", 6),
+ ("7", "Rings", "Rings", 7),
+ ("8", "Spiral", "Spiral", 8),
+ ("9", "Square", "Square", 9),
+ ("10", "Blocks", "Blocks", 10),
+ ("11", "Grid", "Grid", 11),
+ ("12", "Tech", "Tech", 12),
+ ("13", "Crackle", "Crackle", 13),
+ ("14", "Cracks", "Cracks", 14),
+ ("15", "Rock", "Rock noise", 15),
+ ("16", "Lunar", "Craters", 16),
+ ("17", "Cosine", "Cosine", 17),
+ ("18", "Spikey", "Spikey", 18),
+ ("19", "Stone", "Stone", 19),
+ ("20", "Flat Turb", "Flat turbulence", 20),
+ ("21", "Flat Voronoi", "Flat voronoi", 21)
+ ]
+ )
+ fx_bias = EnumProperty(
+ name="Effect Bias",
+ default="0",
+ description="Effect bias type",
+ items = [
+ ("0", "Sin", "Sin", 0),
+ ("1", "Cos", "Cos", 1),
+ ("2", "Tri", "Tri", 2),
+ ("3", "Saw", "Saw", 3),
+ ("4", "None", "None", 4)]
+ )
+ fx_turb = FloatProperty(
+ name="Distortion",
+ default=0.0,
+ min=0.0,
+ max=1000.0,
+ description="Effect turbulence distortion"
+ )
+ fx_depth = IntProperty(
+ name="Depth",
+ default=0,
+ min=0,
+ max=16,
+ description="Effect depth - number of frequencies."
+ )
+ fx_amplitude = FloatProperty(
+ name="Amp",
+ default=0.5,
+ min=0.01,
+ max=1.0,
+ description="Amplitude"
+ )
+ fx_frequency = FloatProperty(
+ name="Freq",
+ default=2.0,
+ min=0.01,
+ max=5.0,
+ description="Frequency"
+ )
+ fx_size = FloatProperty(
+ name="Effect Size",
+ default=1.0,
+ min=0.01,
+ max=1000.0,
+ description="Effect size"
+ )
+ fx_loc_x = FloatProperty(
+ name="Offset X",
+ default=0.0,
+ description="Effect x offset"
+ )
+ fx_loc_y = FloatProperty(
+ name="Offset Y",
+ default=0.0,
+ description="Effect y offset"
+ )
+ fx_height = FloatProperty(
+ name="Intensity",
+ default=1.0,
+ min=-1000.0,
+ max=1000.0,
+ description="Effect intensity scale"
+ )
+ fx_invert = BoolProperty(
+ name="Invert",
+ default=False,
+ description="Effect invert"
+ )
+ fx_offset = FloatProperty(
+ name="Offset",
+ default=0.0,
+ min=-1000.0,
+ max=1000.0,
+ description="Effect height offset"
+ )
+
edge_falloff = EnumProperty(
name="Falloff",
default="3",
@@ -458,7 +586,6 @@ class AntAddLandscape(bpy.types.Operator):
description="Automatic refresh"
)
-
def draw(self, context):
draw_ant_refresh(self, context)
draw_ant_main(self, context, generate=True)
@@ -536,7 +663,21 @@ class AntAddLandscape(bpy.types.Operator):
self.water_plane,
self.water_level,
self.vert_group,
- self.remove_double
+ self.remove_double,
+ self.fx_mixfactor,
+ self.fx_mix_mode,
+ self.fx_type,
+ self.fx_bias,
+ self.fx_turb,
+ self.fx_depth,
+ self.fx_frequency,
+ self.fx_amplitude,
+ self.fx_size,
+ self.fx_loc_x,
+ self.fx_loc_y,
+ self.fx_height,
+ self.fx_offset,
+ self.fx_invert
]
scene = context.scene
diff --git a/ant_landscape/ant_functions.py b/ant_landscape/ant_functions.py
index 8adacc0b..c566617d 100644
--- a/ant_landscape/ant_functions.py
+++ b/ant_landscape/ant_functions.py
@@ -30,24 +30,12 @@ from bpy.props import (
StringProperty,
EnumProperty,
IntProperty,
- PointerProperty
- )
-from mathutils.noise import (
- seed_set,
- turbulence,
- turbulence_vector,
- fractal,
- hybrid_multi_fractal,
- multi_fractal,
- ridged_multi_fractal,
- hetero_terrain,
- random_unit_vector,
- variable_lacunarity,
+ PointerProperty,
)
from math import (
- floor, sqrt,
sin, cos, pi,
)
+from .ant_noise import noise_gen
# ------------------------------------------------------------
# Create a new mesh (object) from verts/edges/faces.
@@ -137,6 +125,213 @@ def sphere_gen(sub_d_x, sub_d_y, tri, meshsize, props, water_plane, water_level)
return verts, faces
+# ------------------------------------------------------------
+# Do refresh - redraw
+class AntLandscapeRefresh(bpy.types.Operator):
+ bl_idname = "mesh.ant_landscape_refresh"
+ bl_label = "Refresh"
+ bl_description = "Refresh landscape with current settings"
+ bl_options = {'REGISTER', 'UNDO'}
+
+
+ @classmethod
+ def poll(cls, context):
+ ob = bpy.context.active_object
+ return (ob.ant_landscape and not ob.ant_landscape['sphere_mesh'])
+
+
+ def execute(self, context):
+ # turn off undo
+ undo = bpy.context.user_preferences.edit.use_global_undo
+ bpy.context.user_preferences.edit.use_global_undo = False
+
+ # ant object items
+ obj = bpy.context.active_object
+
+ bpy.ops.object.mode_set(mode = 'EDIT')
+ bpy.ops.object.mode_set(mode = 'OBJECT')
+
+ if obj and obj.ant_landscape.keys():
+ ob = obj.ant_landscape
+ obi = ob.items()
+ prop = []
+ for i in range(len(obi)):
+ prop.append(obi[i][1])
+
+ # redraw verts
+ mesh = obj.data
+
+ if ob['vert_group'] != "" and ob['vert_group'] in obj.vertex_groups:
+ vertex_group = obj.vertex_groups[ob['vert_group']]
+ gi = vertex_group.index
+ for v in mesh.vertices:
+ for g in v.groups:
+ if g.group == gi:
+ v.co[2] = 0.0
+ v.co[2] = vertex_group.weight(v.index) * noise_gen(v.co, prop)
+ else:
+ for v in mesh.vertices:
+ v.co[2] = 0.0
+ v.co[2] = noise_gen(v.co, prop)
+ mesh.update()
+ else:
+ pass
+
+ # restore pre operator undo state
+ context.user_preferences.edit.use_global_undo = undo
+
+ return {'FINISHED'}
+
+# ------------------------------------------------------------
+# Do regenerate
+class AntLandscapeRegenerate(bpy.types.Operator):
+ bl_idname = "mesh.ant_landscape_regenerate"
+ bl_label = "Regenerate"
+ bl_description = "Regenerate landscape with current settings"
+ bl_options = {'REGISTER', 'UNDO'}
+
+
+ @classmethod
+ def poll(cls, context):
+ return bpy.context.active_object.ant_landscape
+
+
+ def execute(self, context):
+
+ # turn off undo
+ undo = bpy.context.user_preferences.edit.use_global_undo
+ bpy.context.user_preferences.edit.use_global_undo = False
+
+ scene = bpy.context.scene
+ # ant object items
+ obj = bpy.context.active_object
+
+ if obj and obj.ant_landscape.keys():
+ ob = obj.ant_landscape
+ obi = ob.items()
+ ant_props = []
+ for i in range(len(obi)):
+ ant_props.append(obi[i][1])
+
+ new_name = obj.name
+
+ # Main function, create landscape mesh object
+ if ob['sphere_mesh']:
+ # sphere
+ verts, faces = sphere_gen(
+ ob['subdivision_y'],
+ ob['subdivision_x'],
+ ob['tri_face'],
+ ob['mesh_size'],
+ ant_props,
+ False,
+ 0.0
+ )
+ new_ob = create_mesh_object(context, verts, [], faces, new_name).object
+ if ob['remove_double']:
+ new_ob.select = True
+ bpy.ops.object.mode_set(mode = 'EDIT')
+ bpy.ops.mesh.remove_doubles(threshold=0.0001, use_unselected=False)
+ bpy.ops.object.mode_set(mode = 'OBJECT')
+ else:
+ # grid
+ verts, faces = grid_gen(
+ ob['subdivision_x'],
+ ob['subdivision_y'],
+ ob['tri_face'],
+ ob['mesh_size_x'],
+ ob['mesh_size_y'],
+ ant_props,
+ False,
+ 0.0
+ )
+ new_ob = create_mesh_object(context, verts, [], faces, new_name).object
+
+ new_ob.select = True
+
+ if ob['smooth_mesh']:
+ bpy.ops.object.shade_smooth()
+
+ # Landscape Material
+ if ob['land_material'] != "" and ob['land_material'] in bpy.data.materials:
+ mat = bpy.data.materials[ob['land_material']]
+ bpy.context.object.data.materials.append(mat)
+
+ # Water plane
+ if ob['water_plane']:
+ if ob['sphere_mesh']:
+ # sphere
+ verts, faces = sphere_gen(
+ ob['subdivision_y'],
+ ob['subdivision_x'],
+ ob['tri_face'],
+ ob['mesh_size'],
+ ant_props,
+ ob['water_plane'],
+ ob['water_level']
+ )
+ wobj = create_mesh_object(context, verts, [], faces, new_name+"_plane").object
+ if ob['remove_double']:
+ wobj.select = True
+ bpy.ops.object.mode_set(mode = 'EDIT')
+ bpy.ops.mesh.remove_doubles(threshold=0.0001, use_unselected=False)
+ bpy.ops.object.mode_set(mode = 'OBJECT')
+ else:
+ # grid
+ verts, faces = grid_gen(
+ 2,
+ 2,
+ ob['tri_face'],
+ ob['mesh_size_x'],
+ ob['mesh_size_y'],
+ ant_props,
+ ob['water_plane'],
+ ob['water_level']
+ )
+ wobj = create_mesh_object(context, verts, [], faces, new_name+"_plane").object
+
+ wobj.select = True
+
+ if ob['smooth_mesh']:
+ bpy.ops.object.shade_smooth()
+
+ # Water Material
+ if ob['water_material'] != "" and ob['water_material'] in bpy.data.materials:
+ mat = bpy.data.materials[ob['water_material']]
+ bpy.context.object.data.materials.append(mat)
+
+ # Loc Rot Scale
+ if ob['water_plane']:
+ wobj.location = obj.location
+ wobj.rotation_euler = obj.rotation_euler
+ wobj.scale = obj.scale
+ wobj.select = False
+
+ new_ob.location = obj.location
+ new_ob.rotation_euler = obj.rotation_euler
+ new_ob.scale = obj.scale
+
+ # Store props
+ new_ob = store_properties(ob, new_ob)
+
+ # Delete old object
+ new_ob.select = False
+
+ obj.select = True
+ scene.objects.active = obj
+ bpy.ops.object.delete(use_global=False)
+
+ # Select landscape and make active
+ new_ob.select = True
+ scene.objects.active = new_ob
+
+ # restore pre operator undo state
+ context.user_preferences.edit.use_global_undo = undo
+
+ return {'FINISHED'}
+
+
+# ------------------------------------------------------------
# Z normal value to vertex group (Slope map)
class AntVgSlopeMap(bpy.types.Operator):
bl_idname = "mesh.ant_slope_map"
@@ -217,434 +412,6 @@ class AntVgSlopeMap(bpy.types.Operator):
# ------------------------------------------------------------
-# A.N.T. Noise:
-
-# Functions for marble_noise:
-def sin_bias(a):
- return 0.5 + 0.5 * sin(a)
-
-
-def cos_bias(a):
- return 0.5 + 0.5 * cos(a)
-
-
-def tri_bias(a):
- b = 2 * pi
- a = 1 - 2 * abs(floor((a * (1 / b)) + 0.5) - (a * (1 / b)))
- return a
-
-
-def saw_bias(a):
- b = 2 * pi
- n = int(a / b)
- a -= n * b
- if a < 0:
- a += b
- return a / b
-
-
-def soft(a):
- return a
-
-
-def sharp(a):
- return a**0.5
-
-
-def sharper(a):
- return sharp(sharp(a))
-
-
-def shapes(x, y, z, shape=0):
- p = pi
- if shape is 1:
- # ring
- x = x * p
- y = y * p
- s = cos(x**2 + y**2) / (x**2 + y**2 + 0.5)
- elif shape is 2:
- # swirl
- x = x * p
- y = y * p
- s = ((x * sin(x * x + y * y) + y * cos(x * x + y * y)) / (x**2 + y**2 + 0.5))
- elif shape is 3:
- # bumps
- x = x * p
- y = y * p
- z = z * p
- s = 1 - ((cos(x * p) + cos(y * p) + cos(z * p)) - 0.5)
- elif shape is 4:
- # wave
- x = x * p * 2
- y = y * p * 2
- s = sin(x + sin(y))
- elif shape is 5:
- # z grad.
- s = (z * p)
- elif shape is 6:
- # y grad.
- s = (y * p)
- elif shape is 7:
- # x grad.
- s = (x * p)
- else:
- # marble default
- s = ((x + y + z) * 5)
- return s
-
-
-# marble_noise
-def marble_noise(x, y, z, origin, size, shape, bias, sharpnes, turb, depth, hard, basis, amp, freq):
-
- s = shapes(x, y, z, shape)
- x += origin[0]
- y += origin[1]
- z += origin[2]
- value = s + turb * turbulence_vector((x, y, z), depth, hard, basis)[1]
-
- if bias is 1:
- value = cos_bias(value)
- elif bias is 2:
- value = tri_bias(value)
- elif bias is 3:
- value = saw_bias(value)
- else:
- value = sin_bias(value)
-
- if sharpnes is 1:
- value = 1.0 - sharp(value)
- elif sharpnes is 2:
- value = 1.0 - sharper(value)
- elif sharpnes is 3:
- value = soft(value)
- elif sharpnes is 4:
- value = sharp(value)
- elif sharpnes is 5:
- value = sharper(value)
- else:
- value = 1.0 - soft(value)
-
- return value
-
-
-# vl_noise_turbulence:
-def vlnTurbMode(coords, distort, basis, vlbasis, hardnoise):
- # hard noise
- if hardnoise:
- return (abs(-variable_lacunarity(coords, distort, basis, vlbasis)))
- # soft noise
- else:
- return variable_lacunarity(coords, distort, basis, vlbasis)
-
-
-def vl_noise_turbulence(coords, distort, depth, basis, vlbasis, hardnoise, amp, freq):
- x, y, z = coords
- value = vlnTurbMode(coords, distort, basis, vlbasis, hardnoise)
- i=0
- for i in range(depth):
- i+=1
- value += vlnTurbMode((x * (freq * i), y * (freq * i), z * (freq * i)), distort, basis, vlbasis, hardnoise) * (amp * 0.5 / i)
- return value
-
-
-## duo_multiFractal:
-def double_multiFractal(coords, H, lacunarity, octaves, offset, gain, basis, vlbasis):
- x, y, z = coords
- n1 = multi_fractal((x * 1.5 + 1, y * 1.5 + 1, z * 1.5 + 1), 1.0, 1.0, 1.0, basis) * (offset * 0.5)
- n2 = multi_fractal((x - 1, y - 1, z - 1), H, lacunarity, octaves, vlbasis) * (gain * 0.5)
- return (n1 * n1 + n2 * n2) * 0.5
-
-
-## distorted_heteroTerrain:
-def distorted_heteroTerrain(coords, H, lacunarity, octaves, offset, distort, basis, vlbasis):
- x, y, z = coords
- h1 = (hetero_terrain((x, y, z), 1.0, 2.0, 1.0, 1.0, basis) * 0.5)
- d = h1 * distort
- h2 = (hetero_terrain((x + d, y + d, z + d), H, lacunarity, octaves, offset, vlbasis) * 0.25)
- return (h1 * h1 + h2 * h2) * 0.5
-
-
-## SlickRock:
-def slick_rock(coords, H, lacunarity, octaves, offset, gain, distort, basis, vlbasis):
- x, y, z = coords
- n = multi_fractal((x,y,z), 1.0, 2.0, 2.0, basis) * distort * 0.25
- r = ridged_multi_fractal((x + n, y + n, z + n), H, lacunarity, octaves, offset + 0.1, gain * 2, vlbasis)
- return (n + (n * r)) * 0.5
-
-
-## vlhTerrain
-def vl_hTerrain(coords, H, lacunarity, octaves, offset, basis, vlbasis, distort):
- x, y, z = coords
- ht = hetero_terrain((x, y, z), H, lacunarity, octaves, offset, basis ) * 0.25
- vl = ht * variable_lacunarity((x, y, z), distort, basis, vlbasis) * 0.5 + 0.5
- return vl * ht
-
-
-# another turbulence
-def ant_turbulence(coords, depth, hardnoise, nbasis, amp, freq, distortion):
- x, y, z = coords
- t = turbulence_vector((x/2, y/2, z/2), depth, 0, nbasis, amp, freq) * 0.5 * distortion
- return turbulence((t[0], t[1], t[2]), 2, hardnoise, 3) * 0.5 + 0.5
-
-
-# rocks noise
-def rocks_noise(coords, depth, hardnoise, nbasis, distortion):
- x,y,z = coords
- p = turbulence((x, y, z), 4, 0, 0) * 0.125 * distortion
- xx, yy, zz = x, y, z
- a = turbulence((xx + p, yy + p, zz), 2, 0, 7)
- pa = a * 0.1875 * distortion
- b = turbulence((x, y, z + pa), depth, hardnoise, nbasis)
- return ((a + 0.5 * (b - a)) * 0.5 + 0.5)
-
-
-# shattered_hterrain:
-def shattered_hterrain(coords, H, lacunarity, octaves, offset, distort, basis):
- x, y, z = coords
- d = (turbulence_vector(coords, 6, 0, 0)[0] * 0.5 + 0.5) * distort * 0.5
- t1 = (turbulence_vector((x + d, y + d, z + d), 0, 0, 7)[0] + 0.5)
- t2 = (hetero_terrain((x * 2, y * 2, z * 2), H, lacunarity, octaves, offset, basis) * 0.5)
- return ((t1 * t2) + t2 * 0.5) * 0.5
-
-
-# strata_hterrain
-def strata_hterrain(coords, H, lacunarity, octaves, offset, distort, basis):
- x, y, z = coords
- value = hetero_terrain((x, y, z), H, lacunarity, octaves, offset, basis) * 0.5
- steps = (sin(value * (distort * 5) * pi) * (0.1 / (distort * 5) * pi))
- return (value * (1.0 - 0.5) + steps * 0.5)
-
-
-# Planet Noise by: Farsthary
-# https://farsthary.com/2010/11/24/new-planet-procedural-texture/
-def planet_noise(coords, oct=6, hard=0, noisebasis=1, nabla=0.001):
- x, y, z = coords
- d = 0.001
- offset = nabla * 1000
- x = turbulence((x, y, z), oct, hard, noisebasis)
- y = turbulence((x + offset, y, z), oct, hard, noisebasis)
- z = turbulence((x, y + offset, z), oct, hard, noisebasis)
- xdy = x - turbulence((x, y + d, z), oct, hard, noisebasis)
- xdz = x - turbulence((x, y, z + d), oct, hard, noisebasis)
- ydx = y - turbulence((x + d, y, z), oct, hard, noisebasis)
- ydz = y - turbulence((x, y, z + d), oct, hard, noisebasis)
- zdx = z - turbulence((x + d, y, z), oct, hard, noisebasis)
- zdy = z - turbulence((x, y + d, z), oct, hard, noisebasis)
- return (zdy - ydz), (zdx - xdz), (ydx - xdy)
-
-
-# ------------------------------------------------------------
-# landscape_gen
-def noise_gen(coords, props):
-
- terrain_name = props[0]
- cursor = props[1]
- smooth = props[2]
- triface = props[3]
- sphere = props[4]
- land_mat = props[5]
- water_mat = props[6]
- texture_name = props[7]
- subd_x = props[8]
- subd_y = props[9]
- meshsize_x = props[10]
- meshsize_y = props[11]
- meshsize = props[12]
- rseed = props[13]
- x_offset = props[14]
- y_offset = props[15]
- z_offset = props[16]
- size_x = props[17]
- size_y = props[18]
- size_z = props[19]
- nsize = props[20]
- ntype = props[21]
- nbasis = int(props[22])
- vlbasis = int(props[23])
- distortion = props[24]
- hardnoise = int(props[25])
- depth = props[26]
- amp = props[27]
- freq = props[28]
- dimension = props[29]
- lacunarity = props[30]
- offset = props[31]
- gain = props[32]
- marblebias = int(props[33])
- marblesharpnes = int(props[34])
- marbleshape = int(props[35])
- height = props[36]
- height_invert = props[37]
- height_offset = props[38]
- maximum = props[39]
- minimum = props[40]
- falloff = int(props[41])
- edge_level = props[42]
- falloffsize_x = props[43]
- falloffsize_y = props[44]
- stratatype = props[45]
- strata = props[46]
- addwater = props[47]
- waterlevel = props[48]
-
- x, y, z = coords
-
- # Origin
- if rseed is 0:
- origin = x_offset, y_offset, z_offset
- origin_x = x_offset
- origin_y = y_offset
- origin_z = z_offset
- o_range = 1.0
- else:
- # Randomise origin
- o_range = 10000.0
- seed_set(rseed)
- origin = random_unit_vector()
- ox = (origin[0] * o_range)
- oy = (origin[1] * o_range)
- oz = (origin[2] * o_range)
- origin_x = (ox - (ox / 2)) + x_offset
- origin_y = (oy - (oy / 2)) + y_offset
- origin_z = (oz - (oz / 2)) + z_offset
-
- ncoords = (x / (nsize * size_x) + origin_x, y / (nsize * size_y) + origin_y, z / (nsize * size_z) + origin_z)
-
- # Noise basis type's
- if nbasis == 9:
- nbasis = 14 # Cellnoise
- if vlbasis == 9:
- vlbasis = 14
-
- # Noise type's
- if ntype in [0, 'multi_fractal']:
- value = multi_fractal(ncoords, dimension, lacunarity, depth, nbasis) * 0.5
-
- elif ntype in [1, 'ridged_multi_fractal']:
- value = ridged_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis) * 0.5
-
- elif ntype in [2, 'hybrid_multi_fractal']:
- value = hybrid_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis) * 0.5
-
- elif ntype in [3, 'hetero_terrain']:
- value = hetero_terrain(ncoords, dimension, lacunarity, depth, offset, nbasis) * 0.25
-
- elif ntype in [4, 'fractal']:
- value = fractal(ncoords, dimension, lacunarity, depth, nbasis)
-
- elif ntype in [5, 'turbulence_vector']:
- value = turbulence_vector(ncoords, depth, hardnoise, nbasis, amp, freq)[0]
-
- elif ntype in [6, 'variable_lacunarity']:
- value = variable_lacunarity(ncoords, distortion, nbasis, vlbasis)
-
- elif ntype in [7, 'marble_noise']:
- value = marble_noise(
- (ncoords[0] - origin_x + x_offset),
- (ncoords[1] - origin_y + y_offset),
- (ncoords[2] - origin_z + z_offset),
- (origin[0] + x_offset, origin[1] + y_offset, origin[2] + z_offset), nsize,
- marbleshape, marblebias, marblesharpnes,
- distortion, depth, hardnoise, nbasis, amp, freq
- )
- elif ntype in [8, 'shattered_hterrain']:
- value = shattered_hterrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis)
-
- elif ntype in [9, 'strata_hterrain']:
- value = strata_hterrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis)
-
- elif ntype in [10, 'ant_turbulence']:
- value = ant_turbulence(ncoords, depth, hardnoise, nbasis, amp, freq, distortion)
-
- elif ntype in [11, 'vl_noise_turbulence']:
- value = vl_noise_turbulence(ncoords, distortion, depth, nbasis, vlbasis, hardnoise, amp, freq)
-
- elif ntype in [12, 'vl_hTerrain']:
- value = vl_hTerrain(ncoords, dimension, lacunarity, depth, offset, nbasis, vlbasis, distortion)
-
- elif ntype in [13, 'distorted_heteroTerrain']:
- value = distorted_heteroTerrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis, vlbasis)
-
- elif ntype in [14, 'double_multiFractal']:
- value = double_multiFractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis, vlbasis)
-
- elif ntype in [15, 'rocks_noise']:
- value = rocks_noise(ncoords, depth, hardnoise, nbasis, distortion)
-
- elif ntype in [16, 'slick_rock']:
- value = slick_rock(ncoords,dimension, lacunarity, depth, offset, gain, distortion, nbasis, vlbasis)
-
- elif ntype in [17, 'planet_noise']:
- value = planet_noise(ncoords, depth, hardnoise, nbasis)[2] * 0.5 + 0.5
-
- elif ntype in [18, 'blender_texture']:
- if texture_name != "" and texture_name in bpy.data.textures:
- value = bpy.data.textures[texture_name].evaluate(ncoords)[3]
- else:
- value = 0.0
- else:
- value = 0.5
-
- # Adjust height
- if height_invert:
- value = 1.0 - value
- value = value * height + height_offset
- else:
- value = value * height + height_offset
-
- # Edge falloff:
- if not sphere:
- if falloff:
- ratio_x, ratio_y = abs(x) * 2 / meshsize_x, abs(y) * 2 / meshsize_y
- fallofftypes = [0,
- sqrt(ratio_y**falloffsize_y),
- sqrt(ratio_x**falloffsize_x),
- sqrt(ratio_x**falloffsize_x + ratio_y**falloffsize_y)
- ]
- dist = fallofftypes[falloff]
- value -= edge_level
- if(dist < 1.0):
- dist = (dist * dist * (3 - 2 * dist))
- value = (value - value * dist) + edge_level
- else:
- value = edge_level
-
- # Strata / terrace / layers
- if stratatype not in [0, "0"]:
- if stratatype in [1, "1"]:
- strata = strata / height
- strata *= 2
- steps = (sin(value * strata * pi) * (0.1 / strata * pi))
- value = (value * 0.5 + steps * 0.5) * 2.0
-
- elif stratatype in [2, "2"]:
- strata = strata / height
- steps = -abs(sin(value * strata * pi) * (0.1 / strata * pi))
- value = (value * 0.5 + steps * 0.5) * 2.0
-
- elif stratatype in [3, "3"]:
- strata = strata / height
- steps = abs(sin(value * strata * pi) * (0.1 / strata * pi))
- value = (value * 0.5 + steps * 0.5) * 2.0
-
- elif stratatype in [4, "4"]:
- strata = strata / height
- value = int( value * strata ) * 1.0 / strata
-
- elif stratatype in [5, "5"]:
- strata = strata / height
- steps = (int( value * strata ) * 1.0 / strata)
- value = (value * (1.0 - 0.5) + steps * 0.5)
-
- # Clamp height min max
- if (value < minimum):
- value = minimum
- if (value > maximum):
- value = maximum
-
- return value
-
-# ------------------------------------------------------------
# draw properties
def draw_ant_refresh(self, context):
@@ -711,7 +478,8 @@ def draw_ant_noise(self, context, generate=True):
col = box.column(align=True)
col.prop(self, "noise_offset_x")
col.prop(self, "noise_offset_y")
- col.prop(self, "noise_offset_z")
+ if self.sphere_mesh == True or generate == False:
+ col.prop(self, "noise_offset_z")
col.prop(self, "noise_size_x")
col.prop(self, "noise_size_y")
if self.sphere_mesh == True or generate == False:
@@ -792,7 +560,7 @@ def draw_ant_noise(self, context, generate=True):
col.prop(self, "frequency")
col.prop(self, "distortion")
col.separator()
- col.prop(self, "vl_basis_type")
+ box.prop(self, "vl_basis_type")
col.separator()
row = col.row(align=True)
row.prop(self, "hard_noise", expand=True)
@@ -803,7 +571,7 @@ def draw_ant_noise(self, context, generate=True):
col.prop(self, "offset")
col.prop(self, "distortion")
col.separator()
- col.prop(self, "vl_basis_type")
+ box.prop(self, "vl_basis_type")
elif self.noise_type == "distorted_heteroTerrain":
col.prop(self, "noise_depth")
col.prop(self, "dimension")
@@ -811,7 +579,7 @@ def draw_ant_noise(self, context, generate=True):
col.prop(self, "offset")
col.prop(self, "distortion")
col.separator()
- col.prop(self, "vl_basis_type")
+ box.prop(self, "vl_basis_type")
elif self.noise_type == "double_multiFractal":
col.prop(self, "noise_depth")
col.prop(self, "dimension")
@@ -819,7 +587,7 @@ def draw_ant_noise(self, context, generate=True):
col.prop(self, "offset")
col.prop(self, "gain")
col.separator()
- col.prop(self, "vl_basis_type")
+ box.prop(self, "vl_basis_type")
elif self.noise_type == "rocks_noise":
col.prop(self, "noise_depth")
col.prop(self, "distortion")
@@ -834,13 +602,42 @@ def draw_ant_noise(self, context, generate=True):
col.prop(self, "offset")
col.prop(self, "distortion")
col.separator()
- col.prop(self, "vl_basis_type")
+ box.prop(self, "vl_basis_type")
elif self.noise_type == "planet_noise":
col.prop(self, "noise_depth")
col.separator()
row = col.row(align=True)
row.prop(self, "hard_noise", expand=True)
+ # Effects mix
+ col = box.column(align=False)
+ box.prop(self, "fx_type")
+ if self.fx_type != "0":
+ if int(self.fx_type) <= 12:
+ box.prop(self, "fx_bias")
+
+ box.prop(self, "fx_mix_mode")
+ col = box.column(align=True)
+ col.prop(self, "fx_mixfactor")
+
+ col = box.column(align=True)
+ col.prop(self, "fx_loc_x")
+ col.prop(self, "fx_loc_y")
+ col.prop(self, "fx_size")
+
+ col = box.column(align=True)
+ col.prop(self, "fx_depth")
+ if self.fx_depth != 0:
+ col.prop(self, "fx_frequency")
+ col.prop(self, "fx_amplitude")
+ col.prop(self, "fx_turb")
+
+ col = box.column(align=True)
+ row = col.row(align=True).split(0.92, align=True)
+ row.prop(self, "fx_height")
+ row.prop(self, "fx_invert", toggle=True, text="", icon='ARROW_LEFTRIGHT')
+ col.prop(self, "fx_offset")
+
def draw_ant_displace(self, context, generate=True):
layout = self.layout
@@ -946,6 +743,20 @@ def store_properties(operator, ob):
ob.ant_landscape.water_level = operator.water_level
ob.ant_landscape.vert_group = operator.vert_group
ob.ant_landscape.remove_double = operator.remove_double
+ ob.ant_landscape.fx_mixfactor = operator.fx_mixfactor
+ ob.ant_landscape.fx_mix_mode = operator.fx_mix_mode
+ ob.ant_landscape.fx_type = operator.fx_type
+ ob.ant_landscape.fx_bias = operator.fx_bias
+ ob.ant_landscape.fx_turb = operator.fx_turb
+ ob.ant_landscape.fx_depth = operator.fx_depth
+ ob.ant_landscape.fx_frequency = operator.fx_frequency
+ ob.ant_landscape.fx_amplitude = operator.fx_amplitude
+ ob.ant_landscape.fx_size = operator.fx_size
+ ob.ant_landscape.fx_loc_x = operator.fx_loc_x
+ ob.ant_landscape.fx_loc_y = operator.fx_loc_y
+ ob.ant_landscape.fx_height = operator.fx_height
+ ob.ant_landscape.fx_offset = operator.fx_offset
+ ob.ant_landscape.fx_invert = operator.fx_invert
return ob
@@ -999,7 +810,6 @@ class Eroder(bpy.types.Operator):
min=1,
soft_max=10
)
-
Ef = FloatProperty(
name="Rain on Plains",
description="1 gives equal rain across the terrain, 0 rains more at the mountain tops",
@@ -1014,7 +824,6 @@ class Eroder(bpy.types.Operator):
min=0,
soft_max=100
)
-
Kt = FloatProperty(
name="Kt",
description="Maximum stable talus angle",
@@ -1023,7 +832,6 @@ class Eroder(bpy.types.Operator):
max=radians(90),
subtype='ANGLE'
)
-
Kr = FloatProperty(
name="Rain amount",
description="Total Rain amount",
@@ -1044,7 +852,6 @@ class Eroder(bpy.types.Operator):
description="Use active vertex group as a rain map",
default=True
)
-
Ks = FloatProperty(
name="Soil solubility",
description="Soil solubility - how quickly water quickly reaches saturation point",
@@ -1086,13 +893,11 @@ class Eroder(bpy.types.Operator):
min=0,
soft_max=2
)
-
numexpr = BoolProperty(
name="Numexpr",
description="Use numexpr module (if available)",
default=True
)
-
Pd = FloatProperty(
name="Diffusion Amount",
description="Diffusion probability",
@@ -1114,13 +919,11 @@ class Eroder(bpy.types.Operator):
min=0,
max=1
)
-
smooth = BoolProperty(
name="Smooth",
description="Set smooth shading",
default=True
)
-
showiterstats = BoolProperty(
name="Iteration Stats",
description="Show iteraration statistics",
diff --git a/ant_landscape/ant_landscape_refresh.py b/ant_landscape/ant_landscape_refresh.py
deleted file mode 100644
index b809619e..00000000
--- a/ant_landscape/ant_landscape_refresh.py
+++ /dev/null
@@ -1,238 +0,0 @@
-# ##### BEGIN GPL LICENSE BLOCK #####
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# ##### END GPL LICENSE BLOCK #####
-
-# Another Noise Tool - Landscape Redraw - Regenerate
-# Jimmy Hazevoet
-
-# ------------------------------------------------------------
-# import modules
-import bpy
-
-from .ant_functions import (
- noise_gen,
- grid_gen,
- sphere_gen,
- create_mesh_object,
- store_properties,
- )
-
-# ------------------------------------------------------------
-# Do refresh - redraw
-class AntLandscapeRefresh(bpy.types.Operator):
- bl_idname = "mesh.ant_landscape_refresh"
- bl_label = "Refresh"
- bl_description = "Refresh landscape with current settings"
- bl_options = {'REGISTER', 'UNDO'}
-
-
- @classmethod
- def poll(cls, context):
- ob = bpy.context.active_object
- return (ob.ant_landscape and not ob.ant_landscape['sphere_mesh'])
-
-
- def execute(self, context):
- # turn off undo
- undo = bpy.context.user_preferences.edit.use_global_undo
- bpy.context.user_preferences.edit.use_global_undo = False
-
- # ant object items
- obj = bpy.context.active_object
-
- bpy.ops.object.mode_set(mode = 'EDIT')
- bpy.ops.object.mode_set(mode = 'OBJECT')
-
- if obj and obj.ant_landscape.keys():
- ob = obj.ant_landscape
- obi = ob.items()
- prop = []
- for i in range(len(obi)):
- prop.append(obi[i][1])
-
- # redraw verts
- mesh = obj.data
-
- if ob['vert_group'] != "" and ob['vert_group'] in obj.vertex_groups:
- vertex_group = obj.vertex_groups[ob['vert_group']]
- gi = vertex_group.index
- for v in mesh.vertices:
- for g in v.groups:
- if g.group == gi:
- v.co[2] = 0.0
- v.co[2] = vertex_group.weight(v.index) * noise_gen(v.co, prop)
- else:
- for v in mesh.vertices:
- v.co[2] = 0
- v.co[2] = noise_gen(v.co, prop)
- mesh.update()
- else:
- pass
-
- # restore pre operator undo state
- context.user_preferences.edit.use_global_undo = undo
-
- return {'FINISHED'}
-
-
-# ------------------------------------------------------------
-# Do regenerate
-class AntLandscapeRegenerate(bpy.types.Operator):
- bl_idname = "mesh.ant_landscape_regenerate"
- bl_label = "Regenerate"
- bl_description = "Regenerate landscape with current settings"
- bl_options = {'REGISTER', 'UNDO'}
-
-
- @classmethod
- def poll(cls, context):
- return bpy.context.active_object.ant_landscape
-
-
- def execute(self, context):
-
- # turn off undo
- undo = bpy.context.user_preferences.edit.use_global_undo
- bpy.context.user_preferences.edit.use_global_undo = False
-
- scene = bpy.context.scene
- # ant object items
- obj = bpy.context.active_object
-
- if obj and obj.ant_landscape.keys():
- ob = obj.ant_landscape
- obi = ob.items()
- ant_props = []
- for i in range(len(obi)):
- ant_props.append(obi[i][1])
-
- new_name = obj.name
-
- # Main function, create landscape mesh object
- if ob['sphere_mesh']:
- # sphere
- verts, faces = sphere_gen(
- ob['subdivision_y'],
- ob['subdivision_x'],
- ob['tri_face'],
- ob['mesh_size'],
- ant_props,
- False,
- 0.0
- )
- new_ob = create_mesh_object(context, verts, [], faces, new_name).object
- if ob['remove_double']:
- new_ob.select = True
- bpy.ops.object.mode_set(mode = 'EDIT')
- bpy.ops.mesh.remove_doubles(threshold=0.0001, use_unselected=False)
- bpy.ops.object.mode_set(mode = 'OBJECT')
- else:
- # grid
- verts, faces = grid_gen(
- ob['subdivision_x'],
- ob['subdivision_y'],
- ob['tri_face'],
- ob['mesh_size_x'],
- ob['mesh_size_y'],
- ant_props,
- False,
- 0.0
- )
- new_ob = create_mesh_object(context, verts, [], faces, new_name).object
-
- new_ob.select = True
-
- if ob['smooth_mesh']:
- bpy.ops.object.shade_smooth()
-
- # Landscape Material
- if ob['land_material'] != "" and ob['land_material'] in bpy.data.materials:
- mat = bpy.data.materials[ob['land_material']]
- bpy.context.object.data.materials.append(mat)
-
- # Water plane
- if ob['water_plane']:
- if ob['sphere_mesh']:
- # sphere
- verts, faces = sphere_gen(
- ob['subdivision_y'],
- ob['subdivision_x'],
- ob['tri_face'],
- ob['mesh_size'],
- ant_props,
- ob['water_plane'],
- ob['water_level']
- )
- wobj = create_mesh_object(context, verts, [], faces, new_name+"_plane").object
- if ob['remove_double']:
- wobj.select = True
- bpy.ops.object.mode_set(mode = 'EDIT')
- bpy.ops.mesh.remove_doubles(threshold=0.0001, use_unselected=False)
- bpy.ops.object.mode_set(mode = 'OBJECT')
- else:
- # grid
- verts, faces = grid_gen(
- 2,
- 2,
- ob['tri_face'],
- ob['mesh_size_x'],
- ob['mesh_size_y'],
- ant_props,
- ob['water_plane'],
- ob['water_level']
- )
- wobj = create_mesh_object(context, verts, [], faces, new_name+"_plane").object
-
- wobj.select = True
-
- if ob['smooth_mesh']:
- bpy.ops.object.shade_smooth()
-
- # Water Material
- if ob['water_material'] != "" and ob['water_material'] in bpy.data.materials:
- mat = bpy.data.materials[ob['water_material']]
- bpy.context.object.data.materials.append(mat)
-
- # Loc Rot Scale
- if ob['water_plane']:
- wobj.location = obj.location
- wobj.rotation_euler = obj.rotation_euler
- wobj.scale = obj.scale
- wobj.select = False
-
- new_ob.location = obj.location
- new_ob.rotation_euler = obj.rotation_euler
- new_ob.scale = obj.scale
-
- # Store props
- new_ob = store_properties(ob, new_ob)
-
- # Delete old object
- new_ob.select = False
-
- obj.select = True
- scene.objects.active = obj
- bpy.ops.object.delete(use_global=False)
-
- # Select landscape and make active
- new_ob.select = True
- scene.objects.active = new_ob
-
- # restore pre operator undo state
- context.user_preferences.edit.use_global_undo = undo
-
- return {'FINISHED'}
diff --git a/ant_landscape/ant_noise.py b/ant_landscape/ant_noise.py
new file mode 100644
index 00000000..22a308a1
--- /dev/null
+++ b/ant_landscape/ant_noise.py
@@ -0,0 +1,705 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# Another Noise Tool - Noise and Effects
+# Jimmy Hazevoet
+
+import bpy
+from mathutils.noise import (
+ seed_set,
+ noise,
+ turbulence,
+ turbulence_vector,
+ fractal,
+ hybrid_multi_fractal,
+ multi_fractal,
+ ridged_multi_fractal,
+ hetero_terrain,
+ random_unit_vector,
+ variable_lacunarity,
+ voronoi,
+ )
+from math import (
+ floor, sqrt,
+ sin, cos, pi,
+ )
+
+# ------------------------------------------------------------
+# Height scale:
+def Height_Scale(input, iscale, offset, invert):
+ if invert != 0:
+ return (1.0 - input) * iscale + offset
+ else:
+ return input * iscale + offset
+
+
+# Functions for marble_noise and effects:
+
+def Dist(x, y):
+ return sqrt((x * x) + (y * y))
+
+
+def sin_bias(a):
+ return 0.5 + 0.5 * sin(a)
+
+
+def cos_bias(a):
+ return 0.5 + 0.5 * cos(a)
+
+
+def tri_bias(a):
+ b = 2 * pi
+ a = 1 - 2 * abs(floor((a * (1 / b)) + 0.5) - (a * (1 / b)))
+ return a
+
+
+def saw_bias(a):
+ b = 2 * pi
+ n = int(a / b)
+ a -= n * b
+ if a < 0:
+ a += b
+ return a / b
+
+
+def soft(a):
+ return a
+
+
+def sharp(a):
+ return a**0.5
+
+
+def sharper(a):
+ return sharp(sharp(a))
+
+
+def no_bias(a):
+ return a
+
+
+def shapes(x, y, z, shape=0):
+ p = pi
+ if shape is 1:
+ # ring
+ x = x * p
+ y = y * p
+ s = cos(x**2 + y**2) / (x**2 + y**2 + 0.5)
+ elif shape is 2:
+ # swirl
+ x = x * p
+ y = y * p
+ s = ((x * sin(x * x + y * y) + y * cos(x * x + y * y)) / (x**2 + y**2 + 0.5))
+ elif shape is 3:
+ # bumps
+ x = x * p
+ y = y * p
+ z = z * p
+ s = 1 - ((cos(x * p) + cos(y * p) + cos(z * p)) - 0.5)
+ elif shape is 4:
+ # wave
+ x = x * p * 2
+ y = y * p * 2
+ s = sin(x + sin(y))
+ elif shape is 5:
+ # z grad.
+ s = (z * p)
+ elif shape is 6:
+ # y grad.
+ s = (y * p)
+ elif shape is 7:
+ # x grad.
+ s = (x * p)
+ else:
+ # marble default
+ s = ((x + y + z) * 5)
+ return s
+
+
+# marble_noise
+def marble_noise(x, y, z, origin, size, shape, bias, sharpnes, turb, depth, hard, basis, amp, freq):
+
+ s = shapes(x, y, z, shape)
+ x += origin[0]
+ y += origin[1]
+ z += origin[2]
+ value = s + turb * turbulence_vector((x, y, z), depth, hard, basis)[1]
+
+ if bias is 1:
+ value = cos_bias(value)
+ elif bias is 2:
+ value = tri_bias(value)
+ elif bias is 3:
+ value = saw_bias(value)
+ else:
+ value = sin_bias(value)
+
+ if sharpnes is 1:
+ value = 1.0 - sharp(value)
+ elif sharpnes is 2:
+ value = 1.0 - sharper(value)
+ elif sharpnes is 3:
+ value = soft(value)
+ elif sharpnes is 4:
+ value = sharp(value)
+ elif sharpnes is 5:
+ value = sharper(value)
+ else:
+ value = 1.0 - soft(value)
+
+ return value
+
+
+# vl_noise_turbulence:
+def vlnTurbMode(coords, distort, basis, vlbasis, hardnoise):
+ # hard noise
+ if hardnoise:
+ return (abs(-variable_lacunarity(coords, distort, basis, vlbasis)))
+ # soft noise
+ else:
+ return variable_lacunarity(coords, distort, basis, vlbasis)
+
+
+def vl_noise_turbulence(coords, distort, depth, basis, vlbasis, hardnoise, amp, freq):
+ x, y, z = coords
+ value = vlnTurbMode(coords, distort, basis, vlbasis, hardnoise)
+ i=0
+ for i in range(depth):
+ i+=1
+ value += vlnTurbMode((x * (freq * i), y * (freq * i), z * (freq * i)), distort, basis, vlbasis, hardnoise) * (amp * 0.5 / i)
+ return value
+
+
+## duo_multiFractal:
+def double_multiFractal(coords, H, lacunarity, octaves, offset, gain, basis, vlbasis):
+ x, y, z = coords
+ n1 = multi_fractal((x * 1.5 + 1, y * 1.5 + 1, z * 1.5 + 1), 1.0, 1.0, 1.0, basis) * (offset * 0.5)
+ n2 = multi_fractal((x - 1, y - 1, z - 1), H, lacunarity, octaves, vlbasis) * (gain * 0.5)
+ return (n1 * n1 + n2 * n2) * 0.5
+
+
+## distorted_heteroTerrain:
+def distorted_heteroTerrain(coords, H, lacunarity, octaves, offset, distort, basis, vlbasis):
+ x, y, z = coords
+ h1 = (hetero_terrain((x, y, z), 1.0, 2.0, 1.0, 1.0, basis) * 0.5)
+ d = h1 * distort
+ h2 = (hetero_terrain((x + d, y + d, z + d), H, lacunarity, octaves, offset, vlbasis) * 0.25)
+ return (h1 * h1 + h2 * h2) * 0.5
+
+
+## SlickRock:
+def slick_rock(coords, H, lacunarity, octaves, offset, gain, distort, basis, vlbasis):
+ x, y, z = coords
+ n = multi_fractal((x,y,z), 1.0, 2.0, 2.0, basis) * distort * 0.25
+ r = ridged_multi_fractal((x + n, y + n, z + n), H, lacunarity, octaves, offset + 0.1, gain * 2, vlbasis)
+ return (n + (n * r)) * 0.5
+
+
+## vlhTerrain
+def vl_hTerrain(coords, H, lacunarity, octaves, offset, basis, vlbasis, distort):
+ x, y, z = coords
+ ht = hetero_terrain((x, y, z), H, lacunarity, octaves, offset, basis ) * 0.25
+ vl = ht * variable_lacunarity((x, y, z), distort, basis, vlbasis) * 0.5 + 0.5
+ return vl * ht
+
+
+# another turbulence
+def ant_turbulence(coords, depth, hardnoise, nbasis, amp, freq, distortion):
+ x, y, z = coords
+ t = turbulence_vector((x/2, y/2, z/2), depth, 0, nbasis, amp, freq) * 0.5 * distortion
+ return turbulence((t[0], t[1], t[2]), 2, hardnoise, 3) * 0.5 + 0.5
+
+
+# rocks noise
+def rocks_noise(coords, depth, hardnoise, nbasis, distortion):
+ x,y,z = coords
+ p = turbulence((x, y, z), 4, 0, 0) * 0.125 * distortion
+ xx, yy, zz = x, y, z
+ a = turbulence((xx + p, yy + p, zz), 2, 0, 7)
+ pa = a * 0.1875 * distortion
+ b = turbulence((x, y, z + pa), depth, hardnoise, nbasis)
+ return ((a + 0.5 * (b - a)) * 0.5 + 0.5)
+
+
+# shattered_hterrain:
+def shattered_hterrain(coords, H, lacunarity, octaves, offset, distort, basis):
+ x, y, z = coords
+ d = (turbulence_vector(coords, 6, 0, 0)[0] * 0.5 + 0.5) * distort * 0.5
+ t1 = (turbulence_vector((x + d, y + d, z + d), 0, 0, 7)[0] + 0.5)
+ t2 = (hetero_terrain((x * 2, y * 2, z * 2), H, lacunarity, octaves, offset, basis) * 0.5)
+ return ((t1 * t2) + t2 * 0.5) * 0.5
+
+
+# strata_hterrain
+def strata_hterrain(coords, H, lacunarity, octaves, offset, distort, basis):
+ x, y, z = coords
+ value = hetero_terrain((x, y, z), H, lacunarity, octaves, offset, basis) * 0.5
+ steps = (sin(value * (distort * 5) * pi) * (0.1 / (distort * 5) * pi))
+ return (value * (1.0 - 0.5) + steps * 0.5)
+
+
+# Planet Noise by: Farsthary
+# https://farsthary.com/2010/11/24/new-planet-procedural-texture/
+def planet_noise(coords, oct=6, hard=0, noisebasis=1, nabla=0.001):
+ x, y, z = coords
+ d = 0.001
+ offset = nabla * 1000
+ x = turbulence((x, y, z), oct, hard, noisebasis)
+ y = turbulence((x + offset, y, z), oct, hard, noisebasis)
+ z = turbulence((x, y + offset, z), oct, hard, noisebasis)
+ xdy = x - turbulence((x, y + d, z), oct, hard, noisebasis)
+ xdz = x - turbulence((x, y, z + d), oct, hard, noisebasis)
+ ydx = y - turbulence((x + d, y, z), oct, hard, noisebasis)
+ ydz = y - turbulence((x, y, z + d), oct, hard, noisebasis)
+ zdx = z - turbulence((x + d, y, z), oct, hard, noisebasis)
+ zdy = z - turbulence((x, y + d, z), oct, hard, noisebasis)
+ return (zdy - ydz), (zdx - xdz), (ydx - xdy)
+
+
+###----------------------------------------------------------------------
+# v.1.04 Effect functions:
+
+def maximum(a, b):
+ if (a > b): b = a
+ return b
+
+
+def minimum(a, b):
+ if (a < b): b = a
+ return b
+
+
+def Mix_Modes(a, b, mixfactor, mode):
+ mode = int(mode)
+ a = a * (1.0 - mixfactor)
+ b = b * (1.0 + mixfactor)
+ #1 mix
+ if mode == 0:
+ return (a * (1.0 - 0.5) + b * 0.5)
+ #2 add
+ elif mode == 1:
+ return (a + b)
+ #3 sub.
+ elif mode == 2:
+ return (a - b)
+ #4 mult.
+ elif mode == 3:
+ return (a * b)
+ #5 abs diff.
+ elif mode == 4:
+ return (abs(a - b))
+ #6 screen
+ elif mode == 5:
+ return 1.0 - ((1.0 - a) * (1.0 - b) / 1.0)
+ #7 addmodulo
+ elif mode == 6:
+ return (a + b) % 1.0
+ #8 min.
+ elif mode == 7:
+ return minimum(a, b)
+ #9 max.
+ elif mode == 8:
+ return maximum(a, b)
+ else:
+ return 0
+
+
+Bias_Types = [sin_bias, cos_bias, tri_bias, saw_bias, no_bias]
+Sharp_Types = [soft, sharp, sharper]
+
+
+# Transpose effect coords:
+def Trans_Effect(coords, size, loc):
+ x, y, z = coords
+ x = (x * 2.0 / size + loc[0])
+ y = (y * 2.0 / size + loc[1])
+ return x, y, z
+
+
+# Effect_Basis_Function:
+def Effect_Basis_Function(coords, type, bias):
+ bias = int(bias)
+ type = int(type)
+ x, y, z = coords
+ iscale = 1.0
+ offset = 0.0
+
+ ## gradient:
+ if type == 1:
+ effect = offset + iscale * (Bias_Types[bias](x + y))
+ ## waves / bumps:
+ elif type == 2:
+ effect = offset + iscale * 0.5 * (Bias_Types[bias](x * pi) + Bias_Types[bias](y * pi))
+ ## zigzag:
+ elif type == 3:
+ effect = offset + iscale * Bias_Types[bias](offset + iscale * sin(x * pi + sin(y * pi)))
+ ## wavy:
+ elif type == 4:
+ effect = offset + iscale * (Bias_Types[bias](cos(x) + sin(y) + cos(x * 2 + y * 2) - sin(-x * 4 + y * 4)))
+ ## sine bump:
+ elif type == 5:
+ effect = offset + iscale * 1 - Bias_Types[bias]((sin(x * pi) + sin(y * pi)))
+ ## dots:
+ elif type == 6:
+ effect = offset + iscale * (Bias_Types[bias](x * pi * 2) * Bias_Types[bias](y * pi * 2)) - 0.5
+ ## rings:
+ elif type == 7:
+ effect = offset + iscale * (Bias_Types[bias ](1.0 - (x * x + y * y)))
+ ## spiral:
+ elif type == 8:
+ effect = offset + iscale * Bias_Types[bias]( (x * sin(x * x + y * y) + y * cos(x * x + y * y)) / (x**2 + y**2 + 0.5)) * 2
+ ## square / piramide:
+ elif type == 9:
+ effect = offset + iscale * Bias_Types[bias](1.0 - sqrt((x * x)**10 + (y * y)**10)**0.1)
+ ## blocks:
+ elif type == 10:
+ effect = (0.5 - max(Bias_Types[bias](x * pi) , Bias_Types[bias](y * pi)))
+ if effect > 0.0:
+ effect = 1.0
+ effect = offset + iscale * effect
+ ## grid:
+ elif type == 11:
+ effect = (0.025 - min(Bias_Types[bias](x * pi), Bias_Types[bias](y * pi)))
+ if effect > 0.0:
+ effect = 1.0
+ effect = offset + iscale * effect
+ ## tech:
+ elif type == 12:
+ a = max(Bias_Types[bias](x * pi), Bias_Types[bias](y * pi))
+ b = max(Bias_Types[bias](x * pi * 2 + 2), Bias_Types[bias](y * pi * 2 + 2))
+ effect = min(Bias_Types[bias](a), Bias_Types[bias](b)) * 3.0 - 2.0
+ if effect > 0.5:
+ effect = 1.0
+ effect = offset + iscale * effect
+ ## crackle:
+ elif type == 13:
+ t = turbulence((x, y, 0), 6, 0, 0) * 0.25
+ effect = variable_lacunarity((x, y, t), 0.25, 0, 8)
+ if effect > 0.5:
+ effect = 0.5
+ effect = offset + iscale * effect
+ ## sparse cracks noise:
+ elif type == 14:
+ effect = 2.5 * abs(noise((x * 0.5, y * 0.5, 0), 1)) - 0.1
+ if effect > 0.25:
+ effect = 0.25
+ effect = offset + iscale * (effect * 2.5)
+ ## shattered rock noise:
+ elif type == 15:
+ effect = 0.5 + noise((x, y, 0), 7)
+ if effect > 0.75:
+ effect = 0.75
+ effect = offset + iscale * effect
+ ## lunar noise:
+ elif type == 16:
+ effect = 0.25 + 1.5 * voronoi((x, y, 0), 1)[0][0]
+ if effect > 0.5:
+ effect = 0.5
+ effect = offset + iscale * effect
+ ## cosine noise:
+ elif type == 17:
+ effect = cos(5 * noise((x, y, 0), 0))
+ effect = offset + iscale * (effect * 0.5)
+ ## spikey noise:
+ elif type == 18:
+ n = 0.5 + 0.5 * turbulence((x * 5, y * 5, 0), 8, 0, 0)
+ effect = ((n * n)**5)
+ effect = offset + iscale * effect
+ ## stone noise:
+ elif type == 19:
+ effect = offset + iscale * (noise((x * 2, y * 2, 0), 0) * 1.5 - 0.75)
+ ## Flat Turb:
+ elif type == 20:
+ t = turbulence((x, y, 0), 6, 0, 0)
+ effect = t * 2.0
+ if effect > 0.25:
+ effect = 0.25
+ effect = offset + iscale * effect
+ ## Flat Voronoi:
+ elif type == 21:
+ t = 1 - voronoi((x, y, 0), 1)[0][0]
+ effect = t * 2 - 1.5
+ if effect > 0.25:
+ effect = 0.25
+ effect = offset + iscale * effect
+ else:
+ effect = 0.0
+
+ if effect < 0.0:
+ effect = 0.0
+
+ return effect
+
+
+# fractalize Effect_Basis_Function: ------------------------------
+def Effect_Function(coords, type, bias, turb, depth, frequency, amplitude):
+
+ x, y, z = coords
+ ## turbulence:
+ if turb > 0.0:
+ t = turb * ( 0.5 + 0.5 * turbulence(coords, 6, 0, 0))
+ x = x + t
+ y = y + t
+ z = z + t
+
+ result = Effect_Basis_Function((x, y, z), type, bias) * amplitude
+ ## fractalize:
+ if depth != 0:
+ i=0
+ for i in range(depth):
+ i+=1
+ x *= frequency
+ y *= frequency
+ result += Effect_Basis_Function((x, y, z), type, bias) * amplitude / i
+
+ return result
+
+
+# ------------------------------------------------------------
+# landscape_gen
+def noise_gen(coords, props):
+
+ terrain_name = props[0]
+ cursor = props[1]
+ smooth = props[2]
+ triface = props[3]
+ sphere = props[4]
+ land_mat = props[5]
+ water_mat = props[6]
+ texture_name = props[7]
+ subd_x = props[8]
+ subd_y = props[9]
+ meshsize_x = props[10]
+ meshsize_y = props[11]
+ meshsize = props[12]
+ rseed = props[13]
+ x_offset = props[14]
+ y_offset = props[15]
+ z_offset = props[16]
+ size_x = props[17]
+ size_y = props[18]
+ size_z = props[19]
+ nsize = props[20]
+ ntype = props[21]
+ nbasis = int(props[22])
+ vlbasis = int(props[23])
+ distortion = props[24]
+ hardnoise = int(props[25])
+ depth = props[26]
+ amp = props[27]
+ freq = props[28]
+ dimension = props[29]
+ lacunarity = props[30]
+ offset = props[31]
+ gain = props[32]
+ marblebias = int(props[33])
+ marblesharpnes = int(props[34])
+ marbleshape = int(props[35])
+ height = props[36]
+ height_invert = props[37]
+ height_offset = props[38]
+ maximum = props[39]
+ minimum = props[40]
+ falloff = int(props[41])
+ edge_level = props[42]
+ falloffsize_x = props[43]
+ falloffsize_y = props[44]
+ stratatype = props[45]
+ strata = props[46]
+ addwater = props[47]
+ waterlevel = props[48]
+ vert_group = props[49]
+ remove_double = props[50]
+ fx_mixfactor = props[51]
+ fx_mix_mode = props[52]
+ fx_type = props[53]
+ fx_bias = props[54]
+ fx_turb = props[55]
+ fx_depth = props[56]
+ fx_frequency = props[57]
+ fx_amplitude = props[58]
+ fx_size = props[59]
+ fx_loc_x = props[60]
+ fx_loc_y = props[61]
+ fx_height = props[62]
+ fx_offset = props[63]
+ fx_invert = props[64]
+
+ x, y, z = coords
+
+ # Origin
+ if rseed is 0:
+ origin = x_offset, y_offset, z_offset
+ origin_x = x_offset
+ origin_y = y_offset
+ origin_z = z_offset
+ o_range = 1.0
+ else:
+ # Randomise origin
+ o_range = 10000.0
+ seed_set(rseed)
+ origin = random_unit_vector()
+ ox = (origin[0] * o_range)
+ oy = (origin[1] * o_range)
+ oz = (origin[2] * o_range)
+ origin_x = (ox - (ox / 2)) + x_offset
+ origin_y = (oy - (oy / 2)) + y_offset
+ origin_z = (oz - (oz / 2)) + z_offset
+
+ ncoords = (x / (nsize * size_x) + origin_x, y / (nsize * size_y) + origin_y, z / (nsize * size_z) + origin_z)
+
+ # Noise basis type's
+ if nbasis == 9:
+ nbasis = 14 # Cellnoise
+ if vlbasis == 9:
+ vlbasis = 14
+
+ # Noise type's
+ if ntype in [0, 'multi_fractal']:
+ value = multi_fractal(ncoords, dimension, lacunarity, depth, nbasis) * 0.5
+
+ elif ntype in [1, 'ridged_multi_fractal']:
+ value = ridged_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis) * 0.5
+
+ elif ntype in [2, 'hybrid_multi_fractal']:
+ value = hybrid_multi_fractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis) * 0.5
+
+ elif ntype in [3, 'hetero_terrain']:
+ value = hetero_terrain(ncoords, dimension, lacunarity, depth, offset, nbasis) * 0.25
+
+ elif ntype in [4, 'fractal']:
+ value = fractal(ncoords, dimension, lacunarity, depth, nbasis)
+
+ elif ntype in [5, 'turbulence_vector']:
+ value = turbulence_vector(ncoords, depth, hardnoise, nbasis, amp, freq)[0]
+
+ elif ntype in [6, 'variable_lacunarity']:
+ value = variable_lacunarity(ncoords, distortion, nbasis, vlbasis)
+
+ elif ntype in [7, 'marble_noise']:
+ value = marble_noise(
+ (ncoords[0] - origin_x + x_offset),
+ (ncoords[1] - origin_y + y_offset),
+ (ncoords[2] - origin_z + z_offset),
+ (origin[0] + x_offset, origin[1] + y_offset, origin[2] + z_offset), nsize,
+ marbleshape, marblebias, marblesharpnes,
+ distortion, depth, hardnoise, nbasis, amp, freq
+ )
+ elif ntype in [8, 'shattered_hterrain']:
+ value = shattered_hterrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis)
+
+ elif ntype in [9, 'strata_hterrain']:
+ value = strata_hterrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis)
+
+ elif ntype in [10, 'ant_turbulence']:
+ value = ant_turbulence(ncoords, depth, hardnoise, nbasis, amp, freq, distortion)
+
+ elif ntype in [11, 'vl_noise_turbulence']:
+ value = vl_noise_turbulence(ncoords, distortion, depth, nbasis, vlbasis, hardnoise, amp, freq)
+
+ elif ntype in [12, 'vl_hTerrain']:
+ value = vl_hTerrain(ncoords, dimension, lacunarity, depth, offset, nbasis, vlbasis, distortion)
+
+ elif ntype in [13, 'distorted_heteroTerrain']:
+ value = distorted_heteroTerrain(ncoords, dimension, lacunarity, depth, offset, distortion, nbasis, vlbasis)
+
+ elif ntype in [14, 'double_multiFractal']:
+ value = double_multiFractal(ncoords, dimension, lacunarity, depth, offset, gain, nbasis, vlbasis)
+
+ elif ntype in [15, 'rocks_noise']:
+ value = rocks_noise(ncoords, depth, hardnoise, nbasis, distortion)
+
+ elif ntype in [16, 'slick_rock']:
+ value = slick_rock(ncoords,dimension, lacunarity, depth, offset, gain, distortion, nbasis, vlbasis)
+
+ elif ntype in [17, 'planet_noise']:
+ value = planet_noise(ncoords, depth, hardnoise, nbasis)[2] * 0.5 + 0.5
+
+ elif ntype in [18, 'blender_texture']:
+ if texture_name != "" and texture_name in bpy.data.textures:
+ value = bpy.data.textures[texture_name].evaluate(ncoords)[3]
+ else:
+ value = 0.0
+ else:
+ value = 0.5
+
+ # Effect mix
+ if fx_type != "0":
+ fxcoords = Trans_Effect((x, y, z), fx_size, (fx_loc_x, fx_loc_y))
+ effect = Effect_Function(fxcoords, fx_type, fx_bias, fx_turb, fx_depth, fx_frequency, fx_amplitude)
+ effect = Height_Scale(effect, fx_height, fx_offset, fx_invert)
+ fxval = Mix_Modes(value, effect, fx_mixfactor, fx_mix_mode)
+ else:
+ fx_mixfactor = 0.0
+ fxval = value
+ value = fxval
+
+ # Adjust height
+ value = Height_Scale(value, height, height_offset, height_invert)
+
+ # Edge falloff:
+ if not sphere:
+ if falloff:
+ ratio_x, ratio_y = abs(x) * 2 / meshsize_x, abs(y) * 2 / meshsize_y
+ fallofftypes = [0,
+ sqrt(ratio_y**falloffsize_y),
+ sqrt(ratio_x**falloffsize_x),
+ sqrt(ratio_x**falloffsize_x + ratio_y**falloffsize_y)
+ ]
+ dist = fallofftypes[falloff]
+ value -= edge_level
+ if(dist < 1.0):
+ dist = (dist * dist * (3 - 2 * dist))
+ value = (value - value * dist) + edge_level
+ else:
+ value = edge_level
+
+ # Strata / terrace / layers
+ if stratatype not in [0, "0"]:
+ if stratatype in [1, "1"]:
+ strata = strata / height
+ strata *= 2
+ steps = (sin(value * strata * pi) * (0.1 / strata * pi))
+ value = (value * 0.5 + steps * 0.5) * 2.0
+
+ elif stratatype in [2, "2"]:
+ strata = strata / height
+ steps = -abs(sin(value * strata * pi) * (0.1 / strata * pi))
+ value = (value * 0.5 + steps * 0.5) * 2.0
+
+ elif stratatype in [3, "3"]:
+ strata = strata / height
+ steps = abs(sin(value * strata * pi) * (0.1 / strata * pi))
+ value = (value * 0.5 + steps * 0.5) * 2.0
+
+ elif stratatype in [4, "4"]:
+ strata = strata / height
+ value = int( value * strata ) * 1.0 / strata
+
+ elif stratatype in [5, "5"]:
+ strata = strata / height
+ steps = (int( value * strata ) * 1.0 / strata)
+ value = (value * (1.0 - 0.5) + steps * 0.5)
+
+ # Clamp height min max
+ if (value < minimum):
+ value = minimum
+ if (value > maximum):
+ value = maximum
+
+ return value
diff --git a/ant_landscape/mesh_ant_displace.py b/ant_landscape/mesh_ant_displace.py
index 7e1439b4..fb691abf 100644
--- a/ant_landscape/mesh_ant_displace.py
+++ b/ant_landscape/mesh_ant_displace.py
@@ -30,13 +30,13 @@ from bpy.props import (
StringProperty,
FloatVectorProperty,
)
-
from .ant_functions import (
- noise_gen,
draw_ant_refresh,
+ draw_ant_main,
draw_ant_noise,
draw_ant_displace,
)
+from .ant_noise import noise_gen
# ------------------------------------------------------------
# Do vert displacement
@@ -343,6 +343,136 @@ class AntMeshDisplace(bpy.types.Operator):
max=10000.0,
description="Height offset"
)
+
+ fx_mixfactor = FloatProperty(
+ name="Mix Factor",
+ default=0.0,
+ min=-1.0,
+ max=1.0,
+ description="Effect mix factor: -1.0 = Noise, +1.0 = Effect"
+ )
+ fx_mix_mode = EnumProperty(
+ name="Effect Mix",
+ default="0",
+ description="Effect mix mode",
+ items = [
+ ("0", "Mix", "Mix", 0),
+ ("1", "Add", "Add", 1),
+ ("2", "Sub", "Subtract", 2),
+ ("3", "Mul", "Multiply", 3),
+ ("4", "Abs", "Absolute", 4),
+ ("5", "Scr", "Screen", 5),
+ ("6", "Mod", "Modulo", 6),
+ ("7", "Min", "Minimum", 7),
+ ("8", "Max", "Maximum", 8)
+ ]
+ )
+ fx_type = EnumProperty(
+ name="Effect Type",
+ default="0",
+ description="Effect type",
+ items = [
+ ("0", "None", "No effect", 0),
+ ("1", "Gradient", "Gradient", 1),
+ ("2", "Waves", "Waves - Bumps", 2),
+ ("3", "Zigzag", "Zigzag", 3),
+ ("4", "Wavy", "Wavy", 4),
+ ("5", "Bump", "Bump", 5),
+ ("6", "Dots", "Dots", 6),
+ ("7", "Rings", "Rings", 7),
+ ("8", "Spiral", "Spiral", 8),
+ ("9", "Square", "Square", 9),
+ ("10", "Blocks", "Blocks", 10),
+ ("11", "Grid", "Grid", 11),
+ ("12", "Tech", "Tech", 12),
+ ("13", "Crackle", "Crackle", 13),
+ ("14", "Cracks", "Cracks", 14),
+ ("15", "Rock", "Rock noise", 15),
+ ("16", "Lunar", "Craters", 16),
+ ("17", "Cosine", "Cosine", 17),
+ ("18", "Spikey", "Spikey", 18),
+ ("19", "Stone", "Stone", 19),
+ ("20", "Flat Turb", "Flat turbulence", 20),
+ ("21", "Flat Voronoi", "Flat voronoi", 21)
+ ]
+ )
+ fx_bias = EnumProperty(
+ name="Effect Bias",
+ default="0",
+ description="Effect bias type",
+ items = [
+ ("0", "Sin", "Sin", 0),
+ ("1", "Cos", "Cos", 1),
+ ("2", "Tri", "Tri", 2),
+ ("3", "Saw", "Saw", 3),
+ ("4", "None", "None", 4)
+ ]
+ )
+ fx_turb = FloatProperty(
+ name="Distortion",
+ default=0.0,
+ min=0.0,
+ max=1000.0,
+ description="Effect turbulence distortion"
+ )
+ fx_depth = IntProperty(
+ name="Depth",
+ default=0,
+ min=0,
+ max=16,
+ description="Effect depth - number of frequencies"
+ )
+ fx_amplitude = FloatProperty(
+ name="Amp",
+ default=0.5,
+ min=0.01,
+ max=1.0,
+ description="Amplitude"
+ )
+ fx_frequency = FloatProperty(
+ name="Freq",
+ default=2.0,
+ min=0.01,
+ max=5.0,
+ description="Frequency"
+ )
+ fx_size = FloatProperty(
+ name="Effect Size",
+ default=1.0,
+ min=0.01,
+ max=1000.0,
+ description="Effect size"
+ )
+ fx_loc_x = FloatProperty(
+ name="Offset X",
+ default=0.0,
+ description="Effect x offset"
+ )
+ fx_loc_y = FloatProperty(
+ name="Offset Y",
+ default=0.0,
+ description="Effect y offset"
+ )
+ fx_height = FloatProperty(
+ name="Intensity",
+ default=1.0,
+ min=-1000.0,
+ max=1000.0,
+ description="Effect intensity scale"
+ )
+ fx_invert = BoolProperty(
+ name="Invert",
+ default=False,
+ description="Effect invert"
+ )
+ fx_offset = FloatProperty(
+ name="Offset",
+ default=0.0,
+ min=-1000.0,
+ max=1000.0,
+ description="Effect height offset"
+ )
+
edge_falloff = EnumProperty(
name="Falloff",
default="0",
@@ -423,7 +553,11 @@ class AntMeshDisplace(bpy.types.Operator):
max=10000.0,
description="Water level"
)
-
+ remove_double = BoolProperty(
+ name="Remove Doubles",
+ default=False,
+ description="Remove doubles"
+ )
direction = EnumProperty(
name="Direction",
default="NORMAL",
@@ -460,7 +594,6 @@ class AntMeshDisplace(bpy.types.Operator):
description="Automatic refresh"
)
-
def draw(self, context):
draw_ant_refresh(self, context)
draw_ant_noise(self, context, generate=False)
@@ -539,7 +672,22 @@ class AntMeshDisplace(bpy.types.Operator):
self.strata,
self.water_plane,
self.water_level,
- self.vert_group
+ self.vert_group,
+ self.remove_double,
+ self.fx_mixfactor,
+ self.fx_mix_mode,
+ self.fx_type,
+ self.fx_bias,
+ self.fx_turb,
+ self.fx_depth,
+ self.fx_frequency,
+ self.fx_amplitude,
+ self.fx_size,
+ self.fx_loc_x,
+ self.fx_loc_y,
+ self.fx_height,
+ self.fx_offset,
+ self.fx_invert
]
# do displace
@@ -547,6 +695,7 @@ class AntMeshDisplace(bpy.types.Operator):
if self.vert_group != "" and self.vert_group in ob.vertex_groups:
vertex_group = ob.vertex_groups[self.vert_group]
+
if vertex_group:
gi = vertex_group.index
if self.direction == "X":
@@ -554,16 +703,19 @@ class AntMeshDisplace(bpy.types.Operator):
for g in v.groups:
if g.group == gi:
v.co[0] += vertex_group.weight(v.index) * noise_gen(v.co, props)
+
if self.direction == "Y":
for v in mesh.vertices:
for g in v.groups:
if g.group == gi:
v.co[1] += vertex_group.weight(v.index) * noise_gen(v.co, props)
+
if self.direction == "Z":
for v in mesh.vertices:
for g in v.groups:
if g.group == gi:
v.co[2] += vertex_group.weight(v.index) * noise_gen(v.co, props)
+
else:
for v in mesh.vertices:
for g in v.groups:
@@ -574,12 +726,15 @@ class AntMeshDisplace(bpy.types.Operator):
if self.direction == "X":
for v in mesh.vertices:
v.co[0] += noise_gen(v.co, props)
+
elif self.direction == "Y":
for v in mesh.vertices:
v.co[1] += noise_gen(v.co, props)
+
elif self.direction == "Z":
for v in mesh.vertices:
v.co[2] += noise_gen(v.co, props)
+
else:
for v in mesh.vertices:
v.co += v.normal * noise_gen(v.co, props)