@@ -23,7 +23,7 @@ const _matrixWorldInv = /*@__PURE__*/ new Matrix4();
2323class SkeletonHelper extends LineSegments {
2424
2525 /**
26- * Constructs a new hemisphere light helper.
26+ * Constructs a new skeleton helper.
2727 *
2828 * @param {Object3D } object - Usually an instance of {@link SkinnedMesh}. However, any 3D object
2929 * can be used if it represents a hierarchy of bones (see {@link Bone}).
@@ -37,9 +37,6 @@ class SkeletonHelper extends LineSegments {
3737 const vertices = [ ] ;
3838 const colors = [ ] ;
3939
40- const color1 = new Color ( 0 , 0 , 1 ) ;
41- const color2 = new Color ( 0 , 1 , 0 ) ;
42-
4340 for ( let i = 0 ; i < bones . length ; i ++ ) {
4441
4542 const bone = bones [ i ] ;
@@ -48,8 +45,8 @@ class SkeletonHelper extends LineSegments {
4845
4946 vertices . push ( 0 , 0 , 0 ) ;
5047 vertices . push ( 0 , 0 , 0 ) ;
51- colors . push ( color1 . r , color1 . g , color1 . b ) ;
52- colors . push ( color2 . r , color2 . g , color2 . b ) ;
48+ colors . push ( 0 , 0 , 0 ) ;
49+ colors . push ( 0 , 0 , 0 ) ;
5350
5451 }
5552
@@ -90,6 +87,13 @@ class SkeletonHelper extends LineSegments {
9087 this . matrix = object . matrixWorld ;
9188 this . matrixAutoUpdate = false ;
9289
90+ // colors
91+
92+ const color1 = new Color ( 0x0000ff ) ;
93+ const color2 = new Color ( 0x00ff00 ) ;
94+
95+ this . setColors ( color1 , color2 ) ;
96+
9397 }
9498
9599 updateMatrixWorld ( force ) {
@@ -127,6 +131,31 @@ class SkeletonHelper extends LineSegments {
127131
128132 }
129133
134+ /**
135+ * Defines the colors of the helper.
136+ *
137+ * @param {Color } color1 - The first line color for each bone.
138+ * @param {Color } color2 - The second line color for each bone.
139+ * @return {SkeletonHelper } A reference to this helper.
140+ */
141+ setColors ( color1 , color2 ) {
142+
143+ const geometry = this . geometry ;
144+ const colorAttribute = geometry . getAttribute ( 'color' ) ;
145+
146+ for ( let i = 0 ; i < colorAttribute . count ; i += 2 ) {
147+
148+ colorAttribute . setXYZ ( i , color1 . r , color1 . g , color1 . b ) ;
149+ colorAttribute . setXYZ ( i + 1 , color2 . r , color2 . g , color2 . b ) ;
150+
151+ }
152+
153+ colorAttribute . needsUpdate = true ;
154+
155+ return this ;
156+
157+ }
158+
130159 /**
131160 * Frees the GPU-related resources allocated by this instance. Call this
132161 * method whenever this instance is no longer used in your app.
0 commit comments