How to grouping meshes?

Hello to all! There is a model that I import into the project. After import, I get about 40 meshes. Is there a way to merge them into one mesh, so that you can set, for example, position, rotation?

Probably the easiest way is to create a TransformNode as a parent. in your onSuccess callback you can do something like:

var root = new BABYLON.TransformNode();
meshes.forEach(mesh => {
  // leave meshes already parented to maintain model hierarchy:
  if (!mesh.parent) {
    mesh.parent = root

// then you can rotate/position group using the TransformNode
root.rotation.y = Math.PI / 2

You can merge the meshes and you will get better performance, but then you need to share materials and cannot move the child meshes.

Good solution! Thanx! But i realy can’t create main group mesh and than move childMeshes? Just like:
mesh.childMeshes[0].position = … ??

Using a parent as brianzinn suggested then you can position and rotate child meshes. It is when you use the mergeMeshes method that a single mesh is created from the geometry of the merged meshes and as a single mesh you can no longer access the meshes it was built from.

I think it’s a bad idea to add TransformNode, just add a parent node, change the location of the model, but I want to add a bounding box or a collision or more information to the model, and I still have to find the child node, find the model itself, to get the data, just like I did

We may have found a problem with this approach. It seems to break Google SceneViewer when exporting a GLB. We created a PG to demonstrate the issue: If you run that PG, open inspector, export GLB, and then load the resulting GLB into SceneViewer preview (Scene Viewer), you will see that the model comes in with all of the color washed out. However, if you comment out line 30 in the PG and repeat the export, the model looks correct in SceneViewer. Are there any better suggestions for being able to add meshes under a specific node other than use AssetContainer? We started down that path, but the team felt it would be more complicated to manage than using a Transform Node. Also, is there any thoughts as to whether this is a bug in SceneViewer or and should a bug be filed there?

Adding @Drigax to double check the exporter

The exporter seems fine, the WebGL engines appear to render the exported scene without issue:


I’d suspect that the bug is in SceneViewer, but I don’t really have the time to verify this

1 Like