How can I z-order the faces of a 3d object just using the 4 vertices of each of its faces? I’ve tried using a z-buffer where I store the average z value of each face; this works great most of the times, but fails when an object have large and small faces.
I’m building a small 3d-engine in flash, just for the fun of learning, so the only data i have is those 4 vertices and the normal of the face.
Thanks!
You’re butting up against the Visibility Problem, and there’s no simple answer. This page describes the issue in a bit more detail, and may give you some thoughts. The way “real” 3D engines solve this is, they draw the scene pixel by pixel, and they keep running track of the Z coord of the topmost object drawn to any given pixel so far. This approach is not available to us in Flash, so the best we can generally do is approximate or generalize.
One common approach (described in the earlier link) is to group the faces into convex polygons, because it’s easy to depth-sort the faces of a convex polygon, and relatively easy to depth-sort the polygons themselves. If this is feasible, it’s the way I’d go.