| 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/camera_3d.h" |
| 34 |
#include "scene/3d/node_3d.h" |
| 35 |
#include "scene/resources/3d/shape_3d.h" |
| 36 |
|
| 37 |
class CollisionObject3D : public Node3D { |
| 38 |
GDCLASS(CollisionObject3D, Node3D); |
| 39 |
|
| 40 |
public: |
| 41 |
static constexpr AncestralClass static_ancestral_class = AncestralClass::COLLISION_OBJECT_3D; |
| 42 |
|
| 43 |
enum DisableMode { |
| 44 |
DISABLE_MODE_REMOVE, |
| 45 |
DISABLE_MODE_MAKE_STATIC, |
| 46 |
DISABLE_MODE_KEEP_ACTIVE, |
| 47 |
}; |
| 48 |
|
| 49 |
private: |
| 50 |
uint32_t collision_layer = 1; |
| 51 |
uint32_t collision_mask = 1; |
| 52 |
real_t collision_priority = 1.0; |
| 53 |
|
| 54 |
bool area = false; |
| 55 |
|
| 56 |
RID rid; |
| 57 |
uint32_t callback_lock = 0; |
| 58 |
|
| 59 |
DisableMode disable_mode = DISABLE_MODE_REMOVE; |
| 60 |
|
| 61 |
PhysicsServer3D::BodyMode body_mode = PhysicsServer3D::BODY_MODE_STATIC; |
| 62 |
|
| 63 |
struct ShapeData { |
| 64 |
ObjectID owner_id; |
| 65 |
Transform3D xform; |
| 66 |
struct ShapeBase { |
| 67 |
RID debug_shape; |
| 68 |
Ref<Shape3D> shape; |
| 69 |
int index = 0; |
| 70 |
}; |
| 71 |
|
| 72 |
Vector<ShapeBase> shapes; |
| 73 |
bool disabled = false; |
| 74 |
}; |
| 75 |
|
| 76 |
int total_subshapes = 0; |
| 77 |
|
| 78 |
RBMap<uint32_t, ShapeData> shapes; |
| 79 |
|
| 80 |
bool only_update_transform_changes = false; |
| 81 |
|
| 82 |
bool capture_input_on_drag = false; |
| 83 |
bool ray_pickable = true; |
| 84 |
|
| 85 |
HashSet<uint32_t> debug_shapes_to_update; |
| 86 |
int debug_shapes_count = 0; |
| 87 |
Transform3D debug_shape_old_transform; |
| 88 |
|
| 89 |
void _update_pickable(); |
| 90 |
|
| 91 |
bool _are_collision_shapes_visible(); |
| 92 |
void _update_shape_data(uint32_t p_owner); |
| 93 |
void _shape_changed(const Ref<Shape3D> &p_shape); |
| 94 |
void _update_debug_shapes(); |
| 95 |
void _clear_debug_shapes(); |
| 96 |
|
| 97 |
void _apply_disabled(); |
| 98 |
void _apply_enabled(); |
| 99 |
|
| 100 |
protected: |
| 101 |
CollisionObject3D(RID p_rid, bool p_area); |
| 102 |
|
| 103 |
_FORCE_INLINE_ void lock_callback() { callback_lock++; } |
| 104 |
_FORCE_INLINE_ void unlock_callback() { |
| 105 |
ERR_FAIL_COND(callback_lock == 0); |
| 106 |
callback_lock--; |
| 107 |
} |
| 108 |
|
| 109 |
void _notification(int p_what); |
| 110 |
static void _bind_methods(); |
| 111 |
|
| 112 |
void _on_transform_changed(); |
| 113 |
|
| 114 |
friend class Viewport; |
| 115 |
virtual void _input_event_call(Camera3D *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape); |
| 116 |
virtual void _mouse_enter(); |
| 117 |
virtual void _mouse_exit(); |
| 118 |
|
| 119 |
void set_body_mode(PhysicsServer3D::BodyMode p_mode); |
| 120 |
|
| 121 |
virtual void _space_changed(const RID &p_new_space); |
| 122 |
|
| 123 |
void set_only_update_transform_changes(bool p_enable); |
| 124 |
bool is_only_update_transform_changes_enabled() const; |
| 125 |
|
| 126 |
GDVIRTUAL5(_input_event, RequiredParam<Camera3D>, RequiredParam<InputEvent>, Vector3, Vector3, int) |
| 127 |
GDVIRTUAL0(_mouse_enter) |
| 128 |
GDVIRTUAL0(_mouse_exit) |
| 129 |
public: |
| 130 |
void set_collision_layer(uint32_t p_layer); |
| 131 |
uint32_t get_collision_layer() const; |
| 132 |
|
| 133 |
void set_collision_mask(uint32_t p_mask); |
| 134 |
uint32_t get_collision_mask() const; |
| 135 |
|
| 136 |
void set_collision_layer_value(int p_layer_number, bool p_value); |
| 137 |
bool get_collision_layer_value(int p_layer_number) const; |
| 138 |
|
| 139 |
void set_collision_mask_value(int p_layer_number, bool p_value); |
| 140 |
bool get_collision_mask_value(int p_layer_number) const; |
| 141 |
|
| 142 |
void set_collision_priority(real_t p_priority); |
| 143 |
real_t get_collision_priority() const; |
| 144 |
|
| 145 |
void set_disable_mode(DisableMode p_mode); |
| 146 |
DisableMode get_disable_mode() const; |
| 147 |
|
| 148 |
uint32_t create_shape_owner(Object *p_owner); |
| 149 |
void remove_shape_owner(uint32_t owner); |
| 150 |
void get_shape_owners(List<uint32_t> *r_owners); |
| 151 |
PackedInt32Array _get_shape_owners(); |
| 152 |
|
| 153 |
void shape_owner_set_transform(uint32_t p_owner, const Transform3D &p_transform); |
| 154 |
Transform3D shape_owner_get_transform(uint32_t p_owner) const; |
| 155 |
Object *shape_owner_get_owner(uint32_t p_owner) const; |
| 156 |
|
| 157 |
void shape_owner_set_disabled(uint32_t p_owner, bool p_disabled); |
| 158 |
bool is_shape_owner_disabled(uint32_t p_owner) const; |
| 159 |
|
| 160 |
void shape_owner_add_shape(uint32_t p_owner, RequiredParam<Shape3D> rp_shape); |
| 161 |
int shape_owner_get_shape_count(uint32_t p_owner) const; |
| 162 |
Ref<Shape3D> shape_owner_get_shape(uint32_t p_owner, int p_shape) const; |
| 163 |
int shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const; |
| 164 |
|
| 165 |
void shape_owner_remove_shape(uint32_t p_owner, int p_shape); |
| 166 |
void shape_owner_clear_shapes(uint32_t p_owner); |
| 167 |
|
| 168 |
uint32_t shape_find_owner(int p_shape_index) const; |
| 169 |
|
| 170 |
void set_ray_pickable(bool p_ray_pickable); |
| 171 |
bool is_ray_pickable() const; |
| 172 |
|
| 173 |
void set_capture_input_on_drag(bool p_capture); |
| 174 |
bool get_capture_input_on_drag() const; |
| 175 |
|
| 176 |
_FORCE_INLINE_ RID get_rid() const { return rid; } |
| 177 |
|
| 178 |
PackedStringArray get_configuration_warnings() const override; |
| 179 |
|
| 180 |
CollisionObject3D(); |
| 181 |
~CollisionObject3D(); |
| 182 |
}; |
| 183 |
|
| 184 |
VARIANT_ENUM_CAST(CollisionObject3D::DisableMode); |