Skip to content
Snippets Groups Projects
Commit 29a11b10 authored by Andrew Hale's avatar Andrew Hale
Browse files

Added the ability to use rectangular leaves with UV mapping

parent 173e9d32
No related branches found
No related tags found
No related merge requests found
......@@ -19,9 +19,9 @@
bl_info = {
"name": "Sapling",
"author": "Andrew Hale (TrumanBlending)",
"version": (0, 2, 3),
"version": (0, 2, 4),
"blender": (2, 5, 8),
"api": 38289,
"api": 38479,
"location": "View3D > Add > Curve",
"description": ("Adds a parametric tree. The method is presented by "
"Jason Weber & Joseph Penn in their paper 'Creation and Rendering of "
......@@ -29,8 +29,8 @@ bl_info = {
"warning": "", # used for warning icon and text in addons panel
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.5/Py/"\
"Scripts/Curve/Sapling_Tree",
"tracker_url": "http://projects.blender.org/tracker/index.php?"\
"func=detail&aid=27226&group_id=153&atid=468",
"tracker_url": "http://projects.blender.org/tracker/"\
"?func=detail&atid=469&aid=27226&group_id=153",
"category": "Add Curve"}
if "bpy" in locals():
......@@ -327,6 +327,10 @@ class AddTree(bpy.types.Operator):
'(LeafScaleX)'),
min=0.0,
default=1.0)
leafShape = leafDist = EnumProperty(name='Leaf Shape',
description='The shape of the leaves, rectangular are UV mapped',
items=(('hex', 'Hexagonal', '0'), ('rect', 'Rectangular', '1')),
default='hex')
bend = FloatProperty(name='Leaf Bend',
description='The proportion of bending applied to the leaf (Bend)',
min=0.0,
......@@ -523,6 +527,8 @@ class AddTree(bpy.types.Operator):
row = box.row()
row.prop(self, 'showLeaves')
row = box.row()
row.prop(self, 'leafShape')
row = box.row()
row.prop(self, 'leaves')
row = box.row()
row.prop(self, 'leafDist')
......@@ -586,4 +592,4 @@ def unregister():
bpy.types.INFO_MT_curve_add.remove(menu_func)
if __name__ == "__main__":
register()
register()
\ No newline at end of file
......@@ -313,10 +313,15 @@ def growSpline(stem,numSplit,splitAng,splitAngV,splineList,attractUp,hType,splin
stem.updateEnd()
#return splineList
def genLeafMesh(leafScale,leafScaleX,loc,quat,index,downAngle,downAngleV,rotate,rotateV,oldRot,bend,leaves):
verts = [Vector((0,0,0)),Vector((0.5,0,1/3)),Vector((0.5,0,2/3)),Vector((0,0,1)),Vector((-0.5,0,2/3)),Vector((-0.5,0,1/3))]
edges = [[0,1],[1,2],[2,3],[3,4],[4,5],[5,0],[0,3]]
faces = [[0,1,2,3],[0,3,4,5]]
def genLeafMesh(leafScale,leafScaleX,loc,quat,index,downAngle,downAngleV,rotate,rotateV,oldRot,bend,leaves, leafShape):
if leafShape == 'hex':
verts = [Vector((0,0,0)),Vector((0.5,0,1/3)),Vector((0.5,0,2/3)),Vector((0,0,1)),Vector((-0.5,0,2/3)),Vector((-0.5,0,1/3))]
edges = [[0,1],[1,2],[2,3],[3,4],[4,5],[5,0],[0,3]]
faces = [[0,1,2,3],[0,3,4,5]]
elif leafShape == 'rect':
verts = [Vector((1,0,0)),Vector((1,0,1)),Vector((-1,0,1)),Vector((-1,0,0))]
edges = [[0,1],[1,2],[2,3],[3,0]]
faces = [[0,1,2,3],]
#faces = [[0,1,5],[1,2,4,5],[2,3,4]]
vertsList = []
......@@ -429,6 +434,7 @@ def addTree(props):
pruneRatio = props.pruneRatio#
leafScale = props.leafScale#
leafScaleX = props.leafScaleX#
leafShape = props.leafShape
bend = props.bend#
leafDist = int(props.leafDist)#
bevelRes = props.bevelRes#
......@@ -732,12 +738,12 @@ def addTree(props):
if leaves < 0:
oldRot = -rotate[n]/2
for g in range(abs(leaves)):
(vertTemp,faceTemp,oldRot) = genLeafMesh(leafScale,leafScaleX,cp.co,cp.quat,len(leafVerts),downAngle[n],downAngleV[n],rotate[n],rotateV[n],oldRot,bend,leaves)
(vertTemp,faceTemp,oldRot) = genLeafMesh(leafScale,leafScaleX,cp.co,cp.quat,len(leafVerts),downAngle[n],downAngleV[n],rotate[n],rotateV[n],oldRot,bend,leaves, leafShape)
leafVerts.extend(vertTemp)
leafFaces.extend(faceTemp)
# Otherwise just add the leaves like splines.
else:
(vertTemp,faceTemp,oldRot) = genLeafMesh(leafScale,leafScaleX,cp.co,cp.quat,len(leafVerts),downAngle[n],downAngleV[n],rotate[n],rotateV[n],oldRot,bend,leaves)
(vertTemp,faceTemp,oldRot) = genLeafMesh(leafScale,leafScaleX,cp.co,cp.quat,len(leafVerts),downAngle[n],downAngleV[n],rotate[n],rotateV[n],oldRot,bend,leaves, leafShape)
leafVerts.extend(vertTemp)
leafFaces.extend(faceTemp)
# Create the leaf mesh and object, add geometry using from_pydata, edges are currently added by validating the mesh which isn't great
......@@ -747,6 +753,11 @@ def addTree(props):
leafObj.parent = treeOb
leafMesh.from_pydata(leafVerts,(),leafFaces)
leafMesh.validate()
if leafShape == 'rect':
uv = leafMesh.uv_textures.new("leafUV")
for tf in uv.data:
tf.uv1, tf.uv2, tf.uv3, tf.uv4 = Vector((1, 0)), Vector((1, 1)), Vector((1 - leafScaleX, 1)), Vector((1 - leafScaleX, 0))
# This can be used if we need particle leaves
# if (storeN == levels-1) and leaves:
......@@ -904,4 +915,4 @@ def addTree(props):
for p in armOb.pose.bones:
p.rotation_mode = 'XYZ'
treeOb.parent = armOb
#print(time.time()-startTime)
#print(time.time()-startTime)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment