Papervision3D: understanding Plane object – part 6
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 to “Papervision3D: understanding Plane object – part 6”
Leave a Reply
Trackbacks
-
Weekly Shared Items – 16. June, 2009 | TOXIN LABS - weblog of a german design student from wuerzburg on
June 16th, 2009 10:22 am
[...] Papervision3D: understanding Plane object – part 6 [...]
-
Weekly Shared Items – 17. June, 2009 | TOXIN LABS - weblog of a german design student from wuerzburg on
June 17th, 2009 6:05 am
[...] Papervision3D: understanding Plane object – part 6 [...]
- Get up to $100,000 for your next Flash game with Mochi GAME Developer Fund
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines – 17 lines version
- Sell sitelocked version of your Flash games and even .fla sources to Free Online Games
- Protect your work from ActionScript code theft with SWF Protector
- Create a dynamic content animated footer ad for your site in just 9 jQuery lines
- Understanding Box2D’s one-way platforms, aka CLOUDS
- Triqui MochiAds Arcade plugin for WordPress upgraded to 1.2
- Box2D Flash game creation tutorial – part 2
- 11 Flash isometric engines you can use in your games
- Monetize your Flash games with GamesChart
- Create a Lightbox effect only with CSS - no javascript needed
- Flash game creation tutorial - part 1
- Create a Flash Racing Game Tutorial
- Flash game creation tutorial - part 2
- Make a Flash game like Flash Element Tower Defense - Part 2
- Flash game creation tutorial - part 3
- Make a Flash game like Flash Element Tower Defense - Part 1
- Create a flash draw game like Line Rider or others - part 1
- Triqui MochiAds Arcade plugin for WordPress official page
- Create a flash artillery game - step 1
- Flash game creation tutorial – part 5.2 (4.88/5)
- Create a flash artillery game – step 1 (4.79/5)
- Create a Flash Racing Game Tutorial (4.76/5)
- Create a flash artillery game – step 2 (4.74/5)
- Create a survival horror game in Flash tutorial – part 1 (4.73/5)
- Creation of a Flash arcade site using WordPress – step 2 (4.73/5)
- Flash game creation tutorial – part 2 (4.71/5)
- Flash game creation tutorial – part 1 (4.70/5)
- Create a flash draw game like Line Rider or others – part 1 (4.69/5)
- Creation of a platform game with Flash – step 2 (4.68/5)

(5 votes, average: 4.80 out of 5)





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