Enhance TransformControls.js to center gizmo on geometry bounding box
See original GitHub issueHi,
Not sure it is the right to ask for an enhancement.
I have used transformControls.js (V64) and realised that the gizmo is centered on local position (0,0,0) of an element. This doesn’t mean it is the real center of the mesh.
I have modified the update function, may be you could add it to the next release.
this.update = function () {
if ( scope.object === undefined ) return;
//sho - Add 2014/01/10 - set the gizmo at object center.
if (scope.object.geometry) {
if (!scope.object.geometry.boundingBox)
scope.object.geometry.computeBoundingBox();
worldPosition.getPositionFromMatrix(scope.object.matrixWorld);
worldPosition.add(scope.object.geometry.boundingBox.center());
} else {
worldPosition.getPositionFromMatrix(scope.object.matrixWorld);
}
/******/
/*scope.object.updateMatrixWorld();
worldPosition.setFromMatrixPosition( scope.object.matrixWorld );
worldRotation.setFromRotationMatrix( tempMatrix.extractRotation( scope.object.matrixWorld ) );*/
camera.updateMatrixWorld();
camPosition.setFromMatrixPosition( camera.matrixWorld );
camRotation.setFromRotationMatrix( tempMatrix.extractRotation( camera.matrixWorld ) );
scale = worldPosition.distanceTo( camPosition ) / 6 * scope.size;
this.position.copy( worldPosition )
this.scale.set( scale, scale, scale );
eye.copy( camPosition ).sub( worldPosition ).normalize();
if ( scope.space == "local" )
this.gizmo[_mode].update( worldRotation, eye );
else if ( scope.space == "world" )
this.gizmo[_mode].update( new THREE.Euler(), eye );
this.gizmo[_mode].highlight( scope.axis );
}
Issue Analytics
- State:
- Created 10 years ago
- Comments:12 (8 by maintainers)
Top Results From Across the Web
(Three.JS) Transform controls for translation (Size Issue)
If you are getting the bounding box of the object from its geometry, that will be wrong because it doesn't take the objects...
Read more >TransformControls – three.js docs
This class can be used to transform objects in 3D space by adapting a similar interaction model of DCC tools like Blender. Unlike...
Read more >how do i set the origin to the center of the bounding box?
Change the transform pivot point to Bounding Box Center and set the origin to Geometry using the right click menu. Transform pivot point....
Read more >@react-three/drei - npm
GizmoHelper ; PivotControls; TransformControls; Grid; useHelper ... A box buffer geometry with rounded corners, done with extrusion.
Read more >Center the pivot point | Maya - Autodesk Knowledge Network
(Optional) Select a transform tool. · Make a component selection. · Select Modify > Center Pivot. · The pivot centers on the bounding...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

“If you want the conceptual origin to be somewhere other than (0, 0, 0), put your mesh in an Object3D and translate it such that the conceptual center of the mesh is at the Object3D’s origin.” This advice saved me so much time. Thanks a ton eric-wieser!
@SebastienHo: Why is the center of the bounding box more meaningful than the origin of the mesh? The origin won’t move with respect to the rest of the model after an
.applyMatrix, but the center of a bounding box will, due to it being axis aligned. If you want the conceptual origin to be somewhere other than (0, 0, 0), put your mesh in an Object3D and translate it such that the conceptual center of the mesh is at the Object3D’s origin.