From 17b2ddbac6e4f172e21b59715b90a9d018957dfc Mon Sep 17 00:00:00 2001 From: imcasper Date: Thu, 12 Jan 2023 12:52:43 +0300 Subject: [PATCH] improved settings for the distribution of leaves by branches --- .gitignore | 1 + sapling_4/__init__.py | 6 ++++++ sapling_4/presets/Small Pine.py | 2 +- sapling_4/presets/White Birch.py | 2 +- sapling_4/utils.py | 18 +++++++++++++++++- 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85e7c1d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea/ diff --git a/sapling_4/__init__.py b/sapling_4/__init__.py index 311125e..ad0c1b8 100644 --- a/sapling_4/__init__.py +++ b/sapling_4/__init__.py @@ -449,6 +449,11 @@ def no_update_tree(self, context): min=0.0, max=1.0, default=0.20, update=update_tree) + leafBaseLevel: IntProperty(name='Leaf Start Level', + description='Level of branches on which leaves appear', + min=0, + max=4 , + default=1, update=update_tree) splitHeight: FloatProperty(name='Split Height', description='Fraction of tree height with no splits', min=0.0, @@ -894,6 +899,7 @@ def draw(self, context): box.prop(self, 'leafDist') box.label(text="") + box.prop(self, 'leafBaseLevel') box.prop(self, 'leafType') box.prop(self, 'leafangle') row = box.row() diff --git a/sapling_4/presets/Small Pine.py b/sapling_4/presets/Small Pine.py index 8722cc3..7cc7f2f 100644 --- a/sapling_4/presets/Small Pine.py +++ b/sapling_4/presets/Small Pine.py @@ -1 +1 @@ -{'bevel': True, 'showLeaves': True, 'useArm': False, 'seed': 0, 'handleType': '0', 'bevelRes': 2, 'resU': 4, 'levels': 3, 'length': (1.0, 0.33000001311302185, 0.75, 0.44999998807907104), 'lengthV': (0.0, 0.15000000596046448, 0.25, 0.0), 'taperCrown': 0.0, 'branches': (0, 36, 10, 10), 'curveRes': (10, 5, 3, 1), 'curve': (0.0, 40.0, 30.0, 0.0), 'curveV': (12.5, 20.0, 33.33333206176758, 0.0), 'curveBack': (0.0, 0.0, 0.0, 0.0), 'baseSplits': 0, 'segSplits': (0.0, 0.30000001192092896, 0.4000000059604645, 0.0), 'splitByLen': True, 'rMode': 'rotate', 'splitStraight': 0.5, 'splitLength': 0.0, 'splitAngle': (0.0, 44.0, 50.0, 0.0), 'splitAngleV': (0.0, 5.0, 0.0, 0.0), 'scale': 4.0, 'scaleV': 1.0, 'attractUp': (2.0, 0.0, 0.5, 0.5), 'attractOut': (0.0, 0.0, 0.0, 0.0), 'shape': '8', 'shapeS': '4', 'customShape': (1.0, 1.0, 0.20000000298023224, 0.20000000298023224), 'branchDist': 1.5, 'nrings': 7, 'baseSize': 0.06799984723329544, 'baseSize_s': 0.25, 'leafBaseSize': 0.20000000298023224, 'splitHeight': 0.20000000298023224, 'splitBias': 0.0, 'ratio': 0.019999999552965164, 'minRadius': 0.001500000013038516, 'closeTip': False, 'rootFlare': 1.25, 'splitRadiusRatio': 0.0, 'autoTaper': True, 'taper': (1.0, 1.0, 1.0, 1.0), 'noTip': False, 'radiusTweak': (1.0, 1.0, 1.0, 1.0), 'ratioPower': 1.0, 'downAngle': (90.0, 110.0, 45.0, 45.0), 'downAngleV': (0.0, 42.0, 10.0, 10.0), 'useOldDownAngle': False, 'useParentAngle': True, 'rotate': (99.5, 137.5, -90.0, 137.5), 'rotateV': (15.0, 0.0, 0.0, 0.0), 'scale0': 1.0, 'scaleV0': 0.10000000149011612, 'attachment': '1', 'leaves': 500, 'leafType': '5', 'leafDownAngle': 65.0, 'leafDownAngleV': 55.0, 'leafRotate': 137.5, 'leafRotateV': 30.0, 'leafObjZ': '+2', 'leafObjY': '+1', 'leafScale': 0.20000000298023224, 'leafScaleX': 0.019999999552965164, 'leafScaleT': 0.25, 'leafScaleV': 0.10000000149011612, 'leafShape': 'rect', 'leafangle': -10.0, 'leafDist': '3', 'armAnim': False, 'previewArm': False, 'leafAnim': False, 'frameRate': 1.0, 'loopFrames': 0, 'wind': 1.0, 'gust': 1.0, 'gustF': 0.07500000298023224, 'af1': 1.0, 'af2': 1.0, 'af3': 4.0, 'makeMesh': False, 'armLevels': 2, 'boneStep': (1, 1, 1, 1), 'matIndex': (0, 0, 0, 0)} \ No newline at end of file +{'bevel': True, 'showLeaves': True, 'useArm': False, 'seed': 0, 'handleType': '0', 'bevelRes': 2, 'resU': 4, 'levels': 3, 'length': (1.0, 0.33000001311302185, 0.75, 0.44999998807907104), 'lengthV': (0.0, 0.15000000596046448, 0.25, 0.0), 'taperCrown': 0.0, 'branches': (0, 36, 10, 10), 'curveRes': (10, 5, 3, 1), 'curve': (0.0, 40.0, 30.0, 0.0), 'curveV': (12.5, 20.0, 33.33333206176758, 0.0), 'curveBack': (0.0, 0.0, 0.0, 0.0), 'baseSplits': 0, 'segSplits': (0.0, 0.30000001192092896, 0.4000000059604645, 0.0), 'splitByLen': True, 'rMode': 'rotate', 'splitStraight': 0.5, 'splitLength': 0.0, 'splitAngle': (0.0, 44.0, 50.0, 0.0), 'splitAngleV': (0.0, 5.0, 0.0, 0.0), 'scale': 4.0, 'scaleV': 1.0, 'attractUp': (2.0, 0.0, 0.5, 0.5), 'attractOut': (0.0, 0.0, 0.0, 0.0), 'shape': '8', 'shapeS': '4', 'customShape': (1.0, 1.0, 0.20000000298023224, 0.20000000298023224), 'branchDist': 1.5, 'nrings': 7, 'baseSize': 0.06799984723329544, 'baseSize_s': 0.25, 'leafBaseSize': 0.20000000298023224, 'leafBaseLevel': 2, 'splitHeight': 0.20000000298023224, 'splitBias': 0.0, 'ratio': 0.019999999552965164, 'minRadius': 0.001500000013038516, 'closeTip': False, 'rootFlare': 1.25, 'splitRadiusRatio': 0.0, 'autoTaper': True, 'taper': (1.0, 1.0, 1.0, 1.0), 'noTip': False, 'radiusTweak': (1.0, 1.0, 1.0, 1.0), 'ratioPower': 1.0, 'downAngle': (90.0, 110.0, 45.0, 45.0), 'downAngleV': (0.0, 42.0, 10.0, 10.0), 'useOldDownAngle': False, 'useParentAngle': True, 'rotate': (99.5, 137.5, -90.0, 137.5), 'rotateV': (15.0, 0.0, 0.0, 0.0), 'scale0': 1.0, 'scaleV0': 0.10000000149011612, 'attachment': '1', 'leaves': 1500, 'leafType': '5', 'leafDownAngle': 65.0, 'leafDownAngleV': 55.0, 'leafRotate': 137.5, 'leafRotateV': 30.0, 'leafObjZ': '+2', 'leafObjY': '+1', 'leafScale': 0.20000000298023224, 'leafScaleX': 0.019999999552965164, 'leafScaleT': 0.25, 'leafScaleV': 0.10000000149011612, 'leafShape': 'rect', 'leafangle': -10.0, 'leafDist': '3', 'armAnim': False, 'previewArm': False, 'leafAnim': False, 'frameRate': 1.0, 'loopFrames': 0, 'wind': 1.0, 'gust': 1.0, 'gustF': 0.07500000298023224, 'af1': 1.0, 'af2': 1.0, 'af3': 4.0, 'makeMesh': False, 'armLevels': 2, 'boneStep': (1, 1, 1, 1), 'matIndex': (0, 0, 0, 0)} \ No newline at end of file diff --git a/sapling_4/presets/White Birch.py b/sapling_4/presets/White Birch.py index 3d782e4..9488035 100644 --- a/sapling_4/presets/White Birch.py +++ b/sapling_4/presets/White Birch.py @@ -1 +1 @@ -{'bevel': True, 'showLeaves': True, 'useArm': False, 'seed': 0, 'handleType': '0', 'bevelRes': 2, 'resU': 2, 'levels': 3, 'length': (1.0, 0.33000001311302185, 0.375, 0.44999998807907104), 'lengthV': (0.05000000074505806, 0.20000000298023224, 0.3499999940395355, 0.0), 'taperCrown': 0.0, 'branches': (0, 60, 30, 10), 'curveRes': (10, 8, 3, 1), 'curve': (0.0, 30.0, 25.0, 0.0), 'curveV': (10.0, 10.0, 25.0, 0.0), 'curveBack': (0.0, 0.0, 0.0, 0.0), 'baseSplits': 2, 'segSplits': (0.3499999940395355, 0.3499999940395355, 0.3499999940395355, 0.0), 'splitByLen': True, 'rMode': 'rotate', 'splitStraight': 0.0, 'splitLength': 0.0, 'splitAngle': (20.0, 36.0, 32.0, 0.0), 'splitAngleV': (2.0, 2.0, 0.0, 0.0), 'scale': 12.0, 'scaleV': 2.0, 'attractUp': (0.0, -1.0, -0.6499999761581421, 0.0), 'attractOut': (0.0, 0.20000000298023224, 0.25, 0.0), 'shape': '8', 'shapeS': '7', 'customShape': (0.699999988079071, 1.0, 0.30000001192092896, 0.5900000333786011), 'branchDist': 1.5, 'nrings': 0, 'baseSize': 0.3499999940395355, 'baseSize_s': 0.800000011920929, 'leafBaseSize': 0.20000000298023224, 'splitHeight': 0.550000011920929, 'splitBias': 0.0, 'ratio': 0.019999999552965164, 'minRadius': 0.0020000000949949026, 'closeTip': False, 'rootFlare': 1.149999976158142, 'splitRadiusRatio': 0.0, 'autoTaper': True, 'taper': (1.0, 1.0, 1.0, 1.0), 'noTip': False, 'radiusTweak': (1.0, 1.0, 1.0, 1.0), 'ratioPower': 1.0, 'downAngle': (90.0, 60.0, 50.0, 45.0), 'downAngleV': (0.0, 25.0, 30.0, 10.0), 'useOldDownAngle': False, 'useParentAngle': True, 'rotate': (99.5, 137.5, 137.5, 137.5), 'rotateV': (0.0, 0.0, 0.0, 0.0), 'scale0': 1.0, 'scaleV0': 0.10000000149011612, 'attachment': '0', 'leaves': 16, 'leafType': '0', 'leafDownAngle': 45.0, 'leafDownAngleV': 10.0, 'leafRotate': 137.5, 'leafRotateV': 0.0, 'leafObjZ': '+2', 'leafObjY': '+1', 'leafScale': 0.20000000298023224, 'leafScaleX': 0.5, 'leafScaleT': 0.20000000298023224, 'leafScaleV': 0.25, 'leafShape': 'hex', 'leafangle': -45.0, 'leafDist': '6', 'armAnim': False, 'previewArm': False, 'leafAnim': False, 'frameRate': 1.0, 'loopFrames': 0, 'wind': 1.0, 'gust': 1.0, 'gustF': 0.07500000298023224, 'af1': 1.0, 'af2': 1.0, 'af3': 4.0, 'makeMesh': False, 'armLevels': 0, 'boneStep': (1, 1, 1, 1), 'matIndex': (0, 0, 0, 0)} \ No newline at end of file +{'bevel': True, 'showLeaves': True, 'useArm': False, 'seed': 0, 'handleType': '0', 'bevelRes': 2, 'resU': 2, 'levels': 3, 'length': (1.0, 0.33000001311302185, 0.375, 0.44999998807907104), 'lengthV': (0.05000000074505806, 0.20000000298023224, 0.3499999940395355, 0.0), 'taperCrown': 0.0, 'branches': (0, 60, 30, 10), 'curveRes': (10, 8, 3, 1), 'curve': (0.0, 30.0, 25.0, 0.0), 'curveV': (10.0, 10.0, 25.0, 0.0), 'curveBack': (0.0, 0.0, 0.0, 0.0), 'baseSplits': 2, 'segSplits': (0.3499999940395355, 0.3499999940395355, 0.3499999940395355, 0.0), 'splitByLen': True, 'rMode': 'rotate', 'splitStraight': 0.0, 'splitLength': 0.0, 'splitAngle': (20.0, 36.0, 32.0, 0.0), 'splitAngleV': (2.0, 2.0, 0.0, 0.0), 'scale': 12.0, 'scaleV': 2.0, 'attractUp': (0.0, -1.0, -0.6499999761581421, 0.0), 'attractOut': (0.0, 0.20000000298023224, 0.25, 0.0), 'shape': '8', 'shapeS': '7', 'customShape': (0.699999988079071, 1.0, 0.30000001192092896, 0.5900000333786011), 'branchDist': 1.5, 'nrings': 0, 'baseSize': 0.3499999940395355, 'baseSize_s': 0.800000011920929, 'leafBaseSize': 0.20000000298023224, 'splitHeight': 0.550000011920929, 'splitBias': 0.0, 'ratio': 0.019999999552965164, 'minRadius': 0.0020000000949949026, 'closeTip': False, 'rootFlare': 1.149999976158142, 'splitRadiusRatio': 0.0, 'autoTaper': True, 'taper': (1.0, 1.0, 1.0, 1.0), 'noTip': False, 'radiusTweak': (1.0, 1.0, 1.0, 1.0), 'ratioPower': 1.0, 'downAngle': (90.0, 60.0, 50.0, 45.0), 'downAngleV': (0.0, 25.0, 30.0, 10.0), 'useOldDownAngle': False, 'useParentAngle': True, 'rotate': (99.5, 137.5, 137.5, 137.5), 'rotateV': (0.0, 0.0, 0.0, 0.0), 'scale0': 1.0, 'scaleV0': 0.10000000149011612, 'attachment': '0', 'leaves': 100, 'leafStartLength':0.5, 'leafStartLevel':1, 'leafType': '0', 'leafDownAngle': 45.0, 'leafDownAngleV': 10.0, 'leafRotate': 137.5, 'leafRotateV': 0.0, 'leafObjZ': '+2', 'leafObjY': '+1', 'leafScale': 0.20000000298023224, 'leafScaleX': 0.5, 'leafScaleT': 0.20000000298023224, 'leafScaleV': 0.25, 'leafShape': 'hex', 'leafangle': -45.0, 'leafDist': '6', 'armAnim': False, 'previewArm': False, 'leafAnim': False, 'frameRate': 1.0, 'loopFrames': 0, 'wind': 1.0, 'gust': 1.0, 'gustF': 0.07500000298023224, 'af1': 1.0, 'af2': 1.0, 'af3': 4.0, 'makeMesh': False, 'armLevels': 0, 'boneStep': (1, 1, 1, 1), 'matIndex': (0, 0, 0, 0)} \ No newline at end of file diff --git a/sapling_4/utils.py b/sapling_4/utils.py index 5ff5ac3..a2fa409 100755 --- a/sapling_4/utils.py +++ b/sapling_4/utils.py @@ -1611,6 +1611,7 @@ def addTree(props): scale0 = props.scale0# scaleV0 = props.scaleV0# attachment = props.attachment + leafBaseLevel = int(props.leafBaseLevel) leafType = props.leafType leafDownAngle = radians(props.leafDownAngle) leafDownAngleV = radians(props.leafDownAngleV) @@ -1711,6 +1712,7 @@ def addTree(props): scaleVal += copysign(1e-6, scaleVal) # Move away from zero to avoid div by zero childP = [] + summary_leaf_child_points = [] stemList = [] levelCount = [] @@ -1757,6 +1759,20 @@ def addTree(props): splitHeight, attractOut, rMode, splitStraight, splitLength, lengthV, taperCrown, noTip, boneStep, rotate, rotateV, leaves, leafType, attachment, matIndex) + # generating anchor points for leaves. Separated from the generation of branch anchor points. + if leafBaseLevel <= n: + leaves_points = [] + for stem in stemList: + stemLength = stem.offsetLen + (len(stem.spline.bezier_points) - 1) * stem.segL + leafs_amount = int(leaves * stemLength / 10.0 + 0.5) + if leafs_amount > 0: + range_points = [t / leafs_amount for t in range(leafs_amount) if (t / leafs_amount > leafBaseSize) or (leafBaseLevel < n)] + + if len(range_points) > 0: + leaves_points.extend(interpStem(stem, range_points, stemLength, baseSize_s)) + + summary_leaf_child_points.extend(leaves_points) + levelCount.append(len(cu.splines)) # Set curve resolution @@ -1774,7 +1790,7 @@ def addTree(props): oldRot = 0.0 n = min(3, n+1) # For each of the child points we add leaves - for ln, cp in enumerate(childP): + for ln, cp in enumerate(summary_leaf_child_points): # If the special flag is set then we need to add several leaves at the same location if leafType == '4': oldRot = -leafRotate / 2