diff --git a/examples/js/controls/TransformControls.js b/examples/js/controls/TransformControls.js index 15595d6442ba58a11c07e5cd847bfccea43709f1..5637ac842a55a51183528b055bc5ee185948f17e 100644 --- a/examples/js/controls/TransformControls.js +++ b/examples/js/controls/TransformControls.js @@ -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 ); @@ -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 ); @@ -633,6 +656,12 @@ THREE.TransformControls = function ( camera, domElement ) { }; + this.setScaleSnap = function ( scaleSnap ) { + + scope.scaleSnap = scaleSnap; + + }; + this.setSize = function ( size ) { scope.size = size; diff --git a/examples/jsm/controls/TransformControls.js b/examples/jsm/controls/TransformControls.js index 54db65d4d3d3e4c3ad781cae9354da4c97370aac..5a285a835eaca93682f59809c5281c9274e738fa 100644 --- a/examples/jsm/controls/TransformControls.js +++ b/examples/jsm/controls/TransformControls.js @@ -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 ); @@ -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 ); @@ -656,6 +679,12 @@ var TransformControls = function ( camera, domElement ) { }; + this.setScaleSnap = function ( scaleSnap ) { + + scope.scaleSnap = scaleSnap; + + }; + this.setSize = function ( size ) { scope.size = size; diff --git a/examples/misc_controls_transform.html b/examples/misc_controls_transform.html index 234d7b0d238bbfe3f6e9ccee9a76257b34f83b93..d3b9e59db89fcaf68054728eb05047fdd4c7d4e7 100644 --- a/examples/misc_controls_transform.html +++ b/examples/misc_controls_transform.html @@ -84,6 +84,7 @@ case 17: // Ctrl control.setTranslationSnap( 100 ); control.setRotationSnap( THREE.Math.degToRad( 15 ) ); + control.setScaleSnap( 0.25 ); break; case 87: // W @@ -135,6 +136,7 @@ case 17: // Ctrl control.setTranslationSnap( null ); control.setRotationSnap( null ); + control.setScaleSnap( null ); break; }