| 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/skeleton_modifier_3d.h" |
| 34 |
|
| 35 |
class PhysicalBone3D; |
| 36 |
|
| 37 |
class PhysicalBoneSimulator3D : public SkeletonModifier3D { |
| 38 |
GDCLASS(PhysicalBoneSimulator3D, SkeletonModifier3D); |
| 39 |
|
| 40 |
bool simulating = false; |
| 41 |
|
| 42 |
struct SimulatedBone { |
| 43 |
int parent; |
| 44 |
Vector<int> child_bones; |
| 45 |
|
| 46 |
Transform3D global_pose; |
| 47 |
|
| 48 |
PhysicalBone3D *physical_bone = nullptr; |
| 49 |
PhysicalBone3D *cache_parent_physical_bone = nullptr; |
| 50 |
|
| 51 |
SimulatedBone() { |
| 52 |
parent = -1; |
| 53 |
global_pose = Transform3D(); |
| 54 |
physical_bone = nullptr; |
| 55 |
cache_parent_physical_bone = nullptr; |
| 56 |
} |
| 57 |
}; |
| 58 |
|
| 59 |
LocalVector<SimulatedBone> bones; |
| 60 |
|
| 61 |
|
| 62 |
PhysicalBone3D *_get_physical_bone_parent(int p_bone); |
| 63 |
void _rebuild_physical_bones_cache(); |
| 64 |
void _reset_physical_bones_state(); |
| 65 |
|
| 66 |
protected: |
| 67 |
static void _bind_methods(); |
| 68 |
|
| 69 |
virtual void _set_active(bool p_active) override; |
| 70 |
|
| 71 |
void _bone_list_changed(); |
| 72 |
void _pose_updated(); |
| 73 |
void _bone_pose_updated(Skeleton3D *skeleton, int p_bone_id); |
| 74 |
|
| 75 |
virtual void _process_modification(double p_delta) override; |
| 76 |
|
| 77 |
virtual void _skeleton_changed(Skeleton3D *p_old, Skeleton3D *p_new) override; |
| 78 |
|
| 79 |
public: |
| 80 |
#ifndef DISABLE_DEPRECATED |
| 81 |
bool is_compat = false; |
| 82 |
#endif |
| 83 |
bool is_simulating_physics() const; |
| 84 |
|
| 85 |
int find_bone(const String &p_name) const; |
| 86 |
String get_bone_name(int p_bone) const; |
| 87 |
int get_bone_count() const; |
| 88 |
bool is_bone_parent_of(int p_bone_id, int p_parent_bone_id) const; |
| 89 |
|
| 90 |
Transform3D get_bone_global_pose(int p_bone) const; |
| 91 |
void set_bone_global_pose(int p_bone, const Transform3D &p_pose); |
| 92 |
|
| 93 |
void bind_physical_bone_to_bone(int p_bone, PhysicalBone3D *p_physical_bone); |
| 94 |
void unbind_physical_bone_from_bone(int p_bone); |
| 95 |
|
| 96 |
PhysicalBone3D *get_physical_bone(int p_bone); |
| 97 |
PhysicalBone3D *get_physical_bone_parent(int p_bone); |
| 98 |
|
| 99 |
void physical_bones_stop_simulation(); |
| 100 |
void physical_bones_start_simulation_on(const TypedArray<StringName> &p_bones); |
| 101 |
void physical_bones_add_collision_exception(RID p_exception); |
| 102 |
void physical_bones_remove_collision_exception(RID p_exception); |
| 103 |
|
| 104 |
PhysicalBoneSimulator3D(); |
| 105 |
}; |