# help a 2D image onto a 3D cube

I am just diving into the Stage3D APIs for Flash Player 11. I am trying to figure out a simple way to display isometric 2D content that gets blitted from a sprite sheet onto a 3D cube. The idea being that then the isometric content can be split into the appropriate quads of the cube and handed over to the GPU.

I found this post 2D sprites in 3D space? but I don't understand if the billboard method would split the content properly to ensure depth sorting of the quads.

Are there algorithms for basically projecting the image into the respective quads?

If you were to overlay a 3D box projected isometrically on top of a 2D isometric sprite (say a crate), the faces of the box (i.e. the top, left & right) should line up roughly with the perceived edges of the 2D sprite. I want to chop up the 2D sprite along those edges and apply them to the 3 quads (again the top, left and right faces of the 3D cube).

I'd assume there is some pretty gnarly translations to skew the 2D content to fit that quads yet maintain their perspective when viewed via an iso camera in 3D.

• Your edit doesn't make things much clearer. The way I'm interpreting it is, that you want to project an image of an isometrically drawn crate on an actual 3d cube? Mar 6, 2012 at 17:32
• correct, such that the perceived faces of the 2D content get attached to the 3D cube so that faces can be properly sorted. I will try to find a way to illustrate this and post a link in the meantime. Mar 6, 2012 at 19:50
• Quite honestly, that doesn't seem to make much sense. For a crate it would be simpler to just model and texture a 3D cube. Other objects (eg. a tree or similar) won't work at all with this "project to cube" approach. Mar 6, 2012 at 20:56

You need to learn about UV mapping. For that you'll have to provide UV coordinates with your vertex data. This introduction to stage3D also covers how to use textures and specify UV coordinates (at about 2/3 of the page).

To map a portion of a sprite-sheet to a quad, you have to calculate the UV coordinates for that portion. Imagine your texture is 256 x 256 and you wish to map a sprite with the dimensions of 32 x 32, located at 32, 64 to a quad. Since the texture width and height always maps to 0..1, you calculate the coordinates as follows:

U: 1 / 256 * 32, V: 1 / 256 * 64
/
+----------+
|          |
|          |
|          |   U: 1 / 256 * 64, V: 1 / 256 * 96
|          | /
+----------+

So the UV coordinate for the top-left vertex would be 0.125, 0.25 and 0.25, 0.375 for bottom right. Knowing this, it should be simple to calculate the UVs for all the vertices (assuming you're just dealing with simple quads). Calculating good UVs for arbitrary meshes can of course be very complicated, that's why UV coordinates are usually generated by artists when the "unwrap" a model in a 3D modelling package.

• Thank you for the detailed response. I think I failed to convey a crucial part of what I am trying to do regarding the skewing. I post up above as a comment to my original post. Mar 6, 2012 at 17:17