skeleton_modifier_3d.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**************************************************************************/
  2. /* skeleton_modifier_3d.cpp */
  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. #include "skeleton_modifier_3d.h"
  31. void SkeletonModifier3D::_validate_property(PropertyInfo &p_property) const {
  32. //
  33. }
  34. PackedStringArray SkeletonModifier3D::get_configuration_warnings() const {
  35. PackedStringArray warnings = Node3D::get_configuration_warnings();
  36. if (skeleton_id.is_null()) {
  37. warnings.push_back(RTR("Skeleton3D node not set! SkeletonModifier3D must be child of Skeleton3D."));
  38. }
  39. return warnings;
  40. }
  41. /* Skeleton3D */
  42. Skeleton3D *SkeletonModifier3D::get_skeleton() const {
  43. return Object::cast_to<Skeleton3D>(ObjectDB::get_instance(skeleton_id));
  44. }
  45. void SkeletonModifier3D::_update_skeleton_path() {
  46. skeleton_id = ObjectID();
  47. // Make sure parent is a Skeleton3D.
  48. Skeleton3D *sk = Object::cast_to<Skeleton3D>(get_parent());
  49. if (sk) {
  50. skeleton_id = sk->get_instance_id();
  51. }
  52. }
  53. void SkeletonModifier3D::_update_skeleton() {
  54. if (!is_inside_tree()) {
  55. return;
  56. }
  57. Skeleton3D *old_sk = get_skeleton();
  58. _update_skeleton_path();
  59. Skeleton3D *new_sk = get_skeleton();
  60. if (old_sk != new_sk) {
  61. _skeleton_changed(old_sk, new_sk);
  62. }
  63. update_configuration_warnings();
  64. }
  65. void SkeletonModifier3D::_skeleton_changed(Skeleton3D *p_old, Skeleton3D *p_new) {
  66. //
  67. }
  68. void SkeletonModifier3D::_force_update_skeleton_skin() {
  69. if (!is_inside_tree()) {
  70. return;
  71. }
  72. Skeleton3D *skeleton = get_skeleton();
  73. if (!skeleton) {
  74. return;
  75. }
  76. skeleton->force_update_deferred();
  77. }
  78. /* Process */
  79. void SkeletonModifier3D::set_active(bool p_active) {
  80. if (active == p_active) {
  81. return;
  82. }
  83. active = p_active;
  84. _set_active(active);
  85. _force_update_skeleton_skin();
  86. }
  87. bool SkeletonModifier3D::is_active() const {
  88. return active;
  89. }
  90. void SkeletonModifier3D::_set_active(bool p_active) {
  91. //
  92. }
  93. void SkeletonModifier3D::set_influence(real_t p_influence) {
  94. influence = p_influence;
  95. }
  96. real_t SkeletonModifier3D::get_influence() const {
  97. return influence;
  98. }
  99. void SkeletonModifier3D::process_modification() {
  100. if (!active) {
  101. return;
  102. }
  103. _process_modification();
  104. emit_signal(SNAME("modification_processed"));
  105. }
  106. void SkeletonModifier3D::_process_modification() {
  107. GDVIRTUAL_CALL(_process_modification);
  108. }
  109. void SkeletonModifier3D::_notification(int p_what) {
  110. switch (p_what) {
  111. case NOTIFICATION_ENTER_TREE:
  112. case NOTIFICATION_PARENTED: {
  113. _update_skeleton();
  114. } break;
  115. case NOTIFICATION_EXIT_TREE:
  116. case NOTIFICATION_UNPARENTED: {
  117. _force_update_skeleton_skin();
  118. } break;
  119. }
  120. }
  121. void SkeletonModifier3D::_bind_methods() {
  122. ClassDB::bind_method(D_METHOD("get_skeleton"), &SkeletonModifier3D::get_skeleton);
  123. ClassDB::bind_method(D_METHOD("set_active", "active"), &SkeletonModifier3D::set_active);
  124. ClassDB::bind_method(D_METHOD("is_active"), &SkeletonModifier3D::is_active);
  125. ClassDB::bind_method(D_METHOD("set_influence", "influence"), &SkeletonModifier3D::set_influence);
  126. ClassDB::bind_method(D_METHOD("get_influence"), &SkeletonModifier3D::get_influence);
  127. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "active"), "set_active", "is_active");
  128. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "influence", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_influence", "get_influence");
  129. ADD_SIGNAL(MethodInfo("modification_processed"));
  130. GDVIRTUAL_BIND(_process_modification);
  131. }
  132. SkeletonModifier3D::SkeletonModifier3D() {
  133. }