[Bf-extensions-cvs] [d877bcf1] master: Mesh Icicle Snowflake: fix some issues, add options

lijenstina noreply at git.blender.org
Wed Jan 3 09:39:35 CET 2018


Commit: d877bcf1bae25bdc54c46bda88b3323b786df137
Author: lijenstina
Date:   Wed Jan 3 09:37:59 2018 +0100
Branches: master
https://developer.blender.org/rBACd877bcf1bae25bdc54c46bda88b3323b786df137

Mesh Icicle Snowflake: fix some issues, add options

Bump version to 0.1.1
Pep 8 cleanup
Imports as tuples
Remove unused imports and variables
Update wiki link

Icicles:
- Add a option to fill caps
- UI layout reorganization, tooltip
- Add a poll checking for a mesh object present with one edge
- Add simple logic to handle when min values > max ones
- Use ternary operators were possible for repetitive code

Snowflake:
- Refactor some of the code
- Solve issues with messed up geometry in edit mode (bmesh not cleared)
- Update UI and tooltip
- Add a preset operator / menu
- Add an option for the radius of the initial circle
- Bump some min, max prop values
- Add update undo option, instead of running all the time

Note:
- probably the scripts needs some further testing / refactor

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

M	add_mesh_icicle_snowflake/__init__.py
M	add_mesh_icicle_snowflake/add_mesh_icicle_gen.py
M	add_mesh_icicle_snowflake/add_mesh_snowflake.py

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

diff --git a/add_mesh_icicle_snowflake/__init__.py b/add_mesh_icicle_snowflake/__init__.py
index a11ad37d..b44f6fe3 100644
--- a/add_mesh_icicle_snowflake/__init__.py
+++ b/add_mesh_icicle_snowflake/__init__.py
@@ -21,12 +21,12 @@
 bl_info = {
     "name": "Mesh: Icicle/Snowflake",
     "author": "Eoin Brennan (Mayeoin Bread)",
-    "version": (0, 1, 0),
+    "version": (0, 1, 1),
     "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/"
+    "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/"
                 "Scripts/Add_Mesh/Add_Extra",
     "category": "Add Mesh",
 }
@@ -36,7 +36,6 @@ if "bpy" in locals():
     importlib.reload(add_mesh_icicle_gen)
     importlib.reload(add_mesh_snowflake)
 
-
 else:
     from . import add_mesh_icicle_gen
     from . import add_mesh_snowflake
@@ -58,13 +57,12 @@ class INFO_MT_mesh_icy_add(bpy.types.Menu):
         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")
+    self.layout.menu("INFO_MT_mesh_ice_add", text="Ice & Snow", icon="FREEZE")
 
 
 def register():
@@ -80,5 +78,6 @@ def unregister():
     # 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
index a50094f6..f0ee5468 100644
--- a/add_mesh_icicle_snowflake/add_mesh_icicle_gen.py
+++ b/add_mesh_icicle_snowflake/add_mesh_icicle_gen.py
@@ -1,103 +1,184 @@
-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"}
+bl_info = {
+    "name": "Icicle Generator",
+    "author": "Eoin Brennan (Mayeoin Bread)",
+    "version": (2, 2, 1),
+    "blender": (2, 7, 4),
+    "location": "View3D > Add > Mesh",
+    "description": "Construct 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
+from math import (
+        pi, sin,
+        cos, atan,
+        )
+from bpy.props import (
+        EnumProperty,
+        FloatProperty,
+        IntProperty,
+        )
 import random
 
 
 class IcicleGenerator(bpy.types.Operator):
-    """Icicle Generator"""
     bl_idname = "mesh.icicle_gen"
     bl_label = "Icicle Generator"
+    bl_description = ("Create Icicles on selected Edges of an existing Mesh Object\n"
+                      "Note: doesn't work with vertical Edges")
     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")
+    maxR = FloatProperty(
+            name="Max",
+            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")
+    minR = FloatProperty(
+            name="Min",
+            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")
+    maxD = FloatProperty(
+            name="Max",
+            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")
+    minD = FloatProperty(
+            name="Min",
+            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)
+    verts = IntProperty(
+            name="Vertices",
+            description="Number of vertices at the icicle base",
+            default=8,
+            min=3,
+            max=24
+            )
+    addCap = EnumProperty(
+            name="Fill cap",
+            description="Fill the icicle cone base",
+            items=[
+                ('NGON', "Ngon", "Fill with Ngons"),
+                ('NOTHING', "None", "Do not fill"),
+                ('TRIFAN', "Triangle fan", "Fill with triangles")
+            ],
+            default='NGON',
+            )
     # 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)
+    its = IntProperty(
+            name="Iterations",
+            description="Number of iterations before giving up, prevents freezing/crashing",
+            default=2000,
+            min=1,
+            max=10000
+            )
+    verticalEdges = False
+
+    @classmethod
+    def poll(cls, context):
+        obj = context.active_object
+        return obj and obj.type == "MESH"
+
+    def draw(self, context):
+        layout = self.layout
+        col = layout.column(align=True)
+
+        col.label("Radius:")
+        col.prop(self, "minR")
+        col.prop(self, "maxR")
+
+        col.label("Depth:")
+        col.prop(self, "minD")
+        col.prop(self, "maxD")
+
+        col.label("Base:")
+        col.prop(self, "verts")
+        col.prop(self, "addCap", text="")
+
+        layout.prop(self, "its")
 
-    ##
-    # Main function
-    ##
     def execute(self, context):
+        # Variables
+        if self.minR > self.maxR:
+            self.maxR = self.minR
+
+        if self.minD > self.maxD:
+            self.maxD = self.minD
+
         rad = self.maxR
         radM = self.minR
         depth = self.maxD
         minD = self.minD
+        addCap = self.addCap
+        self.verticalEdges = False
+
+        # --- Nested utility functions START --- #
+
+        def test_data(obj):
+            me = obj.data
+            is_edges = bool(len(me.edges) > 0)
+            is_selected = False
+
+            for edge in me.edges:
+                if edge.select:
+                    is_selected = True
+                    break
+
+            return (is_edges and is_selected)
+
+        def flip_to_edit_mode():
+            bpy.ops.object.mode_set(mode='OBJECT')
+            bpy.ops.object.mode_set(mode='EDIT')
 
-        ##
         # 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_cone(x, y, z, randrad, rd, fill="NGON"):
+            bpy.ops.mesh.primitive_cone_add(
+                    vertices=self.verts,
+                    radius1=randrad,
+                    radius2=0.0,
+                    depth=rd,
+                    end_fill_type=fill,
+                    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
+            obj = bpy.context.active_object
             bm = bmesh.from_edit_mesh(obj.data)
             wm = obj.matrix_world
+
             # Vectors for selected verts
             for v in bm.verts:
                 if v.select:
@@ -107,8 +188,7 @@ class IcicleGenerator(bpy.types.Operator):
                     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
@@ -131,16 +211,15 @@ class IcicleGenerator(bpy.types.Operator):
             # 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):
+  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list