I used AssetLoader to load mesh and animation data in sequence like below.
1. create new AssetLoader and listen AssetComplete event.
2. after loading mesh data completes, make mesh
3. make new AssetLoader instance to load animation data, and listen AssetComplete
then after animation data loaded, the first instance of AssetLoader catches AssetComplete event that should be dispatched second instance of AssetLoader.
So, it causes error at onMeshLoaded method.
Did i do something wrong?
class Model3DCache extends EventDispatcher
{
private var _modelURL:String;
private var _textureURL:String;
private var _animationURL:String;
private var _mesh:Mesh;
private var _controller:SmoothSkeletonAnimator;
public function Model3DCache(modelURL:String, textureURL:String, animationURL:String = null)
{
this._modelURL = modelURL;
this._textureURL = textureURL;
this._animationURL = animationURL;
// create first instance of AssetLoader, loading Mesh here.
var ldr:AssetLoader = new AssetLoader();
ldr.load(new URLRequest(this._modelURL));
ldr.addEventListener(AssetEvent.ASSET_COMPLETE, onMeshLoaded);
}
protected function onMeshLoaded(event:AssetEvent):void
{
trace('onMeshLoaded');
this._mesh = event.asset as Mesh;
this.setMaterial();
this.loadAnimation();
}
private function setMaterial():void
{
var mat:BitmapFileMaterial = new BitmapFileMaterial(this._textureURL);
this._mesh.material = mat;
}
private function loadAnimation():void
{
// create second instance of AssetLoader, loading Animation here.
var ldr:AssetLoader = new AssetLoader();
ldr.load(new URLRequest(this._animationURL));
ldr.addEventListener(AssetEvent.ASSET_COMPLETE, onAnimationLoaded);
}
protected function onAnimationLoaded(event:AssetEvent):void
{
var seq:SkeletonAnimationSequence = event.asset as SkeletonAnimationSequence;
seq.name = event.asset.assetNamespace;
_controller = new SmoothSkeletonAnimator(SkeletonAnimationState(this._mesh.animationState));
_controller.addSequence(seq);
_controller.play(seq.name);
}
}