[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2162] branches/ivygen/truman_ivy/ add_curve_ivygen.py: - Version 0.0.3
Andrew Hale
TrumanBlending at gmail.com
Sat Jul 23 15:25:46 CEST 2011
Revision: 2162
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2162
Author: trumanblending
Date: 2011-07-23 13:25:45 +0000 (Sat, 23 Jul 2011)
Log Message:
-----------
- Version 0.0.3
- Removed scaling of parameters with the object size
- Changed default parameter values to better suit new implementation above
- Added a check on the nearest point distance (thanks to PKHG) to prevent nan vector
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-22 06:43:30 UTC (rev 2161)
+++ branches/ivygen/truman_ivy/add_curve_ivygen.py 2011-07-23 13:25:45 UTC (rev 2162)
@@ -21,7 +21,7 @@
bl_info = {
"name": "IvyGen",
"author": "testscreenings, PKHG, TrumanBlending",
- "version": (0, 0, 2),
+ "version": (0, 0, 3),
"blender": (2, 5, 8),
"api": 38479,
"location": "View3D > Add > Curve",
@@ -41,13 +41,13 @@
import time
-def createIvyLeaves(IVY, radius):
+def createIvyLeaves(IVY):
# Create the ivy leaves
# Order location of the vertices
signList = [(-1, 1), (1, 1), (1, -1), (-1, -1)]
# Get the local size
- local_ivyLeafSize = radius * IVY.ivySize * IVY.ivyLeafSize
+ local_ivyLeafSize = IVY.ivyLeafSize # * radius * IVY.ivySize
# Initialise the vertex and face lists
vertList = deque()
@@ -64,14 +64,17 @@
prevIvyLength = 1 / root.ivyNodes[-1].length
# Loop over all node ten times
for i in range(10):
- for node in root.ivyNodes:
+ for j in range(len(root.ivyNodes) - 1):
+ node = root.ivyNodes[j]
+ nodeNext = root.ivyNodes[j + 1]
+
# Find the weight and normalise the smooth adhesion vector
- weight = pow(node.length / prevIvyLength, 0.7)
+ weight = pow(node.length * prevIvyLength, 0.7)
normalAd = node.smoothAdhesionVector.normalized()
# Calculate the ground ivy and the new weight
groundIvy = max(0.0, -normalAd.z)
- weight += groundIvy * pow(1 - node.length / prevIvyLength, 2)
+ weight += groundIvy * pow(1 - node.length * prevIvyLength, 2)
# Generate the probability
probability = rand_val()
@@ -93,7 +96,8 @@
rand_val() - 0.5))
# Find the leaf center
- center = node.pos + local_ivyLeafSize * randomVector
+ center = node.pos.lerp(nodeNext.pos, i / 10) +\
+ local_ivyLeafSize * randomVector
# Find the size weight
sizeWeight = 1.5 - (cos(2 * pi * weight) * 0.5 + 0.5)
@@ -122,8 +126,8 @@
basisVecX.rotate(vertRot)
basisVecY.rotate(vertRot)
- basisVecX *= local_ivyLeafSize * sizeWeight
- basisVecY *= local_ivyLeafSize * sizeWeight
+ basisVecX *= leafSize
+ basisVecY *= leafSize
randomVector = Vector((rand_val() - 0.5,
rand_val() - 0.5, rand_val() - 0.5))
@@ -150,10 +154,10 @@
return ob
-def createIvyCurves(IVY, radius):
+def createIvyCurves(IVY):
'''Create the curve geometry for IVY'''
# Compute the local size and the gauss weight filter
- local_ivyBranchSize = radius * IVY.ivySize * IVY.ivyBranchSize
+ 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
@@ -258,13 +262,13 @@
gravityWeight=1.0,
adhesionWeight=0.1,
branchingProbability=0.95,
- leafProbability=0.7,
- ivySize=0.005,
- ivyLeafSize=1.5,
- ivyBranchSize=0.15,
- maxFloatLength=0.1,
- maxAdhesionDistance=0.1,
- randomSeed=1,
+ leafProbability=0.65,
+ ivySize=0.02,
+ ivyLeafSize=0.02,
+ ivyBranchSize=0.001,
+ maxFloatLength=0.5,
+ maxAdhesionDistance=1.0,
+ randomSeed=0.0,
maxIvyLength=0.0,
maxTime=0.0):
@@ -297,11 +301,11 @@
tmpRoot.ivyNodes.append(tmpIvy)
self.ivyRoots.append(tmpRoot)
- def grow(self, radius, ob):
+ 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
@@ -408,8 +412,8 @@
if nearest_result[2] != -1:
# Compute the distance to the nearest point
distance = (nearest_result[0] - loc).length
- # If it's less than the maximum allowed, continue
- if distance < max_l:
+ # 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.normalize()
@@ -457,7 +461,7 @@
ob = context.active_object
# Compute bounding sphere radius
- radius = computeBoundingSphere(ob)
+ #radius = computeBoundingSphere(ob) # Not needed anymore
# Get the seeding point
seedPoint = context.scene.cursor_location
@@ -473,7 +477,7 @@
checkAlive = True
checkTime = False
- maxLength = radius * ivyProps.maxIvyLength
+ maxLength = ivyProps.maxIvyLength # * radius
# If we need to check time set the flag
if ivyProps.maxTime != 0.0:
@@ -487,7 +491,7 @@
(IVY.maxLength < maxLength) and\
(not checkTime or (time.time() - t < ivyProps.maxTime)):
# Grow the ivy for this iteration
- IVY.grow(radius, ob)
+ IVY.grow(ob)
# Print the proportion of ivy growth to console
if (IVY.maxLength / maxLength * 100) > (startPercent // 10) * 10:
@@ -502,10 +506,10 @@
checkAlive = (True in checkAliveIter)
# Create the curve and leaf geometry
- curveOb = createIvyCurves(IVY, radius)
+ curveOb = createIvyCurves(IVY)
print("Curve Generation Complete")
- leafOb = createIvyLeaves(IVY, radius)
+ leafOb = createIvyLeaves(IVY)
print("Leaf Generation Complete")
# Parent the leave to the curve
@@ -517,8 +521,7 @@
class IvyProps(bpy.types.PropertyGroup):
maxIvyLength = FloatProperty(name="Max Ivy Length",
- description="Maximum ivy length as a proportion"\
- "of bounding sphere radius",
+ description="Maximum ivy length in Blender Units.",
default=1.0,
min=0.0,
soft_max=3.0,
@@ -550,41 +553,37 @@
soft_max=1.0)
leafProbability = FloatProperty(name="Leaf Probability",
description="Probability of a leaf forming.",
- default=0.95,
+ default=0.65,
min=0.0,
- soft_max=1.0,)
+ soft_max=1.0)
ivySize = FloatProperty(name="Ivy Size",
- description="The size of the ivy in relation to"\
- "bounding sphere radius.",
- default=0.005,
+ description="The length of an ivy segment in Blender"\
+ " Units.",
+ default=0.02,
min=0.0,
soft_max=1.0)
ivyLeafSize = FloatProperty(name="Ivy Leaf Size",
- description="The size of the ivy leaves in relation to"\
- "bounding sphere radius.",
- default=1.5,
+ description="The size of the ivy leaves",
+ default=0.02,
min=0.0,
soft_max=2)
ivyBranchSize = FloatProperty(name="Ivy Branch Size",
- description="The size of the ivy branches in relation to"\
- "bounding sphere radius.",
- default=0.15,
+ description="The size of the ivy branches",
+ default=0.001,
min=0.0,
soft_max=1.0)
maxFloatLength = FloatProperty(name="Max Float Length",
- description="The maximum distance (as a fraction of"\
- "bounding sphere radius) that a branch"\
+ description="The maximum distance that a branch"\
"can live while floating.",
- default=0.1,
+ default=0.5,
min=0.0,
soft_max=1.0)
maxAdhesionDistance = FloatProperty(name="Max Adhesion Length",
- description="The maximum distance (as a fraction of"\
- "bounding sphere radius) that a branch"\
+ description="The maximum distance that a branch"\
"will feel the effects of adhesion.",
- default=0.1,
+ default=1.0,
min=0.0,
- soft_max=1.0)
+ soft_max=2.0)
randomSeed = FloatProperty(name="Random Seed",
description="The seed governing random generation.",
default=0,
More information about the Bf-extensions-cvs
mailing list