Просмотр исходного кода

TransformControls: Add min/max constraints. (#29602)

* add min/max constraints to TransformControls

* update TransformControls documentation
Makio64 1 год назад
Родитель
Сommit
279db99aaa

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

@@ -132,6 +132,36 @@
 			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>

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

@@ -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
 
@@ -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 ) {

粤ICP备19079148号