Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolaus Leopold <nikolaus.leopold@gmail.com>2014-11-10 14:48:11 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2014-11-10 14:48:11 +0300
commit95a71fb815641a6b55c8d796c0106d1a159fd125 (patch)
tree47b1b4ea4ca3b359dd8d2a98ef31f6edaa1c1800 /add_curve_sapling
parentfba637f3162f91c57525b1c3cc9438ad1eb463fe (diff)
Final fix for 'division by zero' issues in sapling addon.
Review and minor cleanup by Bastien Montagne (mont29). Note: this addon would need a full complete style cleanup. :/ Differential Revision: D874
Diffstat (limited to 'add_curve_sapling')
-rw-r--r--add_curve_sapling/__init__.py4
-rw-r--r--add_curve_sapling/utils.py16
2 files changed, 11 insertions, 9 deletions
diff --git a/add_curve_sapling/__init__.py b/add_curve_sapling/__init__.py
index b27dd6a9..719675ed 100644
--- a/add_curve_sapling/__init__.py
+++ b/add_curve_sapling/__init__.py
@@ -195,7 +195,7 @@ class AddTree(bpy.types.Operator):
default=3, update=update_tree)
length = FloatVectorProperty(name='Length',
description='The relative lengths of each branch level (nLength)',
- min=0.000001,
+ min=1e-6,
default=[1, 0.3, 0.6, 0.45],
size=4, update=update_tree)
lengthV = FloatVectorProperty(name='Length Variation',
@@ -258,7 +258,7 @@ class AddTree(bpy.types.Operator):
default='7', update=update_tree)
baseSize = FloatProperty(name='Base Size',
description='Fraction of tree height with no branches (BaseSize)',
- min=0.0,
+ min=0.001,
max=1.0,
default=0.4, update=update_tree)
ratio = FloatProperty(name='Ratio',
diff --git a/add_curve_sapling/utils.py b/add_curve_sapling/utils.py
index f17ecb8b..b7740723 100644
--- a/add_curve_sapling/utils.py
+++ b/add_curve_sapling/utils.py
@@ -132,14 +132,14 @@ def declination(quat):
# Determine the length of a child stem
def lengthChild(lMax,offset,lPar,shape=False,lBase=None):
if shape:
- return lPar*lMax*shapeRatio(shape,(lPar - offset)/(lPar - lBase))
+ return lPar*lMax*shapeRatio(shape,(lPar - offset) / max((lPar - lBase), 1e-6))
else:
return lMax*(lPar - 0.6*offset)
# Find the actual downAngle taking into account the special case
def downAngle(downAng,downAngV,lPar=None,offset=None,lBase=None):
if downAngV < 0:
- return downAng + (uniform(-downAngV,downAngV)*(1 - 2*shapeRatio(0,(lPar - offset)/(lPar - lBase))))
+ return downAng + (uniform(-downAngV,downAngV)*(1 - 2*shapeRatio(0,(lPar - offset) / max((lPar - lBase), 1e-6))))
else:
return downAng + uniform(-downAngV,downAngV)
@@ -445,7 +445,7 @@ def create_armature(armAnim, childP, cu, frameRate, leafMesh, leafObj, leafShape
bxOffset = uniform(0, 2 * pi)
byOffset = uniform(0, 2 * pi)
# Set the phase multiplier for the spline
- bMult = (s.bezier_points[0].radius / splineL) * (1 / 15) * (1 / frameRate)
+ bMult = (s.bezier_points[0].radius / max(splineL, 1e-6)) * (1 / 15) * (1 / frameRate)
# For all the points in the curve (less the last) add a bone and name it by the spline it will affect
for n in range(numPoints):
oldBone = b
@@ -481,7 +481,7 @@ def create_armature(armAnim, childP, cu, frameRate, leafMesh, leafObj, leafShape
# Add the animation to the armature if required
if armAnim:
# Define all the required parameters of the wind sway by the dimension of the spline
- a0 = 4 * splineL * (1 - n / (numPoints + 1)) / s.bezier_points[n].radius
+ a0 = 4 * splineL * (1 - n / (numPoints + 1)) / max(s.bezier_points[n].radius, 1e-6)
a1 = (windSpeed / 50) * a0
a2 = (windGust / 50) * a0 + a1 / 2
@@ -592,11 +592,12 @@ def fabricate_stems(addsplinetobone, addstem, baseSize, branches, childP, cu, cu
if leaves < 0:
childStems = False
else:
- childStems = leaves * shapeRatio(leafDist, p.offset / max(p.lengthPar, 1e-6))
+ childStems = leaves * shapeRatio(leafDist, p.offset / p.lengthPar)
elif n == 1:
# If this is the first level of branching then upward attraction has no effect and a special formula is used to find branch length and the number of child stems
vertAtt = 0.0
lMax = length[1] + uniform(-lengthV[1], lengthV[1])
+ lMax += copysign(1e-6, lMax) # Move away from zero to avoid div by zero
branchL = p.lengthPar * lMax * shapeRatio(shape,
(p.lengthPar - p.offset) / (p.lengthPar - baseSize * scaleVal))
childStems = branches[2] * (0.2 + 0.8 * (branchL / p.lengthPar) / lMax)
@@ -681,10 +682,10 @@ def perform_pruning(baseSize, baseSplits, childP, cu, currentMax, currentMin, cu
# Check each endpoint to see if it is inside
for s in splineList:
coordMag = (s.spline.bezier_points[-1].co.xy).length
- ratio = (scaleVal - s.spline.bezier_points[-1].co.z) / (scaleVal * (1 - baseSize))
+ ratio = (scaleVal - s.spline.bezier_points[-1].co.z) / (scaleVal * max(1 - baseSize, 1e-6))
# Don't think this if part is needed
if (n == 0) and (s.spline.bezier_points[-1].co.z < baseSize * scaleVal):
- pass # insideBool = True
+ insideBool = True # Init to avoid UnboundLocalError later
else:
insideBool = (
(coordMag / scaleVal) < pruneWidth * shapeRatio(8, ratio, pruneWidthPeak, prunePowerHigh,
@@ -819,6 +820,7 @@ def addTree(props):
# Fix the scale of the tree now
scaleVal = scale + uniform(-scaleV,scaleV)
+ scaleVal += copysign(1e-6, scaleVal) # Move away from zero to avoid div by zero
# If pruning is turned on we need to draw the pruning envelope
if prune: