Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TransformControls: Added scaleSnap. #18146

Merged
merged 1 commit into from Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions examples/js/controls/TransformControls.js
Expand Up @@ -34,6 +34,7 @@ THREE.TransformControls = function ( camera, domElement ) {
defineProperty( "mode", "translate" );
defineProperty( "translationSnap", null );
defineProperty( "rotationSnap", null );
defineProperty( "scaleSnap", null );
defineProperty( "space", "world" );
defineProperty( "size", 1 );
defineProperty( "dragging", false );
Expand Down Expand Up @@ -459,6 +460,28 @@ THREE.TransformControls = function ( camera, domElement ) {

object.scale.copy( scaleStart ).multiply( _tempVector2 );

if ( this.scaleSnap ) {

if ( axis.search( 'X' ) !== - 1 ) {

object.scale.x = Math.round( object.scale.x / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;

}

if ( axis.search( 'Y' ) !== - 1 ) {

object.scale.y = Math.round( object.scale.y / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;

}

if ( axis.search( 'Z' ) !== - 1 ) {

object.scale.z = Math.round( object.scale.z / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;

}

}

} else if ( mode === 'rotate' ) {

offset.copy( pointEnd ).sub( pointStart );
Expand Down Expand Up @@ -633,6 +656,12 @@ THREE.TransformControls = function ( camera, domElement ) {

};

this.setScaleSnap = function ( scaleSnap ) {

scope.scaleSnap = scaleSnap;

};

this.setSize = function ( size ) {

scope.size = size;
Expand Down
29 changes: 29 additions & 0 deletions examples/jsm/controls/TransformControls.js
Expand Up @@ -57,6 +57,7 @@ var TransformControls = function ( camera, domElement ) {
defineProperty( "mode", "translate" );
defineProperty( "translationSnap", null );
defineProperty( "rotationSnap", null );
defineProperty( "scaleSnap", null );
defineProperty( "space", "world" );
defineProperty( "size", 1 );
defineProperty( "dragging", false );
Expand Down Expand Up @@ -482,6 +483,28 @@ var TransformControls = function ( camera, domElement ) {

object.scale.copy( scaleStart ).multiply( _tempVector2 );

if ( this.scaleSnap ) {

if ( axis.search( 'X' ) !== - 1 ) {

object.scale.x = Math.round( object.scale.x / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;

}

if ( axis.search( 'Y' ) !== - 1 ) {

object.scale.y = Math.round( object.scale.y / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;

}

if ( axis.search( 'Z' ) !== - 1 ) {

object.scale.z = Math.round( object.scale.z / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;

}

}

} else if ( mode === 'rotate' ) {

offset.copy( pointEnd ).sub( pointStart );
Expand Down Expand Up @@ -656,6 +679,12 @@ var TransformControls = function ( camera, domElement ) {

};

this.setScaleSnap = function ( scaleSnap ) {

scope.scaleSnap = scaleSnap;

};

this.setSize = function ( size ) {

scope.size = size;
Expand Down
2 changes: 2 additions & 0 deletions examples/misc_controls_transform.html
Expand Up @@ -84,6 +84,7 @@
case 17: // Ctrl
control.setTranslationSnap( 100 );
control.setRotationSnap( THREE.Math.degToRad( 15 ) );
control.setScaleSnap( 0.25 );
break;

case 87: // W
Expand Down Expand Up @@ -135,6 +136,7 @@
case 17: // Ctrl
control.setTranslationSnap( null );
control.setRotationSnap( null );
control.setScaleSnap( null );
break;

}
Expand Down