Combined all meshes for my object to have one object

Hello ,

I load mesh using BABYLON.SceneLoader.ImportMesh :

if (!pickInfo.hit) {
var position = getGroundPosition();
BABYLON.SceneLoader.ImportMesh("", “./assets/images/obj/”, “sonic-the-hedgehog.babylon”, scene, function (newMeshes) {
newMeshes.forEach(function (mesh)
mesh.position = position;

                    })
                });
            }

My object contain many meshes.
I want to combined all meshes for my object to have one object.

Thanks for help :slight_smile:

Mrs. Google knows the answer! :slight_smile:

https://doc.babylonjs.com/how_to/how_to_merge_meshes

Merge with this:

var mesh = BABYLON.Mesh.MergeMeshes([mesh1, mesh2, mesh3], true, false, undefined, false, true);

2 Likes

i always get this :
babylon.js:16 BJS - [11:44:47]: Unable to import meshes from ./assets/images/obj/sonic-the-hedgehog.babylon: Error in onSuccess callback: TypeError: Cannot read property ‘length’ of undefined

if (!pickInfo.hit) {
var position = getGroundPosition();
BABYLON.SceneLoader.ImportMesh("", “./assets/images/obj/”, “sonic-the-hedgehog.babylon”, scene, function (newMeshes) {
newMeshes.forEach(function (mesh) {
mesh = BABYLON.Mesh.MergeMeshes([mesh], true, false, undefined, false, true);
mesh.position = position;
j = j + 1;
list.push({id: j, obj1: mesh, obj2: mesh, link: null});

                    })
                });
            }

google can fix this !!
babylon.js:16 BJS - [11:44:47]: Unable to import meshes from ./assets/images/obj/sonic-the-hedgehog.babylon: Error in onSuccess callback: TypeError: Cannot read property ‘length’ of undefined :confused:

Google can find information for you about how to do something it cannot fix coding errors :frowning_face:

Try

BABYLON.SceneLoader.ImportMesh("", “./assets/images/obj/”, “sonic-the-hedgehog.babylon”, scene,
    function (newMeshes) {
        mesh = BABYLON.Mesh.MergeMeshes(newMeshes, true, false, undefined, false, true);
});

If you still have problems please try posting a playground with either a model you can directly import into the playground Available Meshes to Import - Babylon.js Documentation or your own model via https://doc.babylonjs.com/resources/External_PG_assets

Wishing you success :slightly_smiling_face:

1 Like

thanks for ur time :slight_smile:

1 Like

finally resolved with : BABYLON.VertexBuffer.PositionKind

var position = getGroundPosition();

                BABYLON.SceneLoader.ImportMesh("", "./assets/images/obj/", "us-c-130-hercules-airplane.babylon", scene, function (newMeshes) {
                  
                    var meshes = [];
                    newMeshes.forEach(function (mesh) {

                      
                        if (!mesh.getVerticesData(BABYLON.VertexBuffer.PositionKind)) {
                            console.log("problems with: " + mesh.name);
                        } else {
                            meshes.push(mesh);
                        }
                    });
                    var x = BABYLON.Mesh.MergeMeshes(meshes);
                    x.position = position;
                  
                });
3 Likes