LogoLogo
  • Home
  • Projects
  • About
  • Contact

“Double Sided Plane” with Papervision

Devon O. · January 15, 2008 · Actionscript, Flash · 0 comments
2

Here’s a little trick I learned from playing with After Effects (“postcards in space”, man).

If you’d like to have a double sided Plane object (playing card, flipping piece of paper, etc), simply create a DisplayObject3D instance, add your two sides as planes, push one side back a single pixel on the z axis, then rotate the DisplayObject3D item (which of course will rotate both front and back image as though they were a single item).

Of course this would probably make a little more sense in code form, so here’s a quick example:

C#
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
/**
* Example of a Double Sided "Card" with Papervision3D
*/        
 
package {        
 
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.filters.DropShadowFilter;        
 
    //papervision
    import org.papervision3d.materials.BitmapAssetMaterial;
    import org.papervision3d.cameras.Camera3D;
    import org.papervision3d.objects.Plane;
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.Papervision3D;
    import org.papervision3d.scenes.Scene3D;        
 
    public class CardExample extends Sprite {
        private var container:Sprite;
        private var scene:Scene3D;
        private var camera:Camera3D;
        private var card:DisplayObject3D;
        public function CardExample() {
            Papervision3D.VERBOSE=false;        
 
            init();
        }        
 
        private function init():void {
            init3d();
            createCard();
            addEventListener(Event.ENTER_FRAME,render);
        }        
 
        private function createCard():void {
            // "Face" and "Back" are two bitmaps imported into .fla library
            //and set to link for actionscript with those class names.        
 
            var faceMat:BitmapAssetMaterial=new BitmapAssetMaterial("Face");
            faceMat.oneSide=false;
            var backMat:BitmapAssetMaterial=new BitmapAssetMaterial("Back");
            var face:Plane=new Plane(faceMat,0,0,2);        
 
            //push the face back one pixel in z space
            face.z=1;        
 
            var back:Plane=new Plane(backMat,0,0,2);        
 
            card.addChild(back);
            card.addChild(face);        
 
        }        
 
        private function init3d():void {
            container=new Sprite  ;
            container.x=stage.stageWidth * .5;
            container.y=stage.stageHeight * .5 - 30;
            container.filters=[new DropShadowFilter(75,45,0x000000,.8,50,50)];
            addChild(container);        
 
            card=new DisplayObject3D  ;        
 
            //give the card a jaunty little angle
            card.rotationZ=10;        
 
            scene=new Scene3D(container);
            scene.addChild(card);        
 
            camera=new Camera3D  ;
            camera.focus=250;
            camera.zoom=4;
        }        
 
        private function render(e:Event):void {
            //spin the card
            card.rotationY+= 5;
            scene.renderCamera(camera);
        }
    }
}

And that will give you:

Nice, huh?

  Facebook   Pinterest   Twitter   Google+
  • Jiglib + Augmented Reality : Playing with Balls
    May 12, 2009 · 12 comments
    2690
    4
    Read more
  • Game Development Tips from the Trenches of PopCap
    August 01, 2011 · 5 comments
    3711
    5
    Read more
  • Real Drawing to Augmented Reality
    October 23, 2009 · 4 comments
    7040
    4
    Read more

Sorry, the comment form is closed at this time.

Devon O. Wolfgang

AIR | Unity3D | AR/VR

Unity Certified Developer

Technical Reviewer of “The Essential Guide to Flash CS4 AIR Development” and “Starling Game Development Essentials”

Reviewer of “The Starling Handbook”

Unity Engineer at Touch Press.

Categories
  • Actionscript (95)
  • AIR (16)
  • Flash (99)
  • Games (7)
  • Liberty (13)
  • Life (53)
  • Shaders (20)
  • Unity3D (21)
Recent Comments
  • MainDepth on Unity Ripple or Shock Wave Effect
  • Devon O. on Unity Ripple or Shock Wave Effect
  • Feral_Pug on Unity Ripple or Shock Wave Effect
  • bavvireal on Unity3D Endless Runner Part I – Curved Worlds
  • Danielius Vargonas on Custom Post Processing with the LWRP
Archives
  • December 2020 (1)
  • December 2019 (1)
  • September 2019 (1)
  • February 2019 (2)
  • December 2018 (1)
  • July 2018 (1)
  • June 2018 (1)
  • May 2018 (2)
  • January 2018 (1)
  • December 2017 (2)
  • October 2017 (1)
  • September 2017 (2)
  • January 2017 (1)
  • July 2016 (1)
  • December 2015 (2)
  • March 2015 (1)
  • September 2014 (1)
  • January 2014 (1)
  • August 2013 (1)
  • July 2013 (1)
  • May 2013 (1)
  • March 2013 (2)
  • December 2012 (1)
  • November 2012 (1)
  • September 2012 (3)
  • June 2012 (2)
  • May 2012 (1)
  • April 2012 (1)
  • December 2011 (2)
  • October 2011 (3)
  • September 2011 (1)
  • August 2011 (1)
  • July 2011 (1)
  • May 2011 (2)
  • April 2011 (2)
  • March 2011 (1)
  • February 2011 (1)
  • January 2011 (2)
  • December 2010 (3)
  • October 2010 (5)
  • September 2010 (1)
  • July 2010 (2)
  • May 2010 (5)
  • April 2010 (2)
  • March 2010 (7)
  • February 2010 (5)
  • January 2010 (5)
  • December 2009 (3)
  • November 2009 (1)
  • October 2009 (5)
  • September 2009 (5)
  • August 2009 (1)
  • July 2009 (1)
  • June 2009 (2)
  • May 2009 (6)
  • April 2009 (4)
  • March 2009 (2)
  • February 2009 (4)
  • January 2009 (1)
  • December 2008 (5)
  • November 2008 (2)
  • September 2008 (1)
  • August 2008 (6)
  • July 2008 (6)
  • June 2008 (9)
  • May 2008 (4)
  • April 2008 (3)
  • March 2008 (4)
  • February 2008 (9)
  • January 2008 (7)
  • December 2007 (6)
Copyright © 2021 Devon O. Wolfgang