3D Pixel Fun
[Edit]Don’t forget to check out my new 3D pixel art iPad app
Recently a client asked me to do something which involved a lot of 3D cubes. I did some tests with cubes in the past and I knew the number of cubes you can render in Flash are relatively limited. Lets say you want 10x10x10 cubes = 1000 cubes =6000 sides = 12000 triangles, which is near or already over the limit. So I decided to take a different approach.
When you use an isometric perspective, the cubes are all the same. So instead of rendering each cube every frame, you can render only one cube and use that cube as a particle to render a full scene. This way you can easily extend the limit of +-1000 cubes to 20000 or more cubes.
Motivated by the very cool 3D pixel editor Q-BLOCK by Okuyama Kazuya, but mostly because it was great fun to make, I decided to take it one step further and started to build a simple 3D pixel engine.
Use the arrow keys to move the character, drag to rotate the scene.
At this point, the Pixel3DObjects have x, y, z, rotationX, rotationY, rotationZ properties + they support very basic animation (gotoAndStop). As input it uses transparent bitmapdata (I use pngs) Where the horizontal “sprites” are the depth layers, and the vertical “sprites” the animation frames (see img below).
For a good result I had to raytrace the mesh from different angles and regularly check for duplicated cubes. But for big or complicated objects it takes a while to generate all the needed data. So the elephant is actually pre-rendered and just uses the output data from the raytrace object.
I include the source code (with the two examples) but its not what you call user friendly and most features are incomplete or buggy at this point. So you are warned.
Source code: [download#21#nohits]