papervision3D模板(smart Program)

翻译来自 : Papervision3D Essentials

 

codes :

 

 

不用BasicView 时:

 

package {
 import flash.display.Sprite;// 在以后的程序中,我们将会让文档类继承pv3d内置的BasicView类。
 import flash.events.Event;
 import org.papervision3d.cameras.Camera3D;
 import org.papervision3d.objects.primitives.Sphere;
 import org.papervision3d.render.BasicRenderEngine;
 import org.papervision3d.scenes.Scene3D;
 import org.papervision3d.view.Viewport3D;
 public class FirstApplication extends Sprite {
  private var scene:Scene3D;
  private var viewport:Viewport3D;
  private var camera:Camera3D;
  private var renderEngine:BasicRenderEngine;
  private var sphere:Sphere;
  public function FirstApplication() {
   stage.frameRate=40;//在pv3d  帧频要设置为40 ,这为最佳 ! 此句一般放在构造函数的第一句
   scene = new Scene3D();
   camera = new Camera3D();
   sphere = new Sphere();
   scene.addChild(sphere);
   viewport = new Viewport3D();
   addChild(viewport);
   renderEngine = new BasicRenderEngine();
   this.addEventListener(Event.ENTER_FRAME,handleEnterFrame);

  }
  private function handleEnterFrame(e:Event):void {
   sphere.localRotationY+=2;
   sphere.localRotationX+=2;
   sphere.localRotationZ+=2;//实现旋转
   renderEngine.renderScene(scene,camera,viewport);//其作为渲染用,只执行一次!故放在enterFrame事件中。
  }
 }
}

使用BasicView    <可以把下面的代码当做模板使用,简洁代码>  :

 

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() {
   /* super.BasicView(width=640,height=480,scaleToStage(是否让viewPort3D视窗为舞台大小));
                当想改变大小时可以用它

*/
            /*
    * @ author :夜梦惊魂
    */
   stage.frameRate=40;
   //下面只需定义3D对象, 在将其add到scene中
   sphere = new Sphere();
   scene.addChild(sphere);
   startRendering();//创建secne3D basicRenderEngine  viewPort3D camera3D 
  }
  // 重写 onRenderTick 及其 调用父类onRenderTick ;
  override protected function onRenderTick(e:Event=null):void {
   sphere.localRotationY+=1;//旋转轴
   super.onRenderTick();//开始渲染
  }
 }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值