2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* skeleton.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2019-01-01 12:53:14 +01:00
|
|
|
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 02:10:30 +01: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. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifndef SKELETON_H
|
|
|
|
#define SKELETON_H
|
|
|
|
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/rid.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/3d/spatial.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
@author Juan Linietsky <reduzio@gmail.com>
|
|
|
|
*/
|
2017-10-03 18:49:32 +02:00
|
|
|
|
2018-07-01 11:54:13 +02:00
|
|
|
#ifndef _3D_DISABLED
|
2017-10-03 18:49:32 +02:00
|
|
|
typedef int BoneId;
|
|
|
|
|
2017-10-03 18:49:32 +02:00
|
|
|
class PhysicalBone;
|
2018-07-01 11:54:13 +02:00
|
|
|
#endif // _3D_DISABLED
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
class Skeleton : public Spatial {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
GDCLASS(Skeleton, Spatial);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
struct Bone {
|
|
|
|
|
|
|
|
String name;
|
|
|
|
|
|
|
|
bool enabled;
|
|
|
|
int parent;
|
2018-08-07 03:35:09 +02:00
|
|
|
int sort_index; //used for re-sorting process order
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-10-03 18:49:32 +02:00
|
|
|
bool ignore_animation;
|
|
|
|
|
2015-09-24 23:06:15 +02:00
|
|
|
bool disable_rest;
|
2014-02-10 02:10:30 +01:00
|
|
|
Transform rest;
|
|
|
|
Transform rest_global_inverse;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Transform pose;
|
|
|
|
Transform pose_global;
|
|
|
|
|
|
|
|
bool custom_pose_enable;
|
|
|
|
Transform custom_pose;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-12-29 15:34:36 +01:00
|
|
|
Transform transform_final;
|
|
|
|
|
2018-07-01 11:54:13 +02:00
|
|
|
#ifndef _3D_DISABLED
|
2017-10-03 18:49:32 +02:00
|
|
|
PhysicalBone *physical_bone;
|
|
|
|
PhysicalBone *cache_parent_physical_bone;
|
2018-07-01 11:54:13 +02:00
|
|
|
#endif // _3D_DISABLED
|
2017-10-03 18:49:32 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
List<uint32_t> nodes_bound;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Bone() {
|
|
|
|
parent = -1;
|
|
|
|
enabled = true;
|
2017-10-03 18:49:32 +02:00
|
|
|
ignore_animation = false;
|
2017-03-05 16:44:50 +01:00
|
|
|
custom_pose_enable = false;
|
|
|
|
disable_rest = false;
|
2018-07-02 07:35:43 +02:00
|
|
|
#ifndef _3D_DISABLED
|
2017-10-03 18:49:32 +02:00
|
|
|
physical_bone = NULL;
|
|
|
|
cache_parent_physical_bone = NULL;
|
2018-07-02 07:35:43 +02:00
|
|
|
#endif // _3D_DISABLED
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
bool rest_global_inverse_dirty;
|
|
|
|
|
|
|
|
Vector<Bone> bones;
|
2018-08-07 03:35:09 +02:00
|
|
|
Vector<int> process_order;
|
|
|
|
bool process_order_dirty;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
RID skeleton;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void _make_dirty();
|
|
|
|
bool dirty;
|
2019-03-03 16:23:03 +01:00
|
|
|
bool use_bones_in_world_transform;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-10-03 18:49:32 +02:00
|
|
|
// bind helpers
|
2014-02-10 02:10:30 +01:00
|
|
|
Array _get_bound_child_nodes_to_bone(int p_bone) const {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Array bound;
|
2018-01-18 21:37:17 +01:00
|
|
|
List<Node *> children;
|
|
|
|
get_bound_child_nodes_to_bone(p_bone, &children);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2018-01-18 21:37:17 +01:00
|
|
|
for (int i = 0; i < children.size(); i++) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2018-01-18 21:37:17 +01:00
|
|
|
bound.push_back(children[i]);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
return bound;
|
|
|
|
}
|
|
|
|
|
2018-08-07 03:35:09 +02:00
|
|
|
void _update_process_order();
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
protected:
|
2017-08-11 21:10:05 +02:00
|
|
|
bool _get(const StringName &p_path, Variant &r_ret) const;
|
|
|
|
bool _set(const StringName &p_path, const Variant &p_value);
|
2017-03-05 16:44:50 +01:00
|
|
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
public:
|
|
|
|
enum {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
NOTIFICATION_UPDATE_SKELETON = 50
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
RID get_skeleton() const;
|
|
|
|
|
|
|
|
// skeleton creation api
|
2017-03-05 16:44:50 +01:00
|
|
|
void add_bone(const String &p_name);
|
2018-05-10 13:23:05 +02:00
|
|
|
int find_bone(const String &p_name) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
String get_bone_name(int p_bone) const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2018-05-10 13:23:05 +02:00
|
|
|
bool is_bone_parent_of(int p_bone_id, int p_parent_bone_id) const;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void set_bone_parent(int p_bone, int p_parent);
|
|
|
|
int get_bone_parent(int p_bone) const;
|
|
|
|
|
2017-08-11 21:10:05 +02:00
|
|
|
void unparent_bone_and_rest(int p_bone);
|
2015-09-24 23:06:15 +02:00
|
|
|
|
2017-10-03 18:49:32 +02:00
|
|
|
void set_bone_ignore_animation(int p_bone, bool p_ignore);
|
|
|
|
bool is_bone_ignore_animation(int p_bone) const;
|
|
|
|
|
2015-09-24 23:06:15 +02:00
|
|
|
void set_bone_disable_rest(int p_bone, bool p_disable);
|
|
|
|
bool is_bone_rest_disabled(int p_bone) const;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
int get_bone_count() const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_bone_rest(int p_bone, const Transform &p_rest);
|
2014-02-10 02:10:30 +01:00
|
|
|
Transform get_bone_rest(int p_bone) const;
|
|
|
|
Transform get_bone_transform(int p_bone) const;
|
2014-08-14 15:31:38 +02:00
|
|
|
Transform get_bone_global_pose(int p_bone) const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_bone_global_pose(int p_bone, const Transform &p_pose);
|
2014-10-28 02:54:32 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void set_bone_enabled(int p_bone, bool p_enabled);
|
|
|
|
bool is_bone_enabled(int p_bone) const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01: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-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void clear_bones();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
// posing api
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_bone_pose(int p_bone, const Transform &p_pose);
|
2014-02-10 02:10:30 +01:00
|
|
|
Transform get_bone_pose(int p_bone) const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void set_bone_custom_pose(int p_bone, const Transform &p_custom_pose);
|
2014-02-10 02:10:30 +01:00
|
|
|
Transform get_bone_custom_pose(int p_bone) const;
|
|
|
|
|
|
|
|
void localize_rests(); // used for loaders and tools
|
2018-08-07 03:35:09 +02:00
|
|
|
int get_process_order(int p_idx);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2019-03-03 16:23:03 +01:00
|
|
|
void set_use_bones_in_world_transform(bool p_enable);
|
|
|
|
bool is_using_bones_in_world_transform() const;
|
|
|
|
|
2018-07-01 11:54:13 +02:00
|
|
|
#ifndef _3D_DISABLED
|
2017-10-03 18:49:32 +02:00
|
|
|
// Physical bone API
|
|
|
|
|
|
|
|
void bind_physical_bone_to_bone(int p_bone, PhysicalBone *p_physical_bone);
|
|
|
|
void unbind_physical_bone_from_bone(int p_bone);
|
|
|
|
|
|
|
|
PhysicalBone *get_physical_bone(int p_bone);
|
|
|
|
PhysicalBone *get_physical_bone_parent(int p_bone);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// This is a slow API os it's cached
|
|
|
|
PhysicalBone *_get_physical_bone_parent(int p_bone);
|
|
|
|
void _rebuild_physical_bones_cache();
|
|
|
|
|
|
|
|
public:
|
2018-05-10 13:23:05 +02:00
|
|
|
void physical_bones_stop_simulation();
|
|
|
|
void physical_bones_start_simulation_on(const Array &p_bones);
|
2017-10-03 18:49:32 +02:00
|
|
|
void physical_bones_add_collision_exception(RID p_exception);
|
|
|
|
void physical_bones_remove_collision_exception(RID p_exception);
|
2018-07-01 11:54:13 +02:00
|
|
|
#endif // _3D_DISABLED
|
2017-10-03 18:49:32 +02:00
|
|
|
|
|
|
|
public:
|
2016-03-09 00:00:52 +01:00
|
|
|
Skeleton();
|
2014-02-10 02:10:30 +01:00
|
|
|
~Skeleton();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|