骨架(Skeleton)

优质
小牛编辑
115浏览
2023-12-01

使用一个bones数组来创建一个可以由SkinnedMesh使用的骨架。

代码示例

// Create a simple "arm"
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 );
bones.push( elbow );
bones.push( hand );
shoulder.position.y = -5;
elbow.position.y = 0;
hand.position.y = 5;
const armSkeleton = new THREE.Skeleton( bones );

请查看SkinnedMesh页面,来查看其在标准的BufferGeometry中使用的示例。

构造器

Skeleton( bones : Array, boneInverses : Array )

bones —— 包含有一组bone的数组,默认值是一个空数组。
boneInverses —— (可选) 包含Matrix4的数组。

创建一个新的Skeleton.

属性

.bones : Array

包含有一组bone的数组。请注意,这是一份原始数组的拷贝,不是引用,所以你可以在不对当前数组造成影响的情况下,修改原始数组。

.boneInverses : Array

包含有一组Matrix4,表示每个独立骨骼matrixWorld矩阵的逆矩阵。

.boneMatrices : Float32Array

当使用顶点纹理时,数组缓冲区保存着骨骼数据。

.boneTexture : DataTexture

当使用顶点纹理时,DataTexture保存着骨骼数据。

.boneTextureSize : Integer

The size of the .boneTexture.

方法

.clone () : Skeleton

返回一个当前Skeleton对象的克隆。

.calculateInverses () : null

如果没有在构造器中提供,生成boneInverses数组。

.computeBoneTexture () : null

Computes an instance of DataTexture in order to pass the bone data more efficiently to the shader. The texture is assigned to boneTexture.

.pose () : null

返回骨架的基础姿势。

.update () : null

在改变骨骼后,更新boneMatricesboneTexture的值。 如果骨架被用于SkinnedMesh,则它将会被WebGLRenderer自动调用。

.getBoneByName ( name : String ) : Bone

name —— 匹配Bone对象中.name属性的字符串。

在骨架中的骨骼数组中遍览,并返回第一个能够和name匹配上的骨骼对象。

.dispose () : null

Can be used if an instance of Skeleton becomes obsolete in an application. The method will free internal resources.

源代码

src/objects/Skeleton.js