2
0
Эх сурвалжийг харах

TransformControls.js: Added reset() method (#22972)

* TransformControls.js: Added reset() method

Added method to reset object to state when the transform dragging started. The transform action can also be stopped immediately after by using the optional parameter set to `true`.

* Removed optional parameter

Removed the optional parameter for stopping transform after reset.

* Update TransformControls.js

* Update TransformControls.js

Continue transform from the reset state.

* Updated the non-jsm version

Updated the `js` version as well.

* Updated documentation

Added missing documentation for `setScaleSnap()` and moved `reset()` to the correct alphabetical place.

Co-authored-by: Michael Herzog <[email protected]>
Philip 3 жил өмнө
parent
commit
098003f696

+ 15 - 0
docs/examples/en/controls/TransformControls.html

@@ -174,6 +174,11 @@
 			Returns the transformation mode.
 		</p>
 
+		<h3>[method:undefined reset] ()</h3>
+		<p>
+			Resets the object's position, rotation and scale to when the current transform began.
+		</p>
+
 		<h3>[method:undefined setMode] ( [param:String mode] )</h3>
 		<p>
 			<p>
@@ -194,6 +199,16 @@
 			</p>
 		</p>
 
+		<h3>[method:undefined setScaleSnap] ( [param:Number scaleSnap] )</h3>
+		<p>
+			<p>
+				[page:Number scaleSnap]: The scale snap.
+			</p>
+			<p>
+				Sets the scale snap.
+			</p>
+		</p>
+
 		<h3>[method:undefined setSize] ( [param:Number size] )</h3>
 		<p>
 			<p>

+ 19 - 0
examples/js/controls/TransformControls.js

@@ -532,6 +532,25 @@
 
 		}
 
+		reset() {
+
+			if ( ! this.enabled ) return;
+
+			if ( this.dragging ) {
+
+				this.object.position.copy( this._positionStart );
+				this.object.quaternion.copy( this._quaternionStart );
+				this.object.scale.copy( this._scaleStart );
+
+				this.dispatchEvent( _changeEvent );
+				this.dispatchEvent( _objectChangeEvent );
+
+				this.pointStart.copy( this.pointEnd );
+
+			}
+
+		}
+
 		getRaycaster() {
 
 			return _raycaster;

+ 19 - 0
examples/jsm/controls/TransformControls.js

@@ -564,6 +564,25 @@ class TransformControls extends Object3D {
 
 	}
 
+	reset() {
+
+		if ( ! this.enabled ) return;
+
+		if ( this.dragging ) {
+
+			this.object.position.copy( this._positionStart );
+			this.object.quaternion.copy( this._quaternionStart );
+			this.object.scale.copy( this._scaleStart );
+
+			this.dispatchEvent( _changeEvent );
+			this.dispatchEvent( _objectChangeEvent );
+
+			this.pointStart.copy( this.pointEnd );
+
+		}
+
+	}
+
 	getRaycaster() {
 
 		return _raycaster;

+ 5 - 0
examples/misc_controls_transform.html

@@ -12,6 +12,7 @@
 			"W" translate | "E" rotate | "R" scale | "+/-" adjust size<br />
 			"Q" toggle world/local space |  "Shift" snap to grid<br />
 			"X" toggle X | "Y" toggle Y | "Z" toggle Z | "Spacebar" toggle enabled<br />
+			"Esc" reset current transform<br />
 			"C" toggle camera | "V" random zoom
 		</div>
 
@@ -156,6 +157,10 @@
 							control.enabled = ! control.enabled;
 							break;
 
+						case 27: // Esc
+							control.reset();
+							break;
+
 					}
 
 				} );