[Bf-extensions-cvs] [0891ff2e] master: update ant landscape

jimmyhaze noreply at git.blender.org
Sun May 21 02:08:58 CEST 2017


Commit: 0891ff2efcfe371d932b5b377b02ab9af7c46680
Author: jimmyhaze
Date:   Sun May 21 10:08:29 2017 +1000
Branches: master
https://developer.blender.org/rBA0891ff2efcfe371d932b5b377b02ab9af7c46680

update ant landscape

===================================================================

M	add_mesh_ant_landscape.py

===================================================================

diff --git a/add_mesh_ant_landscape.py b/add_mesh_ant_landscape.py
index 76f8c713..eaa19b54 100644
--- a/add_mesh_ant_landscape.py
+++ b/add_mesh_ant_landscape.py
@@ -65,7 +65,6 @@ Y_Offset:        Noise y offset in blender units
 Cursor:          Place at cursor location
 Vertex Group:    Slope map, z normal value to vertex group weight,
                     and select vertices on flat area's
-                 Height map, z coordinate value to vertex group weight
 
 NOISE OPTIONS: ( Many of these options are the same as in blender textures. )
 Random seed:     Use this to randomise the origin of the noise function.
@@ -104,7 +103,6 @@ Level:          Adjust plane level
 MATERIAL:       Use materials
 """
 
-# ------------------------------------------------------------
 # import modules
 import bpy
 from bpy.props import (
@@ -133,8 +131,170 @@ from math import (
         sin, cos, pi,
         )
 
+
+# Create a new mesh (object) from verts/edges/faces.
+# verts/edges/faces ... List of vertices/edges/faces for the
+#                    new mesh (as used in from_pydata).
+# name ... Name of the new mesh (& object).
+def create_mesh_object(context, verts, edges, faces, name):
+    # Create new mesh
+    mesh = bpy.data.meshes.new(name)
+
+    # Make a mesh from a list of verts/edges/faces.
+    mesh.from_pydata(verts, edges, faces)
+
+    # Update mesh geometry after adding stuff.
+    mesh.update()
+
+    from bpy_extras import object_utils
+
+    return object_utils.object_data_add(context, mesh, operator=None)
+
+
+# ------------------------------------------------------------
+# Generate XY Grid
+def grid_gen(sub_d_x, sub_d_y, tri, meshsize_x, meshsize_y, options, water_plane, water_level):
+    verts = []
+    faces = []
+    for i in range (0, sub_d_x):
+        x = meshsize_x * (i / (sub_d_x - 1) - 1 / 2)
+        for j in range(0, sub_d_y):
+            y = meshsize_y * (j / (sub_d_y - 1) - 1 / 2)
+            if water_plane:
+                z = water_level
+            else:
+                z = landscape_gen(x, y, 0, meshsize_x, meshsize_y, options)
+
+            verts.append((x,y,z))
+
+    count = 0
+    for i in range (0, sub_d_y * (sub_d_x - 1)):
+        if count < sub_d_y - 1 :
+            A = i + 1
+            B = i
+            C = (i + sub_d_y)
+            D = (i + sub_d_y) + 1
+            if tri:
+                faces.append((A, B, D))
+                faces.append((B, C, D))
+            else:
+                faces.append((A, B, C, D))
+            count = count + 1
+        else:
+            count = 0
+
+    return verts, faces
+
+
+# Generate UV Sphere
+def sphere_gen(sub_d_x, sub_d_y, tri, meshsize, options, water_plane, water_level):
+    verts = []
+    faces = []
+    sub_d_x += 1
+    sub_d_y += 1
+    for i in range(0, sub_d_x):
+        for j in range(0, sub_d_y):
+            u = sin(j * pi * 2 / (sub_d_y - 1)) * cos(-pi / 2 + i * pi / (sub_d_x - 1)) * meshsize / 2
+            v = cos(j * pi * 2 / (sub_d_y - 1)) * cos(-pi / 2 + i * pi / (sub_d_x - 1)) * meshsize / 2
+            w = sin(-pi / 2 + i * pi / (sub_d_x - 1)) * meshsize / 2
+            if water_plane:
+                h = water_level
+            else:
+                h = landscape_gen(u, v, w, meshsize, meshsize, options) / meshsize
+            verts.append(((u + u * h), (v + v * h), (w + w * h)))
+
+    count = 0
+    for i in range (0, sub_d_y * (sub_d_x - 1)):
+        if count < sub_d_y - 1 :
+            A = i + 1
+            B = i
+            C = (i + sub_d_y)
+            D = (i + sub_d_y) + 1
+            if tri:
+                faces.append((A, B, D))
+                faces.append((B, C, D))
+            else:
+                faces.append((A, B, C, D))
+            count = count + 1
+        else:
+            count = 0
+
+    return verts, faces
+
+
 # ------------------------------------------------------------
-# some functions for marble_noise
+# Z normal value to vertex group (Slope map)
+class ANTSlopeVGroup(bpy.types.Operator):
+    bl_idname = "mesh.ant_slope_vgroup"
+    bl_label = "Slope Map"
+    bl_description = "Slope map - z normal value to vertex group weight"
+    #bl_options = {'REGISTER'} 
+
+    z_method = EnumProperty(
+            name="Method:",
+            default='SLOPE_Z',
+            items=[
+                ('SLOPE_Z', "Slope Z", "Slope for planar mesh"),
+                ('SLOPE_XYZ', "Slope XYZ", "Slope for spherical mesh")
+                ])
+    group_name = StringProperty(
+            name="Vertex Group Name:",
+            default="Slope",
+            description="Name"
+            )
+    select_flat = BoolProperty(
+            name="Vert Select:",
+            default=True,
+            description="Select vertices on flat surface"
+            )
+    select_range = FloatProperty(
+            name="Vert Select Range:",
+            default=0.0,
+            min=0.0,
+            max=1.0,
+            description="Increase to select more vertices"
+            )
+
+    def invoke(self, context, event):
+        wm = context.window_manager
+        return wm.invoke_props_dialog(self)
+
+
+    def execute(self, context):
+        message = "Popup Values: %d, %f, %s, %s" % \
+            (self.select_flat, self.select_range, self.group_name, self.z_method)
+        self.report({'INFO'}, message)
+
+        ob = bpy.context.active_object
+
+        if self.select_flat:
+            bpy.ops.object.mode_set(mode='EDIT')
+            bpy.ops.mesh.select_all(action='DESELECT')
+            bpy.context.tool_settings.mesh_select_mode = [True, False, False]
+            bpy.ops.object.mode_set(mode='OBJECT')
+
+        bpy.ops.object.vertex_group_add()
+        vg_normal = ob.vertex_groups.active
+
+        for v in ob.data.vertices:
+            if self.z_method == 'SLOPE_XYZ':
+                zno = (v.co.normalized() * v.normal.normalized()) * 2 - 1
+            else:
+                zno = v.normal[2]
+
+            vg_normal.add([v.index], zno, 'REPLACE')
+
+            if self.select_flat:
+                if zno >= (1.0 - self.select_range):
+                    v.select = True
+
+        vg_normal.name = self.group_name
+
+        return {'FINISHED'}
+
+# ------------------------------------------------------------
+# ------------------------------------------------------------
+# Marble_noise:
 def sin_bias(a):
     return 0.5 + 0.5 * sin(a)
 
@@ -215,7 +375,7 @@ def marble_noise(x, y, z, origin, size, shape, bias, sharpnes, turb, depth, hard
 
     if bias is 1:
         value = cos_bias(value)
-    if bias is 2:
+    elif bias is 2:
         value = tri_bias(value)
     elif bias is 3:
         value = saw_bias(value)
@@ -237,8 +397,7 @@ def marble_noise(x, y, z, origin, size, shape, bias, sharpnes, turb, depth, hard
 
     return value
 
-# ------------------------------------------------------------
-# custom noise types
+# A.N.T. Noise variations:
 
 # vl_noise_turbulence: 
 def vlnTurbMode(coords, distort, basis, vlbasis, hardnoise):
@@ -394,6 +553,12 @@ def landscape_gen(x, y, z, meshsize_x, meshsize_y, props):
 
     ncoords = (x / (nsize * size_x) + origin_x, y / (nsize * size_y) + origin_y, z / nsize + origin_z)
 
+    # noise basis type's
+    if nbasis == 9:
+        nbasis = 14  # cellnoise
+    if vlbasis ==9:
+        vlbasis = 14
+
     # noise type's
     if ntype == 'multi_fractal':
         value = multi_fractal(ncoords, dimension, lacunarity, depth, nbasis) * 0.5
@@ -453,7 +618,7 @@ def landscape_gen(x, y, z, meshsize_x, meshsize_y, props):
         value = planet_noise(ncoords, depth, hardnoise, nbasis)[2] * 0.5 + 0.5
 
     elif ntype == 'blender_texture':
-        if texture_name in bpy.data.textures:
+        if texture_name != "" and texture_name in bpy.data.textures:
             value = bpy.data.textures[texture_name].evaluate(ncoords)[3]
         else:
             value = 0.0
@@ -516,169 +681,8 @@ def landscape_gen(x, y, z, meshsize_x, meshsize_y, props):
 
     return value
 
-# ------------------------------------------------------------
-# ------------------------------------------------------------
-# Generate XY Grid
-def grid_gen(sub_d_x, sub_d_y, tri, meshsize_x, meshsize_y, options, water_plane, water_level):
-    verts = []
-    faces = []
-    for i in range (0, sub_d_x):
-        x = meshsize_x * (i / (sub_d_x - 1) - 1 / 2)
-        for j in range(0, sub_d_y):
-            y = meshsize_y * (j / (sub_d_y - 1) - 1 / 2)
-            if water_plane:
-                z = water_level
-            else:
-                z = landscape_gen(x, y, 0, meshsize_x, meshsize_y, options)
-
-            verts.append((x,y,z))
-
-    count = 0
-    for i in range (0, sub_d_y * (sub_d_x - 1)):
-        if count < sub_d_y - 1 :
-            A = i + 1
-            B = i
-            C = (i + sub_d_y)
-            D = (i + sub_d_y) + 1
-            if tri:
-                faces.append((A, B, D))
-                faces.append((B, C, D))
-            else:
-                faces.append((A, B, C, D))
-            count = count + 1
-        else:
-            count = 0
-
-    return verts, faces
-
-
-# Generate UV Sphere
-def sphere_gen(sub_d_x, sub_d_y, tri, meshsize, options, water_plane, water_level):
-    verts = []
-    faces = []
-    sub_d_x += 1
-    sub_d_y += 1
-    for i in range(0, sub_d_x):
-        for j in range(0, sub_d_y):
-            u = sin(j * pi * 2 / (sub_d_y - 1)) * cos(-pi / 2 + i * pi / (sub_d_x - 1)) * meshsize / 2
-            v = cos(j * pi * 2 / (sub_d_y - 1)) * cos(-pi / 2 + i * pi / (sub_d_x - 1)) * meshsize / 2
-            w = sin(-pi / 2 + i * pi / (sub_d_x - 1)) * meshsize / 2
-            if water_plane:
-                h = water_level
-            else:
-                h = landscape_gen(u, v, w, meshsize, meshsize, options) / meshsize
-            verts.append(((u + u * h), (v + v * h), (w + w * h)))
-
-    count = 0
-    for i in range (0, sub_d_y * (sub_d_x - 1)):
-        if count < sub_d_y - 1 :
-            A = i + 1
-            B = i
-            C = (i + sub_d_y)
-            D = (i + sub_d_y) + 1
-            if tri:
-                faces.append((A, B, D))
-                faces.append((B, C, D))
-            else:
-          

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list