Apply Morph Target Deformer to Mesh
Contents
[
Hide
]
Apply Morph Target Deformer to Mesh
A morph target deformer blends one or more pre-defined target shapes onto a mesh, controlled by a weight per target. This is the standard mechanism for effects like facial expressions or shape key animation.
The MorphTargetDeformer holds one or more MorphTargetChannels. Each channel has a list of target shapes — Shape instances built from the same vertex layout as the base mesh — and a list of weights, one per target.
Adding a Morph Target
This code example creates a box mesh and adds a single morph target whose positions are scaled by two, blended at weight 0.7:
from aspose.threed import Scene, FileFormat
from aspose.threed.deformers import MorphTargetDeformer, MorphTargetChannel
from aspose.threed.entities import Box, Shape
from aspose.threed.utilities import Vector3
# Create a scene with a box mesh
scene = Scene()
mesh = Box(1.0, 1.0, 1.0).to_mesh()
# Morph target: same vertex layout with positions scaled by 2, built as a Shape
control_points = []
for cp in mesh.control_points:
control_points.append(Vector3(cp.x * 2.0, cp.y * 2.0, cp.z * 2.0))
target = Shape.from_control_points(control_points)
# Create the morph target deformer with one channel
deformer = MorphTargetDeformer("morph")
channel = MorphTargetChannel("squeeze")
channel.targets.append(target)
channel.weights.append(0.7)
deformer.channels.append(channel)
# Attach the deformer to the mesh and add the mesh to the scene
mesh.deformers.append(deformer)
scene.root_node.create_child_node("morph-box", mesh)
# Save to FBX, the morph target is written as a BlendShape deformer
scene.save("morph.fbx", FileFormat.FBX7400ASCII)Notes on File Formats
Morph targets roundtrip through FBX, where the deformer is written as a BlendShape with a BlendShapeChannel per channel.