retargeting_3d_skeletons.rst 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. .. _doc_retargeting_3d_skeletons:
  2. Retargeting 3D Skeletons
  3. ========================
  4. To share animations among multiple Skeletons
  5. --------------------------------------------
  6. Godot has Position/Rotation/Scale 3D tracks (which this document calls "Transform" tracks)
  7. with Nodepaths to bones for Skeleton bone animation. This means you can't
  8. share animations between multiple Skeletons just by using the same bone
  9. names.
  10. Godot allows each bone to have a parent-child relationship and can have rotation
  11. and scale as well as position, which means that bones that share a name can still
  12. have different Transform values.
  13. The Skeleton stores the Transform values necessary for the default pose as Bone Rest.
  14. If Bone Pose is equal to Bone Rest, it means that the Skeleton is in the default pose.
  15. .. note:: Godot 3.x and Godot 4.0+ have different Bone Pose behaviors.
  16. In Godot 3.x, Bone Pose is relative to Bone Rest, but in Godot 4.0+,
  17. it includes Bone Rest. See this `article <https://godotengine.org/article/animation-data-redesign-40>`__.
  18. Skeletal models have different Bone Rests depending on the environment from
  19. which they were exported. For example, the bones of a glTF model output from Blender
  20. have "Edit Bone Orientation" as the Bone Rest rotation. However, there are skeletal
  21. models without any Bone Rest rotations, such as the glTF model output from Maya.
  22. To share animations in Godot, it is necessary to match Bone Rests as well as Bone Names
  23. to remove unwanted tracks in some cases. In Godot 4.0+, you can do that using the scene
  24. importer.
  25. Options for Retargeting
  26. -----------------------
  27. Bone Map
  28. ~~~~~~~~
  29. When you select the Skeleton3D node in the advanced scene import menu, a menu will appear
  30. on the right-hand side containing the "Retarget" section. The Retarget section has a single
  31. property ``bone_map``.
  32. .. image:: img/retargeting1.webp
  33. With the Skeleton node selected, first set up a new :ref:`class_bonemap` and :ref:`class_skeletonprofile`.
  34. Godot has a preset called :ref:`class_skeletonprofilehumanoid` for humanoid models.
  35. This tutorial proceeds with the assumption that you are using :ref:`class_skeletonprofilehumanoid`.
  36. .. note:: If you need a profile that is different from :ref:`class_skeletonprofilehumanoid`, you can export
  37. a :ref:`class_skeletonprofile` from the editor by selecting a Skeleton3D and using the **Skeleton3D** menu in the 3D viewport's toolbar.
  38. When you use :ref:`class_skeletonprofilehumanoid`, auto-mapping will be performed when the
  39. :ref:`class_skeletonprofile` is set. If the auto-mapping does not work well, you can map bones manually.
  40. .. image:: img/retargeting2.webp
  41. Any missing, duplicate or incorrect parent-child relationship mappings will be indicated
  42. by a magenta / red button (depending on the editor setting). It does not block the import process,
  43. but it warns that animations may not be shared correctly.
  44. .. note:: The auto-mapping uses pattern matching for the bone names. So we recommend
  45. to use common English names for bones.
  46. After you set up the ``bone_map``, several options are available in the sections below.
  47. .. image:: img/retargeting3.webp
  48. Remove Tracks
  49. ~~~~~~~~~~~~~
  50. If you import resources as an :ref:`class_animationlibrary` that will be shared, we recommend to enable these options.
  51. However, if you import resources as scenes, these should be disabled in some cases.
  52. For example, if you import a character with animated accessories,
  53. these options may cause the accessories to not animate.
  54. Except Bone Transform
  55. ^^^^^^^^^^^^^^^^^^^^^
  56. Removes any tracks except the bone Transform track from the animations.
  57. Unimportant Positions
  58. ^^^^^^^^^^^^^^^^^^^^^
  59. Removes Position tracks other than ``root_bone`` and ``scale_base_bone``
  60. defined in :ref:`class_skeletonprofile` from the animations. In :ref:`class_skeletonprofilehumanoid`,
  61. this means that to remove Position tracks other than "Root" and "Hips".
  62. Since Godot 4.0+, animations include Bone Rest in the Transform value. If you disable this option,
  63. the animation may change the body shape unpredictably.
  64. Unmapped Bones
  65. ^^^^^^^^^^^^^^
  66. Removes unmapped bone Transform tracks from the animations.
  67. Bone Renamer
  68. ~~~~~~~~~~~~
  69. Rename Bones
  70. ^^^^^^^^^^^^
  71. Rename the mapped bones.
  72. Unique Node
  73. ^^^^^^^^^^^
  74. Makes Skeleton a unique node with the name specified in the ``skeleton_name``.
  75. This allows the animation track paths to be unified independent of the scene hierarchy.
  76. Rest Fixer
  77. ~~~~~~~~~~
  78. Reference poses defined in :ref:`class_skeletonprofilehumanoid` have the following rules:
  79. * The humanoid is T-pose
  80. * The humanoid is facing +Z in the Right-Handed Y-UP Coordinate System
  81. * The humanoid should not have a Transform as Node
  82. * Directs the +Y axis from the parent joint to the child joint
  83. * +X rotation bends the joint like a muscle contracting
  84. These rules are convenient definitions for blend animation and Inverse Kinematics (IK).
  85. If your model does not match this definition, you need to fix it with these options.
  86. Apply Node Transform
  87. ^^^^^^^^^^^^^^^^^^^^
  88. If the asset is not exported correctly for sharing, the imported Skeleton may have
  89. a Transform as a Node. For example, a glTF exported from Blender with no "Apply Transform"
  90. executed is one such case. It looks like the model matches the definition,
  91. but the internal Transforms are different from the definition.
  92. This option fixes such models by applying Transforms on import.
  93. .. note:: If the imported scene contains objects other than Skeletons, this option may have a negative effect.
  94. Normalize Position Tracks
  95. ^^^^^^^^^^^^^^^^^^^^^^^^^
  96. Position track is used mostly for model movement, but sharing the moving animation
  97. between models with different heights may cause the appearance of slipping
  98. due to the difference in stride length. This option normalizes the Position track values
  99. based on the ``scale_base_bone`` height. The ``scale_base_bone`` height is stored
  100. in the Skeleton as the ``motion_scale``, and the normalized Position track values is
  101. multiplied by that value on playback. If this option is disabled, the Position tracks
  102. is not normalized and the Skeleton's ``motion_scale`` is always imported as ``1.0``.
  103. With :ref:`class_skeletonprofilehumanoid`, ``scale_base_bone`` is "Hips", therefore the Hips' height is used as the ``motion_scale``.
  104. Overwrite Axis
  105. ^^^^^^^^^^^^^^
  106. Unifies the models' Bone Rests by overwriting it to match the reference poses defined in the :ref:`class_skeletonprofile`.
  107. .. note:: This is the most important option for sharing animations in Godot 4.0+,
  108. but be aware that this option can produce horrible results **if the original Bone Rest set externally is important**.
  109. If you want to share animations with keeping the original Bone Rest,
  110. consider to use the `Realtime Retarget Module <https://github.com/TokageItLab/realtime_retarget>`__.
  111. Fix Silhouette
  112. ^^^^^^^^^^^^^^
  113. Attempts to make the model's silhouette match that of the reference poses defined in the :ref:`class_skeletonprofile`,
  114. such as T-Pose. This cannot fix silhouettes which are too different, and it may not work for fixing bone roll.
  115. With :ref:`class_skeletonprofilehumanoid`, this option does not need to be enabled for T-pose models,
  116. but should be enabled for A-pose models. However in that case, the fixed foot results
  117. may be bad depending on the heel height of the model, so it may be necessary to add
  118. the :ref:`class_skeletonprofile` bone names you do not want fixed in the ``filter`` array, as in the below example.
  119. .. image:: img/retargeting4.webp
  120. Also, for models with bent knees or feet, it may be necessary to adjust the ``scale_base_bone`` height.
  121. For that, you can use ``base_height_adjustment`` option.