Calcs for dynamic positioning of 3Dobjects based on h / w + scrH / scrW

So… let me try and explain this best I can.

I have a grid of instances. They are scaled to… whatever size they are scaled to. Scale can change. I need to find out how many of the objects can fit within the viewport / screen based on their current scale. However, I am having a problem determining what the rendered height/width of each object is. Of course, how many of the objects can fit within the screen is also affected by their distance from the camera, which will be fixed in this case.

Q1: What is the best way to determine how many rendered objects, at current scale, can fit into the screen ( in a grid ) at a given distance from the camera? Is there a function for this? I think I am trying to convert rendered widths to pixel widths… ?

Q2: Is it best to even assume the camera distance first? Or should I assume objects are at z:0 and then adjust camera to fit objects?

Thanks in advance!

gives you the viewport width/height, also allows for a target vector. if you have that you can divide it with the width or height of the object.

in the off-chance you’re using react and three then you wouldn’t have to worry about any of it, because you can use flex-box and form real grids that are responsive and can overlap. GitHub - pmndrs/react-three-flex: 💪📦 Flexbox for react-three-fiber

Boom. @drcmda Thank you!