Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Loading 3d Model with Away3d

    • 0
    • 7
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1.16k
    Comment on it

    When working with Away3D youll eventually need to load a complex model. The code for loading a 3D model into Away3D is fairly easy. It is almost as simple as loading a plane, cube, or cone. this code is about loading a 3d stadium.

    1.Load your Model

    var loader3D:Loader3D = new Loader3D();
    loader3D.load(new URLRequest("assets/stadium.md5mesh"));            
    loader3D.addEventListener(AssetEvent.ASSET_COMPLETE, onLoadComplete);
    

    2.Handle the load success

    And here goes the full code

    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Loader;
    import flash.display.LoaderInfo;
    import flash.events.Event;
    import flash.net.URLRequest;
    import com.track.event.ModelEvent;
    
    public class ModelHandler
    {
        private var _mesh:Mesh;
        public function ModelHandler()
        {
                    super();
            }
        public function loadModel(name:String, path:String=""):void// called from manager
        {
            trace("loading model");
            Loader3D.enableParser(MD5MeshParser);
            var loader3D:Loader3D = new Loader3D();
            loader3D.addEventListener(AssetEvent.ASSET_COMPLETE, onLoadComplete);
            loader3D.load(new URLRequest("assets/stadium.md5mesh"));
        }
    
    
        private function onLoadComplete(evt:AssetEvent):void
        {
            if (evt.asset.assetType == AssetType.MESH) 
            {
                trace("loaded model");
                _mesh = evt.asset as Mesh;
    
                loadMaterial();
            }
        }
    
        private function loadMaterial():void
        {
            trace("loading material");
            var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, materialLoaded);
            loader.load(new URLRequest("assets/Stadium_Diff.jpg"));
        }
    
        private function materialLoaded(evt:Event):void
        {
            trace("loaded material");
            var bitmapData:BitmapData = Bitmap(LoaderInfo(evt.target).content).bitmapData;
            _mesh.material = new TextureMaterial(new BitmapTexture(bitmapData));
    
    
        }
    }
    

    }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: