- Home
- Tutorials
- Flash
- Intermediate
- Simple 3D programming for AS2.0
Simple 3D programming for AS2.0
This article has been added to your 'Favorites' list.

Model definition
We will use a simple function to be able to define our cube in 3D.
function generateCube() { ///First we need to define the Vertex, Cube have exacly 8 vertex. points = new Array(); //Each vertex is composed from X Y and Z coordinates in the space points.push({x:-50, y:-50, z:-50}); points.push({x:50, y:-50, z:-50}); points.push({x:50, y:50, z:-50}); points.push({x:-50, y:50, z:-50}); points.push({x:-50, y:-50, z:50}); points.push({x:50, y:-50, z:50}); points.push({x:50, y:50, z:50}); points.push({x:-50, y:50, z:50}); //Then, if we want to draw more than a point, we need to define shapes with those points //Each shape (6) will have 4 vertex, the order is important when we want to use the draw api to fill it. shapes = new Array(); shapes.push([0, 1, 2, 3]); shapes.push([4, 5, 6, 7]); shapes.push([0, 4, 7, 3]); shapes.push([0, 1, 5, 4]); shapes.push([1, 5, 6, 2]); shapes.push([3, 7, 6, 2]); }
Basically we use vertex and shapes. Each shape is made with 4 vertex in this example. We are going to use two arrays, one for vertex, and other for shapes.
Points array, who store vertex, have an object in each position with 3 properties: x, y and z. The numbers in this properties are basically pixels, where the vertex will be in the screen.
Shapes array, have a reference to each vertex array position. With 4 vertex position we have a closed shape.
This seems easy, but you may think is a sort of pain to write all this stuff. Ok, you are right, there is another way.
If you have user PaperVision3D, maybe you know what COLLADA is. Take a look at http://collada.org/mediawiki/index.php/Main_Page if you want. Basically is an easy way to define 3D models in a XML basis. Maybe is not the best explanation. Anyway main idea with this 3D format is that you can get the model definition from this files, and build this files easyly with 3D studio or a similar software. The file usually includes vertex position, shapes definition using vertex, and texture mapping.
If you want, you can always replace this function with a Collada file.
Let start with our 3D space.

