I have a model (glb) where I change the mesh’s visibility.
everything is worked great when I need to change the visibility of all the meshes.
the problems start when i change the visibility of an individual instance mesh. when I select an instance mesh it does not get affected by the visibility property and if i select his parent its changes the visibility of child instance (like he should)
how i can break/destroy the connection between the instance and parent and make each instance unique?
I am asking because I have tried all
change parent to null play with customBuffers and change the alphaMode and try to remove the instance on the parent with the child instance
thanks for the help.
Hi and welcome to the Community,
Hope you like your experience of BJS so far.
To answer your question, I would first want to clarify if we are talking about ‘instances’ or ‘thin-instances’?
There’s a difference in the handling but they also have things in common.
I.E. you cannot ‘break’ the link between the ‘source’ and the instanciated object. Simple instances are taking from the source (same as thin-instances) with the difference that a simple instance can still be worked as a mesh (up to some shared parameters). I.E. Setting the mesh ‘visibility’ individually on a instance can be done straight by selecting the instance (by name or id) and giving the new value for ‘visibility’ - Whereas, thin-instances require you to write to the buffer before they are rendered because of the way they are computed.
From the reading above, I understand you would also need to make a difference between the mesh ‘visibility’ and the ‘material’ settings (with everything related to alpha). A same material can be shared along meshes and instances. Changing this material will affect all meshes and instances using it.
Also, parenting does not affect the way an instance or thin-instance is rendered. Making it a child or nulling it won’t change anything towards how they are linked to the parameters they get from the source.
So, for the short answer, either you manage to set-up a playground environment (best case scenario) and we’ll fix it for you - - OR - - copy/paste some of the code you use to create and manage your instance/thin-instance.
first of all, let me just say thanks for your quick response!
i am sorry that i wasnt clear, i am talking about ‘instances’ and not ‘thin instances’
i know that the material is shared between meshes and instances.
but the problem is when i select instance (by name or id) and set his visibility value nothing happened only if change the source mesh visibility value the source and is instances are changing.
so how can i change an instance mesh visibility without changing the source mesh visibility?
i hope that i have been more clear about my issues.
once again thanks!
Do you know how to load external assets in the playground?
It would be the easiest for us to be able to interact straight with the scene and see the nodes loaded from your glb. Instances should have a different name but eventually they don’t. Sadly, I cannot know without the PG. One thing is sure though, you can give different ‘visibility’ to your instances of meshes (without calling the buffer or anything). I do this all the time. Only thing is, you need to be able to select just the instance you want, so they should have a different name or id.
Edit: One more thing. FYI: Good practice when using instances is that you would make the source mesh invisible and render just the instances (however, this doesn’t change anything for your issue). Try to set-up that PG for us and let us know if you don’t manage…
Apologies. I was using clones in this case, not instances. My bad, sry for the confusion.
You should be able to change the alpha through the ‘instancedBuffers.color’ (as in the link below) but for some reason I’m getting an error when I try this from your glb
May be I’ll ask the expert @Evgeni_Popov to have a look it, will you? Thanks,
Actually, changing the visibility property on instances won’t work because this parameter ends up being a material parameter (it is used in shader code): it will have some effect only on the master mesh, and will affect all instances. You should use the mesh.setEnabled(true/false) function instead.
HI evgeni thanks…
I give it another shot but ‘registerInstancedBuffer(“color”,4)’ throw me an error
“Uncaught TypeError: Cannot read properties of null (reading ‘toArray’)”
so I can’t find any solution to it.
However (LOL) while doing this, I found a way to have it work (like it should in this PG for meshes/Sphere002. Still don’t really get the thing with setParent and having to do a let for mesh selection. Must be just my small brain
Edit 2: Fancy me cannot reproduce the second error now where it couldn’t read the color. LOL.
In fine, I believe it works (somehow) so I guess you can forget about the above
Footnote: Except I would still like to understand why setParent doesn’t seem to work here?
The color of the boombox still won’t be ok because vertex color will be enabled for the instance (because of the BoomBox.registerInstancedBuffer('color', 4) call), but the instanced boom box is not considered as an instance for rendering purpose (see my comment in the PR), so it will be rendered as a regular mesh instead. But the regular boom box doesn’t have a vertex color buffer, so the shader will use a black color instead.
To have the instance being considered as a real instance, the sign of the determinant of its world matrix must be the same than the one of the source mesh. To do that, you can either:
Once again thanks!
i tried to check the implementation of the scene.useRightHandedSystem=true but I am afraid that it will cause me some problems on my current project so I built the next PR. with the second method
I set the same parent to each instance and set all the instances to the same instance color buffer and well it looks good now all I left is to check on my project and hope it will be good .
can I ask one more question…you can see in the example that the balls sometimes disappear when playing with the camera, do you have any idea why?