Jump to content

Load GLTF Mesh from Scene


Recommended Posts



is it actually possible to load a gltf mesh in to Babylon?


I noticed that gltf mesh loading is not working so far, but isnt it possible to add a loaded mesh from scene A to scene B like with the code below?

            BABYLON.SceneLoader.Load("./assets/", "character.gltf", this.engine, function (gltf) {                myotherscene.addMesh(gltf.meshes[0])            });

Actually this is resulting in to a freezed screen...  Am I doing something wrong here or is this just not supported?





Link to comment
Share on other sites

Hi hen,

A mesh belongs to a certain scene and I'm not sure what the consequences are, if you add it to another. I guess you just found out :-)

There are two ways to solve this -

Use the append function, instead of load. This function accepts a scene as a variable, instead of the engine. It will load the objects to this scene, instead of creating a new one.

The second option is to use the mesh's clone function. You could clone it to another scene.

BTW - I am assuming here that the loader is working correctly. You could have the same question for any other file type.

Link to comment
Share on other sites

Hi RaananW,


the append function works actually to load the asset, but it seems that theres no way to track what has been loaded, such as mesh IDs, materials etc...


Using sceneloader.load i did add a loop over the loaded meshes, cloned each and added it to the scene using scene.addMesh(mesh), but this ends up with a freezed screen.


Maybe i need to clone the bones separately?

Link to comment
Share on other sites

scene.addMesh won't probably be enough. the mesh has a private scene reference.

This won't be as easy as I thought. You will need to add the materials, geometries, skeletons etc' to the new scene as well. 


I really think the append function (or the ImportMesh, which can import specific meshes) would be the safest choice. You can use tags, and add a tag to any object that was already processed by you. Then scan the scene for meshes / other nodes that don't have this tag. This way you can easily tell what was appended.

Link to comment
Share on other sites

Hi Luaacro,


yes the loader works well when I append the whole scene, even with more complicated animated meshes.


The application i work on allows collaborative editing of the game levels. To make this work right with gltf, i would need somehow to set the IDs to the meshes.


Actually i dont need to load all content from gltf. Could i maybe clone the geometry and skeleton to create a new mesh in that other scene?



Another question is about attaching skinned mesh props to a skeleton.

Ive seen a demo about bone attachments, but is that working for skinned meshes like character clothings as well?

Link to comment
Share on other sites

Thanks for updating the loader!


Actually I still have problems using it, maybe its because im using the babylon alpha?

The code below is freezing the scene and causes a browser crash.

BABYLON.SceneLoader.ImportMesh(null, "./assets/", "man.gltf", this.scene, function (meshes, particleSystems, skeletons) {            console.log(meshes, skeletons)  // never reached        });
Link to comment
Share on other sites

Thanks hen for the model

I think it is related to the camera view (badly set by the loader or badly set in the file). I'm taking a look on it.


I used this workflow to test your 3D model (created my own camera instead of the one in the glTF file)

var scene = new BABYLON.Scene(engine);var camera = new BABYLON.ArcRotateCamera("camera", 0, 0, 20, BABYLON.Vector3.Zero(), scene);camera.attachControl(canvas);BABYLON.SceneLoader.ImportMesh(null, "Tests/glTF/", "man.gltf", scene, function (meshes) {    camera.target = meshes[0];});
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.

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.


  • Recently Browsing   0 members

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