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: Add min/max constraints. #29602

Merged
merged 2 commits into from
Oct 10, 2024
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
30 changes: 30 additions & 0 deletions docs/examples/en/controls/TransformControls.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,36 @@ <h3>[property:Number translationSnap]</h3>
steps the 3D object should be translated. Default is `null`.
</p>

<h3>[property:Number minX]</h3>
<p>
The minimum allowed X position during translation. Default is `-Infinity`.
</p>

<h3>[property:Number maxX]</h3>
<p>
The maximum allowed X position during translation. Default is `Infinity`.
</p>

<h3>[property:Number minY]</h3>
<p>
The minimum allowed Y position during translation. Default is `-Infinity`.
</p>

<h3>[property:Number maxY]</h3>
<p>
The maximum allowed Y position during translation. Default is `Infinity`.
</p>

<h3>[property:Number minZ]</h3>
<p>
The minimum allowed Z position during translation. Default is `-Infinity`.
</p>

<h3>[property:Number maxZ]</h3>
<p>
The maximum allowed Z position during translation. Default is `Infinity`.
</p>

<h2>Methods</h2>

<p>See the base [page:Controls] class for common methods.</p>
Expand Down
10 changes: 10 additions & 0 deletions examples/jsm/controls/TransformControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ class TransformControls extends Controls {
defineProperty( 'showX', true );
defineProperty( 'showY', true );
defineProperty( 'showZ', true );
defineProperty( 'minX', - Infinity );
defineProperty( 'maxX', Infinity );
defineProperty( 'minY', - Infinity );
defineProperty( 'maxY', Infinity );
defineProperty( 'minZ', - Infinity );
defineProperty( 'maxZ', Infinity );

// Reusable utility variables

Expand Down Expand Up @@ -372,6 +378,10 @@ class TransformControls extends Controls {

}

object.position.x = Math.max( this.minX, Math.min( this.maxX, object.position.x ) );
object.position.y = Math.max( this.minY, Math.min( this.maxY, object.position.y ) );
object.position.z = Math.max( this.minZ, Math.min( this.maxZ, object.position.z ) );

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

if ( axis.search( 'XYZ' ) !== - 1 ) {
Expand Down