[Bf-extensions-cvs] [daf2abde] master: initial commit: add_mesh_icicle_snowflake T38775 T51145

meta-androcto noreply at git.blender.org
Thu Apr 13 06:54:17 CEST 2017


Commit: daf2abdee9cf5ab70596a3a4d01f8610ecb28bfe
Author: meta-androcto
Date:   Thu Apr 13 14:53:40 2017 +1000
Branches: master
https://developer.blender.org/rBACdaf2abdee9cf5ab70596a3a4d01f8610ecb28bfe

initial commit: add_mesh_icicle_snowflake T38775 T51145

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

A	add_mesh_icicle_snowflake/__init__.py
A	add_mesh_icicle_snowflake/add_mesh_icicle_gen.py
A	add_mesh_icicle_snowflake/add_mesh_snowflake.py

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

diff --git a/add_mesh_icicle_snowflake/__init__.py b/add_mesh_icicle_snowflake/__init__.py
new file mode 100644
index 00000000..a11ad37d
--- /dev/null
+++ b/add_mesh_icicle_snowflake/__init__.py
@@ -0,0 +1,84 @@
+# ##### 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 #####
+# Contributed to by
+# Pontiac, Fourmadmen, varkenvarken, tuga3d, meta-androcto, metalliandy, dreampainter & cotejrp1#
+
+bl_info = {
+    "name": "Mesh: Icicle/Snowflake",
+    "author": "Eoin Brennan (Mayeoin Bread)",
+    "version": (0, 1, 0),
+    "blender": (2, 74, 0),
+    "location": "View3D > Add > Mesh",
+    "description": "Add Icicle & Snowflake",
+    "warning": "",
+    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
+                "Scripts/Add_Mesh/Add_Extra",
+    "category": "Add Mesh",
+}
+
+if "bpy" in locals():
+    import importlib
+    importlib.reload(add_mesh_icicle_gen)
+    importlib.reload(add_mesh_snowflake)
+
+
+else:
+    from . import add_mesh_icicle_gen
+    from . import add_mesh_snowflake
+
+
+import bpy
+
+
+class INFO_MT_mesh_icy_add(bpy.types.Menu):
+    # Define the "Ice" menu
+    bl_idname = "INFO_MT_mesh_ice_add"
+    bl_label = "Ice & Snow"
+
+    def draw(self, context):
+        layout = self.layout
+        layout.operator_context = 'INVOKE_REGION_WIN'
+        layout.operator("mesh.icicle_gen",
+                        text="Icicle Generator")
+        layout.operator("mesh.snowflake",
+                        text="Snowflake")
+
+# Register all operators and panels
+
+# Define "Extras" menu
+
+
+def menu_func(self, context):
+    self.layout.menu("INFO_MT_mesh_ice_add", text="Ice & Snow")
+
+
+def register():
+    bpy.utils.register_module(__name__)
+
+    # Add "Extras" menu to the "Add Mesh" menu
+    bpy.types.INFO_MT_mesh_add.append(menu_func)
+
+
+def unregister():
+    bpy.utils.unregister_module(__name__)
+
+    # Remove "Extras" menu from the "Add Mesh" menu.
+    bpy.types.INFO_MT_mesh_add.remove(menu_func)
+
+if __name__ == "__main__":
+    register()
diff --git a/add_mesh_icicle_snowflake/add_mesh_icicle_gen.py b/add_mesh_icicle_snowflake/add_mesh_icicle_gen.py
new file mode 100644
index 00000000..a50094f6
--- /dev/null
+++ b/add_mesh_icicle_snowflake/add_mesh_icicle_gen.py
@@ -0,0 +1,352 @@
+bl_info = {"name": "Icicle Generator",
+           "author": "Eoin Brennan (Mayeoin Bread)",
+           "version": (2, 1),
+           "blender": (2, 7, 4),
+           "location": "View3D > Add > Mesh",
+           "description": "Adds a linear string of icicles of different sizes",
+           "warning": "",
+           "wiki_url": "",
+           "tracker_url": "",
+           "category": "Add Mesh"}
+
+import bpy
+import bmesh
+from mathutils import Vector
+from math import pi, sin, cos, tan, asin, acos, atan
+from bpy.props import FloatProperty, IntProperty
+import random
+
+
+class IcicleGenerator(bpy.types.Operator):
+    """Icicle Generator"""
+    bl_idname = "mesh.icicle_gen"
+    bl_label = "Icicle Generator"
+    bl_options = {"REGISTER", "UNDO"}
+
+    ##
+    # User input
+    ##
+
+    # Maximum radius
+    maxR = FloatProperty(name="Max R",
+                         description="Maximum radius of a cone",
+                         default=0.15,
+                         min=0.01,
+                         max=1.0,
+                         unit="LENGTH")
+    # Minimum radius
+    minR = FloatProperty(name="Min R",
+                         description="Minimum radius of a cone",
+                         default=0.025,
+                         min=0.01,
+                         max=1.0,
+                         unit="LENGTH")
+    # Maximum depth
+    maxD = FloatProperty(name="Max D",
+                         description="Maximum depth (height) of cone",
+                         default=2.0,
+                         min=0.2,
+                         max=2.0,
+                         unit="LENGTH")
+    # Minimum depth
+    minD = FloatProperty(name="Min D",
+                         description="Minimum depth (height) of cone",
+                         default=1.5,
+                         min=0.2,
+                         max=2.0,
+                         unit="LENGTH")
+    # Number of verts at base of cone
+    verts = IntProperty(name="Vertices", description="Number of vertices", default=8, min=3, max=24)
+    # Number of iterations before giving up trying to add cones
+    # Prevents crashes and freezes
+    # Obviously, the more iterations, the more time spent calculating.
+    # Max value (10,000) is safe but can be slow,
+    # 2000 to 5000 should be adequate for 95% of cases
+    its = IntProperty(name="Iterations", description="Number of iterations before giving up, prevents freezing/crashing", default=2000, min=1, max=10000)
+
+    ##
+    # Main function
+    ##
+    def execute(self, context):
+        rad = self.maxR
+        radM = self.minR
+        depth = self.maxD
+        minD = self.minD
+
+        ##
+        # Add cone function
+        ##
+        def add_cone(x, y, z, randrad, rd):
+            ac = bpy.ops.mesh.primitive_cone_add
+            ac(
+                vertices=self.verts,
+                radius1=randrad,
+                radius2=0.0,
+                depth=rd,
+                end_fill_type='NGON',
+                view_align=False,
+                location=(x, y, z),
+                rotation=(pi, 0.0, 0.0))
+        ##
+        # Add icicle function
+        ##
+
+        def add_icicles(rad, radM, depth, minD):
+            pos1 = Vector((0.0, 0.0, 0.0))
+            pos2 = Vector((0.0, 0.0, 0.0))
+            pos = 0
+            obj = bpy.context.object
+            bm = bmesh.from_edit_mesh(obj.data)
+            wm = obj.matrix_world
+            # Vectors for selected verts
+            for v in bm.verts:
+                if v.select:
+                    if pos == 0:
+                        p1 = v.co
+                        pos = 1
+                    elif pos == 1:
+                        p2 = v.co
+                        pos = 2
+                    else:
+                        p5 = v.co
+            # Set first to left most vert on X-axis...
+            if(p1.x > p2.x):
+                pos1 = p2
+                pos2 = p1
+            # Or bottom-most on Y-axis if X-axis not used
+            elif(p1.x == p2.x):
+                if(p1.y > p2.y):
+                    pos1 = p2
+                    pos2 = p1
+                else:
+                    pos1 = p1
+                    pos2 = p2
+            else:
+                pos1 = p1
+                pos2 = p2
+            # World matrix for positioning
+            pos1 = pos1 * wm
+            pos2 = pos2 * wm
+
+            # X values not equal, working on X-Y-Z planes
+            if pos1.x != pos2.x:
+                # Get the angle of the line
+                if(pos2.y != pos1.y):
+                    angle = atan((pos2.x - pos1.x) / (pos2.y - pos1.y))
+                    print("Angle:", angle)
+                else:
+                    angle = pi / 2
+                # Total length of line, neglect Z-value (Z only affects height)
+                xLength = (((pos2.x - pos1.x)**2) + ((pos2.y - pos1.y)**2))**0.5
+                # Slopes if lines
+                ySlope = (pos2.y - pos1.y) / (pos2.x - pos1.x)
+                zSlope = (pos2.z - pos1.z) / (pos2.x - pos1.x)
+                # Fixes positioning error with some angles
+                if (angle < 0):
+                    i = pos2.x
+                    j = pos2.y
+                    k = pos2.z
+                else:
+                    i = pos1.x
+                    j = pos1.y
+                    k = pos1.z
+                l = 0.0
+
+                # Z and Y axis' intercepts
+                zInt = k - (zSlope * i)
+                yInt = j - (ySlope * i)
+
+                # Equal values, therfore radius should be that size
+                if(radM == rad):
+                    randrad = rad
+                # Otherwise randomise it
+                else:
+                    randrad = (rad - radM) * random.random()
+                # Depth, as with radius above
+                if(depth == minD):
+                    rd = depth
+                else:
+                    rd = (depth - minD) * random.random()
+                # Get user iterations
+                iterations = self.its
+                # Counter for iterations
+                c = 0
+                while(l < xLength) and (c < iterations):
+                    if(radM == rad):
+                        rr = randrad
+                    else:
+                        rr = randrad + radM
+                    if(depth == minD):
+                        dd = rd
+                    else:
+                        dd = rd + minD
+                    # Icicles generally taller than wider, check if true
+                    if(dd > rr):
+                        # If the new icicle won't exceed line length
+                        # Fix for overshooting lines
+                        if(l + rr + rr <= xLength):
+                            # Using sine/cosine of angle keeps icicles consistently spaced
+                            i = i + (rr) * sin(angle)
+                            j = j + (rr) * cos(angle)
+                            l = l + rr
+                            # Add a cone in new position
+                            add_cone(i, j, (i * zSlope) + (zInt - (dd) / 2), rr, dd)
+         

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list