Filmback sensor size [width/height] to fit object bounds

Hi all,

I have an object that has bounds and size changing all the time, now, I want to render it but with camera setup that has filmback [sensor width and height] setting dynamically changed as well.

Sensor width needs to fit the width of the objects bounding box converted to screen space so that only wanted object is in the frame, same goes for the sensor height as well.
I have the bounding box information and i convert it to screen space from which i get the new ‘resolution’, I am wondering how to convert those values to sensor dimensions so that it basically crops everything around the object.

For example, if i have resolution of 1280x720 and my objects 2D/screen bounds would be 600x400 how would i convert that data to sensors width and height respectively so that i keep the 1280x720 resolution but have everything other than object cropped out by the sensor?

Is there a specific method by which this can be achieved? Is there something else that needs to go into the account here when converting this data other than ‘x’ and ‘y’ dimensions of an object?

Thanks in advance :face_with_monocle: