Manually setting the position
and fov
of the perspective camera
in THREE.JS is working as expected for me. However, when I try to interact with the scene
later using the TrackBall Controls
, it just shows a black screen with no errors.
Check out this JS Fiddle for reference
Here is the relevant code snippet:
var bbox = new THREE.Box3().setFromObject(scene);
var center = bbox.getCenter();
var size = bbox.getSize();
// Update some control properties
controls.target.set(center.x, center.y, center.z);
// Position the camera on the y axis
camera.position.set(center.x, center.y - size.y, center.z);
// Fit the FOV
var dist = size.y / 2;
var fov = 2 * Math.atan( size.z / ( 2 * dist ) ) * ( 180 / Math.PI );
camera.fov = fov;
camera.updateProjectionMatrix();
What step am I missing in order to properly interact with the scene
afterwards?
Thank you
==== EDITS
After implementing the accepted answer, you can see the updated code in this working fiddle: Updated Fiddle