Page MenuHome

minor issue with tree generator (Sapling add-on)
Closed, ResolvedPublic

Description

System Information
Operating system and graphics Card
Windows 7 Pro 64 bit, Intel on board grapics

Blender Version
Broken: 2.71

Short description of error
When creating a tree, the number of leaves doesn't change if branch splitting level is 2. With level 3 it works.

Exact steps for others to reproduce the error
Add curve -> Tree -> check "bevel". All of the other settings can remain as they are. Then goto section "Leaves" and check "show leaves". The number of leaves attached to the tree doesn't change if you change the value in the belonging input field. If you go to section "branch splitting" and increase the branch level to 3 then you can set the number of the leaves as you want and they are shown / attached correctly.
(Maybe this is actually a feature but to me it appears like a bug.)

Thanks.

Details

Type
Bug

Event Timeline

Ernst Hammann (JASMS) set Type to Bug.
Ernst Hammann (JASMS) created this task.
Ernst Hammann (JASMS) raised the priority of this task from to Needs Triage by Developer.

I found what I believe to be the problem. in the add_curve_sapling/utils.py:

if 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])
    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)
elif storeN <= levels - 2:
    branchL = (length[n] + uniform(-lengthV[n], lengthV[n])) * (p.lengthPar - 0.6 * p.offset)
    childStems = branches[min(3, n + 1)] * (1.0 - 0.5 * p.offset / p.lengthPar)
# If this is the last level before leaves then we need to generate the child points differently
else:
    branchL = (length[n] + uniform(-lengthV[n], lengthV[n])) * (p.lengthPar - 0.6 * p.offset)
    if leaves < 0:
        childStems = False
    else:
        childStems = leaves * shapeRatio(leafDist, p.offset / p.lengthPar)

When levels==2, then the n==1 clause shadows the leaf clause at the end. If we move the leaf clause to the top it works like you want:

if (storeN>= levels-1):
# If this is the last level before leaves then we need to generate the child points differently
    branchL = (length[n] + uniform(-lengthV[n], lengthV[n])) * (p.lengthPar - 0.6 * p.offset)
    if leaves < 0:
        childStems = False
    else:
        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])
    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)
elif storeN <= levels - 2:
    branchL = (length[n] + uniform(-lengthV[n], lengthV[n])) * (p.lengthPar - 0.6 * p.offset)
    childStems = branches[min(3, n + 1)] * (1.0 - 0.5 * p.offset / p.lengthPar)