gltf_skin.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /**************************************************************************/
  2. /* gltf_skin.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. #ifndef GLTF_SKIN_H
  31. #define GLTF_SKIN_H
  32. #include "../gltf_defines.h"
  33. #include "core/io/resource.h"
  34. #include "scene/resources/3d/skin.h"
  35. template <typename T>
  36. class TypedArray;
  37. class GLTFSkin : public Resource {
  38. GDCLASS(GLTFSkin, Resource);
  39. friend class GLTFDocument;
  40. friend class SkinTool;
  41. friend class FBXDocument;
  42. private:
  43. // The "skeleton" property defined in the gltf spec. -1 = Scene Root
  44. GLTFNodeIndex skin_root = -1;
  45. Vector<GLTFNodeIndex> joints_original;
  46. Vector<Transform3D> inverse_binds;
  47. // Note: joints + non_joints should form a complete subtree, or subtrees
  48. // with a common parent
  49. // All nodes that are skins that are caught in-between the original joints
  50. // (inclusive of joints_original)
  51. Vector<GLTFNodeIndex> joints;
  52. // All Nodes that are caught in-between skin joint nodes, and are not
  53. // defined as joints by any skin
  54. Vector<GLTFNodeIndex> non_joints;
  55. // The roots of the skin. In the case of multiple roots, their parent *must*
  56. // be the same (the roots must be siblings)
  57. Vector<GLTFNodeIndex> roots;
  58. // The GLTF Skeleton this Skin points to (after we determine skeletons)
  59. GLTFSkeletonIndex skeleton = -1;
  60. // A mapping from the joint indices (in the order of joints_original) to the
  61. // Godot Skeleton's bone_indices
  62. HashMap<int, int> joint_i_to_bone_i;
  63. HashMap<int, StringName> joint_i_to_name;
  64. // The Actual Skin that will be created as a mapping between the IBM's of
  65. // this skin to the generated skeleton for the mesh instances.
  66. Ref<Skin> godot_skin;
  67. protected:
  68. static void _bind_methods();
  69. public:
  70. GLTFNodeIndex get_skin_root();
  71. void set_skin_root(GLTFNodeIndex p_skin_root);
  72. Vector<GLTFNodeIndex> get_joints_original();
  73. void set_joints_original(Vector<GLTFNodeIndex> p_joints_original);
  74. TypedArray<Transform3D> get_inverse_binds();
  75. void set_inverse_binds(TypedArray<Transform3D> p_inverse_binds);
  76. Vector<GLTFNodeIndex> get_joints();
  77. void set_joints(Vector<GLTFNodeIndex> p_joints);
  78. Vector<GLTFNodeIndex> get_non_joints();
  79. void set_non_joints(Vector<GLTFNodeIndex> p_non_joints);
  80. Vector<GLTFNodeIndex> get_roots();
  81. void set_roots(Vector<GLTFNodeIndex> p_roots);
  82. int get_skeleton();
  83. void set_skeleton(int p_skeleton);
  84. Dictionary get_joint_i_to_bone_i();
  85. void set_joint_i_to_bone_i(Dictionary p_joint_i_to_bone_i);
  86. Dictionary get_joint_i_to_name();
  87. void set_joint_i_to_name(Dictionary p_joint_i_to_name);
  88. Ref<Skin> get_godot_skin();
  89. void set_godot_skin(Ref<Skin> p_godot_skin);
  90. Dictionary to_dictionary();
  91. Error from_dictionary(const Dictionary &dict);
  92. };
  93. #endif // GLTF_SKIN_H