| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "gltf_defines.h" |
| 34 |
|
| 35 |
#include "structures/gltf_node.h" |
| 36 |
#include "structures/gltf_skeleton.h" |
| 37 |
#include "structures/gltf_skin.h" |
| 38 |
|
| 39 |
#include "core/math/disjoint_set.h" |
| 40 |
#include "core/templates/rb_set.h" |
| 41 |
|
| 42 |
using SkinNodeIndex = int; |
| 43 |
using SkinSkeletonIndex = int; |
| 44 |
|
| 45 |
class SkinTool { |
| 46 |
public: |
| 47 |
static String _sanitize_bone_name(const String &p_name); |
| 48 |
static String _gen_unique_bone_name(HashSet<String> &r_unique_names, const String &p_name); |
| 49 |
static SkinNodeIndex _find_highest_node(Vector<Ref<GLTFNode>> &r_nodes, const Vector<SkinNodeIndex> &p_subset); |
| 50 |
static bool _capture_nodes_in_skin(const Vector<Ref<GLTFNode>> &p_nodes, Ref<GLTFSkin> p_skin, const SkinNodeIndex p_node_index); |
| 51 |
static void _capture_nodes_for_multirooted_skin(Vector<Ref<GLTFNode>> &r_nodes, Ref<GLTFSkin> p_skin); |
| 52 |
static void _recurse_children( |
| 53 |
Vector<Ref<GLTFNode>> &r_nodes, |
| 54 |
const SkinNodeIndex p_node_index, |
| 55 |
RBSet<SkinNodeIndex> &r_all_skin_nodes, |
| 56 |
HashSet<SkinNodeIndex> &r_child_visited_set); |
| 57 |
static Error _reparent_non_joint_skeleton_subtrees( |
| 58 |
Vector<Ref<GLTFNode>> &r_nodes, |
| 59 |
Ref<GLTFSkeleton> p_skeleton, |
| 60 |
const Vector<SkinNodeIndex> &p_non_joints); |
| 61 |
static Error _determine_skeleton_roots( |
| 62 |
Vector<Ref<GLTFNode>> &r_nodes, |
| 63 |
Vector<Ref<GLTFSkeleton>> &r_skeletons, |
| 64 |
const SkinSkeletonIndex p_skel_i); |
| 65 |
static Error _map_skin_joints_indices_to_skeleton_bone_indices( |
| 66 |
Vector<Ref<GLTFSkin>> &r_skins, |
| 67 |
Vector<Ref<GLTFSkeleton>> &r_skeletons, |
| 68 |
Vector<Ref<GLTFNode>> &r_nodes); |
| 69 |
static String _gen_unique_name(HashSet<String> &unique_names, const String &p_name); |
| 70 |
static bool _skins_are_same(const Ref<Skin> p_skin_a, const Ref<Skin> p_skin_b); |
| 71 |
static void _remove_duplicate_skins(Vector<Ref<GLTFSkin>> &r_skins); |
| 72 |
static void _check_if_parent_needs_to_become_joint( |
| 73 |
const Vector<Ref<GLTFNode>> &p_all_nodes, |
| 74 |
const Vector<GLTFNodeIndex> &p_skeleton_node_indices, |
| 75 |
const Ref<GLTFNode> &p_gltf_node, |
| 76 |
Vector<GLTFNodeIndex> &r_non_joint_indices); |
| 77 |
|
| 78 |
public: |
| 79 |
static Error _expand_skin(Vector<Ref<GLTFNode>> &r_nodes, Ref<GLTFSkin> p_skin); |
| 80 |
static Error _verify_skin(Vector<Ref<GLTFNode>> &r_nodes, Ref<GLTFSkin> p_skin); |
| 81 |
static Error _asset_parse_skins( |
| 82 |
const Vector<SkinNodeIndex> &p_input_skin_indices, |
| 83 |
const Vector<Ref<GLTFSkin>> &p_input_skins, |
| 84 |
const Vector<Ref<GLTFNode>> &p_input_nodes, |
| 85 |
Vector<SkinNodeIndex> &r_output_skin_indices, |
| 86 |
Vector<Ref<GLTFSkin>> &r_output_skins, |
| 87 |
HashMap<GLTFNodeIndex, bool> &r_joint_mapping); |
| 88 |
static Error _determine_skeletons( |
| 89 |
Vector<Ref<GLTFSkin>> &r_skins, |
| 90 |
Vector<Ref<GLTFNode>> &r_nodes, |
| 91 |
Vector<Ref<GLTFSkeleton>> &r_skeletons, |
| 92 |
const Vector<GLTFNodeIndex> &p_single_skeleton_root, |
| 93 |
bool p_turn_non_joint_descendants_into_bones); |
| 94 |
static Error _create_skeletons( |
| 95 |
HashSet<String> &r_unique_names, |
| 96 |
Vector<Ref<GLTFSkin>> &r_skins, |
| 97 |
Vector<Ref<GLTFNode>> &r_nodes, |
| 98 |
HashMap<ObjectID, GLTFSkeletonIndex> &r_skeleton3d_to_fbx_skeleton, |
| 99 |
Vector<Ref<GLTFSkeleton>> &r_skeletons, |
| 100 |
HashMap<GLTFNodeIndex, Node *> &r_scene_nodes, |
| 101 |
int p_naming_version); |
| 102 |
static Error _create_skins(Vector<Ref<GLTFSkin>> &skins, Vector<Ref<GLTFNode>> &nodes, bool use_named_skin_binds, HashSet<String> &unique_names); |
| 103 |
}; |