This repository has been archived by the owner on Dec 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgltf_skin.h
163 lines (138 loc) · 5.59 KB
/
gltf_skin.h
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*************************************************************************/
/* gltf_skin.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef GLTF_SKIN_H
#define GLTF_SKIN_H
#include "core/io/resource.h"
#include "core/variant/variant_conversion.h"
#include "gltf_document.h"
class GLTFSkin : public Resource {
GDCLASS(GLTFSkin, Resource);
protected:
static void _bind_methods();
public:
String name;
// The "skeleton" property defined in the gltf spec. -1 = Scene Root
GLTFNodeIndex skin_root;
Vector<GLTFNodeIndex> joints_original;
Vector<Transform> inverse_binds;
// Note: joints + non_joints should form a complete subtree, or subtrees
// with a common parent
// All nodes that are skins that are caught in-between the original joints
// (inclusive of joints_original)
Vector<GLTFNodeIndex> joints;
// All Nodes that are caught in-between skin joint nodes, and are not
// defined as joints by any skin
Vector<GLTFNodeIndex> non_joints;
// The roots of the skin. In the case of multiple roots, their parent *must*
// be the same (the roots must be siblings)
Vector<GLTFNodeIndex> roots;
// The GLTF Skeleton this Skin points to (after we determine skeletons)
GLTFSkeletonIndex skeleton;
// A mapping from the joint indices (in the order of joints_original) to the
// Godot Skeleton's bone_indices
Map<int, int> joint_i_to_bone_i;
Map<int, StringName> joint_i_to_name;
// The Actual Skin that will be created as a mapping between the IBM's of
// this skin to the generated skeleton for the mesh instances.
Ref<Skin> godot_skin;
GLTFNodeIndex get_skin_root() {
return this->skin_root;
}
void set_skin_root(GLTFNodeIndex p_skin_root) {
this->skin_root = p_skin_root;
}
Vector<GLTFNodeIndex> get_joints_original() {
return this->joints_original;
}
void set_joints_original(Vector<GLTFNodeIndex> p_joints_original) {
this->joints_original = p_joints_original;
}
Array get_inverse_binds() {
return VariantConversion::to_array(this->inverse_binds);
}
void set_inverse_binds(Array p_inverse_binds) {
VariantConversion::set_from_array(this->inverse_binds, p_inverse_binds);
}
Vector<GLTFNodeIndex> get_joints() {
return this->joints;
}
void set_joints(Vector<GLTFNodeIndex> p_joints) {
this->joints = p_joints;
}
Vector<GLTFNodeIndex> get_non_joints() {
return this->non_joints;
}
void set_non_joints(Vector<GLTFNodeIndex> p_non_joints) {
this->non_joints = p_non_joints;
}
Vector<GLTFNodeIndex> get_roots() {
return this->roots;
}
void set_roots(Vector<GLTFNodeIndex> p_roots) {
this->roots = p_roots;
}
int get_skeleton() {
return this->skeleton;
}
void set_skeleton(int p_skeleton) {
this->skeleton = p_skeleton;
}
Dictionary get_joint_i_to_bone_i() {
return VariantConversion::to_dict(this->joint_i_to_bone_i);
}
void set_joint_i_to_bone_i(Dictionary p_joint_i_to_bone_i) {
VariantConversion::set_from_dict(this->joint_i_to_bone_i, p_joint_i_to_bone_i);
}
Dictionary get_joint_i_to_name() {
Dictionary ret;
Map<int, StringName>::Element *elem = joint_i_to_name.front();
while (elem) {
ret[elem->key()] = String(elem->value());
elem = elem->next();
}
return ret;
}
void set_joint_i_to_name(Dictionary p_joint_i_to_name) {
this->joint_i_to_name = Map<int, StringName>();
Array keys = p_joint_i_to_name.keys();
for (int i = 0; i < keys.size(); i++) {
this->joint_i_to_name[keys[i]] = joint_i_to_name[keys[i]];
}
}
Ref<Skin> get_godot_skin() {
return this->godot_skin;
}
void set_godot_skin(Ref<Skin> p_godot_skin) {
this->godot_skin = p_godot_skin;
}
GLTFSkin() :
skin_root(-1), skeleton(-1) {}
};
#endif