4. 装完后测试一下。打开RotatingCubeExample.as加进下面那代码,再ctrl f11运行一下。就看到水墨效果了,给个截图。
你也可以直接看这里:
package {
import flash.display.Sprite;
import flash.events.Event;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
[SWF ( width = '640', height = '480', backgroundColor = '#ffffff', frameRate = '31' ) ]
public class RotatingCubeExample extends Sprite {
private var viewport:Viewport3D;
private var scene:Scene3D;
private var camera:Camera3D;
private var renderer:BasicRenderEngine;
private var cube:Cube;
public function RotatingCubeExample(){
initPapervision3D();
createCube();
beginRender();
}
private function initPapervision3D():void{
viewport = new Viewport3D();
addChild(viewport);
scene = new Scene3D();
camera = new Camera3D();
renderer = new BasicRenderEngine();
}
private function createCube():void{
var allM:WireframeMaterial = new WireframeMaterial();
var m:MaterialsList = new MaterialsList();
m.addMaterial(allM, "all");
//width, depth, height
var w:Number = 300;
var d:Number = 500;
var h:Number = 700;
//segments S, T, and H
var sS:int = 2;
var sT:int = 3;
var sH:int = 4;
cube = new Cube(m, w, d, h, sS, sT, sH);
scene.addChild(cube);
}
private function beginRender():void{
//calls the render function every frame
addEventListener(Event.ENTER_FRAME, render);
}
private function render(e:Event):void{
//rotates around the vertical axis
cube.yaw(2);
//rotates around the lateral axis
cube.pitch(1);
renderer.renderScene(scene, camera, viewport);
}
}
}