alpha faces, solutions, problems, and a script

I’ll start with a zip containg the script, some documentation, and an example .blend file

http://www.geocities.com/z3r0_d/files/sortFaces.zip

As many here have experienced, translucent faces often appear wrong in the game engine. The reason for this is that they are drawn in the order they appear in an object, but if an opaque face that is further away from the viewer were drawn after a nearer face to the viewer it would appear on top, and look wrong (especially when the viewer and/or the object is/are moving).

here is a ‘tree’ with darker branches at the bottom than the top
wong:
http://mywebpage.netscape.com/YinYangEvilSane/BlenderStuff/badGame.jpg
correct:
http://mywebpage.netscape.com/YinYangEvilSane/BlenderStuff/goodGame.jpg

My solution (and it is what the script does) is to try and find an order that always has the faces drawn from furthest to nearest, by assuming they are only visible from one side.

There is not always a solution. My method is memory (and cpu) inefficent.

I go into much more detail at:
http://www.geocities.com/z3r0_d/alphaSorting/index.html

changing the order objects with translucent faces are drawn (so that multiple objects overlap correctly) is not possible as far as I know without changing the game engine.


Methods to do this manually:

for trees it isn’t very difficult.
Select your object, and put the cursor at the object center.
make all the faces one sided, and pointing upwards
enter edit mode
select everything
press control+f and press on [sort faces in z]

this will sort the upwards facing faces correctly. If you want the tree to render correctly from the bottom [as well] you will need to duplicate it, flip the normals, and flip it along the global z axis (the y axis of both the front and side views), exit edit mode, control+f, enter edit mode, flip it back again, and join with your original object.

(or try my script)


the joining method

If you can determine the order the faces should be drawn yourself, split your object up into parts, and join them back together

Example, you want a cube that is textured on both the inside and outside, and you want the inside to appear behind the outside when the view point is outside of the cube.

You would make one cube, with the normals pointing inside
the other with the normals pointing outside

I just crashed this computer, I’ll have to get back to you
---- edit —
same crash, different computer. Same applies (I now leave to try a mac)
---- edit 2 ---- (xp is annoying)

you would select an object, then the object you want renderd before it (the would that would always be behind the first object), then press control+j to join them together.

For our cube this would be the outside THEN the inside

thanks for the info, i might avoid alpha textures a little less now