1/**************************************************************************/
2/* gltf_skin.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#ifndef GLTF_SKIN_H
32#define GLTF_SKIN_H
33
34#include "../gltf_defines.h"
35
36#include "core/io/resource.h"
37
38template <typename T>
39class TypedArray;
40
41class GLTFSkin : public Resource {
42 GDCLASS(GLTFSkin, Resource);
43 friend class GLTFDocument;
44
45private:
46 // The "skeleton" property defined in the gltf spec. -1 = Scene Root
47 GLTFNodeIndex skin_root = -1;
48
49 Vector<GLTFNodeIndex> joints_original;
50 Vector<Transform3D> inverse_binds;
51
52 // Note: joints + non_joints should form a complete subtree, or subtrees
53 // with a common parent
54
55 // All nodes that are skins that are caught in-between the original joints
56 // (inclusive of joints_original)
57 Vector<GLTFNodeIndex> joints;
58
59 // All Nodes that are caught in-between skin joint nodes, and are not
60 // defined as joints by any skin
61 Vector<GLTFNodeIndex> non_joints;
62
63 // The roots of the skin. In the case of multiple roots, their parent *must*
64 // be the same (the roots must be siblings)
65 Vector<GLTFNodeIndex> roots;
66
67 // The GLTF Skeleton this Skin points to (after we determine skeletons)
68 GLTFSkeletonIndex skeleton = -1;
69
70 // A mapping from the joint indices (in the order of joints_original) to the
71 // Godot Skeleton's bone_indices
72 HashMap<int, int> joint_i_to_bone_i;
73 HashMap<int, StringName> joint_i_to_name;
74
75 // The Actual Skin that will be created as a mapping between the IBM's of
76 // this skin to the generated skeleton for the mesh instances.
77 Ref<Skin> godot_skin;
78
79protected:
80 static void _bind_methods();
81
82public:
83 GLTFNodeIndex get_skin_root();
84 void set_skin_root(GLTFNodeIndex p_skin_root);
85
86 Vector<GLTFNodeIndex> get_joints_original();
87 void set_joints_original(Vector<GLTFNodeIndex> p_joints_original);
88
89 TypedArray<Transform3D> get_inverse_binds();
90 void set_inverse_binds(TypedArray<Transform3D> p_inverse_binds);
91
92 Vector<GLTFNodeIndex> get_joints();
93 void set_joints(Vector<GLTFNodeIndex> p_joints);
94
95 Vector<GLTFNodeIndex> get_non_joints();
96 void set_non_joints(Vector<GLTFNodeIndex> p_non_joints);
97
98 Vector<GLTFNodeIndex> get_roots();
99 void set_roots(Vector<GLTFNodeIndex> p_roots);
100
101 int get_skeleton();
102 void set_skeleton(int p_skeleton);
103
104 Dictionary get_joint_i_to_bone_i();
105 void set_joint_i_to_bone_i(Dictionary p_joint_i_to_bone_i);
106
107 Dictionary get_joint_i_to_name();
108 void set_joint_i_to_name(Dictionary p_joint_i_to_name);
109
110 Ref<Skin> get_godot_skin();
111 void set_godot_skin(Ref<Skin> p_godot_skin);
112};
113
114#endif // GLTF_SKIN_H
115