[Bf-extensions-cvs] [be1ffdc1] master: Cell Fracture Crack It: Fixes, clean up

lijenstina noreply at git.blender.org
Mon Jun 5 14:54:28 CEST 2017


Commit: be1ffdc175be417a0f9eabc95e6c7c6f243dab01
Author: lijenstina
Date:   Mon Jun 5 14:53:42 2017 +0200
Branches: master
https://developer.blender.org/rBAbe1ffdc175be417a0f9eabc95e6c7c6f243dab01

Cell Fracture Crack It: Fixes, clean up

Bumped verison to 0.1.1
Pep8 cleanup
Replace deprecated imp calls with importlib

Small UI changes
Make the Panel by default closed
Move scene properties to a PropertyGroup
they can be accessed with context.scene.crackit

Fixed some polling issues related to using Fracture
(as the operator will ignore objects that are not processed)
causing the operation to fail further on
Added an option for using the original names or the Enum ones
for the materials shipped in the Blend file

More robust error handling
Add a button for the wm.addon_userpref_show to open the
Cell Fracture add-on if it is not enabled

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

M	object_fracture_crack/__init__.py
M	object_fracture_crack/crack_it.py
M	object_fracture_crack/operator.py

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

diff --git a/object_fracture_crack/__init__.py b/object_fracture_crack/__init__.py
index f2aa7593..dc43fbe3 100644
--- a/object_fracture_crack/__init__.py
+++ b/object_fracture_crack/__init__.py
@@ -1,4 +1,4 @@
-#====================== BEGIN GPL LICENSE BLOCK ======================
+# ##### 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
@@ -14,115 +14,135 @@
 #  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 ========================
+# ##### END GPL LICENSE BLOCK #####
 
+bl_info = {
+    "name": "Cell Fracture Crack It",
+    "author": "Nobuyuki Hirakata",
+    "version": (0, 1, 1),
+    "blender": (2, 78, 5),
+    "location": "View3D > Toolshelf > Crack it! Tab",
+    "description": "Displaced Cell Fracture Addon",
+    "warning": "Make sure to enable 'Object: Cell Fracture' Addon",
+    "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/"
+                "Py/Scripts/Object/CrackIt",
+    "category": "Object"
+}
 
 if 'bpy' in locals():
-    import imp
-    imp.reload(operator)
+    import importlib
+    importlib.reload(operator)
 
 else:
     from . import operator
 
 import bpy
+from bpy.types import PropertyGroup
+from bpy.props import (
+        BoolProperty,
+        EnumProperty,
+        FloatProperty,
+        IntProperty,
+        PointerProperty,
+        )
 import os
 
-bl_info = {
-    "name": "Cell Fracture Crack It",
-    "author": "Nobuyuki Hirakata",
-    "version": (0, 1, 0),
-    "blender": (2, 77, 0),
-    "location": "View3D > Toolshelf > Creat Tab",
-    "description": "Displaced Cell Fracture Addon",
-    "warning": "Make sure to enable 'Object: Cell Fracture' Addon",
-    "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Object/CrackIt",
-    "category": "Object"
-}
+
+class CrackItProperties(PropertyGroup):
+    # Input on toolshelf before execution
+    # In Panel subclass, In bpy.types.Operator subclass,
+    # reference them by context.scene.crackit
+
+    fracture_childverts = BoolProperty(
+            name="From Child Verts",
+            description="Use child object's vertices and position for origin of crack",
+            default=False
+            )
+    fracture_scalex = FloatProperty(
+            name="Scale X",
+            description="Scale X",
+            default=1.00,
+            min=0.00,
+            max=1.00
+            )
+    fracture_scaley = FloatProperty(
+            name="Scale Y",
+            description="Scale Y",
+            default=1.00,
+            min=0.00,
+            max=1.00
+            )
+    fracture_scalez = FloatProperty(
+            name="Scale Z",
+            description="Scale Z",
+            default=1.00,
+            min=0.00,
+            max=1.00
+            )
+    fracture_div = IntProperty(
+            name="Max Crack",
+            description="Max Crack",
+            default=100,
+            min=0,
+            max=10000
+            )
+    fracture_margin = FloatProperty(
+            name="Margin Size",
+            description="Margin Size",
+            default=0.001,
+            min=0.000,
+            max=1.000
+            )
+    extrude_offset = FloatProperty(
+            name="Offset",
+            description="Extrude Offset",
+            default=0.10,
+            min=0.00,
+            max=2.00
+            )
+    extrude_random = FloatProperty(
+            name="Random",
+            description="Extrude Random",
+            default=0.30,
+            min=-1.00,
+            max=1.00
+            )
+    # Path of the addon
+    material_addonpath = os.path.dirname(__file__)
+    # Selection of material preset
+    # Note: you can choose the original name in the library blend
+    # or the prop name
+    material_preset = EnumProperty(
+            name="Preset",
+            description="Material Preset",
+            items=[
+                ('crackit_organic_mud', "Organic Mud", "Mud material"),
+                ('crackit_mud1', "Mud", "Mud material"),
+                ('crackit_tree1_moss1', "Tree Moss", "Tree Material"),
+                ('crackit_tree2_dry1', "Tree Dry", "Tree Material"),
+                ('crackit_tree3_red1', "Tree Red", "Tree Material"),
+                ('crackit_rock1', "Rock", "Rock Material")
+                ]
+            )
+    material_lib_name = BoolProperty(
+            name="Library Name",
+            description="Use the original Material name from the .blend library\n"
+                        "instead of the one defined in the Preset",
+            default=True
+            )
+
 
 def register():
     bpy.utils.register_module(__name__)
-    
-    # Input on toolshelf before execution --------------------------
-    #  In Panel subclass, In bpy.types.Operator subclass, reference them by context.scene.~.
-    
-    bpy.types.Scene.crackit_fracture_childverts = bpy.props.BoolProperty(
-        name = 'From Child Verts',
-        description = "Use child object's vertices and position for origin of crack.",
-        default = False
-    )
-    bpy.types.Scene.crackit_fracture_scalex = bpy.props.FloatProperty(
-        name = 'Scale X',
-        description = "Scale X",
-        default = 1.00,
-        min = 0.00,
-        max = 1.00
-    )
-    bpy.types.Scene.crackit_fracture_scaley = bpy.props.FloatProperty(
-        name = 'Scale Y',
-        description = "Scale Y",
-        default = 1.00,
-        min = 0.00,
-        max = 1.00
-    )
-    bpy.types.Scene.crackit_fracture_scalez = bpy.props.FloatProperty(
-        name = 'Scale Z',
-        description = "Scale Z",
-        default = 1.00,
-        min = 0.00,
-        max = 1.00
-    )
-    bpy.types.Scene.crackit_fracture_div = bpy.props.IntProperty(
-        name = 'Max Crack',
-        description = "Max Crack",
-        default = 100,
-        min = 0,
-        max = 10000
-    )
-    bpy.types.Scene.crackit_fracture_margin = bpy.props.FloatProperty(
-        name = 'Margin Size',
-        description = "Margin Size",
-        default = 0.001,
-        min = 0.000,
-        max = 1.000
-    )
-    bpy.types.Scene.crackit_extrude_offset = bpy.props.FloatProperty(
-        name = 'Extrude',
-        description = "Extrude Offset",
-        default = 0.10,
-        min = 0.00,
-        max = 2.00
-    )
-    bpy.types.Scene.crackit_extrude_random = bpy.props.FloatProperty(
-        name = 'Random',
-        description = "Extrude Random",
-        default = 0.30,
-        min = -1.00,
-        max = 1.00
-    )
-    # Path of the addon.
-    bpy.types.Scene.crackit_material_addonpath = os.path.dirname(__file__)
-    # Selection of material preset.
-    bpy.types.Scene.crackit_material_preset = bpy.props.EnumProperty(
-        name = 'Preset',
-        description = "Material Preset",
-        items = [('crackit_organic_mud', 'Organic Mud', "Mud material"),
-                ('crackit_mud1', 'Mud', "Mud material"),
-                ('crackit_tree1_moss1', 'Tree1_moss', "Tree Material"),
-                ('crackit_tree2_dry1', 'Tree2_dry', "Tree Material"),
-                ('crackit_tree3_red1', 'Tree3_red', "Tree Material"),
-                ('crackit_rock1', 'Rock', "Rock Material")]
-    )
+    bpy.types.Scene.crackit = PointerProperty(
+                                    type=CrackItProperties
+                                    )
+
 
 def unregister():
-    # Delete bpy.types.Scene.~.
-    del bpy.types.Scene.crackit_fracture_scalex
-    del bpy.types.Scene.crackit_fracture_scaley
-    del bpy.types.Scene.crackit_fracture_scalez
-    del bpy.types.Scene.crackit_fracture_div
-    del bpy.types.Scene.crackit_fracture_margin
-    del bpy.types.Scene.crackit_extrude_offset
-    
+    del bpy.types.Scene.crackit
     bpy.utils.unregister_module(__name__)
 
+
 if __name__ == "__main__":
     register()
diff --git a/object_fracture_crack/crack_it.py b/object_fracture_crack/crack_it.py
index 6d0cd571..489d2c87 100644
--- a/object_fracture_crack/crack_it.py
+++ b/object_fracture_crack/crack_it.py
@@ -1,77 +1,124 @@
+# gpl: author Nobuyuki Hirakata
+
 import bpy
 
-import bmesh, mathutils, random
-from random import gauss
+import bmesh
+from random import (
+        gauss,
+        seed,
+        )
 from math import radians
-from mathutils import Euler, Vector
+from mathutils import Euler
+
+
+# Allow changing the original material names from the .blend file
+# by replacing them with the UI Names from the EnumProperty
+def get_ui_mat_name(mat_name):
+    mat_ui_name = "CrackIt Material"
+    try:
+        # access the Scene type directly to get the name from the enum
+        mat_items = bpy.types.Scene.crackit[1]["type"].bl_rna.material_preset[1]["items"]
+        for mat_id, mat_list in enumerate(mat_items):
+            if mat_name in mat_list:
+                mat_ui_name = mat_items[mat_id][1]
+                break
+        del mat_items
+    except Exception as e:
+        error_handlers(
+                False, "get_ui_mat_name", e,
+                "Retrieving the EnumProperty key UI Name could not be completed", True
+                )
+        pass
+
+    return mat_ui_name
+
 
-import addon_utils
+def error_handlers(self, op_name, error, reports="ERROR", func=False):
+    if self and reports:
+        self.report({'WARNING'}, reports + " (See Console for more info)")
 
-# ---------------------Crack-------------------
+    is_func = "Function" if func else "Operator"
+    print("\n[Cell Fracture Crack It]\n{}: {}\nError: "
+          "{}\nReport: {}\n".format(is_func, op_name, error, reports))
+
+
+# -------------------- Crack -------------------
 # Cell fracture and post-process:
-def makeFracture(child_verts=False, division=100, noise=0.00, scaleX=1.00, scaleY=1.00, scaleZ=1.00, recursion=0, margin=0.001):
-    # Get active object name and active layer.
+def makeFracture(child_verts=False, division=100, noise=0.00,
+                scaleX=1.00, scaleY=1.00, scaleZ=1.00, recursion=0, margin=0.001):
+
+    # Get active object name and ac

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-extensions-cvs mailing list