skin_tool.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**************************************************************************/
  2. /* skin_tool.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 SKIN_TOOL_H
  31. #define SKIN_TOOL_H
  32. #include "gltf_defines.h"
  33. #include "structures/gltf_node.h"
  34. #include "structures/gltf_skeleton.h"
  35. #include "structures/gltf_skin.h"
  36. #include "core/math/disjoint_set.h"
  37. #include "core/templates/rb_set.h"
  38. using SkinNodeIndex = int;
  39. using SkinSkeletonIndex = int;
  40. class SkinTool {
  41. public:
  42. static String _sanitize_bone_name(const String &p_name);
  43. static String _gen_unique_bone_name(HashSet<String> &r_unique_names, const String &p_name);
  44. static SkinNodeIndex _find_highest_node(Vector<Ref<GLTFNode>> &r_nodes, const Vector<SkinNodeIndex> &p_subset);
  45. static bool _capture_nodes_in_skin(const Vector<Ref<GLTFNode>> &p_nodes, Ref<GLTFSkin> p_skin, const SkinNodeIndex p_node_index);
  46. static void _capture_nodes_for_multirooted_skin(Vector<Ref<GLTFNode>> &r_nodes, Ref<GLTFSkin> p_skin);
  47. static void _recurse_children(
  48. Vector<Ref<GLTFNode>> &r_nodes,
  49. const SkinNodeIndex p_node_index,
  50. RBSet<SkinNodeIndex> &r_all_skin_nodes,
  51. HashSet<SkinNodeIndex> &r_child_visited_set);
  52. static Error _reparent_non_joint_skeleton_subtrees(
  53. Vector<Ref<GLTFNode>> &r_nodes,
  54. Ref<GLTFSkeleton> p_skeleton,
  55. const Vector<SkinNodeIndex> &p_non_joints);
  56. static Error _determine_skeleton_roots(
  57. Vector<Ref<GLTFNode>> &r_nodes,
  58. Vector<Ref<GLTFSkeleton>> &r_skeletons,
  59. const SkinSkeletonIndex p_skel_i);
  60. static Error _map_skin_joints_indices_to_skeleton_bone_indices(
  61. Vector<Ref<GLTFSkin>> &r_skins,
  62. Vector<Ref<GLTFSkeleton>> &r_skeletons,
  63. Vector<Ref<GLTFNode>> &r_nodes);
  64. static String _gen_unique_name(HashSet<String> &unique_names, const String &p_name);
  65. static bool _skins_are_same(const Ref<Skin> p_skin_a, const Ref<Skin> p_skin_b);
  66. static void _remove_duplicate_skins(Vector<Ref<GLTFSkin>> &r_skins);
  67. public:
  68. static Error _expand_skin(Vector<Ref<GLTFNode>> &r_nodes, Ref<GLTFSkin> p_skin);
  69. static Error _verify_skin(Vector<Ref<GLTFNode>> &r_nodes, Ref<GLTFSkin> p_skin);
  70. static Error _asset_parse_skins(
  71. const Vector<SkinNodeIndex> &p_input_skin_indices,
  72. const Vector<Ref<GLTFSkin>> &p_input_skins,
  73. const Vector<Ref<GLTFNode>> &p_input_nodes,
  74. Vector<SkinNodeIndex> &r_output_skin_indices,
  75. Vector<Ref<GLTFSkin>> &r_output_skins,
  76. HashMap<GLTFNodeIndex, bool> &r_joint_mapping);
  77. static Error _determine_skeletons(
  78. Vector<Ref<GLTFSkin>> &r_skins,
  79. Vector<Ref<GLTFNode>> &r_nodes,
  80. Vector<Ref<GLTFSkeleton>> &r_skeletons,
  81. const Vector<GLTFNodeIndex> &p_single_skeleton_roots);
  82. static Error _create_skeletons(
  83. HashSet<String> &r_unique_names,
  84. Vector<Ref<GLTFSkin>> &r_skins,
  85. Vector<Ref<GLTFNode>> &r_nodes,
  86. HashMap<ObjectID, GLTFSkeletonIndex> &r_skeleton3d_to_fbx_skeleton,
  87. Vector<Ref<GLTFSkeleton>> &r_skeletons,
  88. HashMap<GLTFNodeIndex, Node *> &r_scene_nodes);
  89. static Error _create_skins(Vector<Ref<GLTFSkin>> &skins, Vector<Ref<GLTFNode>> &nodes, bool use_named_skin_binds, HashSet<String> &unique_names);
  90. };
  91. #endif // SKIN_TOOL_H