[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [842] branches/ivygen: - something like adhesion is working.
Florian Meyer
florianfelix at web.de
Thu Jul 22 14:41:23 CEST 2010
Revision: 842
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-extensions&revision=842
Author: testscreenings
Date: 2010-07-22 14:41:23 +0200 (Thu, 22 Jul 2010)
Log Message:
-----------
- something like adhesion is working.
- although it turns out the same bug from collision is here too
- really don't try this now
- needs serious optimizations
Modified Paths:
--------------
branches/ivygen/ivy_functions.py
branches/ivygen/ivy_test.py
Modified: branches/ivygen/ivy_functions.py
===================================================================
--- branches/ivygen/ivy_functions.py 2010-07-22 11:09:26 UTC (rev 841)
+++ branches/ivygen/ivy_functions.py 2010-07-22 12:41:23 UTC (rev 842)
@@ -181,6 +181,8 @@
##################################################################################
def altitude(point1, point2, pointn):
+ # returns the orthoprojection distance (i think thats the name)
+ # of pointn to 2 other points
edge1 = point2 - point1
edge2 = pointn - point1
if edge2.length == 0:
@@ -231,11 +233,13 @@
return True
else:
return False
+
- return value
-def distance2(old_pos, ob):
+def adhesion2(old_pos, ob, data, props):
+ targetBoundingSphere = data[0]
#print('cursor', old_pos)
-
+ minimum_dist = targetBoundingSphere[1] * props.ivyMaxAdhesionDist
+ distance = None
for i, face in enumerate(ob.data.faces):
n = face.normal
c = face.center + ob.location
@@ -243,7 +247,7 @@
plane_dist = (n.dot(old_pos) +
( -n.x*c.x -
-n.y*c.y -
- -n.z*c .z))
+ -n.z*c.z))
print('plane_dist', plane_dist)
# up to here this works
# plane_dist is the distance to the plane defined by the face.center and face.normal
@@ -252,6 +256,15 @@
# now find the closest distance to the poly
# test if pointOnPlane is already inside the poligon
# else get closest point on the closest edge
+
+
+ if isInside(ob, face, pointOnPlane):
+ if plane_dist < minimum_dist:
+ distances.append(plane_dist)
+ if plane_dist y distances.sort()[0]:
+ adhesionVector = mathutils.Vector((old_pos - pointOnPlane))
+
+ return adhesionVector
'''
print('\n______________')
cur = bpy.context.scene.cursor_location
Modified: branches/ivygen/ivy_test.py
===================================================================
--- branches/ivygen/ivy_test.py 2010-07-22 11:09:26 UTC (rev 841)
+++ branches/ivygen/ivy_test.py 2010-07-22 12:41:23 UTC (rev 842)
@@ -5,7 +5,30 @@
#from ivy_functions import *
import math
+def isInside(ob, face, point):
+ #tests if the point is always on the same side of the edges
+ #seems to work reasonably well, except:
+ #returns False if the point lies directly on a vert
+
+ inside = False
+ bigger = 0
+ smaller = 0
+ for edge in face.edge_keys:
+ v1 = ob.data.verts[edge[0]]
+ v2 = ob.data.verts[edge[1]]
+ val = (v1.co - v2.co).cross(point - v1.co)
+ com = (v1.co - v2.co).cross(point - ob.data.verts[edge[0]-2].co)
+ prod = val.dot(com)
+ if prod >= 0:
+ bigger += 1
+ else:
+ smaller += 1
+ if bigger == 0 or smaller == 0:
+ return True
+ else:
+ return False
+
def vertsToArray(root):
splineVerts = []
for ivyNode in root.ivyNodes:
@@ -143,7 +166,7 @@
######### one GROW iteration ######
- def grow(self, props):
+ def grow(self, props, data):
# newRoots = []
rootNr = 0
@@ -172,10 +195,12 @@
primaryVector = prevIvy.primaryVector
# ADHESION VECTOR
+ adhesionVector = adhesion2(prevIvy.position, self.ivyCollider, data, props)
+
-
# GROW VECTOR
growVector = (randomVector * props.ivyRandomWeight +
+ adhesionVector * props.ivyAdhesionWeight +
primaryVector * props.ivyPrimaryWeight) * props.ivyGlobScale
# GRAVITY VECTOR
@@ -264,6 +289,51 @@
#print('newRootsLength', len(self.ivyRoots[-1].ivyNodes))
pass # seed new root
+def adhesion2(old_pos, ob, data, props):
+ targetBoundingSphere = data[0]
+ minimum_dist = targetBoundingSphere[1] * props.ivyMaxAdhesionDist
+ distances = []
+
+ adhesionVector = mathutils.Vector((0,0,0))
+ #print('minimum_dist', minimum_dist)
+ for i, face in enumerate(ob.data.faces):
+ n = face.normal
+ c = face.center + ob.location
+
+ plane_dist = (n.dot(c - old_pos))
+ #print('plane_dist', plane_dist)
+ # up to here this works
+ # plane_dist is the distance to the plane defined by the face.center and face.normal
+ pointOnPlane = old_pos - n * plane_dist
+ #print('pointOnPlane', pointOnPlane)
+ # now find the closest distance to the poly
+ # test if pointOnPlane is already inside the poligon
+ # else get closest point on the closest edge
+
+ if plane_dist < minimum_dist:
+ if isInside(ob, face, pointOnPlane):
+ #print('isInside')
+ #print('plane_dist', plane_dist)
+ if not distances:
+ distances.append(positive(plane_dist))
+ #print('distances [0]', distances[0])
+ if plane_dist < distances[0]:
+ distances.append(positive(plane_dist))
+ distances.sort()
+ #print('shortest', distances[0])
+ adhesionVector = mathutils.Vector((old_pos - pointOnPlane)).normalize()
+
+ #else:
+ #print('is Outside')
+ #print('distance', distances[0])
+ #print('\nADHESION', adhesionVector)
+ return adhesionVector
+
+def positive(val):
+ if val < 0:
+ val *= -1
+ return val
+
def collision(ob, root, new_pos):
prevIvy = root.ivyNodes[-1]
old_pos = prevIvy.position
@@ -322,7 +392,7 @@
#for now usercontrollable growiterations
for i in range(props.ivyIter):
- IVY.grow(props)
+ IVY.grow(props, data)
print('\nIvyNodes[root[0]:', len(IVY.ivyRoots[0].ivyNodes))
print('IvyRoots:', len(IVY.ivyRoots))
@@ -344,7 +414,7 @@
default=0)
ivyIter = IntProperty(name='Iterations',
min=0, soft_min=0,
- default=40)
+ default=19)
ivyGravityWeight = FloatProperty(name='Gravity Weight',
min=0,soft_min=0,
max=1,soft_max=1,
@@ -353,6 +423,10 @@
min=0,soft_min=0,
max=1,soft_max=1,
default=0.5)
+ ivyAdhesionWeight = FloatProperty(name='PAdhesion Weight',
+ min=0,soft_min=0,
+ max=1,soft_max=1,
+ default=0.5)
ivyRandomWeight = FloatProperty(name='Random Weight',
min=0,soft_min=0,
max=1,soft_max=1,
@@ -360,8 +434,10 @@
ivyGlobScale = FloatProperty(name='Globel Scale',
min=0,soft_min=0,
default=1)
+ ivyMaxAdhesionDist = FloatProperty(name='Globel Scale',
+ min=0,soft_min=0,
+ default=0.000001)
-
collider = None
def poll(self, context):
More information about the Bf-extensions-cvs
mailing list