未验证 提交 1ac9c9be 编写于 作者: M Michael Herzog 提交者: GitHub

Merge pull request #18146 from arodic/feature/TransformControlls-scaleSnap

Added scaleSnap to TransformControls. Fixes #14902
......@@ -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;
......
......@@ -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;
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册