Hello everyone, I’m trying to write a program to fit a mesh into a DOM element’s bounds. I firstly use the orthographic camera mode so its perspective is closer to a 2D one.
I searched the calculation of how to calculate bounds from 3D space to 2D pixels, so I make use of this to work out how to calculate the mesh position, like this:
Find current mesh bounds in pixels
Find current mesh bounds in vector3
Find out the x/y differences in pixels the mesh need to move
New mesh position x = current mesh position x + x difference * (mesh width in vector3) / (mesh width in vector3)
I can get the x position calculated correctly, but for y, it seems to be negative so I negate it, but the result is still incorrect. Can anyone advice on how to correctly calculate the new position y of the mesh? Thank you very much!