Is it possible to rotate an Object3D object about its end? I found my object's center with const boundingBox = new THREE.Box3().setFromObject(this.object)
to determine the center. Would rotating at a point mean translating the object to one point, rotate, then translate back?
Asked
Active
Viewed 1,124 times
2

Hannah Bernal
- 133
- 1
- 1
- 10
-
1Possible duplicate of [Three JS Pivot point](https://stackoverflow.com/questions/42812861/three-js-pivot-point) – Mugen87 Feb 11 '19 at 09:48
1 Answers
1
Is it possible to rotate an Object3D object about its end?
Yes. By default, Object3D rotates about its center, but it's possible to change rotation point by "wrapping" object in parent (Object3D) and setting position for parent (this will be also a rotation point):
function changeRotationPoint(obj, scene, position) {
// create parent and add it to scene
const parent = new THREE.Object3D();
parent.add(obj);
if (obj.parent) {
obj.parent.add(parent);
} else {
// add to THREE scene if obj doesn't have a
// parent
scene.add(parent);
}
// position for rotation,
// for example (put your data): { x: 0.1, y: 0.1, z: 0 }
parent.position.set(position.x, position.y, position.z);
// correct position of obj, so only rotation point
// will be changed
const x = obj.position.x - position.x,
const y = obj.position.y - position.y,
const z = obj.position.z - position.z
obj.position.set(x, y, z);
}
// call function
changeRotationPoint(this.object, scene, { x: 0.1, y: 0.1, z: 0 });
// rotate this.object
this.object.parent.rotation.set(0.1, 0.2, 0.3);

Vadi
- 3,279
- 2
- 13
- 30
-
Thank you for the response and example! How would we get the endpoint of our object if we want to rotate around there? From your example, it seems that we need to know the exact point we want to rotate at. – Hannah Bernal Feb 12 '19 at 04:42
-
@HannahBernal yes, you're right, we need to know desired rotating point, or calculate if it's possible. – Vadi Feb 12 '19 at 09:44
-
Hm, ok that makes sense! Just making sure, would `obj.position` reference the center of the object? Also, I don't think your code works if an object is already a child of another object since it detaches from the original parent and resets the scale – Hannah Bernal Feb 13 '19 at 19:00
-
`obj.position reference the center of the object? ` object position by default will be 0, 0, 0, and it will rotate (by default) around its center. But you can find the center using box3d. `Also, I don't think your code works if an object is already a child of another object since it detaches from the original parent and resets the scale` - it works fine and it doesn't impact any of other object property, until you have changed it. Using parent for changing rotation point works in all cases, translation - only for objects with geometry. Check here https://github.com/mrdoob/three.js/issues/1364 – Vadi Feb 14 '19 at 09:33