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:
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 37 | 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…
They can be easily customized to meet the unique requirements of your project.















(4 votes, average: 4.00 out of 5)









This post has 6 comments
Cyclone103
Just thought you might be interested Emanuele, but there is a scene rendering utility for Papervison3D. You can get it at http://www.juxtinteractive.com/work/vizualpv3d/. I find it useful for creating complex scenes.
Papervision3D: understanding Plane object - part 3 : Emanuele Feronato
[...] 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 [...]
Brindy
@Cyclone103 – that’s a very cool tool, but I couldn’t work out how to load the XML it generates in to a Papervision3d application. Any suggestions?
Cyclone103
Brindy, I made a post on the page and asked about that, possibly as a new feature for the next version. This project is very new, it’s been a month since the initial release.
Papervision3D: understanding Plane object - part 4 : Emanuele Feronato
[...] 16-17: This is the creation of a color material as seen in part 2, but this time I am rendering random [...]
Jochen Hasinger
Thank you for the tutorial so far. The first papervision tutorial in clear words and comprehensible steps for me. Good work!