Using a Viewport as a Mask

Sunday, December 7th, 2008 | examples


source

package
{
	import flash.display.Bitmap;
	import flash.events.Event;
 
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;
 
	[SWF(width="640", height="480", backgroundColor="#000000", frameRate="60")]
	public class ViewportAsMask extends BasicView
	{
		[Embed(source="assets/rover.jpg")]
		private var roverAsset:Class;
		private var rover:Bitmap;
		private var plane:Plane;
 
		public function ViewportAsMask()
		{
			rover = new roverAsset() as Bitmap;
			rover.mask = viewport;
			addChild(rover);
 
			var colorMaterial:ColorMaterial = new ColorMaterial(0xffffff);
			plane = new Plane(colorMaterial);
			plane.z = -500;
 
			scene.addChild(plane);
			startRendering();
		}
 
		override protected function onRenderTick(event:Event=null):void
		{
			plane.moveForward(500);
			plane.rotationY = -viewport.containerSprite.mouseX / 320 * 90;
			plane.moveBackward(500);			
 
			renderer.renderScene(scene, camera, viewport);
		}
	}
}

Tags: ,

4 Comments to Using a Viewport as a Mask

Marcus
March 14, 2009

Is there an easy way to use masks inside of a 3D Scene? Like using a plane as mask? I’d like to use FLARToolKit and the marker shape should become a window.. like in the example of “General Electrics’ Smart Grid” and I don’t know how to do it :(

Bakedbeing
April 17, 2009

I’m trying to achieve that too, Marcus. I’m remembering an AR demo with some tanks driving out of a hole in the wall.

Marcus
April 26, 2009

Hey guys, Saqoosha posted a simple example on how to make a hole on his blog:
http://saqoosha.net/en/2009/01/08/1676/

John
May 20, 2009

Thanks Marcus!

That’s so funny, I was googeling for the exact same thing as you guys. Scary to stumble upon some other people that are all experimenting with FLAR toolkit, in a non related article.
Gotta love the internet!

Cheers!

Leave a comment