Changeset View
Standalone View
add_curve_sapling/utils.py
| Context not available. | |||||
| # Determine the length of a child stem | # Determine the length of a child stem | ||||
| def lengthChild(lMax,offset,lPar,shape=False,lBase=None): | def lengthChild(lMax,offset,lPar,shape=False,lBase=None): | ||||
| if shape: | if shape: | ||||
| return lPar*lMax*shapeRatio(shape,(lPar - offset)/(lPar - lBase)) | return lPar*lMax*shapeRatio(shape,(lPar - offset)/ max((lPar - lBase), 1e-6) ) | ||||
| else: | else: | ||||
| return lMax*(lPar - 0.6*offset) | return lMax*(lPar - 0.6*offset) | ||||
| # Find the actual downAngle taking into account the special case | # Find the actual downAngle taking into account the special case | ||||
| def downAngle(downAng,downAngV,lPar=None,offset=None,lBase=None): | def downAngle(downAng,downAngV,lPar=None,offset=None,lBase=None): | ||||
| if downAngV < 0: | 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: | else: | ||||
| return downAng + uniform(-downAngV,downAngV) | return downAng + uniform(-downAngV,downAngV) | ||||
| Context not available. | |||||
| bxOffset = uniform(0, 2 * pi) | bxOffset = uniform(0, 2 * pi) | ||||
| byOffset = uniform(0, 2 * pi) | byOffset = uniform(0, 2 * pi) | ||||
| # Set the phase multiplier for the spline | # 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 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): | for n in range(numPoints): | ||||
| oldBone = b | oldBone = b | ||||
| Context not available. | |||||
| # Add the animation to the armature if required | # Add the animation to the armature if required | ||||
| if armAnim: | if armAnim: | ||||
| # Define all the required parameters of the wind sway by the dimension of the spline | # 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 | a1 = (windSpeed / 50) * a0 | ||||
| a2 = (windGust / 50) * a0 + a1 / 2 | a2 = (windGust / 50) * a0 + a1 / 2 | ||||
| Context not available. | |||||
| # If the -ve flag for downAngle is used we need a special formula to find it | # If the -ve flag for downAngle is used we need a special formula to find it | ||||
| if downAngleV[n] < 0.0: | if downAngleV[n] < 0.0: | ||||
| downV = downAngleV[n] * ( | downV = downAngleV[n] * ( | ||||
| 1 - 2 * shapeRatio(0, (p.lengthPar - p.offset) / (p.lengthPar - baseSize * scaleVal))) | 1 - 2 * shapeRatio(0, (p.lengthPar - p.offset) / (p.lengthPar - baseSize * scaleVal + 1e-6))) | ||||
mont29: Why not rather `max(p.lengthPar - baseSize * scaleVal, 1e-6)` ? Would sound safer to me... | |||||
mangostanikoUnsubmitted Not Done Inline Actionsbecause the whole thing can intentionally become <0 i thought it should not be constraint to 1e-6 as minimum. the thing that was going through my mind was that formerly baseSize was to bet set by the user in [0, 1], and that p.lengthPar can depend on baseSize in some cases even be baseSize, so if the user sets baseSize = 0 we get 0. HOWEVER i changed baseSize to be in [1e-6, 1], since there were many similar issues, but now this is actually not an issue. another thing is that scaleVal = scale + uniform(-scaleV,scaleV) so the chances of the whole thing becoming zero are really low. however if scaleV = 0 and baseSize = 1 if the user slides over scale it might get 0. i am really unsure maybe one might just do a max/min branch. i am not even sure if its necessary since the chances are so low... (is that a terrible argument?) mangostaniko: because the whole thing can intentionally become <0 i thought it should not be constraint to 1e… | |||||
| random() | random() | ||||
| # Otherwise just find a random value | # Otherwise just find a random value | ||||
| else: | else: | ||||
| Context not available. | |||||
| if leaves < 0: | if leaves < 0: | ||||
| childStems = False | childStems = False | ||||
| else: | else: | ||||
| childStems = leaves * shapeRatio(leafDist, p.offset / max(p.lengthPar, 1e-6)) | childStems = leaves * shapeRatio(leafDist, p.offset / p.lengthPar) | ||||
mont29AuthorUnsubmitted Not Done Inline ActionsWhy remove safecheck here? mont29: Why remove safecheck here? | |||||
mangostanikoUnsubmitted Not Done Inline Actionsp.lengthPar can only be 0 if baseSize = 0, and since baseSize was changed from [0, 1] to [1e-6, 1] this can no longer happen. i changed the baseSize interval since there were so many situations like this one. mangostaniko: p.lengthPar can only be 0 if baseSize = 0, and since baseSize was changed from [0, 1] to [1e-6… | |||||
| elif n == 1: | 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 | # 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 | vertAtt = 0.0 | ||||
| lMax = length[1] + uniform(-lengthV[1], lengthV[1]) | 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, | branchL = p.lengthPar * lMax * shapeRatio(shape, | ||||
| (p.lengthPar - p.offset) / (p.lengthPar - baseSize * scaleVal)) | (p.lengthPar - p.offset) / (p.lengthPar - baseSize * scaleVal + 1e-6)) | ||||
mont29AuthorUnsubmitted Not Done Inline ActionsSame as comment line571 mont29: Same as comment line571 | |||||
mangostanikoUnsubmitted Not Done Inline Actionsanswer is also the same mangostaniko: answer is also the same | |||||
| childStems = branches[2] * (0.2 + 0.8 * (branchL / p.lengthPar) / lMax) | childStems = branches[2] * (0.2 + 0.8 * (branchL / p.lengthPar) / lMax) | ||||
| else: | else: | ||||
| branchL = (length[n] + uniform(-lengthV[n], lengthV[n])) * (p.lengthPar - 0.6 * p.offset) | branchL = (length[n] + uniform(-lengthV[n], lengthV[n])) * (p.lengthPar - 0.6 * p.offset) | ||||
| Context not available. | |||||
| # Check each endpoint to see if it is inside | # Check each endpoint to see if it is inside | ||||
| for s in splineList: | for s in splineList: | ||||
| coordMag = (s.spline.bezier_points[-1].co.xy).length | 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 * (1 - baseSize + 1e-6)) | ||||
mont29AuthorUnsubmitted Not Done Inline ActionsSame as comment line571 mont29: Same as comment line571 | |||||
mangostanikoUnsubmitted Not Done Inline Actionsyes this should be (scaleVal * max(1 - baseSize, 1e-6)). scaleVal can not be 0, but baseSize is in [1e-6, 1] and if its 1 we get 0. sorry i really seem to have rushed that too much :/ mangostaniko: yes this should be (scaleVal * max(1 - baseSize, 1e-6)).
scaleVal can not be 0, but baseSize… | |||||
Not Done Inline Actionscorrected this as pointed out. mangostaniko: corrected this as pointed out. | |||||
| # Don't think this if part is needed | # Don't think this if part is needed | ||||
| if (n == 0) and (s.spline.bezier_points[-1].co.z < baseSize * scaleVal): | if (n == 0) and (s.spline.bezier_points[-1].co.z < baseSize * scaleVal): | ||||
| pass # insideBool = True | insideBool = True | ||||
mont29AuthorUnsubmitted Not Done Inline ActionsWhy uncomment? Please add inline comments in those cases. mont29: Why uncomment? Please add inline comments in those cases. | |||||
mangostanikoUnsubmitted Not Done Inline Actionsjust passing it leaves insideBool unassigned which can cause an UnboundLocalError later (tested). you mean phabricator inline comments? sorry for that i am just learning about the whole process :) or do you mean in the code? mangostaniko: just passing it leaves insideBool unassigned which can cause an UnboundLocalError later… | |||||
mont29AuthorUnsubmitted Not Done Inline ActionsOk, think it should be OK then (and I meant comment in code, yes, something like # need to init insideBool here, else we can have UnboundLocalError later.) mont29: Ok, think it should be OK then (and I meant comment in code, yes, something like `# need to… | |||||
Not Done Inline Actionsadded suggested comment. mangostaniko: added suggested comment. | |||||
| else: | else: | ||||
| insideBool = ( | insideBool = ( | ||||
| (coordMag / scaleVal) < pruneWidth * shapeRatio(8, ratio, pruneWidthPeak, prunePowerHigh, | (coordMag / scaleVal) < pruneWidth * shapeRatio(8, ratio, pruneWidthPeak, prunePowerHigh, | ||||
| Context not available. | |||||
| # Fix the scale of the tree now | # Fix the scale of the tree now | ||||
| scaleVal = scale + uniform(-scaleV,scaleV) | 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 pruning is turned on we need to draw the pruning envelope | ||||
| if prune: | if prune: | ||||
| Context not available. | |||||
Why not rather max(p.lengthPar - baseSize * scaleVal, 1e-6) ? Would sound safer to me...