Need help with gsap camera and OrbitControls animations

One possible solution for this issue is to compute the AABB for the object and then animate the camera towards one of its side. This can be achieved by computing the center and size vectors of the AABB. You can then use these vectors to compute the target position. Something like:

var aabb = new THREE.Box3().setFromObject( mesh );
var center = aabb.getCenter( new THREE.Vector3() );
var size = aabb.getSize( new THREE.Vector3() );

gsap.to( camera.position, {
	duration: 1,
	x: center.x,
	y: center.y,
	z: center.z + size.z, // maybe adding even more offset depending on your model
	onUpdate: function() {
		camera.lookAt( center );
	}
} );

Live demo: three.js dev template - module - JSFiddle - Code Playground

5 Likes