gltf_skeleton.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*************************************************************************/
  2. /* gltf_skeleton.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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_skeleton.h"
  31. void GLTFSkeleton::_bind_methods() {
  32. ClassDB::bind_method(D_METHOD("get_joints"), &GLTFSkeleton::get_joints);
  33. ClassDB::bind_method(D_METHOD("set_joints", "joints"), &GLTFSkeleton::set_joints);
  34. ClassDB::bind_method(D_METHOD("get_roots"), &GLTFSkeleton::get_roots);
  35. ClassDB::bind_method(D_METHOD("set_roots", "roots"), &GLTFSkeleton::set_roots);
  36. ClassDB::bind_method(D_METHOD("get_godot_skeleton"), &GLTFSkeleton::get_godot_skeleton);
  37. ClassDB::bind_method(D_METHOD("get_unique_names"), &GLTFSkeleton::get_unique_names);
  38. ClassDB::bind_method(D_METHOD("set_unique_names", "unique_names"), &GLTFSkeleton::set_unique_names);
  39. ClassDB::bind_method(D_METHOD("get_godot_bone_node"), &GLTFSkeleton::get_godot_bone_node);
  40. ClassDB::bind_method(D_METHOD("set_godot_bone_node", "godot_bone_node"), &GLTFSkeleton::set_godot_bone_node);
  41. ClassDB::bind_method(D_METHOD("get_bone_attachment_count"), &GLTFSkeleton::get_bone_attachment_count);
  42. ClassDB::bind_method(D_METHOD("get_bone_attachment", "idx"), &GLTFSkeleton::get_bone_attachment);
  43. ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "joints"), "set_joints", "get_joints"); // PoolVector<GLTFNodeIndex>
  44. ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "roots"), "set_roots", "get_roots"); // PoolVector<GLTFNodeIndex>
  45. ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "unique_names", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_unique_names", "get_unique_names"); // Set<String>
  46. ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "godot_bone_node", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_INTERNAL | PROPERTY_USAGE_EDITOR), "set_godot_bone_node", "get_godot_bone_node"); // Map<int32_t,
  47. }
  48. PoolVector<GLTFNodeIndex> GLTFSkeleton::get_joints() {
  49. return joints;
  50. }
  51. void GLTFSkeleton::set_joints(PoolVector<GLTFNodeIndex> p_joints) {
  52. joints = p_joints;
  53. }
  54. PoolVector<GLTFNodeIndex> GLTFSkeleton::get_roots() {
  55. return roots;
  56. }
  57. void GLTFSkeleton::set_roots(PoolVector<GLTFNodeIndex> p_roots) {
  58. roots = p_roots;
  59. }
  60. Skeleton *GLTFSkeleton::get_godot_skeleton() {
  61. return godot_skeleton;
  62. }
  63. Array GLTFSkeleton::get_unique_names() {
  64. return GLTFDocument::to_array(unique_names);
  65. }
  66. void GLTFSkeleton::set_unique_names(Array p_unique_names) {
  67. GLTFDocument::set_from_array(unique_names, p_unique_names);
  68. }
  69. Dictionary GLTFSkeleton::get_godot_bone_node() {
  70. return GLTFDocument::to_dict(godot_bone_node);
  71. }
  72. void GLTFSkeleton::set_godot_bone_node(Dictionary p_indict) {
  73. GLTFDocument::set_from_dict(godot_bone_node, p_indict);
  74. }
  75. BoneAttachment *GLTFSkeleton::get_bone_attachment(int idx) {
  76. ERR_FAIL_INDEX_V(idx, bone_attachments.size(), nullptr);
  77. return bone_attachments[idx];
  78. }
  79. int32_t GLTFSkeleton::get_bone_attachment_count() {
  80. return bone_attachments.size();
  81. }