Multiple material of invisible object are not invisible

Hello, Than you for this grate framework! :smiley:

I’m trying to build a real time strategy game.
I want to use InstanceMesh to duplicate one mesh for all the objects of the same unite, i. e. all the jeeps should be an instance of one same mesh.

So I import the mesh and make it invisible.
The problem is that the mesh have 3 meaterails and only the first became invisible.
This is hapening with “isVisible” and “setEnable”.

I’m using obj format from Blender (I tryed gltf but got other problems, probablly be in another post).

I’m writing the code in Typescript.
I know I should load it to play ground, is there a way to upload multiple files in Typescript to a playground?

Here is the important bits of the code, (I’m hope I’m not missing anything:

The Loader:

BABYLON.SceneLoader.ImportMesh("", “./mesh/” + key + “/”, meshList[key][“obj”], this.scene, (mesh) => {

                mesh[0].isVisible = false;
                this.meshesLibrary.set(key, mesh[0] as BABYLON.Mesh);

                meshesCounter++;
                if (meshesCounter === numberOfMeshes) resolve();

The instance creation:


let ground2 = new BABYLON.InstancedMesh("", this.meshLoader.getMeshLibrary().get(“ground”));

The instansing actually work OK.
Any help would be greate :smiley:

Hey! Actually I think there are 3 objects in your scene (run scene.debugLayer.show() to see a tree view of your scene).

You must instantiate all of them but I’m glad to tell you that next nightly will introduce node.instantiateHierarchy() which will do all that work for you providing you do it on a node which is the parent of all your meshes :slight_smile:

WOW, you where right ON!

So, let me see that I got it. If I’m importing a mesh that have faces with different materials asign to them, then it will create an object for each material?

Is there a way to combin them to one object after importing?
Am I importing in a good way, or should I do something else?

You did everything correctly :wink:

You cannot merge them as they need to be separated as they have different shaders.

but you can still create a common parent for them (like a TransformNode)

Got it :slight_smile:

But I red somewere that it’s a bad thing to devide objects, and that I should use bones and that it hurts the performence.

It depends :slight_smile: in your case maybe you can merge the meshes if they are using the same material. But as they don’t they must be separated