Spawn leaves properly

This commit is contained in:
CJSatnarine
2023-12-31 17:48:55 -05:00
parent cc10232c0a
commit 7c06b045c3

View File

@@ -54,6 +54,12 @@ def buildTree():
treeZPos = z
treeTrunkHeight = random.randint(3, 5)
# Variables for the leaves
leavesSize = (size * treeTrunkHeight) / 2
leavesXPosition = treeXPos
leavesYPosition = treeYPos
leavesZPosition = treeTrunkHeight + leavesSize
# Add a single block as the location of the tree stump.
# Loop through the treeheight to add a new cube as a chunk of the trunk. Add colour to the trunk.
counter = 1
@@ -70,9 +76,16 @@ def buildTree():
# increase the counter
counter += 1
# Create the leaves of the tree.
createLowPolyLeaves(leavesSize, leavesXPosition, leavesYPosition, leavesZPosition)
# Function to make the low poly leaves for the tree.
def createLowPolyLeaves(size, xPosition, yPosition, zPosition):
bpy.ops.mesh.primitive_cube_add(size = size, location = (xPosition, yPosition, zPosition))
lowPolyLeaves = bpy.ops.mesh.primitive_cube_add(size = size, location = (xPosition, yPosition, zPosition), scale = (size, size, size))
activeObject = bpy.context.active_object
colourOfLeaves = createMaterial(0.007951, 0.349087, 0.0003, 1)
assignMaterial(lowPolyLeaves, colourOfLeaves)
return activeObject
# Function to add a material to the selected object.
def assignMaterial(object, material):