Papervision3D: understanding Plane object – part 3

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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. To test this example, just copy/paste the code in the file you can download at Papervision3D for the absolute beginners.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (4 votes, average: 3.50 out of 5)
Loading ... Loading ...
If you found this post useful, please consider a small donation.
» Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.

9 Responses to “Papervision3D: understanding Plane object – part 3”

  1. tolleder on May 29th, 2009 4:49 pm

    “And that’s all… look at the double sided plane with the Google logo on its back…”
    You mean red and black plane?

  2. Brindy on May 29th, 2009 5:11 pm

    Emmanuel – you have to remember that the Flash Player doesn’t let you load information from arbitrary URLs unless there’s a CrossDomainPolicy in place. Simple solution is to host the swf and image on the same server and use a relative URL. :)

    With debug flash player enabled I get this error:

    SecurityError: Error #2122: Security sandbox violation: Loader.content: http://www.emanueleferonato.com/downloads/papervision4.swf cannot access http://www.google.com/intl/en_ALL/images/logo.gif. A policy file is required, but the checkPolicyFile flag was not set when this media was loaded.
    at flash.display::Loader/get content()
    at org.papervision3d.materials::BitmapFileMaterial/loadBitmapCompleteHandler()

    That said, this is a very useful tutorial. :)

  3. Brindy on May 29th, 2009 5:13 pm

    (oops, sorry for spelling your name wrong)

  4. Monkios on May 29th, 2009 5:40 pm

    Well that’s nice.

    How do you make it so the units automatically become pixels ?

  5. szataniol on May 29th, 2009 6:10 pm

    @Monkios – Pixel precision formula is:
    do3d.z = (camera.zoom * camera.focus) – Math.abs(camera.z)

  6. Alex on May 29th, 2009 8:19 pm

    Front side is red, back side is black. That’s it. No Google logo. No magic. Mac OS 10.4.x FF 3.0.10 Flash player 10.

  7. John Persson on May 30th, 2009 2:13 pm

    About the SecurityError you can also access the image with a little php magic

    http://kb2.adobe.com/cps/165/tn_16520.html

    take care!

  8. John Persson on May 30th, 2009 2:14 pm

    oh sorry

Leave a Reply




Trackbacks

  1. Weekly Shared Items - 3. June, 2009 | TOXIN LABS - weblog of a german design student from wuerzburg on June 3rd, 2009 6:33 am

    [...] Papervision3D: understanding Plane object – part 3 [...]

flash games company