Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/gltf/skin_tool.h
10277 views
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
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
};
104
105