retarget_modifier_3d.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**************************************************************************/
  2. /* retarget_modifier_3d.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef RETARGET_MODIFIER_3D_H
  31. #define RETARGET_MODIFIER_3D_H
  32. #include "scene/3d/skeleton_modifier_3d.h"
  33. #include "scene/resources/skeleton_profile.h"
  34. class RetargetModifier3D : public SkeletonModifier3D {
  35. GDCLASS(RetargetModifier3D, SkeletonModifier3D);
  36. public:
  37. enum TransformFlag {
  38. TRANSFORM_FLAG_POSITION = 1,
  39. TRANSFORM_FLAG_ROTATION = 2,
  40. TRANSFORM_FLAG_SCALE = 4,
  41. TRANSFORM_FLAG_ALL = TRANSFORM_FLAG_POSITION | TRANSFORM_FLAG_ROTATION | TRANSFORM_FLAG_SCALE,
  42. };
  43. private:
  44. Ref<SkeletonProfile> profile;
  45. bool use_global_pose = false;
  46. BitField<TransformFlag> enable_flags = TRANSFORM_FLAG_ALL;
  47. struct RetargetBoneInfo {
  48. int bone_id = -1;
  49. Basis pre_basis;
  50. Basis post_basis;
  51. };
  52. struct RetargetInfo {
  53. ObjectID skeleton_id;
  54. Vector<RetargetBoneInfo> humanoid_bone_rests;
  55. };
  56. Vector<RetargetInfo> child_skeletons;
  57. Vector<int> source_bone_ids;
  58. void _update_child_skeleton_rests(int p_child_skeleton_idx);
  59. void _update_child_skeletons();
  60. void _reset_child_skeleton_poses();
  61. void _reset_child_skeletons();
  62. #ifdef TOOLS_ENABLED
  63. void _force_update_child_skeletons();
  64. #endif // TOOLS_ENABLED
  65. void cache_rests_with_reset();
  66. void cache_rests();
  67. Vector<RetargetBoneInfo> cache_bone_global_rests(Skeleton3D *p_skeleton);
  68. Vector<RetargetBoneInfo> cache_bone_rests(Skeleton3D *p_skeleton);
  69. Vector<RetargetBoneInfo> get_humanoid_bone_rests(Skeleton3D *p_skeleton);
  70. void _retarget_global_pose();
  71. void _retarget_pose();
  72. protected:
  73. virtual void _skeleton_changed(Skeleton3D *p_old, Skeleton3D *p_new) override;
  74. void _profile_changed(Ref<SkeletonProfile> p_old, Ref<SkeletonProfile> p_new);
  75. void _validate_property(PropertyInfo &p_property) const;
  76. static void _bind_methods();
  77. virtual void _notification(int p_what);
  78. virtual void add_child_notify(Node *p_child) override;
  79. virtual void move_child_notify(Node *p_child) override;
  80. virtual void remove_child_notify(Node *p_child) override;
  81. virtual void _set_active(bool p_active) override;
  82. virtual void _process_modification() override;
  83. public:
  84. virtual PackedStringArray get_configuration_warnings() const override;
  85. void set_use_global_pose(bool p_use_global_pose);
  86. bool is_using_global_pose() const;
  87. void set_enable_flags(BitField<TransformFlag> p_enable_flags);
  88. BitField<TransformFlag> get_enable_flags() const;
  89. void set_position_enabled(bool p_enabled);
  90. bool is_position_enabled() const;
  91. void set_rotation_enabled(bool p_enabled);
  92. bool is_rotation_enabled() const;
  93. void set_scale_enabled(bool p_enabled);
  94. bool is_scale_enabled() const;
  95. void set_profile(Ref<SkeletonProfile> p_profile);
  96. Ref<SkeletonProfile> get_profile() const;
  97. #ifdef TOOLS_ENABLED
  98. virtual bool is_processed_on_saving() const override { return true; }
  99. #endif
  100. RetargetModifier3D();
  101. virtual ~RetargetModifier3D();
  102. };
  103. VARIANT_BITFIELD_CAST(RetargetModifier3D::TransformFlag);
  104. #endif // RETARGET_MODIFIER_3D_H