Home

Tutorials

Portfolio

Blog

 

Highlights

 

Using primitives in Papervision 3D

Page 5

1 | 2 | 3 | 4 | 5

Cubes are handled a little differently from the other primitive shapes, as each face of the cube has to be assigned a material.

In this tutorial we will make a simple wireframe cube. A later tutorial will look at creating textures and materials that can be applied to primitives.

A cube has six sides, front, back, left, right, top and bottom. Each of these can be assigned a different material, or they can be assigned the same material. The materials used in a cube must be stored in a MaterialsList.

The following creates a MaterialsList that contains wireframe materials.

var wireMaterial:MaterialsList=new MaterialsList({all:new WireframeMaterial(0xFF0000)});

This line sets all the materials to a red coloured WireframeMaterial. 0xFF0000 specifies the colour red using Hexadecimal notation.

Finally we create the cube, with its materials parameter set to the name of the MaterialsList that we just created. The other parameters for the cube are the width, height and depth.

var box:Cube=new Cube(wireMaterial,200,200,200);
box.x=0;
box.y=300;

Remember to add the cube to the scene.

scene.addChild(box);

Once all of the code is complete, test your movie and you should see the following.

Papervision 3D primitives

The complete code for this is as follows, or you can download the FLA file.

import org.papervision3d.cameras.Camera3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.materials.*;
import org.papervision3d.materials.special.*;
import org.papervision3d.materials.utils.*;
var viewport:Viewport3D=new Viewport3D(stage.stageWidth,stage.stageHeight);
var scene:Scene3D = new Scene3D();
var camera:Camera3D = new Camera3D();
var renderer:BasicRenderEngine = new BasicRenderEngine();
stage.scaleMode="showAll";
var ball:Sphere=new Sphere(null,100,10,10);
ball.x=-500;
ball.y=300;
var wireMaterial:MaterialsList=new MaterialsList({all:new WireframeMaterial(0xFF0000)});
var box:Cube=new Cube(wireMaterial,200,200,200);
box.x=0;
box.y=300;
var cornet:Cone=new Cone(null,100,200,10); 
cornet.x=500;
cornet.y=300;
var can:Cylinder=new Cylinder(null,100,200,10); 
can.x=-500;
can.y=-300;
var flat:Plane=new Plane(null,200,200);
flat.x=0;
flat.y=-300;
var jet:PaperPlane=new PaperPlane(null,2);
jet.x=500;
jet.y=-300;
addChild(viewport);
scene.addChild(ball);
scene.addChild(box);
scene.addChild(cornet);
scene.addChild(can);
scene.addChild(flat);
scene.addChild(jet);
renderer.renderScene(scene, camera, viewport);


End of tuorial.

1 | 2 | 3 | 4 | 5