Papervision3D: understanding Plane object – part 2

Here 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 reader.

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.

To try this experiment, just cut/paste the code in the file you can download at Papervision3D for the absolute beginners.

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

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