retarget_modifier_3d.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #pragma once
  31. #include "scene/3d/skeleton_modifier_3d.h"
  32. #include "scene/resources/skeleton_profile.h"
  33. class RetargetModifier3D : public SkeletonModifier3D {
  34. GDCLASS(RetargetModifier3D, SkeletonModifier3D);
  35. public:
  36. enum TransformFlag {
  37. TRANSFORM_FLAG_POSITION = 1,
  38. TRANSFORM_FLAG_ROTATION = 2,
  39. TRANSFORM_FLAG_SCALE = 4,
  40. TRANSFORM_FLAG_ALL = TRANSFORM_FLAG_POSITION | TRANSFORM_FLAG_ROTATION | TRANSFORM_FLAG_SCALE,
  41. };
  42. private:
  43. Ref<SkeletonProfile> profile;
  44. bool use_global_pose = false;
  45. BitField<TransformFlag> enable_flags = TRANSFORM_FLAG_ALL;
  46. struct RetargetBoneInfo {
  47. int bone_id = -1;
  48. Basis pre_basis;
  49. Basis post_basis;
  50. };
  51. struct RetargetInfo {
  52. ObjectID skeleton_id;
  53. Vector<RetargetBoneInfo> humanoid_bone_rests;
  54. };
  55. Vector<RetargetInfo> child_skeletons;
  56. Vector<int> source_bone_ids;
  57. void _update_child_skeleton_rests(int p_child_skeleton_idx);
  58. void _update_child_skeletons();
  59. void _reset_child_skeleton_poses();
  60. void _reset_child_skeletons();
  61. #ifdef TOOLS_ENABLED
  62. void _force_update_child_skeletons();
  63. #endif // TOOLS_ENABLED
  64. void cache_rests_with_reset();
  65. void cache_rests();
  66. Vector<RetargetBoneInfo> cache_bone_global_rests(Skeleton3D *p_skeleton);
  67. Vector<RetargetBoneInfo> cache_bone_rests(Skeleton3D *p_skeleton);
  68. Vector<RetargetBoneInfo> get_humanoid_bone_rests(Skeleton3D *p_skeleton);
  69. void _retarget_global_pose();
  70. void _retarget_pose();
  71. protected:
  72. virtual void _skeleton_changed(Skeleton3D *p_old, Skeleton3D *p_new) override;
  73. void _profile_changed(Ref<SkeletonProfile> p_old, Ref<SkeletonProfile> p_new);
  74. void _validate_property(PropertyInfo &p_property) const;
  75. static void _bind_methods();
  76. virtual void _notification(int p_what);
  77. virtual void add_child_notify(Node *p_child) override;
  78. virtual void move_child_notify(Node *p_child) override;
  79. virtual void remove_child_notify(Node *p_child) override;
  80. virtual void _set_active(bool p_active) override;
  81. virtual void _process_modification(double p_delta) override;
  82. public:
  83. virtual PackedStringArray get_configuration_warnings() const override;
  84. void set_use_global_pose(bool p_use_global_pose);
  85. bool is_using_global_pose() const;
  86. void set_enable_flags(BitField<TransformFlag> p_enable_flags);
  87. BitField<TransformFlag> get_enable_flags() const;
  88. void set_position_enabled(bool p_enabled);
  89. bool is_position_enabled() const;
  90. void set_rotation_enabled(bool p_enabled);
  91. bool is_rotation_enabled() const;
  92. void set_scale_enabled(bool p_enabled);
  93. bool is_scale_enabled() const;
  94. void set_profile(Ref<SkeletonProfile> p_profile);
  95. Ref<SkeletonProfile> get_profile() const;
  96. #ifdef TOOLS_ENABLED
  97. virtual bool is_processed_on_saving() const override { return true; }
  98. #endif
  99. RetargetModifier3D();
  100. virtual ~RetargetModifier3D();
  101. };
  102. VARIANT_BITFIELD_CAST(RetargetModifier3D::TransformFlag);