Changeset View
Changeset View
Standalone View
Standalone View
add_curve_sapling/utils.py
| Context not available. | |||||
| elif shape == 9: | elif shape == 9: | ||||
| if (ratio < (1 - pruneWidthPeak)) and (ratio > 0.0): | if (ratio < (1 - pruneWidthPeak)) and (ratio > 0.0): | ||||
| return ((ratio/(1 - pruneWidthPeak))**prunePowerHigh) | return (ratio / (1 - pruneWidthPeak)) ** prunePowerHigh | ||||
| elif (ratio >= (1 - pruneWidthPeak)) and (ratio < 1.0): | elif (ratio >= (1 - pruneWidthPeak)) and (ratio < 1.0): | ||||
| return (((1 - ratio)/pruneWidthPeak)**prunePowerLow) | return ((1 - ratio) / pruneWidthPeak) ** prunePowerLow | ||||
| else: | else: | ||||
| return 0.0 | return 0.0 | ||||
| Context not available. | |||||
| numSegs = numPoints - numSplines | numSegs = numPoints - numSplines | ||||
| numPerSeg = numChild/numSegs | numPerSeg = numChild/numSegs | ||||
| numMain = round(numPerSeg*stemList[0].segMax, 0) | numMain = round(numPerSeg*stemList[0].segMax, 0) | ||||
| return [(a+1)/(numMain) for a in range(int(numMain))] | return [(a+1) / numMain for a in range(int(numMain))] | ||||
| def findChildPoints2(stemList, numChild): | def findChildPoints2(stemList, numChild): | ||||
| return [(a+1)/(numChild) for a in range(int(numChild))] | return [(a+1) / numChild for a in range(int(numChild))] | ||||
| # Find the coordinates, quaternion and radius for each t on the stem | # Find the coordinates, quaternion and radius for each t on the stem | ||||
| def interpStem1(stem, tVals, lPar, parRad): | def interpStem1(stem, tVals, lPar, parRad): | ||||
| Context not available. | |||||
| if n == 0: #Special case for trunk splits | if n == 0: #Special case for trunk splits | ||||
| dirVec.rotate(branchRotMat) | dirVec.rotate(branchRotMat) | ||||
| ang = pi - ((tau) / (numSplit + 1)) * (i+1) | ang = pi - (tau / (numSplit + 1)) * (i + 1) | ||||
| dirVec.rotate(Matrix.Rotation(ang, 3, 'Z')) | dirVec.rotate(Matrix.Rotation(ang, 3, 'Z')) | ||||
| # Spread the stem out in a random fashion | # Spread the stem out in a random fashion | ||||
| Context not available. | |||||
| normal.rotate(rotateZ) | normal.rotate(rotateZ) | ||||
| orientationVec.rotate(rotateZ) | orientationVec.rotate(rotateZ) | ||||
| phiBend = atan2((normal.xy).length, normal.z) | phiBend = atan2(normal.xy.length, normal.z) | ||||
| orientation = atan2(orientationVec.y, orientationVec.x) | orientation = atan2(orientationVec.y, orientationVec.x) | ||||
| rotateZOrien = Matrix.Rotation(orientation, 3, 'X') | rotateZOrien = Matrix.Rotation(orientation, 3, 'X') | ||||
| Context not available. | |||||
| # Calculate things for animation | # Calculate things for animation | ||||
| if armAnim: | if armAnim: | ||||
| splineL = numPoints * ((s.bezier_points[0].co - s.bezier_points[1].co).length) | splineL = numPoints * (s.bezier_points[0].co - s.bezier_points[1].co).length | ||||
| # Set the random phase difference of the animation | # Set the random phase difference of the animation | ||||
| bxOffset = uniform(0, tau) | bxOffset = uniform(0, tau) | ||||
| byOffset = uniform(0, tau) | byOffset = uniform(0, tau) | ||||
| Context not available. | |||||
| childStems = branches[min(3, n + 1)] * (0.1 + 0.9 * (branchL / maxbL)) | childStems = branches[min(3, n + 1)] * (0.1 + 0.9 * (branchL / maxbL)) | ||||
| # If this is the last level before leaves then we need to generate the child points differently | # If this is the last level before leaves then we need to generate the child points differently | ||||
| if (storeN == levels - 1): | if storeN == levels - 1: | ||||
| if leaves < 0: | if leaves < 0: | ||||
| childStems = False | childStems = False | ||||
| else: | else: | ||||
| Context not available. | |||||
| if prune: | if prune: | ||||
| # 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 * max(1 - pruneBase, 1e-6)) | ratio = (scaleVal - s.spline.bezier_points[-1].co.z) / (scaleVal * max(1 - pruneBase, 1e-6)) | ||||
| # 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 < pruneBase * scaleVal): | if (n == 0) and (s.spline.bezier_points[-1].co.z < pruneBase * scaleVal): | ||||
| Context not available. | |||||
| for c in range(enNum): | for c in range(enNum): | ||||
| newSpline.bezier_points.add() | newSpline.bezier_points.add() | ||||
| newPoint = newSpline.bezier_points[-1] | newPoint = newSpline.bezier_points[-1] | ||||
| ratioVal = (c+1)/(enNum) | ratioVal = (c + 1) / enNum | ||||
| zVal = scaleVal - scaleVal*(1-pruneBase)*ratioVal | zVal = scaleVal - scaleVal*(1-pruneBase)*ratioVal | ||||
| newPoint.co = Vector((scaleVal*pruneWidth*shapeRatio(9, ratioVal, pruneWidthPeak, prunePowerHigh, prunePowerLow), 0, zVal)) | newPoint.co = Vector((scaleVal*pruneWidth*shapeRatio(9, ratioVal, pruneWidthPeak, prunePowerHigh, prunePowerLow), 0, zVal)) | ||||
| (newPoint.handle_right_type, newPoint.handle_left_type) = (enHandle, enHandle) | (newPoint.handle_right_type, newPoint.handle_left_type) = (enHandle, enHandle) | ||||
| Context not available. | |||||
| for c in range(enNum): | for c in range(enNum): | ||||
| newSpline.bezier_points.add() | newSpline.bezier_points.add() | ||||
| newPoint = newSpline.bezier_points[-1] | newPoint = newSpline.bezier_points[-1] | ||||
| ratioVal = (c+1)/(enNum) | ratioVal = (c + 1) / enNum | ||||
| zVal = scaleVal - scaleVal*(1-pruneBase)*ratioVal | zVal = scaleVal - scaleVal*(1-pruneBase)*ratioVal | ||||
| newPoint.co = Vector((0, scaleVal*pruneWidth*shapeRatio(9, ratioVal, pruneWidthPeak, prunePowerHigh, prunePowerLow), zVal)) | newPoint.co = Vector((0, scaleVal*pruneWidth*shapeRatio(9, ratioVal, pruneWidthPeak, prunePowerHigh, prunePowerLow), zVal)) | ||||
| (newPoint.handle_right_type, newPoint.handle_left_type) = (enHandle, enHandle) | (newPoint.handle_right_type, newPoint.handle_left_type) = (enHandle, enHandle) | ||||
| Context not available. | |||||
| #change base size for each level | #change base size for each level | ||||
| if n > 0: | if n > 0: | ||||
| baseSize *= baseSize_s #decrease at each level | baseSize *= baseSize_s #decrease at each level | ||||
| if (n == levels - 1): | if n == levels - 1: | ||||
| baseSize = 0 | baseSize = 0 | ||||
| childP = [] | childP = [] | ||||
| Context not available. | |||||
| # vindex += 1 | # vindex += 1 | ||||
| #dont make vertex group if above armLevels | #dont make vertex group if above armLevels | ||||
| if (i >= levelCount[armLevels]): | if i >= levelCount[armLevels]: | ||||
| idx = i | idx = i | ||||
| groupName = splineToBone[idx] | groupName = splineToBone[idx] | ||||
| g = True | g = True | ||||
| Context not available. | |||||