Plane with two different sides

Tuesday, December 2nd, 2008 | examples

Create two planes, rotate the back plane 180 degrees, then group them together in a parent DisplayObject3D.


source

package {
	import flash.display.Bitmap;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
 
	import org.papervision3d.events.InteractiveScene3DEvent;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.materials.MovieMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;
 
	[SWF(width="640", height="480", frameRate="60", backgroundColor="#000000")]
	public class TwoSidedPlane extends BasicView 
	{
		[Embed(source="assets/fish.jpg")]
		public var fishAsset:Class;
 
		private var planeGroup:DisplayObject3D;
 
		private var planeFront:Plane;
		private var planeBack:Plane;
 
		private var fishMaterial:BitmapMaterial;
 
		private var movieMaterial:MovieMaterial;
		private var textField:TextField;
 
		public function TwoSidedPlane()
		{
			viewport.interactive = true;
			camera.zoom = 100;
 
			//this will hold both your planes in a group
			planeGroup = new DisplayObject3D();
 
			//standard way to grab bitmap from embedded image
			var fishBitmap:Bitmap = new fishAsset() as Bitmap;
			fishMaterial = new BitmapMaterial(fishBitmap.bitmapData, true);
 
			planeFront = new Plane(fishMaterial);
 
			//a simple movieclip to hold our text field
			var movieClip:MovieClip = new MovieClip();
			movieClip.graphics.lineStyle(5,0xcc0000);
			movieClip.graphics.drawRect(0,0,300,270);
 
			//text field and formatting junk
			textField = new TextField();
			var textFormat:TextFormat = new TextFormat("Arial");
			textFormat.size = 34;
			textFormat.color = 0xcc0000;
 
			textField.autoSize = TextFieldAutoSize.LEFT;
			textField.defaultTextFormat = textFormat;
			textField.text = "default";
 
			movieClip.addChild(textField);
 
			movieMaterial = new MovieMaterial(movieClip, true, true, true);
			//smooth out the text
			movieMaterial.smooth = true;
			movieMaterial.interactive = true;
 
			planeBack = new Plane(movieMaterial);
 
			planeBack.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, objectOverHandler);
			planeBack.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, objectOutHandler);
 
 
			planeGroup.addChild(planeFront);
			/*rotate the plane in the "back" so it looks like the
			back side of the front*/
			planeBack.rotationY = 180;
			planeGroup.addChild(planeBack);
 
			scene.addChild(planeGroup);
 
			startRendering();
		}
 
		private function objectOverHandler(e:InteractiveScene3DEvent):void
		{
			textField.text = "That tickles!";
			viewport.buttonMode = true;
		}
 
		private function objectOutHandler(e:InteractiveScene3DEvent):void
		{
			textField.text = "I'm lonely!";
			viewport.buttonMode = false;
		}
 
		override protected function onRenderTick(event:Event=null):void
		{
			planeGroup.yaw(1);
			renderer.renderScene(scene, camera, viewport);
		}
	}
}

Tags: , ,

  • mike

    now say you wanted to get rid of the Plane specific rollover and just trigger a rollover for the entire object. how would you do this.

    basically i have created a cube using 6 separate planes and placed them inside of a display object. i cant figure out for the life of me how to trigger a mousevent on the displayobject as a whole.

    any ideas?

  • Does this perform better than just creating a cube?

  • baixiaozhe

    good, Thank!
    Now,i know how to draw Material by myself.

blog comments powered by Disqus

Search

Recommended Books

Speaking at FITC Toronto

 

December 2008
M T W T F S S
« Nov   Jan »
1234567
891011121314
15161718192021
22232425262728
293031  

Preferred Video Tutorial Resolution

  • 1024x768 (53%, 85 Votes)
  • 1280x1024 (15%, 24 Votes)
  • 1920x1080 (15%, 24 Votes)
  • 800x600 (13%, 20 Votes)
  • 480x320 (4%, 6 Votes)
  • 640x480 (0%, 2 Votes)

Total Voters: 160

Loading ... Loading ...