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

Papervision3D: understanding Plane object – part 2

 2009-10-20 00:00:00 来源:WEB开发网   
核心提示:This time I am going to explain the basic color material and a trick to make a plane have two materials, one per side.Before you continue reading, let me say yo

This time I am going to explain the basic color material and a trick to make a plane have two materials, one per side.

Before you continue reading, let me say you can’t have a plane with two materials, one per side. So if you are planning to have a double sided plane, such as a gambling card, you’ll have to make a trick…

let me show you this code:

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.WireframeMaterial;
 import org.papervision3d.materials.ColorMaterial;
 public class papervision extends Sprite {
  public var viewport:Viewport3D = new Viewport3D();
  public var scene:Scene3D = new Scene3D();
  public var camera:Camera3D = new Camera3D();
  public var renderer:BasicRenderEngine = new BasicRenderEngine();
  public var wireframe:WireframeMaterial = new WireframeMaterial();
  public var red_material:ColorMaterial=new ColorMaterial(0xff0000);
  public var frontplane:Plane=new Plane(red_material,500,750,4,5);
  public var backplane:Plane=new Plane(wireframe,500,750,4,5);
  public function papervision() {
   addChild(viewport);
   frontplane.x=-200;
   frontplane.y=100;
   backplane.x=-200;
   backplane.y=100;
   backplane.rotationY=180
   scene.addChild(frontplane);
   scene.addChild(backplane);
   addEventListener(Event.ENTER_FRAME, render);
  }
  public function render(e:Event) {
   frontplane.yaw(1);
   backplane.yaw(1);
   renderer.renderScene(scene, camera, viewport);
  }
 }
}

Line 10: importing the ColorMaterial class, the class used to assign colors to objects

Line 17: creating a new ColorMaterial variable called red_material, representing a solid red material as you can see from the 0xff0000 color code.

ColorMaterial accepts more parameters such as alpha and a flag to determine if it’s interactive but at the moment we don’t need them

Lines 18-19: Creating two plane objects of the same size, one with red_material material and one with wireframe material

Lines 22-25: Placing both planes on the same place, and notice that in Papervision3D: understanding Plane object I was making materials as double sided, while now I leave them as single sides. This means planes will disappear once they flips to the other side.

Line 26: Rotating the second plane of 180 degrees along Y axis.

Lines 32-33: Rotating the planes by one degree along Y axis… but since they have a 180 degrees difference between their rotation, when the red plane is visible, the wireframe one is invisible, and when the wireframe plane is visible, the red one is invisible.

This will give us an effect like a flipping card.

Next time, camera adjustment and a real world texture. Yes, I want to make a card game with Papervision3D…

Tags:PapervisionD understanding Plane

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