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.js: Added reset() method #22972

Merged
merged 6 commits into from
Dec 8, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/examples/en/controls/TransformControls.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ <h3>[method:String getMode] ()</h3>
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>
Expand All @@ -194,6 +199,16 @@ <h3>[method:undefined setRotationSnap] ( [param:Number rotationSnap] )</h3>
</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>
Expand Down
19 changes: 19 additions & 0 deletions examples/js/controls/TransformControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions examples/jsm/controls/TransformControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions examples/misc_controls_transform.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -156,6 +157,10 @@
control.enabled = ! control.enabled;
break;

case 27: // Esc
control.reset();
break;

}

} );
Expand Down