[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [795] branches/ivygen/ivy_test.py: -crappy boundingSphere computation

Florian Meyer florianfelix at web.de
Fri Jul 16 03:52:58 CEST 2010


Revision: 795
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=795
Author:   testscreenings
Date:     2010-07-16 03:52:57 +0200 (Fri, 16 Jul 2010)

Log Message:
-----------
-crappy boundingSphere computation
-parenting screws up the positions WTH

Modified Paths:
--------------
    branches/ivygen/ivy_test.py

Modified: branches/ivygen/ivy_test.py
===================================================================
--- branches/ivygen/ivy_test.py	2010-07-15 23:40:16 UTC (rev 794)
+++ branches/ivygen/ivy_test.py	2010-07-16 01:52:57 UTC (rev 795)
@@ -4,13 +4,38 @@
 import random
 
 def createIvy(context, IVY):
+    last = None
     for root in IVY.ivy_Roots:
         bpy.ops.object.add(type='EMPTY',
                             location=root.position)
         context.active_object.empty_draw_type = 'PLAIN_AXES'
+        context.active_object.name ='RootNode'+str(root.chainNumber)
+        ''' WTF why isn't this working
+        if last:
+            context.active_object.parent = last
+            last = context.active_object
+        else:
+            last = context.active_object        
+        '''
+        #print(root.position)
+        
+def computeBoundingSphere(objs):
+    #needs improvement not really a bounding sphere because of use of
+    #corners of boundboxes
+    bb_verts = []
+    for obj in objs:
+        for bb_v in obj.bound_box:
+            bb_verts.append(mathutils.Vector((bb_v[0],bb_v[1],bb_v[2]))*obj.matrix_world)
+    bb_size = mathutils.Vector((0,0,0))
+    for bb_v in bb_verts:
+        bb_size += bb_v
+    center = bb_size / len(bb_verts)
+    radius = 0
+    for bb_v in bb_verts:
+        if bb_v.length > radius:
+            radius = bb_v.length
+    return [center, radius]
 
-        print(root.position)
-
 class IvyNode():
     position = mathutils.Vector()
     primaryDir = mathutils.Vector((0,0,0,5))
@@ -25,6 +50,7 @@
     nodes = []
     alive = True
     parents = 0
+    chainNumber = 0
 
 
 class Ivy():
@@ -37,15 +63,15 @@
     #ma_ximum length of an ivy branch segment that is freely floating [0..1]
     ivy_MaxFloatLength = 1.0
     #maximum distance for adhesion of scene object [0..1]
-    ivy_MaxAdhesionDistance = 1.0
+    #ivy_MaxAdhesionDistance = 1.0 <<< from props
     #weight for the primary grow vector [0..1]
-    ivy_PrimaryWeight = 0.5
+    #ivy_PrimaryWeight = 0.5 <<< from props
     #weight for the random influence vector
-    ivy_RandomWeight = 0.5
+    #ivy_RandomWeight = 0.5 <<< from props
     #weight for the gravity vector [0..1]
-    ivy_GravityWeight = 0.5
+    #ivy_GravityWeight = 0.5 <<< from props
     #weight for the adhesion vector [0..1]
-    ivy_AdhesionWeight = 0.5
+    #ivy_AdhesionWeight = 0.5 <<< from props
     #the probability of producing a new ivy root per iteration [0..1]
     ivy_BranchingProbability = 0.25
     #the probability of creating a new ivy leaf [0..1]
@@ -68,13 +94,23 @@
         
     #one single grow iteration
     def grow(self, props):
-        tmpRoot = IvyRoot()
+        tmpRoot = IvyRoot() # create new RootNode
+
+        #generate random Vector
         randVector = (mathutils.Vector((random.random()-0.5, random.random()-0.5, random.random()-0.5)) +
-                     mathutils.Vector((0,0,0.5)))
+                     mathutils.Vector((0,0,0.2)))
+
+        #set position of new RootNode
         tmpRoot.position = (self.ivy_Roots[-1].position +
                             randVector * props.ivyRandomWeight)
+
+        # add to the chainNumber
+        if tmpRoot.chainNumber == 0 or tmpRoot.chainNumber == self.ivy_Roots[-1].chainNumber:
+            tmpRoot.chainNumber = self.ivy_Roots[-1].chainNumber + 1
+        #print(self.ivy_Roots[-1].chainNumber, self.ivy_Roots[-1].position)
         self.ivy_Roots.append(tmpRoot)
 
+
     #compute the adhesion of scene objects at a point pos
     def computeAdhesion(self, position):
         pass
@@ -101,16 +137,13 @@
 
     IVY.seed()
 
-    for i in range(5):
+    for i in range(props.ivyIter):
         IVY.grow(props)
 
 
     createIvy(context, IVY)
-    print(len(IVY.ivy_Roots))
 
-    print(len(IVY.ivy_Roots))
 
-
     return
 
 class ivy_test(bpy.types.Operator):
@@ -122,6 +155,9 @@
     ivySeed = IntProperty(name='Seed',
                             min=0, soft_min=0,
                             default=0)
+    ivyIter = IntProperty(name='Iterations',
+                            min=0, soft_min=0,
+                            default=5)
     ivyGravityWeigth = FloatProperty(name='Gravity Weight',
                             min=0,soft_min=0,
                             max=1,soft_max=1,
@@ -141,8 +177,10 @@
     def execute(self, context):
         print('\n____________START_____________')
         props = self.properties
-
-
+        if context.active_object and context.active_object.type == 'MESH':
+            targetBoundingSphere = computeBoundingSphere(bpy.context.selected_editable_objects)
+            props.append(targetBoundingSphere)
+            
         main(context, props)
         return {'FINISHED'}
 




More information about the Bf-extensions-cvs mailing list