createInstance creates an invisible instance of mesh

I am trying to create an instance of a mesh with const instancedMesh = mesh.createInstance();. But unfortunately, the new instance is not visible in my scene. However, when I put instancedMesh.showBoundingBox = true;, it shows the bounding box, but still the new instanced mesh is not visible. although the instancedMesh.isVisible and instancedMesh.isEnabled is true. I don’t know what is affecting the scene to not render the instance of the original mesh, although the createInstance() is actually creating an instance of the original mesh.

I can not show you the actual situation in the playground since the same code works fine in the playground but not working in my project.

It could be a winding problem with the material.

Try to set material.backFaceCulling = false. If the mesh does appear it means the winding is inverted. You can try to change the material.sideOrientation value to fix it (but createInstance should not normally needs such a change…).

1 Like

it does not work :pensive:

Maybe you’re freezing the material before the instance is created?

1 Like

I checked the mesh.material.isFrozen it returns false. So the material of the mesh is not frozen before the mesh is created

You didn’t hide the original mesh before creating the instance, did you?
Else, you didn’t mirror the mesh before creating the instance?
Else, you didn’t parent the mesh to a minus scaled root before creating the instance?
Else, you didn’t mirror your material on the source mesh?

Only other scenarios I can think of where you would see the bounding box but not the instance is if the visibility of the mesh is set to a small, non-zero value or if you created a material but didn’t implement instance support. Or are you just using a builtin-in material? And does the mesh have a skeleton? Or instance attributes? Also if you create the instance later after the mesh has been rendered try creating it right after creating the mesh for a quick test? :thinking:

1 Like

Wow! That’s a hell of a lot of assumptions and possibilities :dizzy_face: :wink:, isn’t it? @Ehtesham_Ahmad_Nadim, see how just much easier and more accurate our response would be if you would be able to reproduce in a PG. Else, I’m afraid you would need to check on all that (and more). There’s actually one more thing that cought my attention is when you say, “it works in the playground but not in my scene”. May be you also have some ‘specials’ towards the treatment of materials, registering to the buffer, post-processing, layerMasks, what do I know… :wink:
If you cannot reproduce in PG, I believe all that’s left is to break it down until you find where it breaks.

I have the same problem. Cloned meshes are visible, but instances are not. This applies only to loaded models, everything is fine with the meshes created by the code

Are you able to setup a repro in the Playground?

Hi @ARAMONIS_5

Did you find a solution to this cause I have the same problem. Only my mesh magically appears when i select it with inspector and has gizmo assigned to it and i click the button on inspector to open it in separate window. They show up. I’m stuck on it for a while now.

Regards

Peter

As @Evgeni_Popov mentioned 2 years ago: Are you able to setup a repro in the Playground?

1 Like

Hi @sebavan

I can’t. That’s the problem. I was preparing Playground and all was working on it. But its not working in my app.

I noticed that when I open inspector select the mesh and the gizmo of any kind, move rotate scale is visible, when I press the button to opn inspector to new window the meshes are showing up. I do not know what event is triggered in that moment but they show up.

And simple playground is not making it at all.

Any suggestions how to call something on instanced mesh to rebuild all on it again? Or what moving to new window inspector is triggering on the scene so they are all working after that?

Regards
Peter

Nope, we need a repro of some sort to troubleshoot :frowning:

Can you give me some methods names that I can test to call on meshes to refresh them or something?

@sebavan

I noticed that if I remove the sceleton from the mesh by:

mesh.skeleton = null;

then the mesh show up.

But I need the skeleton at one of the copies.

I have no idea why this all works perfectly fine when I have gizmo and move inspector to new window. No idea. And a simple example works in Playground so I cant replicate it to show it. I already did one and it works perfectly fine.

I’m really stuck on this one.

Regards
Peter

Do you have a repro, even if it’s not inside the Playground? A live link of your project?

Hi @Evgeni_Popov

I know everyone is asking about this. But I cant share it. But the issue is there. I do not know what to do with this anymore.

Is there a force visual update method for skeletons or meshes. Something that I can call? Refresh material or something. I’m digging in your code for last 3 days to find something like this.

What event on the scene is triggered to get rid of all meshes gizmo. Cause this is called when you put inspector to new window?

When I get stuck, I go to the source code at babylonjs github.

The path to master/packages/dev/core/src is most useful.

Try to do `computeWorldMatrix(true)` and `refreshBoundingInfo(true, true)` on your meshes / instances and see if that helps.