| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "scene/3d/node_3d.h" |
| 34 |
|
| 35 |
#include "scene/3d/skeleton_3d.h" |
| 36 |
|
| 37 |
class SkeletonModifier3D : public Node3D { |
| 38 |
GDCLASS(SkeletonModifier3D, Node3D); |
| 39 |
|
| 40 |
void rebind(); |
| 41 |
|
| 42 |
public: |
| 43 |
|
| 44 |
enum BoneAxis { |
| 45 |
BONE_AXIS_PLUS_X, |
| 46 |
BONE_AXIS_MINUS_X, |
| 47 |
BONE_AXIS_PLUS_Y, |
| 48 |
BONE_AXIS_MINUS_Y, |
| 49 |
BONE_AXIS_PLUS_Z, |
| 50 |
BONE_AXIS_MINUS_Z, |
| 51 |
}; |
| 52 |
static String get_hint_bone_axis() { return "+X,-X,+Y,-Y,+Z,-Z"; } |
| 53 |
|
| 54 |
|
| 55 |
enum BoneDirection { |
| 56 |
BONE_DIRECTION_PLUS_X, |
| 57 |
BONE_DIRECTION_MINUS_X, |
| 58 |
BONE_DIRECTION_PLUS_Y, |
| 59 |
BONE_DIRECTION_MINUS_Y, |
| 60 |
BONE_DIRECTION_PLUS_Z, |
| 61 |
BONE_DIRECTION_MINUS_Z, |
| 62 |
BONE_DIRECTION_FROM_PARENT, |
| 63 |
}; |
| 64 |
static String get_hint_bone_direction() { return "+X,-X,+Y,-Y,+Z,-Z,FromParent"; } |
| 65 |
|
| 66 |
|
| 67 |
enum SecondaryDirection { |
| 68 |
SECONDARY_DIRECTION_NONE, |
| 69 |
SECONDARY_DIRECTION_PLUS_X, |
| 70 |
SECONDARY_DIRECTION_MINUS_X, |
| 71 |
SECONDARY_DIRECTION_PLUS_Y, |
| 72 |
SECONDARY_DIRECTION_MINUS_Y, |
| 73 |
SECONDARY_DIRECTION_PLUS_Z, |
| 74 |
SECONDARY_DIRECTION_MINUS_Z, |
| 75 |
SECONDARY_DIRECTION_CUSTOM, |
| 76 |
}; |
| 77 |
static String get_hint_secondary_direction() { return "None,+X,-X,+Y,-Y,+Z,-Z,Custom"; } |
| 78 |
|
| 79 |
|
| 80 |
enum RotationAxis { |
| 81 |
ROTATION_AXIS_X, |
| 82 |
ROTATION_AXIS_Y, |
| 83 |
ROTATION_AXIS_Z, |
| 84 |
ROTATION_AXIS_ALL, |
| 85 |
ROTATION_AXIS_CUSTOM, |
| 86 |
}; |
| 87 |
static String get_hint_rotation_axis() { return "X,Y,Z,All,Custom"; } |
| 88 |
|
| 89 |
protected: |
| 90 |
bool active = true; |
| 91 |
real_t influence = 1.0; |
| 92 |
|
| 93 |
|
| 94 |
ObjectID skeleton_id; |
| 95 |
|
| 96 |
void _update_skeleton(); |
| 97 |
void _update_skeleton_path(); |
| 98 |
void _force_update_skeleton_skin(); |
| 99 |
|
| 100 |
virtual void _skeleton_changed(Skeleton3D *p_old, Skeleton3D *p_new); |
| 101 |
virtual void _validate_bone_names(); |
| 102 |
GDVIRTUAL2(_skeleton_changed, Skeleton3D *, Skeleton3D *); |
| 103 |
GDVIRTUAL0(_validate_bone_names); |
| 104 |
|
| 105 |
void _notification(int p_what); |
| 106 |
static void _bind_methods(); |
| 107 |
|
| 108 |
virtual void _set_active(bool p_active); |
| 109 |
|
| 110 |
virtual void _process_modification(double p_delta); |
| 111 |
|
| 112 |
GDVIRTUAL1(_process_modification_with_delta, double); |
| 113 |
#ifndef DISABLE_DEPRECATED |
| 114 |
GDVIRTUAL0(_process_modification); |
| 115 |
#endif |
| 116 |
|
| 117 |
public: |
| 118 |
virtual PackedStringArray get_configuration_warnings() const override; |
| 119 |
virtual bool has_process() const { return false; } |
| 120 |
|
| 121 |
void set_active(bool p_active); |
| 122 |
bool is_active() const; |
| 123 |
|
| 124 |
void set_influence(real_t p_influence); |
| 125 |
real_t get_influence() const; |
| 126 |
|
| 127 |
Skeleton3D *get_skeleton() const; |
| 128 |
|
| 129 |
void process_modification(double p_delta); |
| 130 |
|
| 131 |
|
| 132 |
static Vector3 get_vector_from_bone_axis(BoneAxis p_axis); |
| 133 |
static Vector3 get_vector_from_axis(Vector3::Axis p_axis); |
| 134 |
static Vector3::Axis get_axis_from_bone_axis(BoneAxis p_axis); |
| 135 |
|
| 136 |
|
| 137 |
static Vector3 limit_length(const Vector3 &p_origin, const Vector3 &p_destination, float p_length); |
| 138 |
static Quaternion get_local_pose_rotation(Skeleton3D *p_skeleton, int p_bone, const Quaternion &p_global_pose_rotation); |
| 139 |
static Quaternion get_from_to_rotation(const Vector3 &p_from, const Vector3 &p_to, const Quaternion &p_prev_rot); |
| 140 |
static Quaternion get_from_to_rotation_by_axis(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_axis); |
| 141 |
static Quaternion get_swing(const Quaternion &p_rotation, const Vector3 &p_axis); |
| 142 |
static Vector3 snap_vector_to_plane(const Vector3 &p_plane_normal, const Vector3 &p_vector); |
| 143 |
static double symmetrize_angle(double p_angle); |
| 144 |
static double get_roll_angle(const Quaternion &p_rotation, const Vector3 &p_roll_axis); |
| 145 |
static Vector3 get_projected_normal(const Vector3 &p_a, const Vector3 &p_b, const Vector3 &p_point); |
| 146 |
|
| 147 |
#ifdef TOOLS_ENABLED |
| 148 |
virtual bool is_processed_on_saving() const { return false; } |
| 149 |
#endif |
| 150 |
|
| 151 |
SkeletonModifier3D(); |
| 152 |
}; |
| 153 |
|
| 154 |
VARIANT_ENUM_CAST(SkeletonModifier3D::BoneAxis); |
| 155 |
VARIANT_ENUM_CAST(SkeletonModifier3D::BoneDirection); |
| 156 |
VARIANT_ENUM_CAST(SkeletonModifier3D::SecondaryDirection); |
| 157 |
VARIANT_ENUM_CAST(SkeletonModifier3D::RotationAxis); |