Skip to content

Commit 7a5a5f0

Browse files
committed
TransformControls: Added hideX, hideY and hideZ property for explicit
axis hiding.
1 parent 854c560 commit 7a5a5f0

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

examples/js/controls/TransformControls.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ THREE.TransformControls = function ( camera, domElement ) {
3131
defineProperty( "space", "world" );
3232
defineProperty( "size", 1 );
3333
defineProperty( "dragging", false );
34+
defineProperty( "showX", true );
35+
defineProperty( "showY", true );
36+
defineProperty( "showZ", true );
3437

3538
var changeEvent = { type: "change" };
3639
var mouseDownEvent = { type: "mouseDown" };
@@ -1193,6 +1196,7 @@ THREE.TransformControlsGizmo = function () {
11931196
var PLANE_HIDE_TRESHOLD = 0.2;
11941197
var AXIS_FLIP_TRESHOLD = -0.4;
11951198

1199+
11961200
if ( handle.name === 'X' || handle.name === 'XYZX' ) {
11971201
if ( Math.abs( alignVector.copy( unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_TRESHOLD ) {
11981202
handle.scale.set( 1e-10, 1e-10, 1e-10 );
@@ -1307,6 +1311,14 @@ THREE.TransformControlsGizmo = function () {
13071311

13081312
}
13091313

1314+
// Hide disabled axes
1315+
for ( var a in handle.name ) {
1316+
handle.visible = handle.visible && ( handle.name.indexOf( "X" ) === -1 || this.showX );
1317+
handle.visible = handle.visible && ( handle.name.indexOf( "Y" ) === -1 || this.showY );
1318+
handle.visible = handle.visible && ( handle.name.indexOf( "Z" ) === -1 || this.showZ );
1319+
handle.visible = handle.visible && ( handle.name.indexOf( "E" ) === -1 || ( this.showX && this.showY && this.showZ ) );
1320+
}
1321+
13101322
// highlight selected axis
13111323

13121324
handle.material._opacity = handle.material._opacity || handle.material.opacity;

examples/misc_controls_transform.html

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,15 @@
2929
<body>
3030

3131
<div id="info">
32-
<a href="javascript:control.setMode( 'translate' );">"W" translate</a> |
33-
<a href="javascript:control.setMode( 'rotate' );">"E" rotate</a> |
34-
<a href="javascript:control.setMode( 'scale' );">"R" scale</a> |
35-
<a href="javascript:control.setSize( control.size + 0.1 );">"+" increase size</a> |
36-
<a href="javascript:control.setSize( Math.max( control.size - 0.1, 0.1 ) );">"-" decrease size</a><br />
37-
Press "Q" to toggle world/local space, keep "Ctrl" down to snap to grid
32+
<a href="javascript:control.setMode( 'translate' );">"W" translate</a> |
33+
<a href="javascript:control.setMode( 'rotate' );">"E" rotate</a> |
34+
<a href="javascript:control.setMode( 'scale' );">"R" scale</a> |
35+
<a href="javascript:control.setSize( control.size + 0.1 );">"+" increase size</a> |
36+
<a href="javascript:control.setSize( Math.max( control.size - 0.1, 0.1 ) );">"-" decrease size</a><br />
37+
<a href="javascript:control.setSpace( control.space === 'local' ? 'world' : 'local' );">"Q" toggle world/local space</a> | Hold "Ctrl" down to snap to grid<br />
38+
<a href="javascript:control.showX = !control.showX">"X" toggle X</a> |
39+
<a href="javascript:control.showY = !control.showY">"Y" toggle Y</a> |
40+
<a href="javascript:control.showZ = !control.showZ">"Z" toggle Z</a><br />
3841
</div>
3942

4043
<script src="../build/three.js"></script>
@@ -119,6 +122,18 @@
119122
control.setSize( Math.max( control.size - 0.1, 0.1 ) );
120123
break;
121124

125+
case 88: // X
126+
control.showX = !control.showX;
127+
break;
128+
129+
case 89: // Y
130+
control.showY = !control.showY;
131+
break;
132+
133+
case 90: // Z
134+
control.showZ = !control.showZ;
135+
break;
136+
122137
}
123138

124139
});

0 commit comments

Comments
 (0)