[page:Object3D] → [page:Mesh] →

蒙皮网格([name])

具有[page:Skeleton](骨架)和[page:Bone bones](骨骼)的网格,可用于给几何体上的顶点添加动画。

代码示例

const geometry = new THREE.CylinderGeometry( 5, 5, 5, 5, 15, 5, 30 ); // create the skin indices and skin weights const position = geometry.attributes.position; const vertex = new THREE.Vector3(); const skinIndices = []; const skinWeights = []; for ( let i = 0; i < position.count; i ++ ) { vertex.fromBufferAttribute( position, i ); // compute skinIndex and skinWeight based on some configuration data const y = ( vertex.y + sizing.halfHeight ); const skinIndex = Math.floor( y / sizing.segmentHeight ); const skinWeight = ( y % sizing.segmentHeight ) / sizing.segmentHeight; skinIndices.push( skinIndex, skinIndex + 1, 0, 0 ); skinWeights.push( 1 - skinWeight, skinWeight, 0, 0 ); } geometry.setAttribute( 'skinIndex', new THREE.Uint16BufferAttribute( skinIndices, 4 ) ); geometry.setAttribute( 'skinWeight', new THREE.Float32BufferAttribute( skinWeights, 4 ) ); // create skinned mesh and skeleton const mesh = new THREE.SkinnedMesh( geometry, material ); const skeleton = new THREE.Skeleton( bones ); // see example from THREE.Skeleton const rootBone = skeleton.bones[ 0 ]; mesh.add( rootBone ); // bind the skeleton to the mesh mesh.bind( skeleton ); // move the bones and manipulate the model skeleton.bones[ 0 ].rotation.x = -0.1; skeleton.bones[ 1 ].rotation.x = 0.2;

构造器

[name]( [param:BufferGeometry geometry], [param:Material material] )

[page:BufferGeometry geometry] —— 一个[page:BufferGeometry]实例。
[page:Material material] —— (可选)一个[page:Material]实例,默认值是一个新的[page:MeshBasicMaterial]。

属性

共有属性请参见其基类[page:Mesh]。

[property:String bindMode]

附加绑定模式(`AttachedBindMode`)或分离绑定模式(`DetachedBindMode`)。`AttachedBindMode` 表示蒙皮网格与骨架共享相同的世界空间。 当使用 `DetachedBindMode` 时,情况并非如此,该模式在跨多个蒙皮网格共享骨架时非常有用。 默认设置为 `AttachedBindMode`。

[property:Matrix4 bindMatrix]

该基础矩阵用于绑定骨骼的变换。

[property:Matrix4 bindMatrixInverse]

该基础矩阵用于重置绑定骨骼的变换。

[property:Box3 boundingBox]

[name] 的包围盒。可以使用 [page:.computeBoundingBox]() 计算。默认值为 `null`。

[property:Sphere boundingSphere]

[name] 的包围球。可以使用 [page:.computeBoundingSphere]() 计算。默认值为 `null`。

[property:Boolean isSkinnedMesh]

只读属性,用于检查给定对象是否为[name]类型。

[property:Skeleton skeleton]

用于表示蒙皮网格中骨骼的层次结构的[page:Skeleton](骨架)。

方法

共有方法请参见其基类[page:Mesh]。

[method:Vector3 applyBoneTransform]( [param:Integer index], [param:Vector3 vector] )

将与给定索引关联的骨骼变换应用于给定的位置向量。返回更新后的向量。

[method:undefined bind]( [param:Skeleton skeleton], [param:Matrix4 bindMatrix] )

[page:Skeleton skeleton] —— 由一棵[page:Bone Bones]树创建的[page:Skeleton]。
[page:Matrix4 bindMatrix] —— 表示骨架基本变换的[page:Matrix4](4x4矩阵)。

将骨架绑定到一个蒙皮网格上。bindMatrix会被保存到.bindMatrix属性中,其逆矩阵.bindMatrixInverse也会被计算出来。

[method:SkinnedMesh clone]()

此方法目前无法正确克隆 [name] 实例。请同时使用 [page:SkeletonUtils.clone]()。

[method:undefined computeBoundingBox]()

计算包围盒,并更新 [page:.boundingBox] 属性。 默认情况下,包围盒不计算。需要显式计算,否则为 `null`。如果 [name] 实例已动画化,则应每帧调用此方法来计算正确的包围盒。

[method:undefined computeBoundingSphere]()

计算包围球,并更新 [page:.boundingSphere] 属性。 默认情况下,包围球不计算。需要显式计算,否则为 `null`。如果 [name] 实例已动画化,则应每帧调用此方法来计算正确的包围球。

[method:undefined normalizeSkinWeights]()

标准化蒙皮的权重。

[method:undefined pose]()

这个方法设置了在“休息”状态下蒙皮网格的姿势(重置姿势)。

源代码

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]