WEB开发网
开发学院图形图像Flash Papervision3D: understanding Plane object – p... 阅读

Papervision3D: understanding Plane object – part 4

 2009-10-21 00:00:00 来源:WEB开发网   
核心提示:Understanding planes has never been so much fun, so here we go with the 4th part.This is full of new features, such as:* Making interactive objects* Giving obje

Understanding planes has never been so much fun, so here we go with the 4th part.

This is full of new features, such as:

* Making interactive objects

* Giving objects a name

* Changing object colors on the fly

This is the same old script as seen in Papervision3D: understanding Plane object – part 3 and previous tutorials, with some modifications.

package {
 import flash.display.Sprite;
 import flash.events.Event;
 import org.papervision3d.cameras.Camera3D;
 import org.papervision3d.render.BasicRenderEngine;
 import org.papervision3d.scenes.Scene3D;
 import org.papervision3d.view.Viewport3D;
 import org.papervision3d.objects.primitives.Plane;
 import org.papervision3d.materials.ColorMaterial;
 import org.papervision3d.events.InteractiveScene3DEvent;
 public class papervision extends Sprite {
  public var viewport:Viewport3D=new Viewport3D(500,400,false,true);
  public var scene:Scene3D = new Scene3D();
  public var camera:Camera3D = new Camera3D();
  public var renderer:BasicRenderEngine = new BasicRenderEngine();
  public var back_material:ColorMaterial=new ColorMaterial(Math.random()*0xffffff);
  public var front_material:ColorMaterial=new ColorMaterial(Math.random()*0xffffff);
  public var front_plane:Plane=new Plane(front_material,200,300,4,5);
  public var back_plane:Plane=new Plane(back_material,200,300,4,5);
  public var rotation_speed=4;
  public function papervision() {
   addChild(viewport);
   camera.focus=100;
   camera.zoom=10;
   back_plane.rotationY=180;
   front_material.interactive=true;
   back_material.interactive=true;
   scene.addChild(front_plane);
   scene.addChild(back_plane);
   front_plane.name = "FRONT";
   back_plane.name = "BACK";
   back_plane.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,on_plane_clicked);
   front_plane.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,on_plane_clicked);
   addEventListener(Event.ENTER_FRAME, render);
  }
  public function render(e:Event) {
   front_plane.yaw(rotation_speed);
   back_plane.yaw(rotation_speed);
   renderer.renderScene(scene, camera, viewport);
  }
  public function on_plane_clicked(e:InteractiveScene3DEvent) {
   rotation_speed*=-1;
   switch (e.displayObject3D.name) {
    case "FRONT" :
     front_material.fillColor=Math.random()*0xffffff;
     break;
    case "BACK" :
     back_material.fillColor=Math.random()*0xffffff;
     break;
   }
  }
 }
}

1 2  下一页

Tags:PapervisionD understanding Plane

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接