three.js Skeleton

2023-02-16 17:47 更新

使用一個(gè)bones數(shù)組來創(chuàng)建一個(gè)可以由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 );

構(gòu)造器

Skeleton( bones : Array, boneInverses : Array )

bones —— 包含有一組bone的數(shù)組,默認(rèn)值是一個(gè)空數(shù)組。
boneInverses —— (可選) 包含Matrix4的數(shù)組。

創(chuàng)建一個(gè)新的Skeleton.

屬性

.bones : Array

包含有一組bone的數(shù)組。請(qǐng)注意,這是一份原始數(shù)組的拷貝,不是引用,所以你可以在不對(duì)當(dāng)前數(shù)組造成影響的情況下,修改原始數(shù)組。

.boneInverses : Array

包含有一組Matrix4,表示每個(gè)獨(dú)立骨骼m(xù)atrixWorld矩陣的逆矩陣。

.boneMatrices : Float32Array

當(dāng)使用頂點(diǎn)紋理時(shí),數(shù)組緩沖區(qū)保存著骨骼數(shù)據(jù)。

.boneTexture : DataTexture

當(dāng)使用頂點(diǎn)紋理時(shí),DataTexture保存著骨骼數(shù)據(jù)。

.boneTextureSize : Integer

.boneTexture 的大小。

方法

.clone () : Skeleton

返回一個(gè)當(dāng)前Skeleton對(duì)象的克隆。

.calculateInverses () : undefined

如果沒有在構(gòu)造器中提供,生成boneInverses數(shù)組。

.computeBoneTexture () : this

計(jì)算 DataTexture 的一個(gè)實(shí)例,以便更有效地將骨骼數(shù)據(jù)傳遞給著色器。紋理被分配給 boneTexture。

.pose () : undefined

返回骨架的基礎(chǔ)姿勢(shì)。

.update () : undefined

在改變骨骼后,更新boneMatrices 和 boneTexture的值。 如果骨架被用于SkinnedMesh,則它將會(huì)被WebGLRenderer自動(dòng)調(diào)用。

.getBoneByName ( name : String ) : Bone

name —— 匹配Bone對(duì)象中.name屬性的字符串。

在骨架中的骨骼數(shù)組中遍覽,并返回第一個(gè)能夠和name匹配上的骨骼對(duì)象。

.dispose () : undefined

如果 Skeleton 的實(shí)例在應(yīng)用程序中變得過時(shí),則可以使用。該方法將釋放內(nèi)部資源。

源代碼

src/objects/Skeleton.js


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)