Papervision3D: understanding Plane object

The Plane is the simplest object you can create with Papervision3D.

But “simple” does not mean we don’t have a set of options to custom our planes.

Look at this script, that is quite the same as the one published at Papervision3D for the absolute beginners:

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
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;
	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 plane:Plane = new Plane();
		public function papervision() {
			addChild(viewport);
			scene.addChild(plane);
			addEventListener(Event.ENTER_FRAME, render);
		}
		public function render(e:Event) {
			plane.pitch(1);
			renderer.renderScene(scene, camera, viewport);
		}
	}
}

The only changes are I added an ENTER_FRAME listener to render the scene at every frame because renderScene renders the scene only once, and I added a pitch method to the plane to make it rotate along its x axis by 1 degree at every frame.

Let’s look at the movie:

If you notice, when the plane rotates over 180 degrees, it disappears. By default, planes aren’t double sided.

To create a double sided plane, we’ll need to define a material and set this material as double sided.

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
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;
	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 plane:Plane= new Plane(wireframe);
		public function papervision() {
			addChild(viewport);
			wireframe.doubleSided = true;
			scene.addChild(plane);
			addEventListener(Event.ENTER_FRAME, render);
		}
		public function render(e:Event) {
			plane.pitch(1);
			renderer.renderScene(scene, camera, viewport);
		}
	}
}

Line 9: importing the wireframe material, the simplest one

Line 15: declaring the wireframe variable, WireframeMaterial type – in this example, it’s important you declare it before plane declaration

Line 16: when declaring the plane, now I am passing the material as a parameter. It’s not the only parameter I can pass, but at the moment that’s what I need

Line 19: Setting wireframe material as double sided

And now finally we have a double sided plane

Now let’s see the other parameters you can pass when creating a plane:

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
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;
	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 plane:Plane=new Plane(wireframe,500,750,4,5);
		public function papervision() {
			addChild(viewport);
			plane.rotationY=45;
			plane.x=-200;
			plane.y=100;
			wireframe.doubleSided=true;
			scene.addChild(plane);
			addEventListener(Event.ENTER_FRAME, render);
		}
		public function render(e:Event) {
			plane.pitch(1);
			renderer.renderScene(scene, camera, viewport);
		}
	}
}

Let’s look at plane’s declaration… it now has five parameters…

wireframe is the material as seen before

500 is the width of the plane. 500 pixels? 500 meters? At the moment let’s call them 500 units… I’ll explain in another tutorial how to manage units

750 represents the height

4 is the number of segments in the plane width. The more the segments, the more detailed the final render, the more the CPU will stress. It’s up to you playing carefully with this parameter.

5 represents the same thing for the plane height

Moreover, as you can see at lines 19-21, there are other parameters you can change to make the plane suits what you want, but I’ll explain them later, when we’ll see how Papervision3D manages units.

Here it is:

No downloads this time, just copy/paste one of the codes of this tutorial into the example you can download at Papervision3D for the absolute beginners.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (11 votes, average: 4.45 out of 5)
Loading ... Loading ...
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.
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 7 comments

  1. Irevol

    on May 12, 2009 at 5:38 pm

    Hi Emanuele feronato,

    nice tutorial to start with papervision3D. i think now the next point for tutorial to be start is Multiplayer game in flash ( whatever it is on AS2 or AS3). what do you think about that? i am exploring around web for a basic start but cannot found any tutorial on Multiplayer Game. while i think the best possible place to start with multiplayer game is SmartFox Server and nonoba, i am using nonoba and exploring it. i hope you will give any good news on multiplayer game side.

  2. Collin Douch

    on May 13, 2009 at 7:09 am

    Wow this is great and so relativly simple to Box2D Keep up the good work Emanuele!

  3. Papervision3D: understanding Plane object - part 2 : Emanuele Feronato

    on May 22, 2009 at 7:06 pm

    [...] I am to continue the tutorial about Papervision3D and planes. I suggest to take a look at the first part if you are a new [...]

  4. clarklin

    on June 5, 2009 at 11:14 am

    Hit there Emanuele,
    with regards to this tutorial,
    you mention that you added a pitch method for the plane class but what is the code for that method?

    thanks
    Clark

  5. clarklin

    on June 5, 2009 at 11:19 am

    nevermind i see it is a method from the extended DisplayObjects3D class.

  6. Papervision3D: understanding Plane object – part 6 : Emanuele Feronato

    on June 14, 2009 at 10:13 pm

    [...] understand what segments represent, read part 1 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 36 [...]

  7. nightsucker

    on December 11, 2009 at 5:58 pm

    hi,

    can i change the segments dynamically at runtime – hope you can help me . . .