gltf_skin.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**************************************************************************/
  2. /* gltf_skin.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 "gltf_skin.h"
  31. #include "../gltf_template_convert.h"
  32. #include "scene/resources/skin.h"
  33. void GLTFSkin::_bind_methods() {
  34. ClassDB::bind_method(D_METHOD("get_skin_root"), &GLTFSkin::get_skin_root);
  35. ClassDB::bind_method(D_METHOD("set_skin_root", "skin_root"), &GLTFSkin::set_skin_root);
  36. ClassDB::bind_method(D_METHOD("get_joints_original"), &GLTFSkin::get_joints_original);
  37. ClassDB::bind_method(D_METHOD("set_joints_original", "joints_original"), &GLTFSkin::set_joints_original);
  38. ClassDB::bind_method(D_METHOD("get_inverse_binds"), &GLTFSkin::get_inverse_binds);
  39. ClassDB::bind_method(D_METHOD("set_inverse_binds", "inverse_binds"), &GLTFSkin::set_inverse_binds);
  40. ClassDB::bind_method(D_METHOD("get_joints"), &GLTFSkin::get_joints);
  41. ClassDB::bind_method(D_METHOD("set_joints", "joints"), &GLTFSkin::set_joints);
  42. ClassDB::bind_method(D_METHOD("get_non_joints"), &GLTFSkin::get_non_joints);
  43. ClassDB::bind_method(D_METHOD("set_non_joints", "non_joints"), &GLTFSkin::set_non_joints);
  44. ClassDB::bind_method(D_METHOD("get_roots"), &GLTFSkin::get_roots);
  45. ClassDB::bind_method(D_METHOD("set_roots", "roots"), &GLTFSkin::set_roots);
  46. ClassDB::bind_method(D_METHOD("get_skeleton"), &GLTFSkin::get_skeleton);
  47. ClassDB::bind_method(D_METHOD("set_skeleton", "skeleton"), &GLTFSkin::set_skeleton);
  48. ClassDB::bind_method(D_METHOD("get_joint_i_to_bone_i"), &GLTFSkin::get_joint_i_to_bone_i);
  49. ClassDB::bind_method(D_METHOD("set_joint_i_to_bone_i", "joint_i_to_bone_i"), &GLTFSkin::set_joint_i_to_bone_i);
  50. ClassDB::bind_method(D_METHOD("get_joint_i_to_name"), &GLTFSkin::get_joint_i_to_name);
  51. ClassDB::bind_method(D_METHOD("set_joint_i_to_name", "joint_i_to_name"), &GLTFSkin::set_joint_i_to_name);
  52. ClassDB::bind_method(D_METHOD("get_godot_skin"), &GLTFSkin::get_godot_skin);
  53. ClassDB::bind_method(D_METHOD("set_godot_skin", "godot_skin"), &GLTFSkin::set_godot_skin);
  54. ADD_PROPERTY(PropertyInfo(Variant::INT, "skin_root"), "set_skin_root", "get_skin_root"); // GLTFNodeIndex
  55. ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "joints_original"), "set_joints_original", "get_joints_original"); // Vector<GLTFNodeIndex>
  56. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "inverse_binds", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL), "set_inverse_binds", "get_inverse_binds"); // Vector<Transform>
  57. ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "joints"), "set_joints", "get_joints"); // Vector<GLTFNodeIndex>
  58. ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "non_joints"), "set_non_joints", "get_non_joints"); // Vector<GLTFNodeIndex>
  59. ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "roots"), "set_roots", "get_roots"); // Vector<GLTFNodeIndex>
  60. ADD_PROPERTY(PropertyInfo(Variant::INT, "skeleton"), "set_skeleton", "get_skeleton"); // int
  61. ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "joint_i_to_bone_i", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL), "set_joint_i_to_bone_i", "get_joint_i_to_bone_i"); // Map<int,
  62. ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "joint_i_to_name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL), "set_joint_i_to_name", "get_joint_i_to_name"); // Map<int,
  63. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "godot_skin"), "set_godot_skin", "get_godot_skin"); // Ref<Skin>
  64. }
  65. GLTFNodeIndex GLTFSkin::get_skin_root() {
  66. return skin_root;
  67. }
  68. void GLTFSkin::set_skin_root(GLTFNodeIndex p_skin_root) {
  69. skin_root = p_skin_root;
  70. }
  71. Vector<GLTFNodeIndex> GLTFSkin::get_joints_original() {
  72. return joints_original;
  73. }
  74. void GLTFSkin::set_joints_original(Vector<GLTFNodeIndex> p_joints_original) {
  75. joints_original = p_joints_original;
  76. }
  77. Array GLTFSkin::get_inverse_binds() {
  78. return GLTFTemplateConvert::to_array(inverse_binds);
  79. }
  80. void GLTFSkin::set_inverse_binds(Array p_inverse_binds) {
  81. GLTFTemplateConvert::set_from_array(inverse_binds, p_inverse_binds);
  82. }
  83. Vector<GLTFNodeIndex> GLTFSkin::get_joints() {
  84. return joints;
  85. }
  86. void GLTFSkin::set_joints(Vector<GLTFNodeIndex> p_joints) {
  87. joints = p_joints;
  88. }
  89. Vector<GLTFNodeIndex> GLTFSkin::get_non_joints() {
  90. return non_joints;
  91. }
  92. void GLTFSkin::set_non_joints(Vector<GLTFNodeIndex> p_non_joints) {
  93. non_joints = p_non_joints;
  94. }
  95. Vector<GLTFNodeIndex> GLTFSkin::get_roots() {
  96. return roots;
  97. }
  98. void GLTFSkin::set_roots(Vector<GLTFNodeIndex> p_roots) {
  99. roots = p_roots;
  100. }
  101. int GLTFSkin::get_skeleton() {
  102. return skeleton;
  103. }
  104. void GLTFSkin::set_skeleton(int p_skeleton) {
  105. skeleton = p_skeleton;
  106. }
  107. Dictionary GLTFSkin::get_joint_i_to_bone_i() {
  108. return GLTFTemplateConvert::to_dict(joint_i_to_bone_i);
  109. }
  110. void GLTFSkin::set_joint_i_to_bone_i(Dictionary p_joint_i_to_bone_i) {
  111. GLTFTemplateConvert::set_from_dict(joint_i_to_bone_i, p_joint_i_to_bone_i);
  112. }
  113. Dictionary GLTFSkin::get_joint_i_to_name() {
  114. Dictionary ret;
  115. Map<int, StringName>::Element *elem = joint_i_to_name.front();
  116. while (elem) {
  117. ret[elem->key()] = String(elem->value());
  118. elem = elem->next();
  119. }
  120. return ret;
  121. }
  122. void GLTFSkin::set_joint_i_to_name(Dictionary p_joint_i_to_name) {
  123. joint_i_to_name = Map<int, StringName>();
  124. Array keys = p_joint_i_to_name.keys();
  125. for (int i = 0; i < keys.size(); i++) {
  126. joint_i_to_name[keys[i]] = p_joint_i_to_name[keys[i]];
  127. }
  128. }
  129. Ref<Skin> GLTFSkin::get_godot_skin() {
  130. return godot_skin;
  131. }
  132. void GLTFSkin::set_godot_skin(Ref<Skin> p_godot_skin) {
  133. godot_skin = p_godot_skin;
  134. }