Study/Actionscript 3.02010. 7. 4. 22:25
http://blurryborder.com/lab/Carousel3D/src/Main.as

package  
{
	
	import flash.display.*;
	import org.papervision3d.core.geom.renderables.Line3D;
	import org.papervision3d.core.geom.renderables.Vertex3D;
	
	import flash.events.*;
	import flash.net.URLRequest;
	import flash.net.URLLoader;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.filters.BlurFilter;
	
	import org.flashdevelop.utils.FlashConnect;
	
	import org.papervision3d.scenes.*;
	import org.papervision3d.cameras.*;
	import org.papervision3d.objects.*;
	import org.papervision3d.objects.special.*;
	import org.papervision3d.objects.primitives.*;
	import org.papervision3d.materials.*;
	import org.papervision3d.materials.special.*;
	import org.papervision3d.materials.shaders.*;
	import org.papervision3d.materials.utils.*;
	import org.papervision3d.lights.*;
	import org.papervision3d.render.*;
	import org.papervision3d.view.*;
	import org.papervision3d.events.*;
	import org.papervision3d.core.utils.*;
	import org.papervision3d.core.geom.Lines3D;
	import org.papervision3d.core.geom.renderables.Vertex3D;
	import org.papervision3d.core.geom.renderables.Line3D;
	import org.papervision3d.core.utils.virtualmouse.VirtualMouse;
	
	import ascensionsystems.mirror.reflect;
	
	public class Main extends Sprite
	{
		private var thumbTemp:Sprite;
		public var itemTotal:Number;
		private var centerGraph:Item;
		public var r:Number = 200;
		private var lines3D:Lines3D;
		private var objectContainer:DisplayObject3D;
		//------------------------------------------------
		private var v0:Vertex3D;
		private var skin2:LineMaterial;
		private var lines3D2:Lines3D;
		//------------------------------------------------
		private var viewport:Viewport3D;
		private var renderer:BasicRenderEngine;
		public var scene:Scene3D;
		private var camera:Camera3D;
		//------------------------------------------------
		public var planeArr:Array=new Array();
		public var itemArr:Array = new Array();
		//------------------------------------------------
		private var title_txt:TextField;
		private var desc_txt:TextField;
		
		public function Main() 
		{
			thumbTemp = new Sprite();
			thumbTemp.blendMode = BlendMode.ERASE;
			this.addChild(thumbTemp);
			loadXML();
			
			init3D()
		}
		private function loadXML():void
		{
			
			var xmlLoader:URLLoader = new URLLoader();
			xmlLoader.addEventListener(Event.COMPLETE, onXmlLoaded);
			xmlLoader.load(new URLRequest('content.xml'));
		}
		private function onXmlLoaded(e:Event):void
		{
			var xml:XML = new XML(e.target.data);
			centerGraph = new Item( -1, unescape(xml.attribute('title').replace(/\+/g, " ")), xml.attribute('url'), unescape(xml.attribute('desc').replace(/\+/g, " ")), 0, false);
			thumbTemp.addChild(centerGraph);
			var il:XMLList = xml.image;
			itemTotal = il.length();
			for (var i:uint = 0; i < il.length(); i++)
			{
				var theItem:Item = new Item(i, unescape(il[i].attribute('title').replace(/\+/g, " ")), il[i].attribute('url'), unescape(il[i].attribute('desc').replace(/\+/g, " ")), i+1, true);
				thumbTemp.addChild(theItem);
				itemArr.push(theItem);
			}
		}
		private function init3D():void
		{
			FlashConnect.trace("-----init Papervision3D-----");
			viewport=new Viewport3D(0, 0, true, true);
			addChild(viewport);
			viewport.buttonMode = true;
			renderer=new BasicRenderEngine();
			scene = new Scene3D();
			
			objectContainer = new DisplayObject3D();
			objectContainer.rotationX = -90;
			objectContainer.y = -170;
			scene.addChild(objectContainer);
			
			v0 = new Vertex3D(0, 0, 0);
			skin2= new LineMaterial(0x6593b5, .2);
			lines3D2= new Lines3D(skin2);
			objectContainer.addChild(lines3D2);
			
			camera = new Camera3D();
			
			camera.zoom = 10;
			camera.focus = 100;
			
			//drawAxis();
			this.addEventListener(Event.ENTER_FRAME, render);
			
		}
		public function create3DPlane(mc:MovieClip, angle:Number):void
		{
			var mam:MovieMaterial = new MovieMaterial(mc, true, true, true);
			mam.interactive = true;
			mam.smooth = true;
			mam.oneSide = false;
			mam.movieTransparent = true;
			var p:Plane = new Plane(mam, mc.width, mc.height, 4, 4);
			p.rotationX = 90;
			p.x = Math.round(r * Math.cos(angle));
			p.y = Math.round(r * Math.sin(angle));
			FlashConnect.trace('('+p.x+' , '+p.y+')');
			objectContainer.addChild(p);
			planeArr.push(p);
			
			//drawLineFromCenter(new Vertex3D(p.x, p.y, p.z));
			
		}
		public function createCenterGraph(mc:MovieClip):void 
		{
			FlashConnect.trace('create center graphe'+mc);
			var mam:MovieMaterial = new MovieMaterial(mc, true, true, true);
			mam.interactive = true;
			mam.smooth = true;
			mam.oneSide = false;
			mam.movieTransparent = true;
			var p:Plane = new Plane(mam, mc.width, mc.height, 4, 4);
			p.y = -190;
			scene.addChild(p);
		}
		//-------------------------------text----------------------------------
		public function showMainTitle(txt:String):void 
		{
			
			title_txt = new TextField();
			addChild(title_txt);
			title_txt.text = txt;
			title_txt.width = 300;
			title_txt.autoSize = 'center';
			FlashConnect.trace('title width:' + title_txt.width);
			if (title_txt.width > 300)
			{
				title_txt.width = 300;
				title_txt.multiline = true;
				title_txt.wordWrap = true;
			}
			title_txt.x = (stage.stageWidth-title_txt.width)/2;
			title_txt.y = 10;
			
			title_txt.selectable = false;
			title_txt.antiAliasType = 'advanced';
			var titleFormat:TextFormat = new TextFormat();   
			titleFormat.color = 0xacced9;    
			titleFormat.size = 18;
			titleFormat.font = 'Century';
			title_txt.setTextFormat(titleFormat);  
		}
		public function showMainDesc(txt:String):void 
		{
			desc_txt = new TextField();
			addChild(desc_txt);
			desc_txt.width = title_txt.width;
			desc_txt.height = 100;
			desc_txt.x = (stage.stageWidth-desc_txt.width)/2;
			desc_txt.y = title_txt.y+title_txt.height+5;
			desc_txt.text = txt;
			desc_txt.selectable = true;
			desc_txt.multiline = true;
			desc_txt.wordWrap = true;
			//desc_txt.antiAliasType = 'advanced';
			var descFormat:TextFormat = new TextFormat();   
			descFormat.color = 0xacced9;    
			descFormat.size = 10;
			descFormat.font = 'Arial';
			desc_txt.setTextFormat(descFormat);  
		}
		
		//-------------------------------utils----------------------------------
		private function render(e:Event):void{
			renderer.renderScene(scene, camera, viewport);
			objectContainer.rotationY += 1;
			for (var i:uint = 0; i < planeArr.length; i++)
			{
				planeArr[i].rotationZ = -objectContainer.rotationY;
			}
		}
		public function stopRotate():void
		{
			this.removeEventListener('enterFrame', render);
		}
		public function startRotate():void
		{
			this.addEventListener('enterFrame', render);
		}
		private function drawAxis():void
		{
			var v1:Vertex3D = new Vertex3D(0, 50, 0);
			var v2:Vertex3D = new Vertex3D(20, 0, 0);
			var v3:Vertex3D = new Vertex3D(0, -50, 0);
			var v4:Vertex3D = new Vertex3D(-20, 0, 0);
			var v5:Vertex3D = new Vertex3D(0, 0, 100);
			var v6:Vertex3D = new Vertex3D(0, 0, -100);
			var skin1:LineMaterial = new LineMaterial(0x000000, .5);
			var lines3D:Lines3D = new Lines3D(skin1);
			var l1:Line3D = new Line3D(lines3D, skin1, 1, v1, v3) ;
			var l2:Line3D = new Line3D(lines3D, skin1, 1, v2, v4) ;
			var l3:Line3D = new Line3D(lines3D, skin1, 3, v5, v6) ;
			lines3D.addLine(l1);
			lines3D.addLine(l2);
			lines3D.addLine(l3);
			scene.addChild(lines3D);
		}
		private function drawLineFromCenter(p:Vertex3D):void
		{
			var v:Vertex3D = new Vertex3D(p.x, p.y, p.z);
			var l1:Line3D = new Line3D(lines3D2, skin2, 1, v0, v);
			lines3D2.addLine(l1);
		}
		public function reflectMc(mc:MovieClip): void
		{
			var myReflection:reflect = new reflect();
			myReflection.constructReflection(mc, .3, 20, 70, -10);
		}
	}
}
	
Posted by chacolina