Object3DMesh

SkinnedMesh

A mesh that has a Skeleton with bones that can then be used to animate the vertices of the geometry. The material must support skinning and have skinning enabled - see MeshStandardMaterial.skinning.

Example

var geometry = new v3d.CylinderBufferGeometry(5, 5, 5, 5, 15, 5, 30); // create the skin indices and skin weights var position = geometry.attributes.position; var vertex = new v3d.Vector3(); var skinIndices = []; var skinWeights = []; for (var i = 0; i < position.count; i++) { vertex.fromBufferAttribute(position, i); // compute skinIndex and skinWeight based on some configuration data var y = (vertex.y + sizing.halfHeight); var skinIndex = Math.floor(y / sizing.segmentHeight); var skinWeight = (y % sizing.segmentHeight) / sizing.segmentHeight; skinIndices.push(skinIndex, skinIndex + 1, 0, 0); skinWeights.push(1 - skinWeight, skinWeight, 0, 0); } geometry.addAttribute('skinIndex', new v3d.Uint16BufferAttribute(skinIndices, 4)); geometry.addAttribute('skinWeight', new v3d.Float32BufferAttribute(skinWeights, 4)); // create skinned mesh and skeleton var mesh = new v3d.SkinnedMesh(geometry, material); var skeleton = new v3d.Skeleton(bones); // see example from v3d.Skeleton var 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;

Constructor

SkinnedMesh(geometry : BufferGeometry, material : Material)

geometry - an instance of BufferGeometry.
material - (optional) an instance of Material. Default is a new MeshBasicMaterial.

Properties

See the base Mesh class for common properties.

.bindMode : string

Either "attached" or "detached". "attached" uses the SkinnedMesh.matrixWorld property for the base transform matrix of the bones. "detached" uses the SkinnedMesh.bindMatrix. Default is "attached".

.bindMatrix : Matrix4

The base matrix that is used for the bound bone transforms.

.bindMatrixInverse : Matrix4

The base matrix that is used for resetting the bound bone transforms.

.isSkinnedMesh : Boolean

Used to check whether this or derived classes are skinned meshes. Default is true.

You should not change this, as it used internally for optimisation.

.skeleton : Skeleton

Skeleton representing the bone hierarchy of the skinned mesh.

Methods

See the base Mesh class for common methods.

.bind (skeleton : Skeleton, bindMatrix : Matrix4) : null

skeleton - Skeleton created from a Bones tree.
bindMatrix - Matrix4 that represents the base transform of the skeleton.

Bind a skeleton to the skinned mesh. The bindMatrix gets saved to .bindMatrix property and the .bindMatrixInverse gets calculated.

.clone () : SkinnedMesh

Returns a clone of this SkinnedMesh object and any descendants.

.normalizeSkinWeights () : null

Normalizes the skin weights.

.pose () : null

This method sets the skinned mesh in the rest pose (resets the pose).

.updateMatrixWorld (force : Boolean) : null

Updates the MatrixWorld.

Source

For more info on how to obtain the source code of this module see this page.