I have two programs that load the same .obj file in an identical way yet in one program the assetType returned is Geometry with a name set to null and no further processing (so no mesh). In the other program the assetType is [asset Geometry] at first but then a second event (not triggered by me) occurs and the assetType on that second event is [asset Mesh]. Network traffic in the browser shows that the .obj file itself has been properly loaded in both case.
Any idea why would that be? I am attaching some snippets of code here:
Both programs initiate the .obj asset loading in that way:
this.token = AssetLibrary.load(new URLRequest('_assets/tile.obj'));
this.token.addEventListener(LoaderEvent.RESOURCE_COMPLETE, (event:LoaderEvent) => this.onResourceComplete(event));
onResourceComplete() function of broken program:
private onResourceComplete(event:LoaderEvent)
{
var loader:AssetLoader = <AssetLoader> event.target;
var l:number = loader.baseDependency.assets.length;
console.log( 'away.events.LoaderEvent.RESOURCE_COMPLETE' , event , l, loader );
for (var i:number = 0; i < l; i++) {
var asset:IAsset = loader.baseDependency.assets[i];
console.log("assetType:", asset.assetType, "name:", asset.name, "url:", event.url);
console.log("Mesh.assetType is ", Mesh.assetType);
switch (asset.assetType) {
case Mesh.assetType:
//That case never gets triggered? but it does in the other program that works?
if (event.url =='_assets/tile.obj') {
this._tileMesh = <Mesh> asset;
//some code removed for brievety sake here
}
break;
case TextureBase.assetType :
//unrelated and properly working code here has been removed for brievety sake
break;
}
}
}
onResourceComplete() function of working program:
public onResourceComplete(event:LoaderEvent) { //that is taken from one the example program that I simplified a bit
var loader:AssetLoader = <AssetLoader> event.target;
var l:number = loader.baseDependency.assets.length;
console.log('away.events.LoaderEvent.RESOURCE_COMPLETE', event, l, loader);
for (var c:number = 0; c < l; c++) {
var asset:IAsset = loader.baseDependency.assets[c];
console.log("assetType:", asset.assetType, "name:", asset.name, "url:", event.url);
switch (asset.assetType) {
case Mesh.assetType:
//That case gets triggered in that program
if (event.url == '_assets/tile.obj') {
var mesh:Mesh = <Mesh> asset;
//some code removed for brievety sake here
}
break;
case TextureBase.assetType :
//unrelated and properly working code here has been removed for brievety sake
break;
}
}
if (this.mat && this.spartanFlag)
for (var c:number = 0; c < this.meshes.length; c++)
this.meshes[c].material = this.mat;
this.view.scene.addChild(this.doc);
}