How to Add Animation in Python
Aspose.3D for Python models keyframe animation with AnimationClip,
AnimationNode, and KeyframeSequence — these classes are real, working
implementations for creating and reading animation data, not stubs. An
AnimationNode targets a specific named property on a scene object, so the
property must first exist on that object (through the generic property system)
before a keyframe sequence can be bound to it.
Step-by-Step Guide
Step 1: Install the Package
pip install aspose-3d-fosspython -c "import aspose.threed; print(aspose.threed.__name__)"Step 2: Import Required Classes
from aspose.threed import Scene
from aspose.threed.animation import InterpolationStep 3: Register the Property You Want to Animate
An AnimationNode binds to a property by name through find_property(), so the
target object needs that property registered first — use set_property() to
declare it, with a starting value:
from aspose.threed import Scene
scene = Scene()
light_node = scene.root_node.create_child_node("KeyLight")
light_node.set_property("intensity", 0.0)Step 4: Create an Animation Clip and Node
A Scene can hold multiple named AnimationClip instances. Each clip holds one or
more AnimationNode instances, one per animated object:
clip = scene.create_animation_clip("IntroLighting")
anim_node = clip.create_animation_node("KeyLight")Step 5: Bind a Keyframe Sequence to the Property
AnimationNode.get_keyframe_sequence() looks up (or creates) the bind point for
the named property and returns a KeyframeSequence ready for keyframes:
sequence = anim_node.get_keyframe_sequence(light_node, "intensity")Step 6: Add Keyframes
Call add(time, value, interpolation) once per keyframe. The interpolation
argument defaults to linear if omitted:
from aspose.threed.animation import Interpolation
sequence.add(0.0, 0.0, Interpolation.LINEAR)
sequence.add(1.0, 1.0, Interpolation.LINEAR)
sequence.add(2.0, 0.3, Interpolation.LINEAR)Step 7: Read Back the Animation Data
Walk the scene’s animation-clips list, each clip’s list of animation nodes, and
each AnimationNode’s bind points to inspect what was authored — the same
structures a loaded file’s animation data would populate:
for clip in scene.animation_clips:
print("Clip:", clip.name)
for node in clip.animations:
print(" node target:", node.name)
for bind_point in node.bind_points:
print(" animated property:", bind_point.property.name)Common Issues and Fixes
get_keyframe_sequence() returns nothing. This happens when the target
object does not yet have the named property — AnimationNode resolves the
property through find_property() internally, which only sees properties
previously registered with set_property(). Register the property first (Step 3)
before creating the bind point or keyframe sequence.
Trying to animate a built-in attribute such as a node’s transform directly by
name. Built-in attributes like translation are not stored in the object’s
generic property collection, so find_property("translation") will not find
them. Animate a custom scalar property registered through set_property()
instead, as shown in Step 3.
Keyframes seem to accept only a single numeric value, not a Vector3.
Correct — KeyframeSequence.add() and KeyFrame.value store one float per
keyframe. To animate a 3-component value, use one property/sequence per
component (for example, three properties for the x, y, and z of a custom
position) rather than one sequence of vectors.
Need interactive playback of the authored animation. Reading and writing keyframe data is implemented, but interactive playback/rendering of that data is a separate concern — see the render module limitations covered in How to Render 3D in Python.
Frequently Asked Questions
Is animation support real, or a stub, in this release?
Real. AnimationClip, AnimationNode, AnimationChannel, BindPoint, and
KeyframeSequence are full implementations for creating and reading keyframe
data — none of them are stubs.
What interpolation modes are available for a keyframe?
Interpolation offers constant, linear, Bezier, B-spline, cardinal-spline, and
TCB-spline modes.
Can one AnimationNode drive more than one property?
Yes — an AnimationNode keeps a list of bind points, and each call to
get_keyframe_sequence() with a different property name adds another bind
point to the same node.
How do I find which animation clip is active?
A scene’s current-animation-clip property holds the active clip — it defaults to
the first clip created with create_animation_clip() if none has been set
explicitly.