Papervision3D: understanding Plane object – part 6
- June 14, 2009 by Emanuele Feronato
- Filed under Actionscript 3, Flash | 7 Comments
In part 5 we created a playing card.
Now it’s time to make it a bit more realistic. You know when you play again and again with playing cards, they bend.
We’ll learn how to bend our planes.
To bend objects in Papervision3D we need a 3rd party library called AS3Dmod.
AS3Dmod is a framework for creating static and animated modifier stacks, so you can modify the same object with more than one modifier.
So the steps to add a modifier to an object are:
1) Create a modifier stack and apply it to the object
2) Add a modifier to the stack
3) Configure the modifier
4) Repeat from step 2 if you want to add more than one modifier
5) Apply the queue
Now it’s time to download the library from the official Google Code page and copy the com folder in the same path you copied the org Papervision3D folder. Don’t worry if you can’t find it, at the end of the page I included the full source code with all needed libraries in the proper positions.
Now, the script we already saw at part 5 with the new lines commented.
Plese notice at lines 42 and 43 I added more segments to the planes, to have a smoother blend.
To 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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | 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.MovieMaterial; import org.papervision3d.events.InteractiveScene3DEvent; // AS3Dmod libraries // The Modifier Stack is the base of AS3Dmod. // Holds a reference to the mesh being modified and an array of modifiers. import com.as3dmod.ModifierStack; // Bend class allows to bend an object along an axis. import com.as3dmod.modifiers.Bend; // this is the 3D engine inside AS3Dmod. import com.as3dmod.plugins.pv3d.LibraryPv3d; public class papervision extends Sprite { public var my_card:card = new card(); public var viewport:Viewport3D=new Viewport3D(500,400,false,true); public var scene:Scene3D = new Scene3D(); public var camera:Camera3D = new Camera3D(); public var renderer:BasicRenderEngine = new BasicRenderEngine(); public var front_material:MovieMaterial; public var back_material:MovieMaterial; public var front_plane:Plane; public var back_plane:Plane; public var rotation_speed=0; public var steps=0; // declaring modifiers stacks public var front_mod:ModifierStack; public var back_mod:ModifierStack; // creating bend modifiers public var front_bend:Bend = new Bend(); public var back_bend:Bend = new Bend(); public function papervision() { my_card.gotoAndStop(2); front_material=new MovieMaterial(my_card); my_card.gotoAndStop(1); back_material=new MovieMaterial(my_card); front_plane=new Plane(front_material,200,250,8,10); back_plane=new Plane(back_material,200,250,8,10); addChild(viewport); camera.focus=100; camera.zoom=10; back_plane.rotationY=180; front_material.interactive=true; back_material.interactive=true; // creating front and back modifiers and assigning // them to their respective planes front_mod = new ModifierStack(new LibraryPv3d(), front_plane); back_mod = new ModifierStack(new LibraryPv3d(), back_plane); // adding bends to modifier stacks front_mod.addModifier(front_bend); back_mod.addModifier(back_bend); // setting opposite forces front_bend.force = 0.3; back_bend.force = -0.3; // applying the modifiers front_mod.apply(); back_mod.apply(); scene.addChild(front_plane); scene.addChild(back_plane); back_plane.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,on_plane_clicked); front_plane.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,on_plane_clicked); addEventListener(Event.ENTER_FRAME, render); } public function render(e:Event) { if (rotation_speed) { steps++; front_plane.yaw(rotation_speed); back_plane.yaw(rotation_speed); } if (steps==180/rotation_speed) { steps=0; rotation_speed=0; } renderer.renderScene(scene, camera, viewport); } public function on_plane_clicked(e:InteractiveScene3DEvent) { if (steps==0) { rotation_speed=4; } } } } |
And this is the result…
… the same as before, but now the card has a bend modifier on it. Click on the card to flip it.
Next time we’ll add some shadows and other good looking effects. Download the source code with all needed libraries.
They can be easily customized to meet the unique requirements of your project.
7 Responses
Leave a Reply
TUTORIAL SERIES:
- Una guida completa al gioco del poker online e una selezione dei migliori casino online.
- casino online
- migliori casino online
- BlackJack online
- casinò online

(5 votes, average: 4.80 out of 5)

[...] Papervision3D: understanding Plane object – part 6 [...]
Bless you for this incredible series of tutorials. Words cannot express my gratitude for the fine job you’ve done. Well explained basic tutorials on this subject matter are extremely hard to find. Without a doubt I have learned more from yours than all others combined.
[...] Papervision3D: understanding Plane object – part 6 [...]
Thanks again my friend, you are my ultimate flash mentor, I really approciate your work here.
keep up with the good work!
Great tut! Hey, could you make a flash AS3 RPG tutorial, or tutorials?
sweet! thanks man,
very helpful
can you tell me plz where is this? : Next time we’ll add some shadows and other good looking effects.