Jump to content

addMeshTask calls onSuccess but loadedMeshes is empty.


Zephos
 Share

Recommended Posts

Hi all,

EDIT: Issue solved. See bottom of post.

I am trying to use assetManager and everything seems to be fine but the onSuccess callback is called and passed a task object that has no meshes in loadedMeshes. Here is the relevant code:

export default class GameAssetManager{

    constructor(gameManager, gamePackage){
        this.initialized = false;
        this.gameManager = gameManager;
        this.assetScene = gameManager.gameDisplay.scene;//new BABYLON.Scene(gameManager.gameDisplay.engine);
        this.assetsManager = new BABYLON.AssetsManager(this.assetScene);
        this.gamePackage = gamePackage;
        this.baseMeshesForCloning = {};
        this.gamePackage.fleets.forEach((fleet)=> {fleet.forEach((ship)=>{this.baseMeshesForCloning[ship.shipSpec.mesh.meshID] = ship.shipSpec.mesh; })});
        
        
    }    

initialize(){

        this.GetAllMeshesForCloning();
        this.assetsManager.load();
    }

GetAllMeshesForCloning(){

        for (const key of Object.keys(this.baseMeshesForCloning)) {

            let mesh = this.baseMeshesForCloning[key];

            //load in mesh from specified root and filename.
            let task = this.assetsManager.addMeshTask("mesh_" + mesh.meshID, mesh.meshID, mesh.directory, mesh.filename );
            task.onSuccess = function(task) { mesh["mesh"] = task.loadedMeshes[0]; }
            task.onError = function (task, message, exception) {
                console.log(message, exception);
            }

            var textTask = this.assetsManager.addTextFileTask("text task", "build/msg.txt");
            textTask.onSuccess = function(task) {
                console.log(task.text);
            }

        }
    }
)

 

The odd part is that in my network tab in dev tools the obj files are loaded successfully and the addTextFileTask works fine. The loadedMeshes array is just empty for some odd reason.

The files I am loading are here:

https://raw.githubusercontent.com/WriterZephos/files/master/Fighter.obj

https://raw.githubusercontent.com/WriterZephos/files/master/Fighter.mtl

 

Any help would be greatly appreciated.

 

EDIT: I solved the issue! I didn't realize what the meshNames argument was... though it was just giving a name to the mesh or something, but it was actually looking for a mesh by that name! Wow I am such a noob at this.

 

Thanks.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...