[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2196] branches/ivygen/truman_ivy/ add_curve_ivygen.py: Version 0.0.7
Andrew Hale
TrumanBlending at gmail.com
Fri Jul 29 08:41:48 CEST 2011
Revision: 2196
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2196
Author: trumanblending
Date: 2011-07-29 06:41:47 +0000 (Fri, 29 Jul 2011)
Log Message:
-----------
Version 0.0.7
- Improved description
- Improved efficiency of geometry generation
- Optimised adhesion function
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-29 06:26:13 UTC (rev 2195)
+++ branches/ivygen/truman_ivy/add_curve_ivygen.py 2011-07-29 06:41:47 UTC (rev 2196)
@@ -21,12 +21,13 @@
bl_info = {
"name": "IvyGen",
"author": "testscreenings, PKHG, TrumanBlending",
- "version": (0, 0, 6),
+ "version": (0, 0, 7),
"blender": (2, 5, 8),
"api": 38479,
"location": "View3D > Add > Curve",
- "description": "Adds generated ivy to an object.",
- "warning": "Script in Beta",
+ "description": "Adds generated ivy to a mesh object starting at the 3D"\
+ " cursor.",
+ "warning": "",
"wiki_url": "",
"tracker_url": "",
"category": "Add Curve"}
@@ -44,7 +45,7 @@
def createIvyGeometry(IVY, growLeaves):
'''Create the curve geometry for IVY'''
# Compute the local size and the gauss weight filter
- local_ivyBranchSize = IVY.ivyBranchSize # * radius * IVY.ivySize
+ #local_ivyBranchSize = IVY.ivyBranchSize # * radius * IVY.ivySize
gaussWeight = [1.0, 2.0, 4.0, 7.0, 9.0, 10.0, 9.0, 7.0, 4.0, 2.0, 1.0]
# Create a new curve and intialise it
@@ -59,15 +60,13 @@
signList = [(-1, 1), (1, 1), (1, -1), (-1, -1)]
# Get the local size
- local_ivyLeafSize = IVY.ivyLeafSize # * radius * IVY.ivySize
+ #local_ivyLeafSize = IVY.ivyLeafSize # * radius * IVY.ivySize
# Initialise the vertex and face lists
vertList = deque()
- faceList = deque()
# Store the methods for faster calling
addV = vertList.extend
- addF = faceList.extend
rotMat = Matrix.Rotation
# Loop over all roots to generate its nodes
@@ -77,14 +76,13 @@
if numNodes > 1:
# Calculate the local radius
local_ivyBranchRadius = 1 / (root.parents + 1) + 1
- splineVerts = deque()
- splineRadii = deque()
prevIvyLength = 1 / root.ivyNodes[-1].length
- splineVerts.extend([n.pos.to_4d()[i] for n in
- root.ivyNodes for i in range(4)])
- splineRadii.extend([(local_ivyBranchRadius * local_ivyBranchSize *
- (1.3 - n.length * prevIvyLength)) for n in root.ivyNodes])
+ splineVerts = [ax for n in root.ivyNodes for ax in n.pos.to_4d()]
+ radiusConstant = local_ivyBranchRadius * IVY.ivyBranchSize
+ splineRadii = [radiusConstant * (1.3 - n.length * prevIvyLength)
+ for n in root.ivyNodes]
+
# Add the poly curve and set coords and radii
newSpline = curve.splines.new(type='POLY')
newSpline.points.add(len(splineVerts) // 4 - 1)
@@ -102,7 +100,6 @@
n.smoothAdhesionVector.normalize()
if growLeaves and (i < numNodes - 1):
- count = 0
node = root.ivyNodes[i]
nodeNext = root.ivyNodes[i + 1]
@@ -132,7 +129,7 @@
theta += (rand_val() - 0.5) * (1.1 - alignmentWeight)
# Calculate the leaf size an append the face to the list
- leafSize = local_ivyLeafSize * sizeWeight
+ leafSize = IVY.ivyLeafSize * sizeWeight
for j in range(10):
# Generate the probability
@@ -141,15 +138,13 @@
# If we need to grow a leaf, do so
if (probability * weight) > IVY.leafProbability:
- count += 1
-
# Generate the random vector
randomVector = Vector((rand_val() - 0.5,
rand_val() - 0.5, rand_val() - 0.5))
# Find the leaf center
center = node.pos.lerp(nodeNext.pos, j / 10) +\
- local_ivyLeafSize * randomVector
+ IVY.ivyLeafSize * randomVector
# For each of the verts, rotate/scale and append
basisVecX = Vector((1, 0, 0))
@@ -170,15 +165,14 @@
addV([k1 * basisVecX + k2 * basisVecY + center for
k1, k2 in signList])
- currentVert = len(faceList)
- addF([[4 * k + l for l in range(4)] for k in
- range(currentVert, currentVert + count)])
-
# Add the object and link to scene
newCurve = bpy.data.objects.new("IVY_Curve", curve)
bpy.context.scene.objects.link(newCurve)
if growLeaves:
+ faceList = [[4 * i + l for l in range(4)] for i in
+ range(len(vertList) // 4)]
+
# Generate the new leaf mesh and link
me = bpy.data.meshes.new('IvyLeaf')
me.from_pydata(vertList, [], faceList)
@@ -287,9 +281,9 @@
def grow(self, ob):
# Determine the local sizes
- local_ivySize = self.ivySize # * radius
- local_maxFloatLength = self.maxFloatLength # * radius
- local_maxAdhesionDistance = self.maxAdhesionDistance # * radius
+ #local_ivySize = self.ivySize # * radius
+ #local_maxFloatLength = self.maxFloatLength # * radius
+ #local_maxAdhesionDistance = self.maxAdhesionDistance # * radius
for root in self.ivyRoots:
# Make sure the root is alive, if not, skip
@@ -300,7 +294,7 @@
prevIvy = root.ivyNodes[-1]
# If the node is floating for too long, kill the root
- if prevIvy.floatingLength > local_maxFloatLength:
+ if prevIvy.floatingLength > self.maxFloatLength:
root.alive = False
# Set the primary direction from the last node
@@ -313,17 +307,17 @@
# Calculate the adhesion vector
adhesionVector = adhesion(prevIvy.pos, ob,
- local_maxAdhesionDistance)
+ self.maxAdhesionDistance)
# Calculate the growing vector
- growVector = local_ivySize * (primaryVector * self.primaryWeight +
- randomVector * self.randomWeight +
- adhesionVector * self.adhesionWeight)
+ growVector = self.ivySize * (primaryVector * self.primaryWeight +
+ randomVector * self.randomWeight +
+ adhesionVector * self.adhesionWeight)
# Find the gravity vector
- gravityVector = (local_ivySize * self.gravityWeight *
- Vector((0, 0, -1)))
- gravityVector *= pow(prevIvy.floatingLength / local_maxFloatLength,
+ gravityVector = (self.ivySize * self.gravityWeight *
+ Vector((0, 0, -1)))
+ gravityVector *= pow(prevIvy.floatingLength / self.maxFloatLength,
0.7)
# Determine the new position vector
@@ -334,13 +328,13 @@
# Update the growing vector for any collisions
growVector = newPos - prevIvy.pos - gravityVector
+ growVector.normalize()
# Create a new IvyNode and set its properties
tmpNode = IvyNode()
tmpNode.climb = climbing
tmpNode.pos = newPos
- tmpNode.primaryDir = prevIvy.primaryDir.lerp(
- growVector.normalized(), 0.5)
+ tmpNode.primaryDir = prevIvy.primaryDir.lerp(growVector, 0.5)
tmpNode.primaryDir.normalize()
tmpNode.adhesionVector = adhesionVector
tmpNode.length = prevIvy.length + (newPos - prevIvy.pos).length
@@ -395,15 +389,15 @@
tran_loc = tran_mat * loc
# Compute the adhesion vector by finding the nearest point
- nearest_result = ob.closest_point_on_mesh(tran_loc)
+ nearest_result = ob.closest_point_on_mesh(tran_loc, max_l)
adhesion_vector = Vector((0, 0, 0))
if nearest_result[2] != -1:
# Compute the distance to the nearest point
- distance = (ob.matrix_world * nearest_result[0] - loc).length
+ adhesion_vector = ob.matrix_world * nearest_result[0] - loc
+ distance = adhesion_vector.length
# If it's less than the maximum allowed and not 0, continue
- if (distance < max_l) and distance:
+ if distance:
# Compute the direction vector between the closest point and 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])
@@ -601,10 +595,6 @@
return {'PASS_THROUGH'}
- def invoke(self, context, event):
- self.updateIvy = True
- return self.execute(context)
-
def draw(self, context):
layout = self.layout
row = layout.row()
@@ -677,7 +667,8 @@
def menu_func(self, context):
- self.layout.operator(IvyGen.bl_idname, text="Add Ivy to Mesh", icon='PLUGIN')
+ self.layout.operator(IvyGen.bl_idname, text="Add Ivy to Mesh",
+ icon='PLUGIN').updateIvy = True
def register():
@@ -691,4 +682,4 @@
if __name__ == "__main__":
- register()
+ register()
\ No newline at end of file
More information about the Bf-extensions-cvs
mailing list