From 1d817aff2859e911b7f2e2d60e52ce4bdb9a6867 Mon Sep 17 00:00:00 2001 From: Makio64 Date: Wed, 9 Oct 2024 21:25:36 +0200 Subject: [PATCH 1/2] add min/max constraints to TransformControls --- examples/jsm/controls/TransformControls.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/examples/jsm/controls/TransformControls.js b/examples/jsm/controls/TransformControls.js index 442c5060a06a91..563477d011e1a9 100644 --- a/examples/jsm/controls/TransformControls.js +++ b/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 ) { From e76c73dfc95529d7c54254946d6328891e631e7b Mon Sep 17 00:00:00 2001 From: Makio64 Date: Wed, 9 Oct 2024 22:40:52 +0200 Subject: [PATCH 2/2] update TransformControls documentation --- .../en/controls/TransformControls.html | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docs/examples/en/controls/TransformControls.html b/docs/examples/en/controls/TransformControls.html index 8b826c89935d7a..f9a154a44c419a 100644 --- a/docs/examples/en/controls/TransformControls.html +++ b/docs/examples/en/controls/TransformControls.html @@ -132,6 +132,36 @@

[property:Number translationSnap]

steps the 3D object should be translated. Default is `null`.

+

[property:Number minX]

+

+ The minimum allowed X position during translation. Default is `-Infinity`. +

+ +

[property:Number maxX]

+

+ The maximum allowed X position during translation. Default is `Infinity`. +

+ +

[property:Number minY]

+

+ The minimum allowed Y position during translation. Default is `-Infinity`. +

+ +

[property:Number maxY]

+

+ The maximum allowed Y position during translation. Default is `Infinity`. +

+ +

[property:Number minZ]

+

+ The minimum allowed Z position during translation. Default is `-Infinity`. +

+ +

[property:Number maxZ]

+

+ The maximum allowed Z position during translation. Default is `Infinity`. +

+

Methods

See the base [page:Controls] class for common methods.