2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* skeleton.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:11:42 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* 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 SKELETON_H
|
|
|
|
#define SKELETON_H
|
|
|
|
|
|
|
|
#include "rid.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "scene/3d/spatial.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
@author Juan Linietsky <reduzio@gmail.com>
|
|
|
|
*/
|
|
|
|
class Skeleton : public Spatial {
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
GDCLASS(Skeleton, Spatial);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
struct Bone {
|
|
|
|
|
|
|
|
String name;
|
|
|
|
|
|
|
|
bool enabled;
|
|
|
|
int parent;
|
|
|
|
|
2015-09-24 21:06:15 +00:00
|
|
|
bool disable_rest;
|
2014-02-10 01:10:30 +00:00
|
|
|
Transform rest;
|
|
|
|
Transform rest_global_inverse;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Transform pose;
|
|
|
|
Transform pose_global;
|
|
|
|
|
|
|
|
bool custom_pose_enable;
|
|
|
|
Transform custom_pose;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
List<uint32_t> nodes_bound;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Bone() {
|
|
|
|
parent = -1;
|
|
|
|
enabled = true;
|
|
|
|
custom_pose_enable = false;
|
|
|
|
disable_rest = false;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool rest_global_inverse_dirty;
|
|
|
|
|
|
|
|
Vector<Bone> bones;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
RID skeleton;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void _make_dirty();
|
|
|
|
bool dirty;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
//bind helpers
|
2014-02-10 01:10:30 +00:00
|
|
|
Array _get_bound_child_nodes_to_bone(int p_bone) const {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Array bound;
|
2017-03-05 15:44:50 +00:00
|
|
|
List<Node *> childs;
|
|
|
|
get_bound_child_nodes_to_bone(p_bone, &childs);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (int i = 0; i < childs.size(); i++) {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bound.push_back(childs[i]);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
return bound;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2017-08-11 19:10:05 +00:00
|
|
|
bool _get(const StringName &p_path, Variant &r_ret) const;
|
|
|
|
bool _set(const StringName &p_path, const Variant &p_value);
|
2017-03-05 15:44:50 +00:00
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
public:
|
|
|
|
enum {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
NOTIFICATION_UPDATE_SKELETON = 50
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
RID get_skeleton() const;
|
|
|
|
|
|
|
|
// skeleton creation api
|
2017-03-05 15:44:50 +00:00
|
|
|
void add_bone(const String &p_name);
|
2014-02-10 01:10:30 +00:00
|
|
|
int find_bone(String p_name) const;
|
|
|
|
String get_bone_name(int p_bone) const;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void set_bone_parent(int p_bone, int p_parent);
|
|
|
|
int get_bone_parent(int p_bone) const;
|
|
|
|
|
2017-08-11 19:10:05 +00:00
|
|
|
void unparent_bone_and_rest(int p_bone);
|
2015-09-24 21:06:15 +00:00
|
|
|
|
|
|
|
void set_bone_disable_rest(int p_bone, bool p_disable);
|
|
|
|
bool is_bone_rest_disabled(int p_bone) const;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
int get_bone_count() const;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_bone_rest(int p_bone, const Transform &p_rest);
|
2014-02-10 01:10:30 +00:00
|
|
|
Transform get_bone_rest(int p_bone) const;
|
|
|
|
Transform get_bone_transform(int p_bone) const;
|
2014-08-14 13:31:38 +00:00
|
|
|
Transform get_bone_global_pose(int p_bone) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_bone_global_pose(int p_bone, const Transform &p_pose);
|
2014-10-28 01:54:32 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void set_bone_enabled(int p_bone, bool p_enabled);
|
|
|
|
bool is_bone_enabled(int p_bone) const;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void bind_child_node_to_bone(int p_bone, Node *p_node);
|
|
|
|
void unbind_child_node_from_bone(int p_bone, Node *p_node);
|
|
|
|
void get_bound_child_nodes_to_bone(int p_bone, List<Node *> *p_bound) const;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void clear_bones();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
// posing api
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_bone_pose(int p_bone, const Transform &p_pose);
|
2014-02-10 01:10:30 +00:00
|
|
|
Transform get_bone_pose(int p_bone) const;
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_bone_custom_pose(int p_bone, const Transform &p_custom_pose);
|
2014-02-10 01:10:30 +00:00
|
|
|
Transform get_bone_custom_pose(int p_bone) const;
|
|
|
|
|
|
|
|
void localize_rests(); // used for loaders and tools
|
2016-03-08 23:00:52 +00:00
|
|
|
|
|
|
|
Skeleton();
|
2014-02-10 01:10:30 +00:00
|
|
|
~Skeleton();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|