Apply Skin Deformer to Mesh
Apply Skin Deformer to Mesh
Skeletal animation works by attaching a mesh to a skeleton: a SkinDeformer binds the mesh’s control points to one or more bones, and moving the bone nodes displaces the parts of the mesh they influence.
Each Bone in the deformer is linked to a Node in the scene — the bone node — through its node property. Every control point of the geometry can be bound to more than one bone; the per-control-point blend weights define how strongly each bone influences that point.
Creating a Skinned Mesh
This code example creates a tall box mesh, builds a two-bone skeleton, and binds the lower half of the mesh to the first bone and the upper half to the second:
from aspose.threed import Scene, FileFormat
from aspose.threed.deformers import SkinDeformer, Bone
from aspose.threed.entities import Box
# Create a scene with a tall box mesh
scene = Scene()
mesh = Box(1.0, 8.0, 1.0).to_mesh()
# Skeleton: bone1 at the root, bone2 as its child
bone1_node = scene.root_node.create_child_node("bone1")
bone2_node = bone1_node.create_child_node("bone2")
# Create the skin deformer, each bone is linked to a skeleton node
skin = SkinDeformer("skin")
bone1 = Bone("bone1")
bone1.node = bone1_node
bone2 = Bone("bone2")
bone2.node = bone2_node
skin.bones.append(bone1)
skin.bones.append(bone2)
# Blend weights per control point: lower half follows bone1, upper half follows bone2
for i in range(len(mesh.control_points)):
weight = 1.0 if mesh.control_points[i].y >= 0 else 0.0
bone1.set_weight(i, 1.0 - weight)
bone2.set_weight(i, weight)
# Attach the deformer to the mesh and add the mesh to the scene
mesh.deformers.append(skin)
scene.root_node.create_child_node("skinned-box", mesh)
# Save to FBX, the skin and its bones are written as deformer clusters
scene.save("skinned.fbx", FileFormat.FBX7400ASCII)Animating the Bones
The bones are ordinary scene nodes, so they can be animated with key-frame animation like any other node — animating a bone node’s transform deforms the skinned mesh, see add animation property and setup target camera in 3D document.
Notes on File Formats
Skins roundtrip through FBX, where each bone is written as a deformer cluster.
SkinDeformer saved to glTF 2.0 keeps only the geometry, without warning. If you need the skeleton in glTF, export to FBX and convert with an external tool for now.