[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2178] branches/ivygen/truman_ivy/ add_curve_ivygen.py: Version 0.0.4:

Andrew Hale TrumanBlending at gmail.com
Mon Jul 25 09:51:48 CEST 2011


Revision: 2178
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2178
Author:   trumanblending
Date:     2011-07-25 07:51:47 +0000 (Mon, 25 Jul 2011)
Log Message:
-----------
Version 0.0.4:
- Removed deselection of object after generation
- Removed panel and property group
- Added ivy update button
- Cleaned up registration

Modified Paths:
--------------
    branches/ivygen/truman_ivy/add_curve_ivygen.py

Modified: branches/ivygen/truman_ivy/add_curve_ivygen.py
===================================================================
--- branches/ivygen/truman_ivy/add_curve_ivygen.py	2011-07-25 04:02:19 UTC (rev 2177)
+++ branches/ivygen/truman_ivy/add_curve_ivygen.py	2011-07-25 07:51:47 UTC (rev 2178)
@@ -21,7 +21,7 @@
 bl_info = {
     "name": "IvyGen",
     "author": "testscreenings, PKHG, TrumanBlending",
-    "version": (0, 0, 3),
+    "version": (0, 0, 4),
     "blender": (2, 5, 8),
     "api": 38479,
     "location": "View3D > Add > Curve",
@@ -33,7 +33,7 @@
 
 
 import bpy
-from bpy.props import FloatProperty, IntProperty, PointerProperty
+from bpy.props import FloatProperty, IntProperty, BoolProperty
 from mathutils import Vector, Matrix
 from collections import deque
 from math import pow, cos, pi, atan2
@@ -161,7 +161,6 @@
     gaussWeight = [1.0, 2.0, 4.0, 7.0, 9.0, 10.0, 9.0, 7.0, 4.0, 2.0, 1.0]
 
     # Create a new curve and intialise it
-    bpy.ops.object.select_all(action='DESELECT')
     curve = bpy.data.curves.new("IVY", type='CURVE')
     curve.dimensions = '3D'
     curve.bevel_depth = 1
@@ -202,8 +201,6 @@
     # Add the object and link to scene
     newCurve = bpy.data.objects.new("IVY_Curve", curve)
     bpy.context.scene.objects.link(newCurve)
-    newCurve.select = True
-    bpy.context.scene.objects.active = newCurve
 
     return newCurve
 
@@ -267,10 +264,7 @@
                  ivyLeafSize=0.02,
                  ivyBranchSize=0.001,
                  maxFloatLength=0.5,
-                 maxAdhesionDistance=1.0,
-                 randomSeed=0.0,
-                 maxIvyLength=0.0,
-                 maxTime=0.0):
+                 maxAdhesionDistance=1.0):
 
         self.ivyRoots = deque()
         self.primaryWeight = primaryWeight
@@ -443,89 +437,13 @@
     bl_label = "IvyGen"
     bl_options = {'REGISTER', 'UNDO'}
 
-    @classmethod
-    def poll(self, context):
-        # Check if there's an object and whether it's a mesh
-        ob = context.active_object
-        if (ob is not None) and\
-           (ob.type == 'MESH') and\
-           (context.mode == 'OBJECT'):
-            return True
-        return False
-
-    def execute(self, context):
-        # Get the properties
-        ivyProps = context.window_manager.ivy_props
-
-        # Get the selected object
-        ob = context.active_object
-
-        # Compute bounding sphere radius
-        #radius = computeBoundingSphere(ob)  # Not needed anymore
-
-        # Get the seeding point
-        seedPoint = context.scene.cursor_location
-
-        # Fix the random seed
-        rand_seed(ivyProps.randomSeed)
-
-        # Make the new ivy
-        IVY = Ivy(**dict(ivyProps.items()))
-
-        # Generate first root and node
-        IVY.seed(seedPoint)
-
-        checkAlive = True
-        checkTime = False
-        maxLength = ivyProps.maxIvyLength  # * radius
-
-        # If we need to check time set the flag
-        if ivyProps.maxTime != 0.0:
-            checkTime = True
-
-        t = time.time()
-        startPercent = 0.0
-
-        # Grow until 200 roots is reached or backup counter exceeds limit
-        while checkAlive and\
-              (IVY.maxLength < maxLength) and\
-              (not checkTime or (time.time() - t < ivyProps.maxTime)):
-            # Grow the ivy for this iteration
-            IVY.grow(ob)
-
-            # Print the proportion of ivy growth to console
-            if (IVY.maxLength / maxLength * 100) > (startPercent // 10) * 10:
-                print('%0.2f%% of Ivy nodes have grown' %\
-                                             (IVY.maxLength / maxLength * 100))
-                startPercent += 10
-                if IVY.maxLength / maxLength > 1:
-                    print("Halting Growth")
-
-            # Make an iterator to check if all are alive
-            checkAliveIter = (r.alive for r in IVY.ivyRoots)
-            checkAlive = (True in checkAliveIter)
-
-        # Create the curve and leaf geometry
-        curveOb = createIvyCurves(IVY)
-        print("Curve Generation Complete")
-
-        leafOb = createIvyLeaves(IVY)
-        print("Leaf Generation Complete")
-
-        # Parent the leave to the curve
-        leafOb.parent = curveOb
-
-        print("Ivy generated in %0.2f s" % (time.time() - t))
-        return {'FINISHED'}
-
-
-class IvyProps(bpy.types.PropertyGroup):
     maxIvyLength = FloatProperty(name="Max Ivy Length",
                     description="Maximum ivy length in Blender Units.",
                     default=1.0,
                     min=0.0,
                     soft_max=3.0,
-                    subtype='FACTOR')
+                    subtype='DISTANCE',
+                    unit='LENGTH')
     primaryWeight = FloatProperty(name="Primary Weight",
                     description="Weighting given to the current direction.",
                     default=0.5,
@@ -596,13 +514,8 @@
                     min=0.0,
                     soft_max=10)
 
+    updateIvy = BoolProperty(name="Update Ivy", default=False)
 
-class VIEW3D_PT_tools_ivygen(bpy.types.Panel):
-    bl_space_type = 'VIEW_3D'
-    bl_region_type = 'TOOLS'
-    bl_context = "objectmode"
-    bl_label = "IvyGen"
-
     @classmethod
     def poll(self, context):
         # Check if there's an object and whether it's a mesh
@@ -613,69 +526,136 @@
             return True
         return False
 
+    def execute(self, context):
+        if self.updateIvy:
+            bpy.ops.object.mode_set(mode='EDIT', toggle=False)
+            bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
+
+            # Get the selected object
+            ob = context.active_object
+
+            # Compute bounding sphere radius
+            #radius = computeBoundingSphere(ob)  # Not needed anymore
+
+            # Get the seeding point
+            seedPoint = context.scene.cursor_location
+
+            # Fix the random seed
+            rand_seed(int(self.randomSeed))
+
+            # Make the new ivy
+            IVY = Ivy(**self.as_keywords(ignore=('randomSeed',
+                                      'maxIvyLength', 'maxTime', 'updateIvy')))
+
+            # Generate first root and node
+            IVY.seed(seedPoint)
+
+            checkAlive = True
+            checkTime = False
+            maxLength = self.maxIvyLength  # * radius
+
+            # If we need to check time set the flag
+            if self.maxTime != 0.0:
+                checkTime = True
+
+            t = time.time()
+            startPercent = 0.0
+
+            # Grow until 200 roots is reached or backup counter exceeds limit
+            while checkAlive and\
+                  (IVY.maxLength < maxLength) and\
+                  (not checkTime or (time.time() - t < self.maxTime)):
+                # Grow the ivy for this iteration
+                IVY.grow(ob)
+
+                # Print the proportion of ivy growth to console
+                if (IVY.maxLength / maxLength * 100) > 10 * startPercent // 10:
+                    print('%0.2f%% of Ivy nodes have grown' %\
+                                             (IVY.maxLength / maxLength * 100))
+                    startPercent += 10
+                    if IVY.maxLength / maxLength > 1:
+                        print("Halting Growth")
+
+                # Make an iterator to check if all are alive
+                checkAliveIter = (r.alive for r in IVY.ivyRoots)
+                checkAlive = (True in checkAliveIter)
+
+            # Create the curve and leaf geometry
+            curveOb = createIvyCurves(IVY)
+            print("Curve Generation Complete")
+
+            leafOb = createIvyLeaves(IVY)
+            print("Leaf Generation Complete")
+
+            # Parent the leave to the curve
+            leafOb.parent = curveOb
+
+            print("Ivy generated in %0.2f s" % (time.time() - t))
+
+            self.updateIvy = False
+
+            return {'FINISHED'}
+
+        return {'PASS_THROUGH'}
+
+    def invoke(self, context, event):
+        self.updateIvy = True
+        return self.execute(context)
+
     def draw(self, context):
-        ivyProps = context.window_manager.ivy_props
         layout = self.layout
         row = layout.row()
         row.alignment = 'EXPAND'
-        row.operator('curve.ivy_gen', text="Generate Ivy")
+        row.prop(self, 'updateIvy', icon='CURVE_DATA')
         box = layout.box()
         box.label("Generation Settings")
         row = box.row()
-        row.prop(ivyProps, 'randomSeed')
+        row.prop(self, 'randomSeed')
         row = box.row()
-        row.prop(ivyProps, 'maxTime')
+        row.prop(self, 'maxTime')
         box = layout.box()
         box.label("Size Settings")
         row = box.row()
-        row.prop(ivyProps, 'maxIvyLength')
+        row.prop(self, 'maxIvyLength')
         row = box.row()
-        row.prop(ivyProps, 'ivySize')
+        row.prop(self, 'ivySize')
         row = box.row()
-        row.prop(ivyProps, 'maxFloatLength')
+        row.prop(self, 'maxFloatLength')
         row = box.row()
-        row.prop(ivyProps, 'maxAdhesionDistance')
+        row.prop(self, 'maxAdhesionDistance')
         box = layout.box()
         box.label("Weight Settings")
         row = box.row()
-        row.prop(ivyProps, 'primaryWeight')
+        row.prop(self, 'primaryWeight')
         row = box.row()
-        row.prop(ivyProps, 'randomWeight')
+        row.prop(self, 'randomWeight')
         row = box.row()
-        row.prop(ivyProps, 'gravityWeight')
+        row.prop(self, 'gravityWeight')
         row = box.row()
-        row.prop(ivyProps, 'adhesionWeight')
+        row.prop(self, 'adhesionWeight')
         box = layout.box()
         box.label("Geometry Settings")
         row = box.row()
-        row.prop(ivyProps, 'branchingProbability')
+        row.prop(self, 'branchingProbability')
         row = box.row()
-        row.prop(ivyProps, 'leafProbability')
+        row.prop(self, 'leafProbability')
         row = box.row()
-        row.prop(ivyProps, 'ivyBranchSize')
+        row.prop(self, 'ivyBranchSize')
         row = box.row()
-        row.prop(ivyProps, 'ivyLeafSize')
+        row.prop(self, 'ivyLeafSize')
 
 
+def menu_func(self, context):
+    self.layout.operator(IvyGen.bl_idname, text="Add Ivy", icon='PLUGIN')
+
+
 def register():
-    bpy.utils.register_class(IvyProps)
-    #bpy.utils.register_class(IvyGen)
-    #bpy.utils.register_class(VIEW3D_PT_tools_ivygen)
-    bpy.types.WindowManager.ivy_props =\

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list