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

Papervision3D: understanding Plane object – part 6

 2009-10-21 00:00:00 来源:WEB开发网   
核心提示:In part 5 we created a playing card.Now it’s time to make it a bit more realistic. You know when you play again and again with playing cards, they bend.We

In part 5 we created a playing card.

Now it’s time to make it a bit more realistic. You know when you play again and again with playing cards, they bend.

We’ll learn how to bend our planes.

To bend objects in Papervision3D we need a 3rd party library called AS3Dmod.

AS3Dmod is a framework for creating static and animated modifier stacks, so you can modify the same object with more than one modifier.

So the steps to add a modifier to an object are:

1) Create a modifier stack and apply it to the object

2) Add a modifier to the stack

3) Configure the modifier

4) Repeat from step 2 if you want to add more than one modifier

5) Apply the queue

Now it’s time to download the library from the official Google Code page and copy the com folder in the same path you copied the org Papervision3D folder. Don’t worry if you can’t find it, at the end of the page I included the full source code with all needed libraries in the proper positions.

Now, the script we already saw at part 5 with the new lines commented.

Plese notice at lines 42 and 43 I added more segments to the planes, to have a smoother blend.

To understand what segments represent, read part 1

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.MovieMaterial;
 import org.papervision3d.events.InteractiveScene3DEvent;
 // AS3Dmod libraries
 // The Modifier Stack is the base of AS3Dmod. 
 // Holds a reference to the mesh being modified and an array of modifiers.
 import com.as3dmod.ModifierStack;
 // Bend class allows to bend an object along an axis. 
 import com.as3dmod.modifiers.Bend;
 // this is the 3D engine inside AS3Dmod.
 import com.as3dmod.plugins.pv3d.LibraryPv3d;
 public class papervision extends Sprite {
  public var my_card:card = new card();
  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 front_material:MovieMaterial;
  public var back_material:MovieMaterial;
  public var front_plane:Plane;
  public var back_plane:Plane;
  public var rotation_speed=0;
  public var steps=0;
  // declaring modifiers stacks
  public var front_mod:ModifierStack;
  public var back_mod:ModifierStack;
  // creating bend modifiers
  public var front_bend:Bend = new Bend();
  public var back_bend:Bend = new Bend();
  public function papervision() {
   my_card.gotoAndStop(2);
   front_material=new MovieMaterial(my_card);
   my_card.gotoAndStop(1);
   back_material=new MovieMaterial(my_card);
   front_plane=new Plane(front_material,200,250,8,10);
   back_plane=new Plane(back_material,200,250,8,10);
   addChild(viewport);
   camera.focus=100;
   camera.zoom=10;
   back_plane.rotationY=180;
   front_material.interactive=true;
   back_material.interactive=true;
   // creating front and back modifiers and assigning
   // them to their respective planes
   front_mod = new ModifierStack(new LibraryPv3d(), front_plane);
   back_mod = new ModifierStack(new LibraryPv3d(), back_plane);
   // adding bends to modifier stacks
   front_mod.addModifier(front_bend);
   back_mod.addModifier(back_bend);
   // setting opposite forces 
   front_bend.force = 0.3;
   back_bend.force = -0.3;
   // applying the modifiers
   front_mod.apply();
   back_mod.apply();
   scene.addChild(front_plane);
   scene.addChild(back_plane);
   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) {
   if (rotation_speed) {
    steps++;
    front_plane.yaw(rotation_speed);
    back_plane.yaw(rotation_speed);
   }
   if (steps==180/rotation_speed) {
    steps=0;
    rotation_speed=0;
   }
   renderer.renderScene(scene, camera, viewport);
  }
  public function on_plane_clicked(e:InteractiveScene3DEvent) {
   if (steps==0) {
    rotation_speed=4;
   }
  }
 }
}

1 2  下一页

Tags:PapervisionD understanding Plane

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