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

Papervision3D: understanding Plane object – part 3

 2009-10-21 00:00:00 来源:WEB开发网   
核心提示:In this 3rd part we’ll discover two interesting features:1) How to add a bitmap texture to a plane2) How to set the camera to make Papervision3D units mat

In this 3rd part we’ll discover two interesting features:

1) How to add a bitmap texture to a plane

2) How to set the camera to make Papervision3D units match pixels

Let’s start… the “units Vs pixels” issue can be a problem when we want a plane (or whatever) to have a precise size in pixels.

Settings the camera properly can solve the problem… this is the same script used in Papervision3D: understanding Plane object – part 2 with a couple of 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.materials.BitmapFileMaterial;
 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 bitmap_material:BitmapFileMaterial = new BitmapFileMaterial("http://www.google.com/intl/en_ALL/images/logo.gif");
  public var red_material:ColorMaterial=new ColorMaterial(0xff0000);
  public var frontplane:Plane=new Plane(red_material,200,300,4,5);
  public var backplane:Plane=new Plane(bitmap_material,200,300,4,5);
  public function papervision() {
   addChild(viewport);
   camera.focus=100;
   camera.zoom=10;
   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);
  }
 }
}

At lines 22-23 I am setting the camera in a way the 200 and 300 “units” defining the plane size at lines 18-19 are equivalent to pixels.

Our planes now are 200×300 pixels sized.

Then I introduced a new material, the BitmapFileMaterial one… imported at line 10, declared at line 16 (look how do I import the image… passing the URL) at assigned at line 19

And that’s all… look at the double sided plane with the Google logo on its back…

Next time, we’ll add some interaction.

Tags:PapervisionD understanding Plane

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