Using primitives in Papervision 3D
Page 2
Open Flash and create a new Flash File (Actionscript 3.0).
Select frame one in the timeline and open the Actions Panel (Window - Actions or F9).
First we need to import the required classes.
This first set of classes imports all of the components for creating a 3D Scene.
import org.papervision3d.cameras.Camera3D; import org.papervision3d.render.BasicRenderEngine; import org.papervision3d.scenes.Scene3D; import org.papervision3d.view.Viewport3D;
The second set of imported classes are for creating primitives and materials which cover the 3D shapes.
import org.papervision3d.objects.primitives.*; import org.papervision3d.materials.*; import org.papervision3d.materials.special.*; import org.papervision3d.materials.utils.*;
Next we create all of the necessary objects to create and render the scene.
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";
Now we create the sphere object. The parameters specify the material to be used (null), the radius and number of segments that make up the sphere - height and width. We then place the sphere in the top left corner by altering its x and y coordinates.
var ball:Sphere=new Sphere(null,100,10,10); ball.x=-500; ball.y=300;
Finally we add the viewport and sphere object to the stage ands scene and render the image.
addChild(viewport); scene.addChild(ball);
renderer.renderScene(scene, camera, viewport);
Here's the result - note that the sphere appears slightly squished because of the perspective view. You can download the FLA file here:
Next we'll add another primitive, the cone...
