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

Andrew Hale TrumanBlending at gmail.com
Tue Jul 26 04:45:29 CEST 2011


Revision: 2182
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2182
Author:   trumanblending
Date:     2011-07-26 02:45:29 +0000 (Tue, 26 Jul 2011)
Log Message:
-----------
Version 0.0.5
- Added a "Add New Ivy" button to make adding new ivy with the same properties easy
- Fixed code to be able to work with objects that have not had their transformations applied

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 09:18:38 UTC (rev 2181)
+++ branches/ivygen/truman_ivy/add_curve_ivygen.py	2011-07-26 02:45:29 UTC (rev 2182)
@@ -21,7 +21,7 @@
 bl_info = {
     "name": "IvyGen",
     "author": "testscreenings, PKHG, TrumanBlending",
-    "version": (0, 0, 4),
+    "version": (0, 0, 5),
     "blender": (2, 5, 8),
     "api": 38479,
     "location": "View3D > Add > Curve",
@@ -400,16 +400,20 @@
 
 
 def adhesion(loc, ob, max_l):
+    # Get transfor vector and transformed loc
+    tran_mat = ob.matrix_world.inverted()
+    tran_loc = tran_mat * loc
+
     # Compute the adhesion vector by finding the nearest point
-    nearest_result = ob.closest_point_on_mesh(loc)
+    nearest_result = ob.closest_point_on_mesh(tran_loc)
     adhesion_vector = Vector((0, 0, 0))
     if nearest_result[2] != -1:
         # Compute the distance to the nearest point
-        distance = (nearest_result[0] - loc).length
+        distance = (nearest_result[0] - tran_loc).length
         # If it's less than the maximum allowed and not 0, continue
         if (distance < max_l) and distance:
             # Compute the direction vector between the closest point and loc
-            adhesion_vector = nearest_result[0] - loc
+            adhesion_vector = ob.matrix_world * nearest_result[0] - loc
             adhesion_vector.normalize()
             adhesion_vector *= 1.0 - distance / max_l
             #adhesion_vector *= getFaceWeight(ob.data, nearest_result[2])
@@ -419,15 +423,23 @@
 def collision(ob, pos, new_pos):
     # Check for collision with the object
     climbing = False
-    ray_result = ob.ray_cast(pos, new_pos)
+
+    # Transform vecs
+    tran_mat = ob.matrix_world.inverted()
+    tran_pos = tran_mat * pos
+    tran_new_pos = tran_mat * new_pos
+
+    ray_result = ob.ray_cast(tran_pos, tran_new_pos)
     # If there's a collision we need to check it
     if ray_result[2] != -1:
         # Check whether the collision is going into the object
-        if (new_pos - pos).dot(ray_result[1]) < 0.0:
+        if (tran_new_pos - tran_pos).dot(ray_result[1]) < 0.0:
             # Find projection of the piont onto the plane
-            p0 = new_pos - (new_pos - ray_result[0]).project(ray_result[1])
+            p0 = tran_new_pos - (tran_new_pos - ray_result[0]).project(ray_result[1])
             # Reflect in the plane
-            new_pos += 2 * (p0 - new_pos)
+            tran_new_pos += 2 * (p0 - tran_new_pos)
+            new_pos *= 0
+            new_pos += ob.matrix_world * tran_new_pos
             climbing = True
     return climbing
 
@@ -607,6 +619,24 @@
         row = layout.row()
         row.alignment = 'EXPAND'
         row.prop(self, 'updateIvy', icon='CURVE_DATA')
+
+        row = layout.row()
+        properties = row.operator('curve.ivy_gen', text="Add New Ivy")
+        properties.randomSeed = self.randomSeed
+        properties.maxTime = self.maxTime
+        properties.maxIvyLength = self.maxIvyLength
+        properties.ivySize = self.ivySize
+        properties.maxFloatLength = self.maxFloatLength
+        properties.maxAdhesionDistance = self.maxAdhesionDistance
+        properties.primaryWeight = self.primaryWeight
+        properties.randomWeight = self.randomWeight
+        properties.gravityWeight = self.gravityWeight
+        properties.adhesionWeight = self.adhesionWeight
+        properties.branchingProbability = self.branchingProbability
+        properties.leafProbability = self.leafProbability
+        properties.ivyBranchSize = self.ivyBranchSize
+        properties.ivyLeafSize = self.ivyLeafSize
+
         box = layout.box()
         box.label("Generation Settings")
         row = box.row()
@@ -660,4 +690,4 @@
 
 
 if __name__ == "__main__":
-    register()
+    register()
\ No newline at end of file



More information about the Bf-extensions-cvs mailing list