Skip to content
0.2.0-dev Download ZIP
138 lines ·5.2 KB Raw
1/**************************************************************************/
2/* skeleton_profile.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 "scene/resources/texture.h"
34
35class SkeletonProfile : public Resource {
36 GDCLASS(SkeletonProfile, Resource);
37
38public:
39 enum TailDirection {
40 TAIL_DIRECTION_AVERAGE_CHILDREN,
41 TAIL_DIRECTION_SPECIFIC_CHILD,
42 TAIL_DIRECTION_END
43 };
44
45protected:
46 // Note: SkeletonProfileHumanoid which extends SkeletonProfile exists to unify standard bone names.
47 // That is what is_read_only is for, so don't make it public.
48 bool is_read_only = false;
49
50 struct SkeletonProfileGroup {
51 StringName group_name;
52 Ref<Texture2D> texture;
53 };
54
55 struct SkeletonProfileBone {
56 StringName bone_name;
57 StringName bone_parent;
58 TailDirection tail_direction = TAIL_DIRECTION_AVERAGE_CHILDREN;
59 StringName bone_tail;
60 Transform3D reference_pose;
61 Vector2 handle_offset;
62 StringName group;
63 bool required = false;
64 };
65
66 StringName root_bone;
67 StringName scale_base_bone;
68
69 Vector<SkeletonProfileGroup> groups;
70 Vector<SkeletonProfileBone> bones;
71
72 bool _get(const StringName &p_path, Variant &r_ret) const;
73 bool _set(const StringName &p_path, const Variant &p_value);
74 void _validate_property(PropertyInfo &p_property) const;
75 void _get_property_list(List<PropertyInfo> *p_list) const;
76 static void _bind_methods();
77
78public:
79 StringName get_root_bone();
80 void set_root_bone(const StringName &p_bone_name);
81
82 StringName get_scale_base_bone();
83 void set_scale_base_bone(const StringName &p_bone_name);
84
85 int get_group_size();
86 void set_group_size(int p_size);
87
88 StringName get_group_name(int p_group_idx) const;
89 void set_group_name(int p_group_idx, const StringName &p_group_name);
90
91 Ref<Texture2D> get_texture(int p_group_idx) const;
92 void set_texture(int p_group_idx, const Ref<Texture2D> &p_texture);
93
94 int get_bone_size();
95 void set_bone_size(int p_size);
96
97 int find_bone(const StringName &p_bone_name) const;
98
99 PackedStringArray get_bone_names();
100 StringName get_bone_name(int p_bone_idx) const;
101 void set_bone_name(int p_bone_idx, const StringName &p_bone_name);
102
103 StringName get_bone_parent(int p_bone_idx) const;
104 void set_bone_parent(int p_bone_idx, const StringName &p_bone_parent);
105
106 TailDirection get_tail_direction(int p_bone_idx) const;
107 void set_tail_direction(int p_bone_idx, TailDirection p_tail_direction);
108
109 StringName get_bone_tail(int p_bone_idx) const;
110 void set_bone_tail(int p_bone_idx, const StringName &p_bone_tail);
111
112 Transform3D get_reference_pose(int p_bone_idx) const;
113 void set_reference_pose(int p_bone_idx, const Transform3D &p_reference_pose);
114
115 Vector2 get_handle_offset(int p_bone_idx) const;
116 void set_handle_offset(int p_bone_idx, const Vector2 &p_handle_offset);
117
118 StringName get_group(int p_bone_idx) const;
119 void set_group(int p_bone_idx, const StringName &p_group);
120
121 bool is_required(int p_bone_idx) const;
122 void set_required(int p_bone_idx, bool p_required);
123
124 bool has_bone(const StringName &p_bone_name);
125
126 SkeletonProfile();
127 ~SkeletonProfile();
128};
129
130class SkeletonProfileHumanoid : public SkeletonProfile {
131 GDCLASS(SkeletonProfileHumanoid, SkeletonProfile);
132
133public:
134 SkeletonProfileHumanoid();
135 ~SkeletonProfileHumanoid();
136};
137
138VARIANT_ENUM_CAST(SkeletonProfile::TailDirection);