Skip to content

Commit f7e9e58

Browse files
committed
TransformControls: Added hideX, hideY and hideZ property for explicit
axis hiding.
1 parent ef3ac9a commit f7e9e58

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
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: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
<div id="info">
2929
"W" translate | "E" rotate | "R" scale | "+" increase size | "-" decrease size<br />
30-
Press "Q" to toggle world/local space, keep "Ctrl" down to snap to grid
30+
"Q" to toggle world/local space, Hold "Ctrl" to snap to grid<br />
31+
"X" | "Y" | "Z" toggle axes
3132
</div>
3233

3334
<script src="../build/three.js"></script>
@@ -113,6 +114,18 @@
113114
control.setSize( Math.max( control.size - 0.1, 0.1 ) );
114115
break;
115116

117+
case 88: // X
118+
control.showX = !control.showX;
119+
break;
120+
121+
case 89: // Y
122+
control.showY = !control.showY;
123+
break;
124+
125+
case 90: // Z
126+
control.showZ = !control.showZ;
127+
break;
128+
116129
}
117130

118131
});

0 commit comments

Comments
 (0)