Jump to content

[solved] Problems with material of a cloned mesh loaded with obj loader


Janx
 Share

Recommended Posts

Hi,

I want to clone meshes that I load with the obj loader. The problem seems to be that the material is assigned somewhat later, so when I clone the mesh directly in the callback from the SceneLoader.ImportMesh function, it has no material. If I make another clone from the very same instance some time later, it has material. For example this would lead to no material in the clone:

BABYLON.SceneLoader.ImportMesh("", this.serverUrl, encodeURIComponent(fileName + ".obj"),
  this.scene, (mesh) => {
    meshContainer = mesh.clone(name, undefined, false);
    resolve(meshContainer);
  }

while this would:

BABYLON.SceneLoader.ImportMesh("", this.serverUrl, encodeURIComponent(fileName + ".obj"),
  this.scene, (mesh) => {
    setTimeout(() => {
      meshContainer = mesh.clone(name, undefined, false);
      resolve(meshContainer);
    }, 100);
  }

(It is wrapped inside a Promise)

Is this an expected behaviour? Is it possible to get the callback when everything is loaded completely?

Many thanks,
Cheers,
janx

Edited by Janx
solved
Link to comment
Share on other sites

I get the same thing. If I apply a material after the first completion callback, those  materials are overwritten with blender materials, if the materials were exported from blender. I have seen other posts where people were waiting for second callback, but I was only getting one and materials were not ready.

Link to comment
Share on other sites

Try putting your code in scene.executeWhenReady

BABYLON.SceneLoader.ImportMesh("", this.serverUrl, encodeURIComponent(fileName + ".obj"), this.scene, (mesh) => {
    scene.executeWhenReady( function() {
        meshContainer = mesh.clone(name, undefined, false);
        resolve(meshContainer);
    });
});

(code needs to be adapted to be able to reach scene, mesh, etc)

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...