question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enhance TransformControls.js to center gizmo on geometry bounding box

See original GitHub issue

Hi,

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:closed
  • Created 10 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
mstratercommented, Jul 31, 2015

“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!

1reaction
eric-wiesercommented, Jan 10, 2014

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found