I want to show the loaded model as in an isometric view in my scene.
I’m using PerspectiveCamera, also doing camera.position.set(20, 20, 20);
However, in some cases (depends on model size), the model is not perfectly fit to the scene, zoomed in or zoomed out. I am able to see isometric view, but how to make fit the model to my scene?
Thanks
Jezz
How about using:
var OFFSET = 20;
camera.position.set(object.geometry.boundingSphere.radius + OFFSET, 0, 0 );
var sphericalCoord = new THREE.Spherical();
sphericalCoord.setFromVector3( camera.position );
sphericalCoord.phi = THREE.Math.degToRad( 45 );
sphericalCoord.theta = THREE.Math.degToRad( 45 );
var vec = new THREE.Vector3().setFromSpherical(sphericalCoord);
camera.position.set( vec.x, vec.y, vec.z );
1 Like
Combining both approaches:
camera.position.setScalar(1).setLength(object.geometry.boungindSphere.radius + OFFSET);
1 Like
but still the model is not fit to scene.
May be you can change the offset value as per your need.
If still it doesn’t work, would encourage you to share a sample jsfiddle.
I think, you’re looking for something like this:
I use this function. It sets the camera z position and the far place to include the object, plus an offset to prevent the object filling exactly to the screen edge.
You can also pass in OrbitControls if you are using that and it will set the controls up too. Otherwise it will just point the camera at the object.
Note that there are a couple of expectations - the object should be “in front” of the camera, in particular.
const fitCameraToObject = function ( camera, object, offset, controls ) {
…
2 Likes
this may also be of some interst?
Hello,
I manage to make it works, you can find an example here:
https://codepen.io/bilouwan/project/full/XpgGOp/
As it is quite complex to implements, no really the...
Feature Request
This time being I have handled the situation by
Making camera x and y position to 0, and z position by model size.
Then I used OrbitControls’s rotateLeft and rotateUp methods to make it to appear isometric.
camera.position.set(0, 0, Math.max(mesh.geometry.boundingBox.max.x * 5, mesh.geometry.boundingBox.max.y * 5, mesh.geometry.boundingBox.max.z * 5));
controls.rotateLeft(-.8);
controls.rotateUp(.6);