@@ -888,6 +888,40 @@ class TransformControls extends Controls {
888888
889889 }
890890
891+ /**
892+ * Sets the colors of the control's gizmo.
893+ *
894+ * @param {number|Color|string } xAxis - The x-axis color.
895+ * @param {number|Color|string } yAxis - The y-axis color.
896+ * @param {number|Color|string } zAxis - The z-axis color.
897+ * @param {number|Color|string } active - The color for active elements.
898+ */
899+ setColors ( xAxis , yAxis , zAxis , active ) {
900+
901+ const materialLib = this . _gizmo . materialLib ;
902+
903+ materialLib . xAxis . color . set ( xAxis ) ;
904+ materialLib . yAxis . color . set ( yAxis ) ;
905+ materialLib . zAxis . color . set ( zAxis ) ;
906+ materialLib . active . color . set ( active ) ;
907+ materialLib . xAxisTransparent . color . set ( xAxis ) ;
908+ materialLib . yAxisTransparent . color . set ( yAxis ) ;
909+ materialLib . zAxisTransparent . color . set ( zAxis ) ;
910+ materialLib . activeTransparent . color . set ( active ) ;
911+
912+ // update color caches
913+
914+ if ( materialLib . xAxis . _color ) materialLib . xAxis . _color . set ( xAxis ) ;
915+ if ( materialLib . yAxis . _color ) materialLib . yAxis . _color . set ( yAxis ) ;
916+ if ( materialLib . zAxis . _color ) materialLib . zAxis . _color . set ( zAxis ) ;
917+ if ( materialLib . active . _color ) materialLib . active . _color . set ( active ) ;
918+ if ( materialLib . xAxisTransparent . _color ) materialLib . xAxisTransparent . _color . set ( xAxis ) ;
919+ if ( materialLib . yAxisTransparent . _color ) materialLib . yAxisTransparent . _color . set ( yAxis ) ;
920+ if ( materialLib . zAxisTransparent . _color ) materialLib . zAxisTransparent . _color . set ( zAxis ) ;
921+ if ( materialLib . activeTransparent . _color ) materialLib . activeTransparent . _color . set ( active ) ;
922+
923+ }
924+
891925}
892926
893927// mouse / touch event handlers
@@ -1146,6 +1180,19 @@ class TransformControlsGizmo extends Object3D {
11461180 const matGray = gizmoMaterial . clone ( ) ;
11471181 matGray . color . setHex ( 0x787878 ) ;
11481182
1183+ // materials in the below property are configurable via setColors()
1184+
1185+ this . materialLib = {
1186+ xAxis : matRed ,
1187+ yAxis : matGreen ,
1188+ zAxis : matBlue ,
1189+ active : matYellow ,
1190+ xAxisTransparent : matRedTransparent ,
1191+ yAxisTransparent : matGreenTransparent ,
1192+ zAxisTransparent : matBlueTransparent ,
1193+ activeTransparent : matYellowTransparent
1194+ } ;
1195+
11491196 // reusable geometry
11501197
11511198 const arrowGeometry = new CylinderGeometry ( 0 , 0.04 , 0.1 , 12 ) ;
@@ -1200,16 +1247,16 @@ class TransformControlsGizmo extends Object3D {
12001247 [ new Mesh ( lineGeometry2 , matBlue ) , null , [ Math . PI / 2 , 0 , 0 ] ]
12011248 ] ,
12021249 XYZ : [
1203- [ new Mesh ( new OctahedronGeometry ( 0.1 , 0 ) , matWhiteTransparent . clone ( ) ) , [ 0 , 0 , 0 ] ]
1250+ [ new Mesh ( new OctahedronGeometry ( 0.1 , 0 ) , matWhiteTransparent ) , [ 0 , 0 , 0 ] ]
12041251 ] ,
12051252 XY : [
1206- [ new Mesh ( new BoxGeometry ( 0.15 , 0.15 , 0.01 ) , matBlueTransparent . clone ( ) ) , [ 0.15 , 0.15 , 0 ] ]
1253+ [ new Mesh ( new BoxGeometry ( 0.15 , 0.15 , 0.01 ) , matBlueTransparent ) , [ 0.15 , 0.15 , 0 ] ]
12071254 ] ,
12081255 YZ : [
1209- [ new Mesh ( new BoxGeometry ( 0.15 , 0.15 , 0.01 ) , matRedTransparent . clone ( ) ) , [ 0 , 0.15 , 0.15 ] , [ 0 , Math . PI / 2 , 0 ] ]
1256+ [ new Mesh ( new BoxGeometry ( 0.15 , 0.15 , 0.01 ) , matRedTransparent ) , [ 0 , 0.15 , 0.15 ] , [ 0 , Math . PI / 2 , 0 ] ]
12101257 ] ,
12111258 XZ : [
1212- [ new Mesh ( new BoxGeometry ( 0.15 , 0.15 , 0.01 ) , matGreenTransparent . clone ( ) ) , [ 0.15 , 0 , 0.15 ] , [ - Math . PI / 2 , 0 , 0 ] ]
1259+ [ new Mesh ( new BoxGeometry ( 0.15 , 0.15 , 0.01 ) , matGreenTransparent ) , [ 0.15 , 0 , 0.15 ] , [ - Math . PI / 2 , 0 , 0 ] ]
12131260 ]
12141261 } ;
12151262
@@ -1251,13 +1298,13 @@ class TransformControlsGizmo extends Object3D {
12511298 [ new Line ( TranslateHelperGeometry ( ) , matHelper ) , null , null , null , 'helper' ]
12521299 ] ,
12531300 X : [
1254- [ new Line ( lineGeometry , matHelper . clone ( ) ) , [ - 1e3 , 0 , 0 ] , null , [ 1e6 , 1 , 1 ] , 'helper' ]
1301+ [ new Line ( lineGeometry , matHelper ) , [ - 1e3 , 0 , 0 ] , null , [ 1e6 , 1 , 1 ] , 'helper' ]
12551302 ] ,
12561303 Y : [
1257- [ new Line ( lineGeometry , matHelper . clone ( ) ) , [ 0 , - 1e3 , 0 ] , [ 0 , 0 , Math . PI / 2 ] , [ 1e6 , 1 , 1 ] , 'helper' ]
1304+ [ new Line ( lineGeometry , matHelper ) , [ 0 , - 1e3 , 0 ] , [ 0 , 0 , Math . PI / 2 ] , [ 1e6 , 1 , 1 ] , 'helper' ]
12581305 ] ,
12591306 Z : [
1260- [ new Line ( lineGeometry , matHelper . clone ( ) ) , [ 0 , 0 , - 1e3 ] , [ 0 , - Math . PI / 2 , 0 ] , [ 1e6 , 1 , 1 ] , 'helper' ]
1307+ [ new Line ( lineGeometry , matHelper ) , [ 0 , 0 , - 1e3 ] , [ 0 , - Math . PI / 2 , 0 ] , [ 1e6 , 1 , 1 ] , 'helper' ]
12611308 ]
12621309 } ;
12631310
@@ -1281,7 +1328,7 @@ class TransformControlsGizmo extends Object3D {
12811328
12821329 const helperRotate = {
12831330 AXIS : [
1284- [ new Line ( lineGeometry , matHelper . clone ( ) ) , [ - 1e3 , 0 , 0 ] , null , [ 1e6 , 1 , 1 ] , 'helper' ]
1331+ [ new Line ( lineGeometry , matHelper ) , [ - 1e3 , 0 , 0 ] , null , [ 1e6 , 1 , 1 ] , 'helper' ]
12851332 ]
12861333 } ;
12871334
@@ -1329,7 +1376,7 @@ class TransformControlsGizmo extends Object3D {
13291376 [ new Mesh ( new BoxGeometry ( 0.15 , 0.15 , 0.01 ) , matGreenTransparent ) , [ 0.15 , 0 , 0.15 ] , [ - Math . PI / 2 , 0 , 0 ] ]
13301377 ] ,
13311378 XYZ : [
1332- [ new Mesh ( new BoxGeometry ( 0.1 , 0.1 , 0.1 ) , matWhiteTransparent . clone ( ) ) ] ,
1379+ [ new Mesh ( new BoxGeometry ( 0.1 , 0.1 , 0.1 ) , matWhiteTransparent ) ] ,
13331380 ]
13341381 } ;
13351382
@@ -1362,13 +1409,13 @@ class TransformControlsGizmo extends Object3D {
13621409
13631410 const helperScale = {
13641411 X : [
1365- [ new Line ( lineGeometry , matHelper . clone ( ) ) , [ - 1e3 , 0 , 0 ] , null , [ 1e6 , 1 , 1 ] , 'helper' ]
1412+ [ new Line ( lineGeometry , matHelper ) , [ - 1e3 , 0 , 0 ] , null , [ 1e6 , 1 , 1 ] , 'helper' ]
13661413 ] ,
13671414 Y : [
1368- [ new Line ( lineGeometry , matHelper . clone ( ) ) , [ 0 , - 1e3 , 0 ] , [ 0 , 0 , Math . PI / 2 ] , [ 1e6 , 1 , 1 ] , 'helper' ]
1415+ [ new Line ( lineGeometry , matHelper ) , [ 0 , - 1e3 , 0 ] , [ 0 , 0 , Math . PI / 2 ] , [ 1e6 , 1 , 1 ] , 'helper' ]
13691416 ] ,
13701417 Z : [
1371- [ new Line ( lineGeometry , matHelper . clone ( ) ) , [ 0 , 0 , - 1e3 ] , [ 0 , - Math . PI / 2 , 0 ] , [ 1e6 , 1 , 1 ] , 'helper' ]
1418+ [ new Line ( lineGeometry , matHelper ) , [ 0 , 0 , - 1e3 ] , [ 0 , - Math . PI / 2 , 0 ] , [ 1e6 , 1 , 1 ] , 'helper' ]
13721419 ]
13731420 } ;
13741421
@@ -1749,7 +1796,7 @@ class TransformControlsGizmo extends Object3D {
17491796
17501797 if ( handle . name === this . axis ) {
17511798
1752- handle . material . color . setHex ( 0xffff00 ) ;
1799+ handle . material . color . copy ( this . materialLib . active . color ) ;
17531800 handle . material . opacity = 1.0 ;
17541801
17551802 } else if ( this . axis . split ( '' ) . some ( function ( a ) {
@@ -1758,7 +1805,7 @@ class TransformControlsGizmo extends Object3D {
17581805
17591806 } ) ) {
17601807
1761- handle . material . color . setHex ( 0xffff00 ) ;
1808+ handle . material . color . copy ( this . materialLib . active . color ) ;
17621809 handle . material . opacity = 1.0 ;
17631810
17641811 }
0 commit comments