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)