# [Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [826] branches/ivygen/ivy_test.py: - update to the colliderproblem.

Florian Meyer florianfelix at web.de
Wed Jul 21 03:10:10 CEST 2010

```Revision: 826
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=826
Author:   testscreenings
Date:     2010-07-21 03:10:09 +0200 (Wed, 21 Jul 2010)

Log Message:
-----------
- update to the colliderproblem.
- still not solved
- uncommented it to let someone who is willing try to solve it
- ---why the... has the cube no mesh anymore in the second run

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

Modified: branches/ivygen/ivy_test.py
===================================================================
--- branches/ivygen/ivy_test.py	2010-07-20 22:11:02 UTC (rev 825)
+++ branches/ivygen/ivy_test.py	2010-07-21 01:10:09 UTC (rev 826)
@@ -2,7 +2,7 @@
from bpy.props import *
import mathutils
import random
-from ivy_functions import *
+#from ivy_functions import *
import math

@@ -99,6 +99,7 @@
# list of containing Roots
def __init__(self):
self.ivyRoots = []
+        #self.ivyCollider = obj

ivyRoots = []

@@ -182,19 +183,35 @@
gravityVector *= math.pow(prevIvy.floatingLength / self.maxFloatingLength, 0.7)

# compute COLLISION
-            #collisionResult = collision(self.ivyCollider, root, prevIvy.position + growVector + gravityVector)
-            #update growVector in case of collision
-            #growVector = newPos - root->nodes.back().pos - gravityVector
-
-            #print('old_Grow', growVector)
-            #growVector = collisionResult[1] - prevIvy.position - gravityVector
-            #print('new_Grow', growVector)
-
+            ####################################################################################################
+            ####################################################################################################
+            ####################################################################################################
+            ####### put in here for testing, until the error is fixed ##########################################
+            climbing, new_pos = collision(self.ivyCollider, root, prevIvy.position + growVector + gravityVector)
+            ####### delete, comment out when fixed #############################################################
+            ####################################################################################################
+            ####################################################################################################
+            ####################################################################################################
+
+            try:
+                climbing, new_pos = collision(self.ivyCollider, root, prevIvy.position + growVector + gravityVector)
+                #print('old_Grow', growVector)
+                #update growVector in case of collision
+                growVector = new_pos - prevIvy.position - gravityVector
+                #print('new_Grow', growVector)
+
+            except:
+                print('---COLLISION FAILED---')
+
+
# create new IvyNode
tmpIvy = IvyNode()

# set climbing state
-            #tmpIvy.climbing = collisionResult[0]
+            try:
+                tmpIvy.climbing = climbing
+            except:
+                pass

# set position
tmpIvy.position = prevIvy.position + growVector + gravityVector
@@ -247,8 +264,12 @@
climbing = False

+    #print('Collider Object: ', ob.name)
+
ray_result = ob.ray_cast(old_pos, new_pos)
if ray_result[2] != -1: # if collides with mesh
+        print('Collided with Object: ', ob.name)
+
climbing = True
face = ob.data.faces[ray_result[2]]

@@ -259,42 +280,52 @@
(face.normal * face.normal.dot(ray_result[0]))))

new_pos += 2.0 * (projVec - new_pos)
-        print('colliding')
+        #print('\ncolliding')

-    else:
-        print('not colliding')
+    #else:
+        #print('not colliding')

collisionResult = [climbing, new_pos]
-    return collisionResult
+    return climbing, new_pos

-def main(context, props, data):
+def main(context, props, data, collider):
seedPoint = context.scene.cursor_location  #start the Ivy at the cursor
-    random.seed(props.ivySeed)  #controlling the random seed
-
+    random.seed(props.ivySeed)                 #controlling the random seed
scene = context.scene
-    #try:
-    #    obj = context.active_object
-
-    IVY = Ivy() #create main IvyObject stores all the IvyRoots.IvyNodes
-    #try:
-    #    IVY.ivyCollider = obj
-    #    print('obj.data', IVY.ivyCollider.data)
-
-    # PROBLEM: SOMEHOW DOESN'T WORK
-    IVY.ivyRoots = [] #empty the roots list

-    IVY.seed(seedPoint, parentOrder=0, primaryVector=mathutils.Vector((0,0,1))) #set inital IvyRoot
+    try:
+        obj = context.active_object
+        print('context.active_object', context.active_object.name)
+    except:
+        obj = None

-    for i in range(props.ivyIter): #for now usercontrollable growiterations
+    #create main IvyObject stores all the IvyRoots.IvyNodes
+    IVY = Ivy()
+
+    print('preLoop collider is', IVY.ivyCollider)
+
+    # set collider object
+    IVY.ivyCollider = collider
+    print('setting collider to', IVY.ivyCollider.name)
+
+    #empty the roots list
+    IVY.ivyRoots = []
+
+    #set inital IvyRoot
+    IVY.seed(seedPoint, parentOrder=0, primaryVector=mathutils.Vector((0,0,1)))
+
+    #for now usercontrollable growiterations
+    for i in range(props.ivyIter):
IVY.grow(props)

-    print('IvyNodes[root[0]:', len(IVY.ivyRoots[0].ivyNodes))
+    print('\nIvyNodes[root[0]:', len(IVY.ivyRoots[0].ivyNodes))
print('IvyRoots:', len(IVY.ivyRoots))
-    #createIvy(context, IVY) # create emptis at IvyRoots
-    createIvyCurves(context, IVY) #create Curverepresentation of the Ivy

+    #create Curverepresentation of the Ivy
+    createIvyCurves(context, IVY)

+
return

class ivy_test2(bpy.types.Operator):
@@ -322,18 +353,19 @@
max=1,soft_max=1,
default=0.5)

+    collider = None
+
def poll(self, context):
return context.active_object != None

def execute(self, context):
print('\n____________START_____________')
# turn off undo
-        undo = bpy.context.user_preferences.edit.global_undo
-        bpy.context.user_preferences.edit.global_undo = False
+        #undo = bpy.context.user_preferences.edit.global_undo
+        #bpy.context.user_preferences.edit.global_undo = False

props = self.properties
data = []
-        print(props)
# compute boundingSphere and put into props if abs mesh is selected
if (context.active_object
and context.active_object.select
@@ -341,10 +373,14 @@
targetBoundingSphere = computeBoundingSphere(bpy.context.selected_editable_objects)
data.append(targetBoundingSphere)

+        if self.collider == None:
+            self.collider = context.active_object

-        main(context, props, data)
+

-        bpy.context.user_preferences.edit.global_undo = undo
+        main(context, props, data, self.collider)
+
+        #bpy.context.user_preferences.edit.global_undo = undo

return {'FINISHED'}

```