[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2138] trunk/py/scripts/addons/ add_curve_sapling: Added the ability to use rectangular leaves with UV mapping

Andrew Hale TrumanBlending at gmail.com
Tue Jul 19 16:20:05 CEST 2011


Revision: 2138
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2138
Author:   trumanblending
Date:     2011-07-19 14:20:04 +0000 (Tue, 19 Jul 2011)
Log Message:
-----------
Added the ability to use rectangular leaves with UV mapping

Modified Paths:
--------------
    trunk/py/scripts/addons/add_curve_sapling/__init__.py
    trunk/py/scripts/addons/add_curve_sapling/utils.py

Modified: trunk/py/scripts/addons/add_curve_sapling/__init__.py
===================================================================
--- trunk/py/scripts/addons/add_curve_sapling/__init__.py	2011-07-19 08:11:58 UTC (rev 2137)
+++ trunk/py/scripts/addons/add_curve_sapling/__init__.py	2011-07-19 14:20:04 UTC (rev 2138)
@@ -327,6 +327,10 @@
         '(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 @@
             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 @@
     bpy.types.INFO_MT_curve_add.remove(menu_func)
 
 if __name__ == "__main__":
-    register()
+    register()
\ No newline at end of file

Modified: trunk/py/scripts/addons/add_curve_sapling/utils.py
===================================================================
--- trunk/py/scripts/addons/add_curve_sapling/utils.py	2011-07-19 08:11:58 UTC (rev 2137)
+++ trunk/py/scripts/addons/add_curve_sapling/utils.py	2011-07-19 14:20:04 UTC (rev 2138)
@@ -313,10 +313,15 @@
     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 @@
         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 @@
                     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 @@
                 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 @@
             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



More information about the Bf-extensions-cvs mailing list