I’ve created labels and i am planning to hide them whenever they “go behind” or when the view is blocked by the gltf model what would be the easiest solution to achieve this?
it won’t be that easy, you will have to raycast towards the camera and see if something obstructs the line of sight. in the off chance you use three + react then it’s not even an after though: Mixing HTML and WebGL w/ occlusion - CodeSandbox
I expect the visibility issue to be most thoroughly solved by making the labels true 3D-objects, like textured planes. Maybe add some billboarding for better readability. I would also expect any raycasting to work out of the box for true 3D-objects.
If css2d behaves like css3d I think there is no need for special code to implement occlusion, just like the the react example this can also work in ‘plain’ ThreeJS (most of the screens here are Iframes on css3d that have their own Html pages): What am I missing? Scifi (threeml.org)
Here a quick example how it can work with the css3d object:
The sandbox @drcmda shared has a really nice simple solution that could ported back to plain JS easily.
However it only works for rectangular occlusion and it’s all or nothing - either the HTML shows, or it is hidden. You can’t hide half of it behind a mesh and you won’t be able to use it to get a curved occlusion like the label behind the earth model.
It looks really good in that example because the HTML is placed exactly on a rectangular mesh. If you switch to a sphere or remove the rotation limits on the OrbitControls and view from underneath you’ll see the limitations.
If you need proper 3d occlusion I would try using a sprite or plane like @vielzutun.ch is suggesting.
i am planning to hide them whenever they “go behind” or when the view is blocked by the gltf model what would be the easiest solution to achieve this?
that is raycasting, no? how else will you “hide” a label “behind” a model. you cast a ray towards the camera and if it intersects you hide the label. or are there any other ways to solve that?