Hello, I’m new to babylonjs. I have GUI text -
const advancedTexture = AdvancedDynamicTexture.CreateFullscreenUI(
‘UI’,
true,
this.scene
);
const textBlock = new TextBlock();
textBlock.text = ‘text’;
textBlock.color = ‘white’;
textBlock.fontSize = 12;
advancedTexture.addControl(textBlock);
textBlock.linkWithMesh(meshElement);
I need to position a GUI text element relative to a mesh element, such that the text is always just below the mesh element, regardless of the camera’s position
I need to place the text always at the bottom of the mesh element, so that when the camera moves further or closer, the text is always positioned relative to the mesh element and does not decrease in size. I’m not sure if I need to use GUI text. Unfortunately, I still haven’t found the solution I need.
wow, this is really what we need. Does babylonjs have any out-of-the-box solutions for this case? It certainly looks complicated, if there are a lot of mesh elements with such texts, will this greatly affect performance? If instead of GUI text there is mesh text, will it be easier to implement?
I don’t think so… Sticking to the bottom of the mesh in 2D is quite specific
The current version I would say yes, since it’s computing on all the vertices to get the bouding box.
Most likely if you have heavy meshes to track, is will be better to use 3D text, and stick them under the meshes in 3D
You can solve this by checking the dot product between camera direction (camera.getTarget().subtract(camera.position)) and direction from camera to mesh (mesh.position.subtract(camera.position)), the dot product is >0 only if the mesh is in front of camera Playground