Files
godot-docs-l10n/classes/zh_CN/class_animationmixer.rst
Rémi Verschelde 9581bc9bb3 Sync class reference translations with upstream 4.x
Still only zh_CN for now.
zh_TW is near 100% complete, but it has hundreds of validation errors
which need to be fixed first.
2023-11-21 16:13:45 +01:00

810 lines
44 KiB
ReStructuredText
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

:github_url: hide
.. DO NOT EDIT THIS FILE!!!
.. Generated automatically from Godot engine sources.
.. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
.. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/AnimationMixer.xml.
.. _class_AnimationMixer:
AnimationMixer
==============
**继承:** :ref:`Node<class_Node>` **<** :ref:`Object<class_Object>`
**派生:** :ref:`AnimationPlayer<class_AnimationPlayer>`, :ref:`AnimationTree<class_AnimationTree>`
:ref:`AnimationPlayer<class_AnimationPlayer>`:ref:`AnimationTree<class_AnimationTree>` 的基类。
.. rst-class:: classref-introduction-group
描述
----
:ref:`AnimationPlayer<class_AnimationPlayer>`:ref:`AnimationTree<class_AnimationTree>` 的基类,用于管理动画列表。同时还提供了用于播放和混合的常用属性和方法。
在扩展后的类中实例化播放信息数据后,就会由 **AnimationMixer** 负责处理混合。
.. rst-class:: classref-reftable-group
属性
----
.. table::
:widths: auto
+---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+--------------------+
| :ref:`bool<class_bool>` | :ref:`active<class_AnimationMixer_property_active>` | ``true`` |
+---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+--------------------+
| :ref:`int<class_int>` | :ref:`audio_max_polyphony<class_AnimationMixer_property_audio_max_polyphony>` | ``32`` |
+---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+--------------------+
| :ref:`AnimationCallbackModeMethod<enum_AnimationMixer_AnimationCallbackModeMethod>` | :ref:`callback_mode_method<class_AnimationMixer_property_callback_mode_method>` | ``0`` |
+---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+--------------------+
| :ref:`AnimationCallbackModeProcess<enum_AnimationMixer_AnimationCallbackModeProcess>` | :ref:`callback_mode_process<class_AnimationMixer_property_callback_mode_process>` | ``1`` |
+---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+--------------------+
| :ref:`bool<class_bool>` | :ref:`deterministic<class_AnimationMixer_property_deterministic>` | ``false`` |
+---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+--------------------+
| :ref:`bool<class_bool>` | :ref:`reset_on_save<class_AnimationMixer_property_reset_on_save>` | ``true`` |
+---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+--------------------+
| :ref:`NodePath<class_NodePath>` | :ref:`root_motion_track<class_AnimationMixer_property_root_motion_track>` | ``NodePath("")`` |
+---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+--------------------+
| :ref:`NodePath<class_NodePath>` | :ref:`root_node<class_AnimationMixer_property_root_node>` | ``NodePath("..")`` |
+---------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------+--------------------+
.. rst-class:: classref-reftable-group
方法
----
.. table::
:widths: auto
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Variant<class_Variant>` | :ref:`_post_process_key_value<class_AnimationMixer_private_method__post_process_key_value>` **(** :ref:`Animation<class_Animation>` animation, :ref:`int<class_int>` track, :ref:`Variant<class_Variant>` value, :ref:`Object<class_Object>` object, :ref:`int<class_int>` object_idx **)** |virtual| |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`add_animation_library<class_AnimationMixer_method_add_animation_library>` **(** :ref:`StringName<class_StringName>` name, :ref:`AnimationLibrary<class_AnimationLibrary>` library **)** |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`advance<class_AnimationMixer_method_advance>` **(** :ref:`float<class_float>` delta **)** |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`clear_caches<class_AnimationMixer_method_clear_caches>` **(** **)** |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`StringName<class_StringName>` | :ref:`find_animation<class_AnimationMixer_method_find_animation>` **(** :ref:`Animation<class_Animation>` animation **)** |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`StringName<class_StringName>` | :ref:`find_animation_library<class_AnimationMixer_method_find_animation_library>` **(** :ref:`Animation<class_Animation>` animation **)** |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Animation<class_Animation>` | :ref:`get_animation<class_AnimationMixer_method_get_animation>` **(** :ref:`StringName<class_StringName>` name **)** |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`AnimationLibrary<class_AnimationLibrary>` | :ref:`get_animation_library<class_AnimationMixer_method_get_animation_library>` **(** :ref:`StringName<class_StringName>` name **)** |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`StringName[]<class_StringName>` | :ref:`get_animation_library_list<class_AnimationMixer_method_get_animation_library_list>` **(** **)** |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`get_animation_list<class_AnimationMixer_method_get_animation_list>` **(** **)** |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector3<class_Vector3>` | :ref:`get_root_motion_position<class_AnimationMixer_method_get_root_motion_position>` **(** **)** |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector3<class_Vector3>` | :ref:`get_root_motion_position_accumulator<class_AnimationMixer_method_get_root_motion_position_accumulator>` **(** **)** |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Quaternion<class_Quaternion>` | :ref:`get_root_motion_rotation<class_AnimationMixer_method_get_root_motion_rotation>` **(** **)** |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Quaternion<class_Quaternion>` | :ref:`get_root_motion_rotation_accumulator<class_AnimationMixer_method_get_root_motion_rotation_accumulator>` **(** **)** |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector3<class_Vector3>` | :ref:`get_root_motion_scale<class_AnimationMixer_method_get_root_motion_scale>` **(** **)** |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector3<class_Vector3>` | :ref:`get_root_motion_scale_accumulator<class_AnimationMixer_method_get_root_motion_scale_accumulator>` **(** **)** |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`has_animation<class_AnimationMixer_method_has_animation>` **(** :ref:`StringName<class_StringName>` name **)** |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`has_animation_library<class_AnimationMixer_method_has_animation_library>` **(** :ref:`StringName<class_StringName>` name **)** |const| |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`remove_animation_library<class_AnimationMixer_method_remove_animation_library>` **(** :ref:`StringName<class_StringName>` name **)** |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| void | :ref:`rename_animation_library<class_AnimationMixer_method_rename_animation_library>` **(** :ref:`StringName<class_StringName>` name, :ref:`StringName<class_StringName>` newname **)** |
+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
信号
----
.. _class_AnimationMixer_signal_animation_finished:
.. rst-class:: classref-signal
**animation_finished** **(** :ref:`StringName<class_StringName>` anim_name **)**
动画播放结束时通知。
\ **注意:**\ 如果动画正在循环播放,则不会发出此信号。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_signal_animation_libraries_updated:
.. rst-class:: classref-signal
**animation_libraries_updated** **(** **)**
当动画库发生更改时发出通知。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_signal_animation_list_changed:
.. rst-class:: classref-signal
**animation_list_changed** **(** **)**
当动画列表发生更改时发出通知。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_signal_animation_started:
.. rst-class:: classref-signal
**animation_started** **(** :ref:`StringName<class_StringName>` anim_name **)**
当动画开始播放时发出通知。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_signal_caches_cleared:
.. rst-class:: classref-signal
**caches_cleared** **(** **)**
当缓存被清除时通知,可以是自动清除,也可以是通过 :ref:`clear_caches<class_AnimationMixer_method_clear_caches>` 手动清除。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_signal_mixer_updated:
.. rst-class:: classref-signal
**mixer_updated** **(** **)**
仅用于编辑器。当属性已完成更新进而更新动画播放编辑器中的虚拟 :ref:`AnimationPlayer<class_AnimationPlayer>` 时发出通知。
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
枚举
----
.. _enum_AnimationMixer_AnimationCallbackModeProcess:
.. rst-class:: classref-enumeration
enum **AnimationCallbackModeProcess**:
.. _class_AnimationMixer_constant_ANIMATION_CALLBACK_MODE_PROCESS_PHYSICS:
.. rst-class:: classref-enumeration-constant
:ref:`AnimationCallbackModeProcess<enum_AnimationMixer_AnimationCallbackModeProcess>` **ANIMATION_CALLBACK_MODE_PROCESS_PHYSICS** = ``0``
在物理帧中处理动画(见 :ref:`Node.NOTIFICATION_INTERNAL_PHYSICS_PROCESS<class_Node_constant_NOTIFICATION_INTERNAL_PHYSICS_PROCESS>`\ )。尤其适用于对物理体进行动画处理。
.. _class_AnimationMixer_constant_ANIMATION_CALLBACK_MODE_PROCESS_IDLE:
.. rst-class:: classref-enumeration-constant
:ref:`AnimationCallbackModeProcess<enum_AnimationMixer_AnimationCallbackModeProcess>` **ANIMATION_CALLBACK_MODE_PROCESS_IDLE** = ``1``
在处理帧中处理动画(见 :ref:`Node.NOTIFICATION_INTERNAL_PROCESS<class_Node_constant_NOTIFICATION_INTERNAL_PROCESS>`\ )。
.. _class_AnimationMixer_constant_ANIMATION_CALLBACK_MODE_PROCESS_MANUAL:
.. rst-class:: classref-enumeration-constant
:ref:`AnimationCallbackModeProcess<enum_AnimationMixer_AnimationCallbackModeProcess>` **ANIMATION_CALLBACK_MODE_PROCESS_MANUAL** = ``2``
不处理动画。使用\ :ref:`advance<class_AnimationMixer_method_advance>`\ 手动处理动画。
.. rst-class:: classref-item-separator
----
.. _enum_AnimationMixer_AnimationCallbackModeMethod:
.. rst-class:: classref-enumeration
enum **AnimationCallbackModeMethod**:
.. _class_AnimationMixer_constant_ANIMATION_CALLBACK_MODE_METHOD_DEFERRED:
.. rst-class:: classref-enumeration-constant
:ref:`AnimationCallbackModeMethod<enum_AnimationMixer_AnimationCallbackModeMethod>` **ANIMATION_CALLBACK_MODE_METHOD_DEFERRED** = ``0``
在动画过程中批量调用方法然后在处理完事件后再进行调用。这样就避免了在播放过程中涉及删除节点或修改AnimationPlayer的错误。
.. _class_AnimationMixer_constant_ANIMATION_CALLBACK_MODE_METHOD_IMMEDIATE:
.. rst-class:: classref-enumeration-constant
:ref:`AnimationCallbackModeMethod<enum_AnimationMixer_AnimationCallbackModeMethod>` **ANIMATION_CALLBACK_MODE_METHOD_IMMEDIATE** = ``1``
在动画中达到时立即进行方法调用。
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
属性说明
--------
.. _class_AnimationMixer_property_active:
.. rst-class:: classref-property
:ref:`bool<class_bool>` **active** = ``true``
.. rst-class:: classref-property-setget
- void **set_active** **(** :ref:`bool<class_bool>` value **)**
- :ref:`bool<class_bool>` **is_active** **(** **)**
如果 ``true`` 时,\ **AnimationMixer** 将执行逻辑处理。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_property_audio_max_polyphony:
.. rst-class:: classref-property
:ref:`int<class_int>` **audio_max_polyphony** = ``32``
.. rst-class:: classref-property-setget
- void **set_audio_max_polyphony** **(** :ref:`int<class_int>` value **)**
- :ref:`int<class_int>` **get_audio_max_polyphony** **(** **)**
每个指定的 AudioStreamPlayer 可能同时发出的声音的数量。
例如,如果该值为 ``32`` 并且动画有两个音轨,则分配的两个 :ref:`AudioStreamPlayer<class_AudioStreamPlayer>` 可以同时播放最多 ``32`` 个声音。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_property_callback_mode_method:
.. rst-class:: classref-property
:ref:`AnimationCallbackModeMethod<enum_AnimationMixer_AnimationCallbackModeMethod>` **callback_mode_method** = ``0``
.. rst-class:: classref-property-setget
- void **set_callback_mode_method** **(** :ref:`AnimationCallbackModeMethod<enum_AnimationMixer_AnimationCallbackModeMethod>` value **)**
- :ref:`AnimationCallbackModeMethod<enum_AnimationMixer_AnimationCallbackModeMethod>` **get_callback_mode_method** **(** **)**
方法调用轨道所使用的调用模式。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_property_callback_mode_process:
.. rst-class:: classref-property
:ref:`AnimationCallbackModeProcess<enum_AnimationMixer_AnimationCallbackModeProcess>` **callback_mode_process** = ``1``
.. rst-class:: classref-property-setget
- void **set_callback_mode_process** **(** :ref:`AnimationCallbackModeProcess<enum_AnimationMixer_AnimationCallbackModeProcess>` value **)**
- :ref:`AnimationCallbackModeProcess<enum_AnimationMixer_AnimationCallbackModeProcess>` **get_callback_mode_process** **(** **)**
更新动画的过程通知。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_property_deterministic:
.. rst-class:: classref-property
:ref:`bool<class_bool>` **deterministic** = ``false``
.. rst-class:: classref-property-setget
- void **set_deterministic** **(** :ref:`bool<class_bool>` value **)**
- :ref:`bool<class_bool>` **is_deterministic** **(** **)**
如果为 ``true``\ ,则混合使用确定性算法。总权重不进行归一化,在初始值的基础上进行累加(初始值为 ``0``\ ,表示可能存在的 ``"RESET"`` 动画)。
这意味着如果混合总权重为 ``0.0``\ ,则结果等于 ``"RESET"`` 动画。
如果混合动画之间的轨道数量不同,则缺少轨道的动画将被视为具有初始值。
如果为 ``false``\ ,则混合不会使用确定性算法。总权重将归一化且始终为 ``1.0``\ 。如果混合动画之间的轨道数量不同,则不会对缺少轨道的动画执行任何操作。
\ ** 注意:** 在 :ref:`AnimationTree<class_AnimationTree>` 中,与 :ref:`AnimationNodeAdd2<class_AnimationNodeAdd2>` 、 :ref:`AnimationNodeAdd3<class_AnimationNodeAdd3>` 、 :ref:`AnimationNodeSub2<class_AnimationNodeSub2>` 或权重大于 ``1.0`` 混合可能产生意想不到的结果。
例如,如果 :ref:`AnimationNodeAdd2<class_AnimationNodeAdd2>` 混合了两个取值为 ``1.0`` 的节点,则总权重为 ``2.0``\ ,但它将被归一化使总权重保持 ``1.0``\ ,且结果将等于取值为 ``0.5``:ref:`AnimationNodeBlend2<class_AnimationNodeBlend2>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_property_reset_on_save:
.. rst-class:: classref-property
:ref:`bool<class_bool>` **reset_on_save** = ``true``
.. rst-class:: classref-property-setget
- void **set_reset_on_save_enabled** **(** :ref:`bool<class_bool>` value **)**
- :ref:`bool<class_bool>` **is_reset_on_save_enabled** **(** **)**
由编辑器使用。如果设置为 ``true``\ ,场景将被保存,并应用重置动画(带有键 ``"RESET"`` 的动画)的效果,就好像它已被定位到时间 0 一样,编辑器保留场景在保存之前的值。
这使得在编辑器中预览和编辑动画更加方便,因为对场景的更改,只要在重置动画中被设置,就不会被保存。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_property_root_motion_track:
.. rst-class:: classref-property
:ref:`NodePath<class_NodePath>` **root_motion_track** = ``NodePath("")``
.. rst-class:: classref-property-setget
- void **set_root_motion_track** **(** :ref:`NodePath<class_NodePath>` value **)**
- :ref:`NodePath<class_NodePath>` **get_root_motion_track** **(** **)**
用于根部运动的动画轨道的路径。路径必须是指向节点的场景树有效路径,必须从将实现动画的节点的父节点开始指定。要指定控件属性或骨骼的轨道,请在路径后附加其名称,用 ``":"`` 隔开。例如,\ ``"character/skeleton:ankle"````"character/mesh:transform/local"``\ 。
如果轨道的类型是 :ref:`Animation.TYPE_POSITION_3D<class_Animation_constant_TYPE_POSITION_3D>`\ 、\ :ref:`Animation.TYPE_ROTATION_3D<class_Animation_constant_TYPE_ROTATION_3D>`\ 、或者 :ref:`Animation.TYPE_SCALE_3D<class_Animation_constant_TYPE_SCALE_3D>`\ ,那么将取消视觉上的变换,其动画看起来将是留在原地。参阅 :ref:`get_root_motion_position<class_AnimationMixer_method_get_root_motion_position>`\ 、\ :ref:`get_root_motion_rotation<class_AnimationMixer_method_get_root_motion_rotation>`\ 、\ :ref:`get_root_motion_scale<class_AnimationMixer_method_get_root_motion_scale>`\ 、和 :ref:`RootMotionView<class_RootMotionView>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_property_root_node:
.. rst-class:: classref-property
:ref:`NodePath<class_NodePath>` **root_node** = ``NodePath("..")``
.. rst-class:: classref-property-setget
- void **set_root_node** **(** :ref:`NodePath<class_NodePath>` value **)**
- :ref:`NodePath<class_NodePath>` **get_root_node** **(** **)**
节点路径引用将从其运行的节点。
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
方法说明
--------
.. _class_AnimationMixer_private_method__post_process_key_value:
.. rst-class:: classref-method
:ref:`Variant<class_Variant>` **_post_process_key_value** **(** :ref:`Animation<class_Animation>` animation, :ref:`int<class_int>` track, :ref:`Variant<class_Variant>` value, :ref:`Object<class_Object>` object, :ref:`int<class_int>` object_idx **)** |virtual| |const|
虚函数,用于播放期间在获取关键帧之后的处理。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_add_animation_library:
.. rst-class:: classref-method
:ref:`Error<enum_@GlobalScope_Error>` **add_animation_library** **(** :ref:`StringName<class_StringName>` name, :ref:`AnimationLibrary<class_AnimationLibrary>` library **)**
``library`` 添加到该动画播放器的键 ``name`` 下。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_advance:
.. rst-class:: classref-method
void **advance** **(** :ref:`float<class_float>` delta **)**
手动将动画前进指定的时间(单位为秒)。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_clear_caches:
.. rst-class:: classref-method
void **clear_caches** **(** **)**
**AnimationMixer** 会缓存动画节点。如果一个节点消失,它可能不会注意到;\ :ref:`clear_caches<class_AnimationMixer_method_clear_caches>` 能够强制它再次更新缓存。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_find_animation:
.. rst-class:: classref-method
:ref:`StringName<class_StringName>` **find_animation** **(** :ref:`Animation<class_Animation>` animation **)** |const|
返回 ``animation`` 的键;如果未找到,则返回一个空的 :ref:`StringName<class_StringName>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_find_animation_library:
.. rst-class:: classref-method
:ref:`StringName<class_StringName>` **find_animation_library** **(** :ref:`Animation<class_Animation>` animation **)** |const|
返回包含 ``animation``:ref:`AnimationLibrary<class_AnimationLibrary>` 的键;如果找不到,则返回一个空的 :ref:`StringName<class_StringName>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_get_animation:
.. rst-class:: classref-method
:ref:`Animation<class_Animation>` **get_animation** **(** :ref:`StringName<class_StringName>` name **)** |const|
返回带有键 ``name``:ref:`Animation<class_Animation>`\ 。如果动画不存在,则返回 ``null`` 并记录错误。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_get_animation_library:
.. rst-class:: classref-method
:ref:`AnimationLibrary<class_AnimationLibrary>` **get_animation_library** **(** :ref:`StringName<class_StringName>` name **)** |const|
返回第一个键为 ``name``:ref:`AnimationLibrary<class_AnimationLibrary>`\ ,如果没有找到则返回 ``null``\ 。
要获得 :ref:`AnimationPlayer<class_AnimationPlayer>` 的全局动画库,请使用 ``get_animation_library("")``\ 。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_get_animation_library_list:
.. rst-class:: classref-method
:ref:`StringName[]<class_StringName>` **get_animation_library_list** **(** **)** |const|
返回存储库的键名列表。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_get_animation_list:
.. rst-class:: classref-method
:ref:`PackedStringArray<class_PackedStringArray>` **get_animation_list** **(** **)** |const|
返回存储的动画键列表。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_get_root_motion_position:
.. rst-class:: classref-method
:ref:`Vector3<class_Vector3>` **get_root_motion_position** **(** **)** |const|
将具有 :ref:`root_motion_track<class_AnimationMixer_property_root_motion_track>` 的位置的运动增量,检索为一个可以在其他地方使用的 :ref:`Vector3<class_Vector3>`\ 。
如果 :ref:`root_motion_track<class_AnimationMixer_property_root_motion_track>` 不是 :ref:`Animation.TYPE_POSITION_3D<class_Animation_constant_TYPE_POSITION_3D>` 类型轨道的路径,则返回 ``Vector3(0, 0, 0)``\ 。
另见 :ref:`root_motion_track<class_AnimationMixer_property_root_motion_track>` 和 :ref:`RootMotionView<class_RootMotionView>`\ 。
最基本的示例是将位置应用于 :ref:`CharacterBody3D<class_CharacterBody3D>`\
.. tabs::
.. code-tab:: gdscript
var current_rotation: Quaternion
func _process(delta):
if Input.is_action_just_pressed("animate"):
current_rotation = get_quaternion()
state_machine.travel("Animate")
var velocity: Vector3 = current_rotation * animation_tree.get_root_motion_position() / delta
set_velocity(velocity)
move_and_slide()
通过将其与 :ref:`get_root_motion_position_accumulator<class_AnimationMixer_method_get_root_motion_position_accumulator>` 结合使用,你可以更正确地应用根运动位置来考虑节点的旋转。
.. tabs::
.. code-tab:: gdscript
func _process(delta):
if Input.is_action_just_pressed("animate"):
state_machine.travel("Animate")
set_quaternion(get_quaternion() * animation_tree.get_root_motion_rotation())
var velocity: Vector3 = (animation_tree.get_root_motion_rotation_accumulator().inverse() * get_quaternion()) * animation_tree.get_root_motion_position() / delta
set_velocity(velocity)
move_and_slide()
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_get_root_motion_position_accumulator:
.. rst-class:: classref-method
:ref:`Vector3<class_Vector3>` **get_root_motion_position_accumulator** **(** **)** |const|
检索具有 :ref:`root_motion_track<class_AnimationMixer_property_root_motion_track>` 的位置轨道的混合值,返回的是可以在其他地方使用的 :ref:`Vector3<class_Vector3>`\ 。
在想要遵循动画的初始动画帧值的情况下很有用。
例如,如果前一帧播放的是一个只有单个动画帧 ``Vector3(0, 0, 0)`` 的动画,然后下一帧播放的是一个只有单个动画帧\ ``Vector3(1, 0, 1)`` 的动画,它们之间的差异可以这样计算:
.. tabs::
.. code-tab:: gdscript
var prev_root_motion_position_accumulator: Vector3
func _process(delta):
if Input.is_action_just_pressed("animate"):
state_machine.travel("Animate")
var current_root_motion_position_accumulator: Vector3 = animation_tree.get_root_motion_position_accumulator()
var difference: Vector3 = current_root_motion_position_accumulator - prev_root_motion_position_accumulator
prev_root_motion_position_accumulator = current_root_motion_position_accumulator
transform.origin += difference
不过,如果动画是循环播放的,就可能会发生预料之外的不连续变化,所以这只对一些简单的情况有用。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_get_root_motion_rotation:
.. rst-class:: classref-method
:ref:`Quaternion<class_Quaternion>` **get_root_motion_rotation** **(** **)** |const|
检索带有 :ref:`root_motion_track<class_AnimationMixer_property_root_motion_track>` 的旋转运动,作为一个 :ref:`Quaternion<class_Quaternion>`\ ,可以在其他地方使用。
如果 :ref:`root_motion_track<class_AnimationMixer_property_root_motion_track>` 不是 :ref:`Animation.TYPE_ROTATION_3D<class_Animation_constant_TYPE_ROTATION_3D>` 类型的轨迹的路径,返回 ``Quaternion(0, 0, 0, 1)``
另见 :ref:`root_motion_track<class_AnimationMixer_property_root_motion_track>`:ref:`RootMotionView<class_RootMotionView>`\ 。
最基本的例子是对 :ref:`CharacterBody3D<class_CharacterBody3D>` 应用旋转。
.. tabs::
.. code-tab:: gdscript
func _process(delta):
if Input.is_action_just_pressed("animate"):
state_machine.travel("Animate")
set_quaternion(get_quaternion() * animation_tree.get_root_motion_rotation() )
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_get_root_motion_rotation_accumulator:
.. rst-class:: classref-method
:ref:`Quaternion<class_Quaternion>` **get_root_motion_rotation_accumulator** **(** **)** |const|
检索带有 :ref:`root_motion_track<class_AnimationMixer_property_root_motion_track>` 的旋转轨道的混合值,作为一个 :ref:`Quaternion<class_Quaternion>`\ ,可以在其他地方使用。
这里必须正确地结合根运动位置,并且要考虑到旋转。参考 :ref:`get_root_motion_position<class_AnimationMixer_method_get_root_motion_position>`\ 。
并且,当你想重视动画的初始动画帧的值时,这会很有用。
比如说,如果一个动画在上一帧只播放一个 ``Quaternion(0, 0, 0, 1)`` 动画帧,并且一个动画在下一帧只播放了一个动画帧的 ``Quaternion(0, 0.707, 0, 0.707)`` 时,它们相差的值可以这样求出:
.. tabs::
.. code-tab:: gdscript
var prev_root_motion_rotation_accumulator: Quaternion
func _process(delta):
if Input.is_action_just_pressed("animate"):
state_machine.travel("Animate")
var current_root_motion_rotation_accumulator: Quaternion = animation_tree.get_root_motion_Quaternion_accumulator()
var difference: Quaternion = prev_root_motion_rotation_accumulator.inverse() * current_root_motion_rotation_accumulator
prev_root_motion_rotation_accumulator = current_root_motion_rotation_accumulator
transform.basis *= difference
然而,当一个动画循环时,可能会得到一个意料之外的变化,所以这个只在一些简单情况下才有用。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_get_root_motion_scale:
.. rst-class:: classref-method
:ref:`Vector3<class_Vector3>` **get_root_motion_scale** **(** **)** |const|
获取 :ref:`root_motion_track<class_AnimationMixer_property_root_motion_track>` 的缩放运动增量,类型为 :ref:`Vector3<class_Vector3>`\ ,可以在其他地方使用。
如果 :ref:`root_motion_track<class_AnimationMixer_property_root_motion_track>` 不是类型为 :ref:`Animation.TYPE_SCALE_3D<class_Animation_constant_TYPE_SCALE_3D>` 的轨道的路径,则返回 ``Vector3(0, 0, 0)``
另见 :ref:`root_motion_track<class_AnimationMixer_property_root_motion_track>`:ref:`RootMotionView<class_RootMotionView>`\ 。
最基本的例子是对 :ref:`CharacterBody3D<class_CharacterBody3D>` 应用缩放。
.. tabs::
.. code-tab:: gdscript
var current_scale: Vector3 = Vector3(1, 1, 1)
var scale_accum: Vector3 = Vector3(1, 1, 1)
func _process(delta):
if Input.is_action_just_pressed("animate"):
current_scale = get_scale()
scale_accum = Vector3(1, 1, 1)
state_machine.travel("Animate")
scale_accum += animation_tree.get_root_motion_scale()
set_scale(current_scale * scale_accum)
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_get_root_motion_scale_accumulator:
.. rst-class:: classref-method
:ref:`Vector3<class_Vector3>` **get_root_motion_scale_accumulator** **(** **)** |const|
检索带有 :ref:`root_motion_track<class_AnimationMixer_property_root_motion_track>` 的缩放轨道的混合值,作为一个 :ref:`Vector3<class_Vector3>`\ ,可以在其他地方使用。
例如,如果一个动画在前一帧只播放了一个动画帧 ``Vector3(1, 1, 1)``\ ,并且一个动画在后一帧只播放了一个动画帧 ``Vector3(2, 2, 2)``\ ,他们之间相差的值可以这样求出:
.. tabs::
.. code-tab:: gdscript
var prev_root_motion_scale_accumulator: Vector3
func _process(delta):
if Input.is_action_just_pressed("animate"):
state_machine.travel("Animate")
var current_root_motion_scale_accumulator: Vector3 = animation_tree.get_root_motion_scale_accumulator()
var difference: Vector3 = current_root_motion_scale_accumulator - prev_root_motion_scale_accumulator
prev_root_motion_scale_accumulator = current_root_motion_scale_accumulator
transform.basis = transform.basis.scaled(difference)
然而,当一个动画循环时,可能会得到一个意料之外的变化,所以这个只在一些简单情况下才有用。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_has_animation:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **has_animation** **(** :ref:`StringName<class_StringName>` name **)** |const|
如果该 :ref:`AnimationPlayer<class_AnimationPlayer>` 使用键 ``name`` 存储 :ref:`Animation<class_Animation>`\ ,则返回 ``true``\ 。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_has_animation_library:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **has_animation_library** **(** :ref:`StringName<class_StringName>` name **)** |const|
如果该 :ref:`AnimationPlayer<class_AnimationPlayer>` 使用键 ``name`` 存储 :ref:`AnimationLibrary<class_AnimationLibrary>`\ ,则返回 ``true``\ 。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_remove_animation_library:
.. rst-class:: classref-method
void **remove_animation_library** **(** :ref:`StringName<class_StringName>` name **)**
移除与键 ``name`` 关联的 :ref:`AnimationLibrary<class_AnimationLibrary>`\ 。
.. rst-class:: classref-item-separator
----
.. _class_AnimationMixer_method_rename_animation_library:
.. rst-class:: classref-method
void **rename_animation_library** **(** :ref:`StringName<class_StringName>` name, :ref:`StringName<class_StringName>` newname **)**
将与键 ``name`` 关联的 :ref:`AnimationLibrary<class_AnimationLibrary>` 移动到键 ``newname``\ 。
.. |virtual| replace:: :abbr:`virtual (本方法通常需要用户覆盖才能生效。)`
.. |const| replace:: :abbr:`const (本方法没有副作用。不会修改该实例的任何成员变量。)`
.. |vararg| replace:: :abbr:`vararg (本方法除了在此处描述的参数外,还能够继续接受任意数量的参数。)`
.. |constructor| replace:: :abbr:`constructor (本方法用于构造某个类型。)`
.. |static| replace:: :abbr:`static (调用本方法无需实例,所以可以直接使用类名调用。)`
.. |operator| replace:: :abbr:`operator (本方法描述的是使用本类型作为左操作数的有效操作符。)`
.. |bitfield| replace:: :abbr:`BitField (这个值是由下列标志构成的位掩码整数。)`