Hi I have a model which contains more than 1000 meshes. I grouped everything in a single object3d and added it to the scene and implemented a function to fit everything in the scene. Now I want to rotate set of objects on its own axis. For that, I grouped meshes which needs rotation into a single object3d. Now I am trying to rotate this object3d on its axis but its rotating around whole model’s centre of gravity.
What I tried:
To fit the model:
let boundingBoxOfNode = new THREEJS.Box3().setFromObject(object);
// // Refocus camera the center of the given object
let centerTarget = new THREEJS.Vector3();
let centerOfGravity = boundingBoxOfNode.getCenter(centerTarget);
this.centreOfGravity = centerOfGravity;
let newCameraPosition = new THREEJS.Vector3();
newCameraPosition.subVectors(centerOfGravity, this.trackballControls.target);
this.camera.position.addVectors(this.camera.position, newCameraPosition);
this.camera.lookAt(centerOfGravity);
this.trackballControls.target.set(centerOfGravity.x, centerOfGravity.y, centerOfGravity.z);
// this.orbitControls.target.set(centerOfGravity.x, centerOfGravity.y, centerOfGravity.z);
// // Move camera along z until the object fits into the screen
let sizeTarget = new THREEJS.Vector3();
let sphereSize = boundingBoxOfNode.getSize(sizeTarget).length() * 0.5;
let distToCenter = sphereSize / Math.sin(Math.PI / 180.0 * this.camera.fov * 0.5);
let target = this.trackballControls.target;
let vec = new THREEJS.Vector3();
vec.subVectors(this.camera.position, target);
vec.setLength(distToCenter);
this.camera.position.addVectors(vec, target);
this.camera.zoom = 1;
To rotate the object3d:
this.object3dToRotate.rotateY(0.1);