[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [815] branches/ivygen/ivy_test.py: - added collision again

Florian Meyer florianfelix at web.de
Tue Jul 20 08:53:51 CEST 2010


Revision: 815
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=815
Author:   testscreenings
Date:     2010-07-20 08:53:51 +0200 (Tue, 20 Jul 2010)

Log Message:
-----------
- added collision again
- doesn't work because of two things:
-1. reflection is not correctly calculated yet
-2. more important a pretty serious bug, either in my code or in blenders. but i and others didn't find a solution yet.
-commented out for now

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

Modified: branches/ivygen/ivy_test.py
===================================================================
--- branches/ivygen/ivy_test.py	2010-07-20 00:52:01 UTC (rev 814)
+++ branches/ivygen/ivy_test.py	2010-07-20 06:53:51 UTC (rev 815)
@@ -102,6 +102,8 @@
 
     ivyRoots = []
     
+    ivyCollider = None
+    
     # the ivy size factor, influences the grow behaviour [0..0,1]
     ivySize = 1.0
     
@@ -180,11 +182,20 @@
             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)
+            
             # create new IvyNode
             tmpIvy = IvyNode()
 
+            # set climbing state
+            tmpIvy.climbing = collisionResult[0]
+
             # set position
             tmpIvy.position = prevIvy.position + growVector + gravityVector
             #print('tmpIvy.position', tmpIvy.position)
@@ -230,16 +241,46 @@
                 #print('newRootsLength', len(self.ivyRoots[-1].ivyNodes))
                 pass # seed new root
 
+def collision(ob, root, new_pos):
+    prevIvy = root.ivyNodes[-1]
+    old_pos = prevIvy.position
+    deadlockCounter = 0
+    climbing = False
 
+    ray_result = ob.ray_cast(old_pos, new_pos)
+    if ray_result[2] != -1: # if collides with mesh
+        climbing = True
+        face = ob.data.faces[ray_result[2]]
+        
+        #project newPos to triangle plane
+        #Vector3d p0 = newPos - t->norm * Vector3d::dotProduct(t->norm, newPos - t->v0->pos);
+    
+        projVec = mathutils.Vector((new_pos -
+                                    (face.normal * face.normal.dot(ray_result[0]))))
+    
+        new_pos += 2.0 * (projVec - new_pos)
+        print('colliding')
+
+    else:
+        print('not colliding')
+    
+    collisionResult = [climbing, new_pos]
+    return collisionResult
+    
+                
 def main(context, props, data):
     seedPoint = context.scene.cursor_location  #start the Ivy at the cursor
-
     random.seed(props.ivySeed)  #controlling the random seed
 
     scene = context.scene
-    obj = context.active_object
+    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
 




More information about the Bf-extensions-cvs mailing list