Animation — Aspose.3D FOSS for Python API Reference

Example

Aspose.3D 动画系统围绕一层层对象层级组织,这些对象将时间采样数据绑定到场景属性上。.

  • Example AnimationClip 是一个具名的播放范围(例如“Walk”,“Run”),由 a Scene.
  • Example AnimationNode 存在于剪辑内部,并将动画数据绑定到场景对象的特定属性上。.
  • 一个 BindPoint 连接一个 AnimationNode 到一个具名的 Property 在一个 A3DObject.
  • Example AnimationChannel 保存一个标量 KeyframeSequence 在绑定点内。.
  • 一个 KeyframeSequence 是一个有序列表,包含 KeyFrame 时间‑数值样本。.

所有动画类都位于 aspose.threed.animation 子包中,尽管它们也可以直接从 aspose.threed.

from aspose.threed.animation import (
    AnimationClip,
    AnimationNode,
    AnimationChannel,
    BindPoint,
    KeyFrame,
    KeyframeSequence,
    Interpolation,
    ExtrapolationType,
)

AnimationClip

一个用于单个播放范围的具名容器。一个 Scene 可以容纳多个剪辑。继承自 SceneObject.

Example

ExampleExample
AnimationClip(name=None)创建一个带可选名称的剪辑

Example

ExampleExampleExample
namestr剪辑名称(例如. "Walk")
descriptionstr可选描述
startfloat开始时间(秒)
stopfloat结束时间(秒)
animationslist[AnimationNode]此剪辑中动画节点的只读列表
propertiesPropertyCollection自定义属性

Example

Example返回类型Example
create_animation_node(node_name)AnimationNode创建并注册一个新的 AnimationNode 在此剪辑中

AnimationNode

绑定一个 AnimationClip 到一个或多个 BindPoint 对象,目标为场景对象属性。继承自 A3DObject.

Example

ExampleExample
AnimationNode(name=None)创建一个带可选名称的动画节点

Example

ExampleExampleExample
namestr节点名称
bind_pointslist[BindPoint]绑定点的只读列表
sub_animationslist[AnimationNode]子动画节点的只读列表
propertiesPropertyCollection自定义属性

Example

Example返回类型Example
find_bind_point(target, name)`BindPointNone`
get_bind_point(target, prop_name, create)`BindPointNone`
create_bind_point(obj, prop_name)`BindPointNone`
get_keyframe_sequence(target, prop_name, channel_name, create)`KeyframeSequenceNone`

BindPoint

连接一个 AnimationNode 到单个 Property 在一个 A3DObject.。每个 BindPoint 可以容纳多个 AnimationChannel 对象(每个标量组件一个)。 A3DObject.

Example

ExampleExampleExample
propertyProperty继承自
channels_countint此绑定点所针对的场景对象属性

Example

Example此绑定点中的动画通道数量Example
add_channel(name, value, type=None)bool返回类型
get_channel(channel_name)`AnimationChannelNone`
get_keyframe_sequence(channel_name)`KeyframeSequenceNone`
create_keyframe_sequence(name)KeyframeSequence返回指定通道的关键帧序列 KeyframeSequence 创建一个新的
bind_keyframe_sequence(channel_name, sequence)None关联一个已有的 KeyframeSequence 与通道
reset_channels()None移除所有通道

AnimationChannel

保存单个标量 KeyframeSequence 用于一个动画组件。.

Example

ExampleExampleExample
namestr通道名称(例如. "X", "Y", "Z")
default_valueAny当不存在关键帧数据时使用的值
keyframe_sequence`KeyframeSequenceNone`

KeyframeSequence

有序列表 KeyFrame 单一标量通道的样本。继承自 A3DObject.

Example

ExampleExample
KeyframeSequence(name=None)创建一个空的关键帧序列

Example

ExampleExampleExample
namestr序列名称
key_frameslist[KeyFrame]按时间顺序的只读关键帧列表
pre_behaviorExtrapolation第一个关键帧之前的行为
post_behaviorExtrapolation最后一个关键帧之后的行为
bind_point`BindPointNone`

Example

Example返回类型Example
add(time, value, interpolation=Interpolation.LINEAR)None在…处追加关键帧 time (秒),使用给定的 valueinterpolation 模式
reset()None清除所有关键帧并重置前后行为

KeyFrame

在 a 中的单个时间值样本 KeyframeSequence.

Example

KeyFrame 对象由内部创建 KeyframeSequence.add(); 请勿直接构造它们。.

Example

ExampleExampleExample
timefloat时间位置(秒)
valuefloat此时的动画值
interpolationInterpolation在此关键帧与下一个关键帧之间应用的插值模式
tangent_weight_modeWeightedMode切线权重模式(贝塞尔曲线)
step_modeStepMode步进行为 (PREVIOUS_VALUENEXT_VALUE)
next_in_tangent`Vector2None`
out_tangent`Vector2None`
out_weightfloat出射切线权重
next_in_weightfloat入射切线权重
tensionfloat张力参数(TCB 样条)
continuityfloat连续性参数(TCB 样条)
biasfloat偏置参数(TCB 样条)
independent_tangentboolExample True, 入射和出射切线相互独立
flatboolExample True, 切线被限制为平坦
time_independent_tangentboolExample True, 切线方向独立于时间缩放

Example

控制在连续关键帧之间的数值插值方式。.

ExampleExample
CONSTANTExample
LINEAR数值之间的线性插值
BEZIER使用进/出切线的三次贝塞尔
B_SPLINE均匀 B 样条
CARDINAL_SPLINECardinal 样条
TCB_SPLINE张力–连续性–偏置样条

Example

控制在首帧和尾帧之外的动画行为。.

ExampleExample
CONSTANT保持边界值
GRADIENT在边界关键帧的切线梯度处外推
CYCLE重复关键帧范围(循环)
CYCLE_RELATIVE以累计偏移重复(相对于结束值)
OSCILLATE乒乓(交替正向和反向重复)

Example

from aspose.threed import Scene
from aspose.threed.animation import AnimationClip, Interpolation
from aspose.threed.utilities import Vector3

scene = Scene()
node = scene.root_node.create_child_node("animated_box")
node.transform.translation = Vector3(0.0, 0.0, 0.0)

# Create an animation clip
clip = AnimationClip("Move")
clip.start = 0.0
clip.stop  = 2.0

# Create an animation node inside the clip
anim_node = clip.create_animation_node("box_anim")

# Get keyframe sequences for the X and Y translation channels
seq_x = anim_node.get_keyframe_sequence(node.transform, "Translation", "X", True)
seq_y = anim_node.get_keyframe_sequence(node.transform, "Translation", "Y", True)

if seq_x:
    seq_x.add(0.0,  0.0,  Interpolation.LINEAR)
    seq_x.add(1.0, 10.0,  Interpolation.LINEAR)
    seq_x.add(2.0,  0.0,  Interpolation.LINEAR)

if seq_y:
    seq_y.add(0.0,  0.0, Interpolation.BEZIER)
    seq_y.add(1.0,  5.0, Interpolation.BEZIER)
    seq_y.add(2.0,  0.0, Interpolation.BEZIER)

# Export to FBX to preserve animation data
scene.save("animated.fbx")

另见

 中文