Skip to content

Commit 279db99

Browse files
authored
TransformControls: Add min/max constraints. (#29602)
* add min/max constraints to TransformControls * update TransformControls documentation
1 parent 69e0515 commit 279db99

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

docs/examples/en/controls/TransformControls.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,36 @@ <h3>[property:Number translationSnap]</h3>
132132
steps the 3D object should be translated. Default is `null`.
133133
</p>
134134

135+
<h3>[property:Number minX]</h3>
136+
<p>
137+
The minimum allowed X position during translation. Default is `-Infinity`.
138+
</p>
139+
140+
<h3>[property:Number maxX]</h3>
141+
<p>
142+
The maximum allowed X position during translation. Default is `Infinity`.
143+
</p>
144+
145+
<h3>[property:Number minY]</h3>
146+
<p>
147+
The minimum allowed Y position during translation. Default is `-Infinity`.
148+
</p>
149+
150+
<h3>[property:Number maxY]</h3>
151+
<p>
152+
The maximum allowed Y position during translation. Default is `Infinity`.
153+
</p>
154+
155+
<h3>[property:Number minZ]</h3>
156+
<p>
157+
The minimum allowed Z position during translation. Default is `-Infinity`.
158+
</p>
159+
160+
<h3>[property:Number maxZ]</h3>
161+
<p>
162+
The maximum allowed Z position during translation. Default is `Infinity`.
163+
</p>
164+
135165
<h2>Methods</h2>
136166

137167
<p>See the base [page:Controls] class for common methods.</p>

examples/jsm/controls/TransformControls.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ class TransformControls extends Controls {
110110
defineProperty( 'showX', true );
111111
defineProperty( 'showY', true );
112112
defineProperty( 'showZ', true );
113+
defineProperty( 'minX', - Infinity );
114+
defineProperty( 'maxX', Infinity );
115+
defineProperty( 'minY', - Infinity );
116+
defineProperty( 'maxY', Infinity );
117+
defineProperty( 'minZ', - Infinity );
118+
defineProperty( 'maxZ', Infinity );
113119

114120
// Reusable utility variables
115121

@@ -372,6 +378,10 @@ class TransformControls extends Controls {
372378

373379
}
374380

381+
object.position.x = Math.max( this.minX, Math.min( this.maxX, object.position.x ) );
382+
object.position.y = Math.max( this.minY, Math.min( this.maxY, object.position.y ) );
383+
object.position.z = Math.max( this.minZ, Math.min( this.maxZ, object.position.z ) );
384+
375385
} else if ( mode === 'scale' ) {
376386

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

0 commit comments

Comments
 (0)