[转] [Flash/Flex] 支持 Molehill版本的Flare3D 应用示范

http://bbs.9ria.com/thread-79532-1-1.html


我已经看到很多使用Away3D新版本创建的Molehill 3D范例。但是还有很多其他的3D引擎也将支持Molehill啊。Flare3D就挺好,他们也发布了一个支持Molehill的预览版。这个引擎基于Argentina。下面的范例演示了如何动态加载位图到3D planes模型。它用到了TwitPic API。你输入Twitter ID,它会以3D显示显示这些照片。点击下面的图片来观看范例,再下面是源代码。

  
 public class MoleTest extends Sprite
    {
       
        private var scene:Scene3D;
        private var planes:Vector.<Plane> = new Vector.<Plane>();
        private var shaders:Vector.<Shader3D> = new Vector.<Shader3D>();
        private var numOfImages:int;
        private var txt:Text;
        private var images:XMLList;
       
        public function MoleTest()
        {
            Security.allowDomain("s3.amazonaws.com");
            Security.loadPolicyFile("s3.amazonaws.com/crossdomain.xml");
            var it:InputText = new InputText(this, 50, 50, "leebrimelow");
            it.setSize(130, 20);
            addChild(it);
            var butt:PushButton = new PushButton(this, 200, 50, "Submit", function():void {
                getPics(it.text);  
                removeChild(butt);
                removeChild(it);
            });
            addChild(butt);
        }
       
        private function setup3D():void
        {
            txt = new Text(this,375,280,"LOADING");
            txt.setSize(50, 20);
            addChild(txt);
            scene = new Scene3D(this);
            scene.addEventListener(Scene3D.COMPLETE_EVENT, completeEvent);
            scene.addEventListener(Scene3D.UPDATE_EVENT, updateEvent);
            scene.camera.setPosition(0, 0, -1500);
           
            for(var i:int=0; i<numOfImages; i++)
            {
                var texture0:Texture3D = scene.addTextureFromFile("http://twitpic.com/show/full/"+images[i].short_id);
                shaders[i] = new Shader3D("shader"+i);
                shaders[i].twoSided = true;
                shaders[i].layers.push(new TextureMapLayer(texture0));
                shaders[i].build();
                planes[i] = new Plane("plane"+i, images[i].width, images[i].height);
                scene.addChild(planes[i]);
            }
        }
       
        private function completeEvent(e:Event):void
        {
            removeChild(txt);
            for(var i:int=0; i<numOfImages; i++)
            {
                planes[i].setMaterial(shaders[i]);
                planes[i].x = Math.random()*2000-1000;
                planes[i].y = Math.random()*2000-1000;
                planes[i].z = Math.random()*2000-1000;
            }
        }
       
        private function getPics(tname:String):void
        {
            var loader:URLLoader = new URLLoader();
            loader.addEventListener(Event.COMPLETE, function(e:Event):void {
                var xml:XML = XML(loader.data);
                images = xml.images.image;     
                numOfImages = images.length();
                setup3D();
            });
            try {
                // TwitPic has no cross-domain file so you will need to proxy it
                loader.load(new URLRequest(YOUR_PHP_PROXY_SCRIPT));
            }
            catch(e:Error) {
                trace(e.message);
            }
        }
       
        private function updateEvent(e:Event):void
        {
            if ( Input3D.mouseDown )
            {
                scene.camera.rotateY(Input3D.mouseXSpeed, false, Vector3DUtils.ZERO );
                scene.camera.rotateX(Input3D.mouseYSpeed, true, Vector3DUtils.ZERO );
            }
           
            scene.camera.translateZ( scene.camera.getPosition().length * Input3D.delta / 20 );
           
            scene.defaultLight.rotateY( 2 );
        }
    }

你可能感兴趣的:(xml,Flex,Security,Flash,twitter)