• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 434
  • Last Modified:

AS3 pv3D unable to get my ReflectionView class to render

Please take a look at my code and tell me if you can see the problem with my ReflectionView rendering (or lack thereof).  I have posted my class with commented sections to the ReflectionView.  

Any thoughts?

Thanks!
0
cubical38
Asked:
cubical38
  • 3
  • 2
1 Solution
 
TanLiHaoCommented:
I see no code.
0
 
cubical38Author Commented:
Oops!  I have placed it below.  I am trying to use the papervision3D class ReflectionView which I have imported but alas I am not sure what to do next.

Thanks for the reply and the help!


package {
	import flash.events.Event;
	import br.com.stimuli.loading.BulkLoader;
	import br.com.stimuli.loading.BulkProgressEvent;
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormatAlign;
	import flash.text.AntiAliasType;

	import gs.easing.Quint;
	import gs.TweenLite;
	import org.papervision3d.events.InteractiveScene3DEvent;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.view.Viewport3D;
	import org.papervision3d.core.effects.view.ReflectionView;
	import org.papervision3d.materials.MovieMaterial;

	public class Main extends BasicView {
		protected var planes:Array=[];
		protected var images:Array=[];
		protected var numItems:Number;
		protected var currentItem:Number=3;
		protected var angle:Number=25;
		protected var rightBtn:Sprite;
		protected var leftBtn:Sprite;
		protected var xmlPath:String="xml/imageXML.xml";
		protected var bulkInstance:BulkLoader;
		private var carousel:DisplayObject3D=new DisplayObject3D  ;
		private var bitmapViewport:Viewport3D=new Viewport3D(940,300);

		private var view:ReflectionView;

		public function Main():void {
			super(940,300,true,true);

			addChild(bitmapViewport);
			bitmapViewport.interactive=true;
			loadXML();
		}

		//First load our XML
		protected function loadXML():void {
			bulkInstance=new BulkLoader("bulkInstance");
			bulkInstance.add(xmlPath);
			bulkInstance.addEventListener(BulkProgressEvent.COMPLETE,onXMLReady);
			bulkInstance.start();
		}

		//When our xml is ready parse and load our images
		protected function onXMLReady(evt:BulkProgressEvent):void {
			bulkInstance.removeEventListener(BulkProgressEvent.COMPLETE,onXMLReady);
			bulkInstance.addEventListener(BulkProgressEvent.COMPLETE,onImagesReady);

			var xml:XML=bulkInstance.getXML(xmlPath);
			var xmlList:XMLList=xml.image;

			for (var i:int=0; i<xmlList.length(); i++) {
				var imagePath:String=String(xmlList[i]);
				bulkInstance.add(imagePath);
				images.push(imagePath);
			}
			numItems=images.length;
		}
		protected function onImagesReady(evt:BulkProgressEvent):void {
			init();
		}
		protected function init():void {
			createChildren();
			startRendering();
		}
		protected function createChildren():void {
			for (var i:int=0; i<numItems; i++) {
				var mat:BitmapMaterial=new BitmapMaterial(bulkInstance.getBitmapData(images[i]));
				mat.interactive=true;
				mat.smooth=true;
				var plane:Plane=new Plane(mat,360,280);
				carousel.addChild(plane);
				plane.rotationY=360/numItems*i;
				plane.moveForward(900);
				planes.push(plane);

				//reflection should be implimented here///////////////////////////
				view=new ReflectionView(940,300,true,true);
				addChild(view);
				view.singleRender();


				var textMC:MovieClip=new MovieClip  ;
				var textField:TextField=new TextField  ;
				textField.wordWrap=true;
				textField.width=360;
				textField.height=280;
				textField.multiline=true;
				textField.text="Default Text Is the Default for the Text";
				textField.autoSize=TextFieldAutoSize.LEFT;
				textField.antiAliasType=AntiAliasType.ADVANCED;


				var textFormat:TextFormat=new TextFormat("Arial");
				textFormat.size=34;
				textFormat.color=0x000000;
				textFormat.bold=false;
				textField.setTextFormat(textFormat);
				//Create a rect the size of the MovieClip with an opacity of 0
				//This lets the TextField render properly
				textMC.graphics.beginFill(0x00ff00,0);
				textMC.graphics.drawRect(0,-400,360,280);
				textMC.graphics.endFill();
				textMC.addChild(textField);

				var tfMaterial:MovieMaterial=new MovieMaterial(textMC,true,false,true);
				tfMaterial.interactive=true;
				tfMaterial.smooth=true;
				tfMaterial.tiled=true;
				var tmpPlane:Plane=new Plane(tfMaterial,360,480);
				plane.addChild(tmpPlane);


				plane.id=i;
				plane.addEventListener(InteractiveScene3DEvent.OBJECT_OVER,onPlaneOver);
				plane.addEventListener(InteractiveScene3DEvent.OBJECT_OUT,onPlaneOut);
				plane.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,onPlaneClick);
				scene.addChild(carousel);
				startRendering();
			}
			camera.zoom=80;
		}


		protected function onPlaneOver(evt:InteractiveScene3DEvent):void {
			var plane:Plane=evt.target as Plane;
			trace("over");
		}
		protected function onPlaneOut(evt:InteractiveScene3DEvent):void {
			var plane:Plane=evt.target as Plane;
			trace("onPlaneOut");
		}
		protected function onPlaneClick(evt:InteractiveScene3DEvent):void {
			var plane:Plane=evt.target as Plane;
			trace("onPlaneClick");
		}

		override protected function onRenderTick(event:Event=null):void {
			carousel.rotationY-=viewport.containerSprite.mouseX/100;
			renderer.renderScene(scene,camera,bitmapViewport);
		}
	}
}

Open in new window

0
 
TanLiHaoCommented:
You are not doing it correctly.
 
 There are two ways which you can do this, one is changing your extending of BasicView to ReflectionView. The other is creating a new ReflectionView instance, however it may not work well due to the fact that you need scenes and you will thus have two scenes which are separate, this can cause some conflicts and trouble. Furthermore, ReflectionView extends BasicView so it makes sense to extend ReflectionView instead if you want reflections.

However, you may still not see the problems posed so I'm giving you a choice now and you can test it yourself, you will end up extending ReflectionView I assure you, unless you restructure your code, but that will be too much of a hassle such that extending ReflectionView is way easier.

Of course, it will be truly inefficient for me to write both types of code for you. Thus I have found a great tutorial for you on ReflectionView demonstrating subclassing as well as the instantiating method.

Link: http://tutorials.osbo.com/papervision3d/reflectionview/
0
 
cubical38Author Commented:
I have tried to follow the info on this link and alas I cnnot get any reflections.  What am I doing wrong?


package {
	import flash.events.Event;
	import br.com.stimuli.loading.BulkLoader;
	import br.com.stimuli.loading.BulkProgressEvent;
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.filters.GlowFilter;
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormatAlign;
	import flash.text.AntiAliasType;
	import flash.display.DisplayObject;
	import flash.net.navigateToURL;
	import flash.net.URLRequest;
	import flash.events.Event;
	import flash.filters.BlurFilter;


	import gs.easing.Quint;
	import gs.TweenLite;
	import org.papervision3d.events.InteractiveScene3DEvent;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.objects.DisplayObject3D;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.view.BasicView;
	import org.papervision3d.view.Viewport3D;
	import org.papervision3d.core.effects.view.ReflectionView;
	import org.papervision3d.materials.MovieMaterial;
	import org.papervision3d.utils.*;
	import org.papervision3d.core.math.Matrix3D;
	import org.papervision3d.core.math.Number3D;

	public class Main extends BasicView {
		protected var planes:Array=[];
		protected var images:Array=[];
		protected var numItems:Number;
		protected var currentItem:Number=3;
		protected var angle:Number=25;
		protected var rightBtn:Sprite;
		protected var leftBtn:Sprite;
		protected var xmlPath:String="xml/imageXml.xml";
		protected var bulkInstance:BulkLoader;
		private var carousel:DisplayObject3D=new DisplayObject3D  ;
		private var bitmapViewport:Viewport3D=new Viewport3D(940,300);
		private var xml:XML;
		private var xmlList:XMLList;
		private var view:ReflectionView;



		public function Main():void {
			super(940,300,true,true,"Target");
			buttonMode=true;
			addChild(bitmapViewport);
			bitmapViewport.interactive=true;
			loadXML();

		}

		//First load our XML
		protected function loadXML():void {
			bulkInstance=new BulkLoader("bulkInstance");

			bulkInstance.add(xmlPath,{type:"xml"});
			bulkInstance.addEventListener(BulkProgressEvent.COMPLETE,onXMLReady);
			bulkInstance.start();
		}

		//When our xml is ready parse and load our images
		protected function onXMLReady(evt:BulkProgressEvent):void {
			bulkInstance.removeEventListener(BulkProgressEvent.COMPLETE,onXMLReady);
			bulkInstance.addEventListener(BulkProgressEvent.COMPLETE,onImagesReady);

			//var xml:XML=bulkInstance.getXML(xmlPath);
			//var xmlList:XMLList=xml.image;
			xml=bulkInstance.getXML(xmlPath);
			xmlList=xml.image;
			for (var i:int=0; i<xmlList.length(); i++) {
				var imagePath:String=String(xmlList[i].pic);
				//var textPath:String=String(xmlList[i].copy);
				bulkInstance.add(imagePath);
				images.push(imagePath);
				//images.push(textPath);
				//trace("xmlList[i].pic = " + xmlList[i].pic);
				//trace("xmlList[i].copy = " + xmlList[i].copy);

			}
			numItems=images.length;
		}
		protected function onImagesReady(evt:BulkProgressEvent):void {
			init();
		}
		protected function init():void {
			createChildren();
			startRendering();

		}
		protected function createChildren():void {
			for (var i:int=0; i<numItems; i++) {
				var mat:BitmapMaterial=new BitmapMaterial(bulkInstance.getBitmapData(images[i]));

				mat.interactive=true;
				mat.smooth=true;
				var plane:Plane=new Plane(mat,360,280);
				carousel.addChild(plane);
				plane.rotationY=360/numItems*i;
				plane.moveForward(900);
				planes.push(plane);

				//reflection should be implimented here///////////////////////////
				view=new ReflectionView(940,300,true,true,"FREE");
				addChild(view);
				view.viewportReflection.filters=[new BlurFilter(0,0,3)];
				addEventListener(Event.ENTER_FRAME, enterFrameHandler);

				var textMC:MovieClip=new MovieClip  ;
				var textField:TextField=new TextField  ;
				textField.wordWrap=true;
				textField.width=400;
				textField.height=280;
				textField.multiline=true;
				//textField.text="This is only some sample text This is only some sample text";
				textField.htmlText=xmlList[i].copy;
				textField.autoSize=TextFieldAutoSize.LEFT;
				textField.antiAliasType=AntiAliasType.ADVANCED;



				var textFormat:TextFormat=new TextFormat("Arial");
				textFormat.size=30;
				textFormat.color=0xffffff;
				textFormat.bold=false;
				textFormat.align="center";
				textMC.defaultTextFormat=textFormat;
				textField.setTextFormat(textFormat);
				//Create a rect the size of the MovieClip with an opacity of 0
				//This lets the TextField render properly
				textMC.graphics.beginFill(0x00ff00,0);
				textMC.graphics.drawRect(0,190,360,80);
				textMC.graphics.endFill();
				textMC.addChild(textField);

				var tfMaterial:MovieMaterial=new MovieMaterial(textMC,true,false,true);
				tfMaterial.interactive=true;
				tfMaterial.smooth=true;
				tfMaterial.tiled=true;
				var tmpPlane:Plane=new Plane(tfMaterial,400,380);
				tmpPlane.y=-360;
				plane.addChild(tmpPlane);


				plane.id=i;
				plane.addEventListener(InteractiveScene3DEvent.OBJECT_OVER,onPlaneOver);
				plane.addEventListener(InteractiveScene3DEvent.OBJECT_OUT,onPlaneOut);
				plane.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS,onPlaneClick);
				/*plane.addEventListener(MouseEvent.MOUSE_OVER,onPlaneOver);
				plane.addEventListener(MouseEvent.MOUSE_OUT,onPlaneOut);
				plane.addEventListener(MouseEvent.CLICK,onPlaneClick);*/
				scene.addChild(carousel);
				function enterFrameHandler(e:Event):void {
					view.singleRender();
				}
				function onPlaneOver(evt:InteractiveScene3DEvent):void {
					var plane:Plane=evt.target as Plane;

					/*var distance:Number=200;
					var BACKWARD:Number3D=new Number3D(0,0,-1);
					
					Matrix3D.rotateAxis(plane.transform, BACKWARD);
					
					var target:Number3D = new Number3D();
					target.x=distance*BACKWARD.x+plane.x;
					target.y=distance*BACKWARD.y+plane.y;
					target.z=distance*BACKWARD.z+plane.z;
					
					TweenLite.killTweensOf(plane, true);
					
					TweenLite.to(plane, 1, {x:target.x, y:target.y, z:target.z});
					trace("over");*/
				}
				function onPlaneOut(evt:InteractiveScene3DEvent):void {
					var plane:Plane=evt.target as Plane;

					/*var distance:Number=200;
					var FORWARD:Number3D=new Number3D(0,0,1);
					
					Matrix3D.rotateAxis(plane.transform, FORWARD);
					
					var target:Number3D = new Number3D();
					target.x=distance*FORWARD.x+plane.x;
					target.y=distance*FORWARD.y+plane.y;
					target.z=distance*FORWARD.z+plane.z;
					
					TweenLite.killTweensOf(plane, true);
					
					TweenLite.to(plane, 1, {x:target.x, y:target.y, z:target.z});
					trace("onPlaneOut");*/
				}
				function onPlaneClick(evt:InteractiveScene3DEvent):void {
					var plane:Plane=evt.target as Plane;
					trace("xmlList[i].url = " + xmlList[plane.id].url);
					navigateToURL(new URLRequest(xmlList[plane.id].url), "_self");
					trace("onPlaneClick");

				}

			}
			camera.zoom=80;
		}
		override protected function onRenderTick(event:Event=null):void {
			renderer.renderScene(scene,camera,bitmapViewport);
			if (stage.mouseX>=1240||stage.mouseX<=-300) {
				carousel.rotationY=0;
				trace("off the stage");
			} else if (stage.mouseX<=940||stage.mouseX>=0) {
				carousel.rotationY-=viewport.containerSprite.mouseX/400;
			}
			trace(stage.mouseX);
		}
	}
}

Open in new window

0
 
cubical38Author Commented:
I went a little different way but was able to get it working.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now