skeleton_modifier_3d.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**************************************************************************/
  2. /* skeleton_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/node_3d.h"
  32. #include "scene/3d/skeleton_3d.h"
  33. class SkeletonModifier3D : public Node3D {
  34. GDCLASS(SkeletonModifier3D, Node3D);
  35. void rebind();
  36. public:
  37. enum BoneAxis {
  38. BONE_AXIS_PLUS_X,
  39. BONE_AXIS_MINUS_X,
  40. BONE_AXIS_PLUS_Y,
  41. BONE_AXIS_MINUS_Y,
  42. BONE_AXIS_PLUS_Z,
  43. BONE_AXIS_MINUS_Z,
  44. };
  45. protected:
  46. bool active = true;
  47. real_t influence = 1.0;
  48. // Cache them for the performance reason since finding node with NodePath is slow.
  49. ObjectID skeleton_id;
  50. void _update_skeleton();
  51. void _update_skeleton_path();
  52. void _force_update_skeleton_skin();
  53. virtual void _skeleton_changed(Skeleton3D *p_old, Skeleton3D *p_new);
  54. virtual void _validate_bone_names();
  55. GDVIRTUAL2(_skeleton_changed, Skeleton3D *, Skeleton3D *);
  56. GDVIRTUAL0(_validate_bone_names);
  57. void _validate_property(PropertyInfo &p_property) const;
  58. void _notification(int p_what);
  59. static void _bind_methods();
  60. virtual void _set_active(bool p_active);
  61. virtual void _process_modification(double p_delta);
  62. // TODO: In Godot 5, should obsolete old GDVIRTUAL0(_process_modification); and replace it with _process_modification_with_delta as GDVIRTUAL1(_process_modification, double).
  63. GDVIRTUAL1(_process_modification_with_delta, double);
  64. #ifndef DISABLE_DEPRECATED
  65. GDVIRTUAL0(_process_modification);
  66. #endif
  67. public:
  68. virtual PackedStringArray get_configuration_warnings() const override;
  69. virtual bool has_process() const { return false; } // Return true if modifier needs to modify bone pose without external animation such as physics, jiggle and etc.
  70. void set_active(bool p_active);
  71. bool is_active() const;
  72. void set_influence(real_t p_influence);
  73. real_t get_influence() const;
  74. Skeleton3D *get_skeleton() const;
  75. void process_modification(double p_delta);
  76. // Utility APIs.
  77. static Vector3 get_vector_from_bone_axis(BoneAxis p_axis);
  78. static Vector3 get_vector_from_axis(Vector3::Axis p_axis);
  79. static Vector3::Axis get_axis_from_bone_axis(BoneAxis p_axis);
  80. #ifdef TOOLS_ENABLED
  81. virtual bool is_processed_on_saving() const { return false; }
  82. #endif
  83. SkeletonModifier3D();
  84. };
  85. VARIANT_ENUM_CAST(SkeletonModifier3D::BoneAxis);