skin_tool.h 5.0 KB

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