学习pv3d经常会用到的一些代码
//汇入AS3类别常用:
import flash.display.BitmapData;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLRequest
//汇入PV3D类别常用:
import org.papervision3d.cameras.Camera3D;//摄像机
import org.papervision3d.render.BasicRenderEngine;//渲染引擎
import org.papervision3d.scenes.Scene3D;//场景
import org.papervision3d.view.Viewport3D;//观察口
import org.papervision3d.view.BasicView//包含上面四个类别
import org.papervision3d.materials.ColorMaterial//色彩材质
import org.papervision3d.materials.WireframeMaterial//线筐材质
import org.papervision3d.materials.utils.MaterialsList//六面材质
import org.papervision3d.materials.BitmapAssetMaterial//库中点阵图材质
import org.papervision3d.materials.shaders.FlatShader;
import org.papervision3d.materials.shaders.ShadedMaterial;
import org.papervision3d.materials.BitmapFileMaterial
//外部点阵图材质
import org.papervision3d.materials.MovieMaterial//影片剪辑当材质
import org.papervision3d.events.InteractiveScene3DEvent;//广播事件类别
import org.papervision3d.lights.PointLight3D
//光线类别
import org.papervision3d.core.proto.MaterialObject3D
///////////////////////////////////////////////////////////////////
//
空的物件物件
import org.papervision3d.objects.DisplayObject3D
//平面物件
import org.papervision3d.objects.primitives.Plane
//球物件
import org.papervision3d.objects.primitives.Sphere
//立方体物件
import org.papervision3d.objects.primitives.Cube;
//纸飞机PaperPlane
import org.papervision3d.objects.primitives.PaperPlane;
//箭头 Arrow
import org.papervision3d.objects.primitives.Arrow;
///////////////////////////////////////////////////////////////////
//
汇入Tween类别常用:
import caurina.transitions.Tweener;
import caurina.transitions.properties.FilterShortcuts
//汇入笔者写的反射材质类别常用:
import milkmidi.papervision3d.materials.ReflectionFileMaterial
import milkmidi.display.MiniSlider
//拉动物件
公式代码
Camera的x轴 = Math.cos(目前镜头的角度)*半径
Camera的y轴 = Math.sin(目前镜头的角度)*半径
//摸板
package {
import flash.display.Sprite;
public class DocumentClassExample extends Sprite {
public function DocumentClassExample() {
trace("Hello world!");
}
}
}
//球体模板
package {
import flash.events.Event;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.view.BasicView;
public class BasicViewExample extends BasicView {
private var sphere:Sphere;
public function BasicViewExample() {
stage.frameRate = 40;
init();
startRendering();
}
private function init():void{
sphere = new Sphere();
scene.addChild(sphere);
}
override protected function onRenderTick(e:Event=null):void {
sphere.localRotationX +=1;
super.onRenderTick();
}
}
}
为书中的例子做准备
package {
import flash.events.Event;
import org.papervision3d.view.BasicView;
public class BookExampleTemplate extends BasicView{
public function BookExampleTemplate(){
stage.frameRate = 40;
init();
startRendering();
}
private function init():void {
}
override protected function onRenderTick(e:Event=null):void {
super.onRenderTick();
}
}
}
//几个图形的写法
plane = new Plane(null,300,300,1,1);
scene.addChild(plane);
sphere = new Sphere(null,300,16,12);
var cylinder:Cylinder = new Cylinder(null,80,400,8, 2,-1,false,true);//圆柱体
scene.addChild(cylinder);
var cone:Cone = new Cone(null,150,400,8,4);//圆锥体
Cone
scene.addChild(cone);
//添加颜色材质的立方体
var red:ColorMaterial = new ColorMaterial(0xFF0000);
var blue:ColorMaterial = new ColorMaterial(0x0000FF);
var green:ColorMaterial = new ColorMaterial(0x00FF00);
var materialsList:MaterialsList = new MaterialsList();
materialsList.addMaterial(red,"front");
materialsList.addMaterial(red,"back");
materialsList.addMaterial(blue,"left");
materialsList.addMaterial(blue,"right");
materialsList.addMaterial(green,"top");
materialsList.addMaterial(green,"bottom");
cube = new Cube(materialsList,300,300,300);
scene.addChild(cube);
var paperPlane:PaperPlane = new PaperPlane(null,3);// 纸飞机
scene.addChild(paperPlane);
var arrow:Arrow = new Arrow();//箭头
scene.addChild(arrow);
//材质的添加方法
private function init():void {
var material:WireframeMaterial = new WireframeMaterial(0x000000,0.5,2); //线筐材质
var cone:Cone = new Cone(material,500,500);
scene.addChild(cone);
}
import org.papervision3d.events.FileLoadEvent;
目标摄影机
自由摄影机
调试摄影机
弹性摄影机
import org.papervision3d.cameras.CameraType;
super(stage.stageWidth,stage.stageHeight,true,false, CameraType.TARGET);
转自:http://qiezi0301.blog.163.com/blog/static/11825485201052104243674/