Here is a simple script. What it does is to recalculate the normals of each poly in the model to point directly away from the object’s center, this gives a more volumetric apearance to the leaves, which are afterall, just single planes with a partly transparent texture on them.
here’s the code for 2.49b:
import Mathutils
# get controller
cont = GameLogic.getCurrentController()
# get object the controller is attached to
own = cont.owner
# get the 1st mesh
mesh = own.meshes[0]
# get first material
matID = 0
# get array length of the material
length = mesh.getVertexArrayLength(matID)
# loop through array
for array in range( 0, length):
# get vertex
vert = mesh.getVertex(matID,array)
pos = vert.getXYZ()
a = [0.0,0.0,0.0]
b = pos
ab = (b[0] - a[0],b[1] - a[1],b[2] - a[2])
vect1 = Mathutils.Vector(ab[0], ab[1], ab[2])
# normalize the vector
vert.setNormal(vect1.normalize())
and for 2.63:
import bge
import mathutils
cont = bge.logic.getCurrentController()
# get object the controller is attached to
own = cont.owner
# get the 1st mesh
mesh = own.meshes[0]
# get first material
matID = 0
# get array length of the material
length = mesh.getVertexArrayLength(matID)
# loop through array
for array in range( 0, length):
# get vertex
vert = mesh.getVertex(matID,array)
pos = vert.getXYZ()
a = [0.0,0.0,0.0]
b = pos
ab = (b[0] - a[0],b[1] - a[1],b[2] - a[2])
vect1 = mathutils.Vector((ab[0], ab[1], ab[2]))
# normalize the vector
vect1.normalize()
vert.setNormal(vect1)
Simply run it on on an object the includes only your tree’s leaves, it’s very fast and can be done when your game level starts.
There is only one big limitation, it can only run on objects that are not rigged.
You could also use it to create more realistic grass, though you may have to edit the “a” variable to be [pos[0], pos[1], 0.0] to get the best effect.
Here’s a preview of what it does: