How to get the size of the loaded gltf object in pixels. For example the canvas size is 480x360, how to get how long the object is on the canvas (i.e. pixels), the camera fov is 45, and z position is 20, rest 0.
This gives some vector3:
let bbox = new THREE.Box3().setFromObject(gltf.scene);
let measure = new THREE.Vector3();
let size = bbox.getSize(measure); // HEREyou get the size
What it depends on? Wanted the object size on the canvas, then will create an image out of that. If I create an image from the canvas, it contains lot of blank spaces, wanted image to be the perfect size of the object.
Well, its not easy for me to port this library, there are too many functions call and global variables set elsewhere. Is there a standard Three.js way?
An alternative and naïve approach is to find the size without Three.js. Capture the image, then crop the empty space from top, right, bottom and left. That’s all. This approach is naïve, because it uses more computational resources.
You can try it here (the capture function is at lines 63-115):