| 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/2d/skeleton_2d.h" |
| 34 |
#include "scene/resources/2d/skeleton/skeleton_modification_2d.h" |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
class SkeletonModification2DJiggle : public SkeletonModification2D { |
| 41 |
GDCLASS(SkeletonModification2DJiggle, SkeletonModification2D); |
| 42 |
|
| 43 |
private: |
| 44 |
struct Jiggle_Joint_Data2D { |
| 45 |
int bone_idx = -1; |
| 46 |
NodePath bone2d_node; |
| 47 |
ObjectID bone2d_node_cache; |
| 48 |
|
| 49 |
bool override_defaults = false; |
| 50 |
float stiffness = 3; |
| 51 |
float mass = 0.75; |
| 52 |
float damping = 0.75; |
| 53 |
bool use_gravity = false; |
| 54 |
Vector2 gravity = Vector2(0, 6.0); |
| 55 |
|
| 56 |
Vector2 force = Vector2(0, 0); |
| 57 |
Vector2 acceleration = Vector2(0, 0); |
| 58 |
Vector2 velocity = Vector2(0, 0); |
| 59 |
Vector2 last_position = Vector2(0, 0); |
| 60 |
Vector2 dynamic_position = Vector2(0, 0); |
| 61 |
|
| 62 |
Vector2 last_noncollision_position = Vector2(0, 0); |
| 63 |
}; |
| 64 |
|
| 65 |
Vector<Jiggle_Joint_Data2D> jiggle_data_chain; |
| 66 |
|
| 67 |
NodePath target_node; |
| 68 |
ObjectID target_node_cache; |
| 69 |
void update_target_cache(); |
| 70 |
|
| 71 |
float stiffness = 3; |
| 72 |
float mass = 0.75; |
| 73 |
float damping = 0.75; |
| 74 |
bool use_gravity = false; |
| 75 |
Vector2 gravity = Vector2(0, 6); |
| 76 |
|
| 77 |
bool use_colliders = false; |
| 78 |
uint32_t collision_mask = 1; |
| 79 |
|
| 80 |
void jiggle_joint_update_bone2d_cache(int p_joint_idx); |
| 81 |
void _execute_jiggle_joint(int p_joint_idx, Node2D *p_target, float p_delta); |
| 82 |
void _update_jiggle_joint_data(); |
| 83 |
|
| 84 |
protected: |
| 85 |
static void _bind_methods(); |
| 86 |
bool _set(const StringName &p_path, const Variant &p_value); |
| 87 |
bool _get(const StringName &p_path, Variant &r_ret) const; |
| 88 |
void _get_property_list(List<PropertyInfo> *p_list) const; |
| 89 |
|
| 90 |
public: |
| 91 |
void _execute(float p_delta) override; |
| 92 |
void _setup_modification(SkeletonModificationStack2D *p_stack) override; |
| 93 |
|
| 94 |
void set_target_node(const NodePath &p_target_node); |
| 95 |
NodePath get_target_node() const; |
| 96 |
|
| 97 |
void set_stiffness(float p_stiffness); |
| 98 |
float get_stiffness() const; |
| 99 |
void set_mass(float p_mass); |
| 100 |
float get_mass() const; |
| 101 |
void set_damping(float p_damping); |
| 102 |
float get_damping() const; |
| 103 |
void set_use_gravity(bool p_use_gravity); |
| 104 |
bool get_use_gravity() const; |
| 105 |
void set_gravity(Vector2 p_gravity); |
| 106 |
Vector2 get_gravity() const; |
| 107 |
|
| 108 |
void set_use_colliders(bool p_use_colliders); |
| 109 |
bool get_use_colliders() const; |
| 110 |
void set_collision_mask(int p_mask); |
| 111 |
int get_collision_mask() const; |
| 112 |
|
| 113 |
int get_jiggle_data_chain_length(); |
| 114 |
void set_jiggle_data_chain_length(int p_new_length); |
| 115 |
|
| 116 |
void set_jiggle_joint_bone2d_node(int p_joint_idx, const NodePath &p_target_node); |
| 117 |
NodePath get_jiggle_joint_bone2d_node(int p_joint_idx) const; |
| 118 |
void set_jiggle_joint_bone_index(int p_joint_idx, int p_bone_idx); |
| 119 |
int get_jiggle_joint_bone_index(int p_joint_idx) const; |
| 120 |
|
| 121 |
void set_jiggle_joint_override(int p_joint_idx, bool p_override); |
| 122 |
bool get_jiggle_joint_override(int p_joint_idx) const; |
| 123 |
void set_jiggle_joint_stiffness(int p_joint_idx, float p_stiffness); |
| 124 |
float get_jiggle_joint_stiffness(int p_joint_idx) const; |
| 125 |
void set_jiggle_joint_mass(int p_joint_idx, float p_mass); |
| 126 |
float get_jiggle_joint_mass(int p_joint_idx) const; |
| 127 |
void set_jiggle_joint_damping(int p_joint_idx, float p_damping); |
| 128 |
float get_jiggle_joint_damping(int p_joint_idx) const; |
| 129 |
void set_jiggle_joint_use_gravity(int p_joint_idx, bool p_use_gravity); |
| 130 |
bool get_jiggle_joint_use_gravity(int p_joint_idx) const; |
| 131 |
void set_jiggle_joint_gravity(int p_joint_idx, Vector2 p_gravity); |
| 132 |
Vector2 get_jiggle_joint_gravity(int p_joint_idx) const; |
| 133 |
|
| 134 |
SkeletonModification2DJiggle(); |
| 135 |
~SkeletonModification2DJiggle(); |
| 136 |
}; |