Capítulo 772 de 859

Chapter 772: Skeleton

Core Idea

Class for representing the armatures in three.js. The skeleton is defined by a hierarchy of bones.

Key Concepts

  • boneInverses : Array.<Matrix4>: An array of bone inverse matrices.
  • boneMatrices : Float32Array: An array buffer holding the bone data. Input data for Skeleton#boneTexture.
  • boneTexture : DataTexture: A texture holding the bone data for use in the vertex shader.
  • bones : Array.<Bone>: An array of bones defining the skeleton.

Code Examples

const bones = [];
const shoulder = new THREE.Bone();
const elbow = new THREE.Bone();
const hand = new THREE.Bone();
shoulder.add( elbow );
elbow.add( hand );
bones.push( shoulder , elbow, hand);
shoulder.position.y = -5;
elbow.position.y = 0;
hand.position.y = 5;
const armSkeleton = new THREE.Skeleton( bones );
  • What it demonstrates: Typical usage of Skeleton.

Reference Tables

Constructor

Signature
new Skeleton( bones : Array.<Bone>, boneInverses : Array.<Matrix4> )

Properties

PropertyDescription
.boneInverses : Array.<Matrix4>An array of bone inverse matrices.
.boneMatrices : Float32ArrayAn array buffer holding the bone data. Input data for Skeleton#boneTexture.
.boneTexture : DataTextureA texture holding the bone data for use in the vertex shader.
.bones : Array.<Bone>An array of bones defining the skeleton.

Methods

MethodDescription
.calculateInverses()Computes the bone inverse matrices. This method resets Skeleton#boneInverses and fills it with new matrices.
.clone() : SkeletonReturns a new skeleton with copied values from this instance.
.computeBoneTexture() : SkeletonComputes a data texture for passing bone data to the vertex shader.
.dispose()Frees the GPU-related resources allocated by this instance. Call this method whenever this instance is no longer used in your app.
.fromJSON( json : Object, bones : Object.<string, Bone> ) : SkeletonSetups the skeleton by the given JSON and bones.
`.getBoneByName( name : string ) : Boneundefined`
.init()Initializes the skeleton. This method gets automatically called by the constructor but depending on how the skeleton is created it might be necessary to call this method manually.
.pose()Resets the skeleton to the base pose.
.toJSON() : ObjectSerializes the skeleton into JSON.
.update()Resets the skeleton to the base pose.

Key Takeaways

  1. Most relevant properties: boneInverses, boneMatrices, boneTexture, bones.
  2. Key methods: calculateInverses, clone, computeBoneTexture, dispose.

Connects To