How do I set the exact display size of a fixed-size sprite in 3D?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Cro-Iba

I’d like to render a sprite within a 3D world, but I’d also like that sprite to be rendered billboarded at a fixed size that is also the full size of the base image. Specifically, the image I have is 1080x1080, and I want it to appear on screen at a given resolution at precisely that same size. Essentially, I want it to act like a 2d sprite except that it can intersect and overlap with existing 3d meshes. I have a MeshInstance already made that essentially does this, except that without changing scale or mesh size, it appears significantly larger than the base image; I have to size the mesh from 1 to 0.355 to approximate the size I want at 1080p, but I don’t know how I could possibly discern this number without eyeballing, and it’s almost certainly not precisely accurate.

I figure this can’t be an uncommon want, like to hang GUI above entities but also let them be occluded by terrain. What’s the best way to do this?

I don;t know the specific functions, but if you use a world_to_screen co-ords function, you should be able to get screen size of a 3D object, and scale accordingly.

SteveSmith | 2023-02-10 18:00

:bust_in_silhouette: Reply From: zhyrin

If you have a Sprite3D, in the inspector under the SpriteBase3D section there are flags for billboarding and fixed size. I don’t know how it determines the fixed size, for me it blows up the default icon to a large scale.
You also have a Pixel Size value which determines how big a pixel is in the 3D world.
It’s unusual to work with pixel values in 3D, you might have to come up with a neat solution.
If you find that Fixed Size won’t do, you can also update Pixel Size every frame based on the sprite’s distance from the camera.