2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2020-03-26 21:49:16 +00:00
|
|
|
/* skeleton_3d.h */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 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. */
|
|
|
|
/*************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
#ifndef SKELETON_3D_H
|
|
|
|
#define SKELETON_3D_H
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/templates/rid.h"
|
2020-03-26 21:49:16 +00:00
|
|
|
#include "scene/3d/node_3d.h"
|
2019-09-18 22:46:32 +00:00
|
|
|
#include "scene/resources/skin.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-10-03 16:49:32 +00:00
|
|
|
typedef int BoneId;
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
class PhysicalBone3D;
|
|
|
|
class Skeleton3D;
|
2019-09-18 22:46:32 +00:00
|
|
|
|
2021-06-04 16:03:15 +00:00
|
|
|
class SkinReference : public RefCounted {
|
|
|
|
GDCLASS(SkinReference, RefCounted)
|
2020-03-26 21:49:16 +00:00
|
|
|
friend class Skeleton3D;
|
2019-09-18 22:46:32 +00:00
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
Skeleton3D *skeleton_node;
|
2019-09-18 22:46:32 +00:00
|
|
|
RID skeleton;
|
|
|
|
Ref<Skin> skin;
|
|
|
|
uint32_t bind_count = 0;
|
2020-02-21 10:27:48 +00:00
|
|
|
uint64_t skeleton_version = 0;
|
|
|
|
Vector<uint32_t> skin_bone_indices;
|
|
|
|
uint32_t *skin_bone_indices_ptrs;
|
2019-09-18 22:46:32 +00:00
|
|
|
void _skin_changed();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
RID get_skeleton() const;
|
|
|
|
Ref<Skin> get_skin() const;
|
|
|
|
~SkinReference();
|
|
|
|
};
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
class Skeleton3D : public Node3D {
|
|
|
|
GDCLASS(Skeleton3D, Node3D);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-09-18 22:46:32 +00:00
|
|
|
private:
|
|
|
|
friend class SkinReference;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
struct Bone {
|
|
|
|
String name;
|
|
|
|
|
2021-02-07 21:29:31 +00:00
|
|
|
bool enabled = true;
|
|
|
|
int parent = -1;
|
|
|
|
int sort_index = 0; //used for re-sorting process order
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-02-07 21:29:31 +00:00
|
|
|
bool disable_rest = false;
|
2020-10-17 05:08:21 +00:00
|
|
|
Transform3D rest;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2020-10-17 05:08:21 +00:00
|
|
|
Transform3D pose;
|
|
|
|
Transform3D pose_global;
|
|
|
|
Transform3D pose_global_no_override;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-02-07 21:29:31 +00:00
|
|
|
bool custom_pose_enable = false;
|
2020-10-17 05:08:21 +00:00
|
|
|
Transform3D custom_pose;
|
2019-09-26 11:06:47 +00:00
|
|
|
|
2021-02-07 21:29:31 +00:00
|
|
|
float global_pose_override_amount = 0.0;
|
|
|
|
bool global_pose_override_reset = false;
|
2020-10-17 05:08:21 +00:00
|
|
|
Transform3D global_pose_override;
|
2017-12-29 14:34:36 +00:00
|
|
|
|
2021-02-07 21:29:31 +00:00
|
|
|
PhysicalBone3D *physical_bone = nullptr;
|
|
|
|
PhysicalBone3D *cache_parent_physical_bone = nullptr;
|
2017-10-03 16:49:32 +00:00
|
|
|
|
2020-02-12 17:24:06 +00:00
|
|
|
List<ObjectID> nodes_bound;
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2020-05-26 18:17:11 +00:00
|
|
|
Set<SkinReference *> skin_bindings;
|
|
|
|
|
|
|
|
void _skin_changed();
|
|
|
|
|
2021-02-07 21:29:31 +00:00
|
|
|
bool animate_physical_bones = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector<Bone> bones;
|
2018-08-07 01:35:09 +00:00
|
|
|
Vector<int> process_order;
|
2021-02-07 21:29:31 +00:00
|
|
|
bool process_order_dirty = true;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void _make_dirty();
|
2021-02-07 21:29:31 +00:00
|
|
|
bool dirty = false;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2021-02-07 21:29:31 +00:00
|
|
|
uint64_t version = 1;
|
2020-02-21 10:27:48 +00:00
|
|
|
|
2018-08-07 01:35:09 +00:00
|
|
|
void _update_process_order();
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
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 {
|
2017-03-05 15:44:50 +00:00
|
|
|
NOTIFICATION_UPDATE_SKELETON = 50
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// skeleton creation api
|
2017-03-05 15:44:50 +00:00
|
|
|
void add_bone(const String &p_name);
|
2018-05-10 11:23:05 +00:00
|
|
|
int find_bone(const String &p_name) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
String get_bone_name(int p_bone) const;
|
2020-10-15 14:53:18 +00:00
|
|
|
void set_bone_name(int p_bone, const String &p_name);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2018-05-10 11:23:05 +00:00
|
|
|
bool is_bone_parent_of(int p_bone_id, int p_parent_bone_id) const;
|
|
|
|
|
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
|
|
|
|
2020-10-17 05:08:21 +00:00
|
|
|
void set_bone_rest(int p_bone, const Transform3D &p_rest);
|
|
|
|
Transform3D get_bone_rest(int p_bone) const;
|
|
|
|
Transform3D get_bone_global_pose(int p_bone) const;
|
|
|
|
Transform3D get_bone_global_pose_no_override(int p_bone) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-03-24 08:59:32 +00:00
|
|
|
void clear_bones_global_pose_override();
|
2020-10-17 05:08:21 +00:00
|
|
|
void set_bone_global_pose_override(int p_bone, const Transform3D &p_pose, float p_amount, bool p_persistent = false);
|
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
|
|
|
|
2020-10-17 05:08:21 +00:00
|
|
|
void set_bone_pose(int p_bone, const Transform3D &p_pose);
|
|
|
|
Transform3D get_bone_pose(int p_bone) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-10-17 05:08:21 +00:00
|
|
|
void set_bone_custom_pose(int p_bone, const Transform3D &p_custom_pose);
|
|
|
|
Transform3D get_bone_custom_pose(int p_bone) const;
|
2019-09-26 11:06:47 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void localize_rests(); // used for loaders and tools
|
2018-08-07 01:35:09 +00:00
|
|
|
int get_process_order(int p_idx);
|
2020-02-19 19:48:20 +00:00
|
|
|
Vector<int> get_bone_process_orders();
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2019-09-18 22:46:32 +00:00
|
|
|
Ref<SkinReference> register_skin(const Ref<Skin> &p_skin);
|
2019-03-03 15:23:03 +00:00
|
|
|
|
2020-05-26 18:17:11 +00:00
|
|
|
// Helper functions
|
2020-10-17 05:08:21 +00:00
|
|
|
Transform3D bone_transform_to_world_transform(Transform3D p_transform);
|
|
|
|
Transform3D world_transform_to_bone_transform(Transform3D p_transform);
|
2020-05-26 18:17:11 +00:00
|
|
|
|
2017-10-03 16:49:32 +00:00
|
|
|
// Physical bone API
|
|
|
|
|
2020-02-08 08:52:58 +00:00
|
|
|
void set_animate_physical_bones(bool p_animate);
|
|
|
|
bool get_animate_physical_bones() const;
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
void bind_physical_bone_to_bone(int p_bone, PhysicalBone3D *p_physical_bone);
|
2017-10-03 16:49:32 +00:00
|
|
|
void unbind_physical_bone_from_bone(int p_bone);
|
|
|
|
|
2020-03-26 21:49:16 +00:00
|
|
|
PhysicalBone3D *get_physical_bone(int p_bone);
|
|
|
|
PhysicalBone3D *get_physical_bone_parent(int p_bone);
|
2017-10-03 16:49:32 +00:00
|
|
|
|
|
|
|
private:
|
2020-05-26 18:17:11 +00:00
|
|
|
/// This is a slow API, so it's cached
|
2020-03-26 21:49:16 +00:00
|
|
|
PhysicalBone3D *_get_physical_bone_parent(int p_bone);
|
2017-10-03 16:49:32 +00:00
|
|
|
void _rebuild_physical_bones_cache();
|
|
|
|
|
|
|
|
public:
|
2018-05-10 11:23:05 +00:00
|
|
|
void physical_bones_stop_simulation();
|
2020-04-21 15:16:45 +00:00
|
|
|
void physical_bones_start_simulation_on(const TypedArray<StringName> &p_bones);
|
2017-10-03 16:49:32 +00:00
|
|
|
void physical_bones_add_collision_exception(RID p_exception);
|
|
|
|
void physical_bones_remove_collision_exception(RID p_exception);
|
|
|
|
|
|
|
|
public:
|
2020-03-26 21:49:16 +00:00
|
|
|
Skeleton3D();
|
|
|
|
~Skeleton3D();
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|