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:
var aspose = aspose || {};
aspose.threed = require("aspose.3d");
// Create a scene with a box mesh
var scene = new aspose.threed.Scene();
var mesh = new aspose.threed.Box(1, 1, 1).toMesh();
// Morph target: same vertex layout with positions scaled by 2, built as a Shape
var controlPoints = [];
for (var i = 0; i < mesh.getControlPoints().size(); i++) {
var cp = mesh.getControlPoints().get(i);
controlPoints.push(new aspose.threed.Vector3(cp.x * 2, cp.y * 2, cp.z * 2));
}
var target = aspose.threed.Shape.fromControlPoints(controlPoints);
// Create the morph target deformer with one channel
var deformer = new aspose.threed.MorphTargetDeformer("morph");
var channel = new aspose.threed.MorphTargetChannel("squeeze");
channel.getTargets().add(target);
channel.getWeights().add(0.7);
deformer.getChannels().add(channel);
// Attach the deformer to the mesh and add the mesh to the scene
mesh.getDeformers().add(deformer);
scene.getRootNode().createChildNode("morph-box", mesh);
// Save to FBX, the morph target is written as a BlendShape deformer
scene.save("morph.fbx", aspose.threed.FileFormat.FBX7400ASCII);Notes on File Formats
Morph targets roundtrip through FBX, where the deformer is written as a BlendShape with a BlendShapeChannel per channel.