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:

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.

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:

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.

Get the most popular Phaser 3 book

Through 202 pages, 32 source code examples and an Android Studio project you will learn how to build cross platform HTML5 games and create a complete game along the way.

Get the book

214 GAME PROTOTYPES EXPLAINED WITH SOURCE CODE
// 1+2=3
// 100 rounds
// 10000000
// 2 Cars
// 2048
// A Blocky Christmas
// A Jumping Block
// A Life of Logic
// Angry Birds
// Angry Birds Space
// Artillery
// Astro-PANIC!
// Avoider
// Back to Square One
// Ball Game
// Ball vs Ball
// Ball: Revamped
// Balloon Invasion
// BallPusher
// Ballz
// Bar Balance
// Bejeweled
// Biggification
// Block it
// Blockage
// Bloons
// Boids
// Bombuzal
// Boom Dots
// Bouncing Ball
// Bouncing Ball 2
// Bouncy Light
// BoxHead
// Breakout
// Bricks
// Bubble Chaos
// Bubbles 2
// Card Game
// Castle Ramble
// Chronotron
// Circle Chain
// Circle Path
// Circle Race
// Circular endless runner
// Cirplosion
// CLOCKS - The Game
// Color Hit
// Color Jump
// ColorFill
// Columns
// Concentration
// Crossy Road
// Crush the Castle
// Cube Jump
// CubesOut
// Dash N Blast
// Dashy Panda
// Deflection
// Diamond Digger Saga
// Don't touch the spikes
// Dots
// Down The Mountain
// Drag and Match
// Draw Game
// Drop Wizard
// DROP'd
// Dudeski
// Dungeon Raid
// Educational Game
// Elasticity
// Endless Runner
// Erase Box
// Eskiv
// Farm Heroes Saga
// Filler
// Flappy Bird
// Fling
// Flipping Legend
// Floaty Light
// Fuse Ballz
// GearTaker
// Gem Sweeper
// Globe
// Goat Rider
// Gold Miner
// Grindstone
// GuessNext
// Helicopter
// Hero Emblems
// Hero Slide
// Hexagonal Tiles
// HookPod
// Hop Hop Hop Underwater
// Horizontal Endless Runner
// Hundreds
// Hungry Hero
// Hurry it's Christmas
// InkTd
// Iromeku
// Jet Set Willy
// Jigsaw Game
// Knife Hit
// Knightfall
// Legends of Runeterra
// Lep's World
// Line Rider
// Lumines
// Magick
// MagOrMin
// Mass Attack
// Math Game
// Maze
// Meeblings
// Memdot
// Metro Siberia Underground
// Mike Dangers
// Mikey Hooks
// Nano War
// Nodes
// o:anquan
// One Button Game
// One Tap RPG
// Ononmin
// Pacco
// Perfect Square!
// Perfectionism
// Phyballs
// Pixel Purge
// PixelField
// Planet Revenge
// Plants Vs Zombies
// Platform
// Platform game
// Plus+Plus
// Pocket Snap
// Poker
// Pool
// Pop the Lock
// Pop to Save
// Poux
// Pudi
// Pumpkin Story
// Puppet Bird
// Pyramids of Ra
// qomp
// Quick Switch
// Racing
// Radical
// Rebuild Chile
// Renju
// Rise Above
// Risky Road
// Roguelike
// Roly Poly
// Run Around
// Rush Hour
// SameGame
// SamePhysics
// Save the Totem
// Security
// Serious Scramblers
// Shrink it
// Sling
// Slingy
// Snowflakes
// Sokoban
// Space Checkers
// Space is Key
// Spellfall
// Spinny Gun
// Splitter
// Spring Ninja
// Sproing
// Stabilize!
// Stack
// Stick Hero
// String Avoider
// Stringy
// Sudoku
// Super Mario Bros
// Surfingers
// Survival Horror
// Talesworth Adventure
// Tetris
// The Impossible Line
// The Moops - Combos of Joy
// The Next Arrow
// Threes
// Tic Tac Toe
// Timberman
// Tiny Wings
// Tipsy Tower
// Toony
// Totem Destroyer
// Tower Defense
// Trick Shot
// Tunnelball
// Turn
// Turnellio
// TwinSpin
// vvvvvv
// Warp Shift
// Way of an Idea
// Whack a Creep
// Wheel of Fortune
// Where's my Water
// Wish Upon a Star
// Word Game
// Wordle
// Worms
// Yanga
// Yeah Bunny
// Zhed
// zNumbers