skeleton.h
1 /*************************************************************************/
2 /* skeleton.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef SKELETON_H
30 #define SKELETON_H
31 
32 #include "scene/3d/spatial.h"
33 #include "rid.h"
34 
38 class Skeleton : public Spatial {
39 
40  OBJ_TYPE( Skeleton, Spatial );
41 
42  struct Bone {
43 
44  String name;
45 
46  bool enabled;
47  int parent;
48 
49  bool disable_rest;
50  Transform rest;
51  Transform rest_global_inverse;
52 
53  Transform pose;
54  Transform pose_global;
55 
56  bool custom_pose_enable;
57  Transform custom_pose;
58 
59  List<uint32_t> nodes_bound;
60 
61  Bone() { parent=-1; enabled=true; custom_pose_enable=false; disable_rest=false; }
62  };
63 
64  bool rest_global_inverse_dirty;
65 
66  Vector<Bone> bones;
67 
68  RID skeleton;
69 
70  void _make_dirty();
71  bool dirty;
72 
73 //bind helpers
74  Array _get_bound_child_nodes_to_bone(int p_bone) const {
75 
76  Array bound;
77  List<Node*> childs;
78  get_bound_child_nodes_to_bone(p_bone,&childs);
79 
80  for (int i=0;i<childs.size();i++) {
81 
82  bound.push_back( childs[i] );
83  }
84  return bound;
85  }
86 
87  virtual RES _get_gizmo_geometry() const;
88 
89 protected:
90 
91  bool _get(const StringName& p_name,Variant &r_ret) const;
92  bool _set(const StringName& p_name, const Variant& p_value);
93  void _get_property_list( List<PropertyInfo>* p_list ) const;
94  void _notification(int p_what);
95  static void _bind_methods();
96 
97 public:
98 
99  enum {
100 
101  NOTIFICATION_UPDATE_SKELETON=50
102  };
103 
104 
105  RID get_skeleton() const;
106 
107  // skeleton creation api
108  void add_bone(const String&p_name);
109  int find_bone(String p_name) const;
110  String get_bone_name(int p_bone) const;
111 
112  void set_bone_parent(int p_bone, int p_parent);
113  int get_bone_parent(int p_bone) const;
114 
115  void unparent_bone_and_rest(int p_idx);
116 
117  void set_bone_disable_rest(int p_bone, bool p_disable);
118  bool is_bone_rest_disabled(int p_bone) const;
119 
120  int get_bone_count() const;
121 
122  void set_bone_rest(int p_bone, const Transform& p_rest);
123  Transform get_bone_rest(int p_bone) const;
124  Transform get_bone_transform(int p_bone) const;
125  Transform get_bone_global_pose(int p_bone) const;
126 
127  void set_bone_global_pose(int p_bone,const Transform& p_pose);
128 
129  void set_bone_enabled(int p_bone, bool p_enabled);
130  bool is_bone_enabled(int p_bone) const;
131 
132  void bind_child_node_to_bone(int p_bone,Node *p_node);
133  void unbind_child_node_from_bone(int p_bone,Node *p_node);
134  void get_bound_child_nodes_to_bone(int p_bone,List<Node*> *p_bound) const;
135 
136  void clear_bones();
137 
138  // posing api
139 
140  void set_bone_pose(int p_bone, const Transform& p_pose);
141  Transform get_bone_pose(int p_bone) const;
142 
143  void set_bone_custom_pose(int p_bone, const Transform& p_custom_pose);
144  Transform get_bone_custom_pose(int p_bone) const;
145 
146  void localize_rests(); // used for loaders and tools
147 
148  Skeleton();
149  ~Skeleton();
150 
151 };
152 
153 #endif
Definition: array.h:38
Definition: variant.h:74
Definition: node.h:42
Definition: string_db.h:48
Definition: transform.h:38
Definition: rid.h:47
Definition: skeleton.h:38
Definition: ustring.h:64
Definition: spatial.h:56