Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/api/en/helpers/SkeletonHelper.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ <h3>[method:undefined dispose]()</h3>
Frees the GPU-related resources allocated by this instance. Call this
method whenever this instance is no longer used in your app.
</p>

<h3>[method:this setColors]( [param:Color color1], [param:Color color2] )</h3>
<p>Defines the colors of the helper.</p>

<h2>Source</h2>

<p>
Expand Down
1 change: 1 addition & 0 deletions examples/webgl_animation_walk.html
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@
//

skeleton = new THREE.SkeletonHelper( model );
skeleton.setColors( new THREE.Color( 0xe000ff ), new THREE.Color( 0x00e0ff ) );
skeleton.visible = false;
scene.add( skeleton );

Expand Down
3 changes: 3 additions & 0 deletions src/helpers/CameraHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class CameraHelper extends LineSegments {
* @param {Color} up - The up line color.
* @param {Color} target - The target line color.
* @param {Color} cross - The cross line color.
* @return {CameraHelper} A reference to this helper.
*/
setColors( frustum, cone, up, target, cross ) {

Expand Down Expand Up @@ -215,6 +216,8 @@ class CameraHelper extends LineSegments {

colorAttribute.needsUpdate = true;

return this;

}

/**
Expand Down
41 changes: 35 additions & 6 deletions src/helpers/SkeletonHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const _matrixWorldInv = /*@__PURE__*/ new Matrix4();
class SkeletonHelper extends LineSegments {

/**
* Constructs a new hemisphere light helper.
* Constructs a new skeleton helper.
*
* @param {Object3D} object - Usually an instance of {@link SkinnedMesh}. However, any 3D object
* can be used if it represents a hierarchy of bones (see {@link Bone}).
Expand All @@ -37,9 +37,6 @@ class SkeletonHelper extends LineSegments {
const vertices = [];
const colors = [];

const color1 = new Color( 0, 0, 1 );
const color2 = new Color( 0, 1, 0 );

for ( let i = 0; i < bones.length; i ++ ) {

const bone = bones[ i ];
Expand All @@ -48,8 +45,8 @@ class SkeletonHelper extends LineSegments {

vertices.push( 0, 0, 0 );
vertices.push( 0, 0, 0 );
colors.push( color1.r, color1.g, color1.b );
colors.push( color2.r, color2.g, color2.b );
colors.push( 0, 0, 0 );
colors.push( 0, 0, 0 );

}

Expand Down Expand Up @@ -90,6 +87,13 @@ class SkeletonHelper extends LineSegments {
this.matrix = object.matrixWorld;
this.matrixAutoUpdate = false;

// colors

const color1 = new Color( 0x0000ff );
const color2 = new Color( 0x00ff00 );

this.setColors( color1, color2 );

}

updateMatrixWorld( force ) {
Expand Down Expand Up @@ -127,6 +131,31 @@ class SkeletonHelper extends LineSegments {

}

/**
* Defines the colors of the helper.
*
* @param {Color} color1 - The first line color for each bone.
* @param {Color} color2 - The second line color for each bone.
* @return {SkeletonHelper} A reference to this helper.
*/
setColors( color1, color2 ) {

const geometry = this.geometry;
const colorAttribute = geometry.getAttribute( 'color' );

for ( let i = 0; i < colorAttribute.count; i += 2 ) {

colorAttribute.setXYZ( i, color1.r, color1.g, color1.b );
colorAttribute.setXYZ( i + 1, color2.r, color2.g, color2.b );

}

colorAttribute.needsUpdate = true;

return this;

}

/**
* Frees the GPU-related resources allocated by this instance. Call this
* method whenever this instance is no longer used in your app.
Expand Down
Loading