2008/09/16

The sample code by using Papervision3D 2.0

要使用 Papervision3D 的話,papervision3D 基礎-1是不錯的入門。底下是包含了各種基本物件的範例:


package{
import flash.display.Sprite;

import org.papervision3d.cameras.Camera3D;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;

// import extra modules
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cone;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.objects.primitives.Cylinder;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.objects.primitives.Sphere;
// end of extra modules

public class Panorama extends Sprite{
private var viewport:Viewport3D;
private var scene:Scene3D;
private var camera:Camera3D;
private var renderer:BasicRenderEngine;

public function Panorama()
{
initPapervision3D();
}

private function initPapervision3D():void
{
viewport = new Viewport3D();
addChild(viewport);

scene = new Scene3D();
camera = new Camera3D();
renderer = new BasicRenderEngine();

/* body of the example code */

// Plane
var m:WireframeMaterial = new WireframeMaterial();
var plane:Plane = new Plane(m, 800, 800, 2, 2);
scene.addChild(plane);

// Cone
var m2:WireframeMaterial = new WireframeMaterial(0xFF5600);
var cone:Cone = new Cone(m2, 100, 100, 8, 6);
cone.rotationY = 40;
cone.rotationX = -30;
cone.moveRight(300);
scene.addChild(cone);

// Sphere
var sphere:Sphere = new Sphere();
scene.addChild(sphere);

// Cylinder
var cylinder:Cylinder = new Cylinder(m2, 100, 100, 8, 6, -1);
cylinder.moveUp(300);
scene.addChild(cylinder);

// Cube
var materialsList:MaterialsList = new MaterialsList();
var cube:Cube;
/*
var frontMaterial:WireframeMaterial = new WireframeMaterial(0x00FF56);
var backMaterial:WireframeMaterial = new WireframeMaterial(0x00FF56);
var leftMaterial:WireframeMaterial = new WireframeMaterial(0x00FF56);
var rightMaterial:WireframeMaterial = new WireframeMaterial(0x00FF56);
var topMaterial:WireframeMaterial = new WireframeMaterial(0x00FF56);
var bottomMaterial:WireframeMaterial = new WireframeMaterial(0x00FF56);

materialsList.addMaterial(frontMaterial, "front");
materialsList.addMaterial(backMaterial, "back");
materialsList.addMaterial(leftMaterial, "left");
materialsList.addMaterial(rightMaterial, "right");
materialsList.addMaterial(topMaterial, "top");
materialsList.addMaterial(bottomMaterial, "bottom");
cube = new Cube(materialsList,500,500,500,1,1,1,Cube.ALL);
*/
var allM:WireframeMaterial = new WireframeMaterial();
materialsList.addMaterial(allM, "all");

cube = new Cube(materialsList,500,500,500,1,1,1,Cube.ALL);
cube.moveLeft(400);
cube.moveForward(200);

scene.addChild(cube);

/* end of the body of the example code */

renderer.renderScene(scene, camera, viewport);
}
}
}

0 意見: