Read Animation Information from a 3D Scene

Read Animation Information from a 3D Scene

When a scene with animation is loaded from FBX, glTF or another supported format, Aspose.3D stores the animation data as animation clips. Each clip contains an animation node tree; each animation node holds bind points that connect an object’s property to keyframe curve data, and each bind point exposes a channel per animated property component — a Vector3 property like Translation usually has X/Y/Z channels.

Enumerate the Animation Channels

This code example loads an animated scene and prints every animation channel with its keyframe count:

var aspose = aspose || {};

aspose.threed = require("aspose.3d");

// Load the 3D scene that contains animations
var scene = aspose.threed.Scene.fromFile("PropertyToDocument.fbx");

// Walk over every animation clip and print the animated property channels
var clips = scene.getAnimationClips();
for (var i = 0; i < clips.size(); i++) {
    var clip = clips.get(i);
    console.log("Clip: " + clip.getName());
    var animations = clip.getAnimations();
    for (var j = 0; j < animations.size(); j++) {
        var bindPoints = animations.get(j).getBindPoints();
        for (var k = 0; k < bindPoints.size(); k++) {
            var bindPoint = bindPoints.get(k);
            var channels = bindPoint.getChannels();
            for (var m = 0; m < channels.size(); m++) {
                var channel = channels.get(m);
                var keyframes = channel.getKeyframeSequence() != null
                        ? channel.getKeyframeSequence().getKeyFrames().size() : 0;
                console.log(bindPoint.getName() + "." + channel.getName() + ": " + keyframes + " keyframes");
            }
        }
    }
}

Find the Animations of a Property

Starting from version 26.4, every Property exposes the getBindPoints() collection and the getOwner() object, so you can find out which animation channels target a property without walking the whole clip tree:

var aspose = aspose || {};

aspose.threed = require("aspose.3d");

// Enumerate the bind points that animate the properties of an object, e.g. a node's transform
var node = scene.getRootNode().getChildNodes().get(0);
var properties = node.getTransform().getProperties();
for (var i = 0; i < properties.size(); i++) {
    var property = properties.get(i);
    var bindPoints = property.getBindPoints();
    for (var j = 0; j < bindPoints.size(); j++) {
        var bindPoint = bindPoints.get(j);
        console.log("Property " + property.getName() + " is animated by bind point " + bindPoint.getName());
    }
}

This code example produces the following output for a scene whose cube1 node has a keyframed Translation property:

Clip: AnimClip
Translation.X: 3 keyframes
Translation.Y: 0 keyframes
Translation.Z: 3 keyframes
Property Translation is animated by bind point Translation