| 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 | #ifndef SKELETON_PROFILE_H | 
|---|
| 32 | #define SKELETON_PROFILE_H | 
|---|
| 33 |  | 
|---|
| 34 | #include "texture.h" | 
|---|
| 35 |  | 
|---|
| 36 | class SkeletonProfile : public Resource { | 
|---|
| 37 | GDCLASS(SkeletonProfile, Resource); | 
|---|
| 38 |  | 
|---|
| 39 | public: | 
|---|
| 40 | enum TailDirection { | 
|---|
| 41 | TAIL_DIRECTION_AVERAGE_CHILDREN, | 
|---|
| 42 | TAIL_DIRECTION_SPECIFIC_CHILD, | 
|---|
| 43 | TAIL_DIRECTION_END | 
|---|
| 44 | }; | 
|---|
| 45 |  | 
|---|
| 46 | protected: | 
|---|
| 47 | // Note: SkeletonProfileHumanoid which extends SkeletonProfile exists to unify standard bone names. | 
|---|
| 48 | // That is what is_read_only is for, so don't make it public. | 
|---|
| 49 | bool is_read_only = false; | 
|---|
| 50 |  | 
|---|
| 51 | struct SkeletonProfileGroup { | 
|---|
| 52 | StringName group_name; | 
|---|
| 53 | Ref<Texture2D> texture; | 
|---|
| 54 | }; | 
|---|
| 55 |  | 
|---|
| 56 | struct SkeletonProfileBone { | 
|---|
| 57 | StringName bone_name; | 
|---|
| 58 | StringName bone_parent; | 
|---|
| 59 | TailDirection tail_direction = TAIL_DIRECTION_AVERAGE_CHILDREN; | 
|---|
| 60 | StringName bone_tail; | 
|---|
| 61 | Transform3D reference_pose; | 
|---|
| 62 | Vector2 handle_offset; | 
|---|
| 63 | StringName group; | 
|---|
| 64 | bool require = false; | 
|---|
| 65 | }; | 
|---|
| 66 |  | 
|---|
| 67 | StringName root_bone; | 
|---|
| 68 | StringName scale_base_bone; | 
|---|
| 69 |  | 
|---|
| 70 | Vector<SkeletonProfileGroup> groups; | 
|---|
| 71 | Vector<SkeletonProfileBone> bones; | 
|---|
| 72 |  | 
|---|
| 73 | bool _get(const StringName &p_path, Variant &r_ret) const; | 
|---|
| 74 | bool _set(const StringName &p_path, const Variant &p_value); | 
|---|
| 75 | void _validate_property(PropertyInfo &p_property) const; | 
|---|
| 76 | void _get_property_list(List<PropertyInfo> *p_list) const; | 
|---|
| 77 | static void _bind_methods(); | 
|---|
| 78 |  | 
|---|
| 79 | public: | 
|---|
| 80 | StringName get_root_bone(); | 
|---|
| 81 | void set_root_bone(StringName p_bone_name); | 
|---|
| 82 |  | 
|---|
| 83 | StringName get_scale_base_bone(); | 
|---|
| 84 | void set_scale_base_bone(StringName p_bone_name); | 
|---|
| 85 |  | 
|---|
| 86 | int get_group_size(); | 
|---|
| 87 | void set_group_size(int p_size); | 
|---|
| 88 |  | 
|---|
| 89 | StringName get_group_name(int p_group_idx) const; | 
|---|
| 90 | void set_group_name(int p_group_idx, const StringName p_group_name); | 
|---|
| 91 |  | 
|---|
| 92 | Ref<Texture2D> get_texture(int p_group_idx) const; | 
|---|
| 93 | void set_texture(int p_group_idx, const Ref<Texture2D> &p_texture); | 
|---|
| 94 |  | 
|---|
| 95 | int get_bone_size(); | 
|---|
| 96 | void set_bone_size(int p_size); | 
|---|
| 97 |  | 
|---|
| 98 | int find_bone(const StringName p_bone_name) const; | 
|---|
| 99 |  | 
|---|
| 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, const 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_require(int p_bone_idx) const; | 
|---|
| 122 | void set_require(int p_bone_idx, const bool p_require); | 
|---|
| 123 |  | 
|---|
| 124 | bool has_bone(StringName p_bone_name); | 
|---|
| 125 |  | 
|---|
| 126 | SkeletonProfile(); | 
|---|
| 127 | ~SkeletonProfile(); | 
|---|
| 128 | }; | 
|---|
| 129 |  | 
|---|
| 130 | class SkeletonProfileHumanoid : public SkeletonProfile { | 
|---|
| 131 | GDCLASS(SkeletonProfileHumanoid, SkeletonProfile); | 
|---|
| 132 |  | 
|---|
| 133 | public: | 
|---|
| 134 | SkeletonProfileHumanoid(); | 
|---|
| 135 | ~SkeletonProfileHumanoid(); | 
|---|
| 136 | }; | 
|---|
| 137 |  | 
|---|
| 138 | VARIANT_ENUM_CAST(SkeletonProfile::TailDirection); | 
|---|
| 139 |  | 
|---|
| 140 | #endif // SKELETON_PROFILE_H | 
|---|
| 141 |  | 
|---|