diff options
Diffstat (limited to 'scene/3d/collision_object_3d.cpp')
-rw-r--r-- | scene/3d/collision_object_3d.cpp | 61 |
1 files changed, 19 insertions, 42 deletions
diff --git a/scene/3d/collision_object_3d.cpp b/scene/3d/collision_object_3d.cpp index 5d050e32b0..356992e922 100644 --- a/scene/3d/collision_object_3d.cpp +++ b/scene/3d/collision_object_3d.cpp @@ -34,52 +34,49 @@ #include "servers/physics_server_3d.h" void CollisionObject3D::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_WORLD: { - - if (area) + if (area) { PhysicsServer3D::get_singleton()->area_set_transform(rid, get_global_transform()); - else + } else { PhysicsServer3D::get_singleton()->body_set_state(rid, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform()); + } RID space = get_world_3d()->get_space(); if (area) { PhysicsServer3D::get_singleton()->area_set_space(rid, space); - } else + } else { PhysicsServer3D::get_singleton()->body_set_space(rid, space); + } _update_pickable(); //get space } break; case NOTIFICATION_TRANSFORM_CHANGED: { - - if (area) + if (area) { PhysicsServer3D::get_singleton()->area_set_transform(rid, get_global_transform()); - else + } else { PhysicsServer3D::get_singleton()->body_set_state(rid, PhysicsServer3D::BODY_STATE_TRANSFORM, get_global_transform()); + } } break; case NOTIFICATION_VISIBILITY_CHANGED: { - _update_pickable(); } break; case NOTIFICATION_EXIT_WORLD: { - if (area) { PhysicsServer3D::get_singleton()->area_set_space(rid, RID()); - } else + } else { PhysicsServer3D::get_singleton()->body_set_space(rid, RID()); + } } break; } } void CollisionObject3D::_input_event(Node *p_camera, const Ref<InputEvent> &p_input_event, const Vector3 &p_pos, const Vector3 &p_normal, int p_shape) { - if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_input_event, p_camera, p_input_event, p_pos, p_normal, p_shape); } @@ -87,7 +84,6 @@ void CollisionObject3D::_input_event(Node *p_camera, const Ref<InputEvent> &p_in } void CollisionObject3D::_mouse_enter() { - if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_enter); } @@ -95,7 +91,6 @@ void CollisionObject3D::_mouse_enter() { } void CollisionObject3D::_mouse_exit() { - if (get_script_instance()) { get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_exit); } @@ -103,29 +98,28 @@ void CollisionObject3D::_mouse_exit() { } void CollisionObject3D::_update_pickable() { - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } bool pickable = ray_pickable && is_visible_in_tree(); - if (area) + if (area) { PhysicsServer3D::get_singleton()->area_set_ray_pickable(rid, pickable); - else + } else { PhysicsServer3D::get_singleton()->body_set_ray_pickable(rid, pickable); + } } void CollisionObject3D::set_ray_pickable(bool p_ray_pickable) { - ray_pickable = p_ray_pickable; _update_pickable(); } bool CollisionObject3D::is_ray_pickable() const { - return ray_pickable; } void CollisionObject3D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_ray_pickable", "ray_pickable"), &CollisionObject3D::set_ray_pickable); ClassDB::bind_method(D_METHOD("is_ray_pickable"), &CollisionObject3D::is_ray_pickable); ClassDB::bind_method(D_METHOD("set_capture_input_on_drag", "enable"), &CollisionObject3D::set_capture_input_on_drag); @@ -158,7 +152,6 @@ void CollisionObject3D::_bind_methods() { } uint32_t CollisionObject3D::create_shape_owner(Object *p_owner) { - ShapeData sd; uint32_t id; @@ -176,7 +169,6 @@ uint32_t CollisionObject3D::create_shape_owner(Object *p_owner) { } void CollisionObject3D::remove_shape_owner(uint32_t owner) { - ERR_FAIL_COND(!shapes.has(owner)); shape_owner_clear_shapes(owner); @@ -199,21 +191,18 @@ void CollisionObject3D::shape_owner_set_disabled(uint32_t p_owner, bool p_disabl } bool CollisionObject3D::is_shape_owner_disabled(uint32_t p_owner) const { - ERR_FAIL_COND_V(!shapes.has(p_owner), false); return shapes[p_owner].disabled; } void CollisionObject3D::get_shape_owners(List<uint32_t> *r_owners) { - for (Map<uint32_t, ShapeData>::Element *E = shapes.front(); E; E = E->next()) { r_owners->push_back(E->key()); } } Array CollisionObject3D::_get_shape_owners() { - Array ret; for (Map<uint32_t, ShapeData>::Element *E = shapes.front(); E; E = E->next()) { ret.push_back(E->key()); @@ -223,7 +212,6 @@ Array CollisionObject3D::_get_shape_owners() { } void CollisionObject3D::shape_owner_set_transform(uint32_t p_owner, const Transform &p_transform) { - ERR_FAIL_COND(!shapes.has(p_owner)); ShapeData &sd = shapes[p_owner]; @@ -236,22 +224,20 @@ void CollisionObject3D::shape_owner_set_transform(uint32_t p_owner, const Transf } } } -Transform CollisionObject3D::shape_owner_get_transform(uint32_t p_owner) const { +Transform CollisionObject3D::shape_owner_get_transform(uint32_t p_owner) const { ERR_FAIL_COND_V(!shapes.has(p_owner), Transform()); return shapes[p_owner].xform; } Object *CollisionObject3D::shape_owner_get_owner(uint32_t p_owner) const { - ERR_FAIL_COND_V(!shapes.has(p_owner), nullptr); return shapes[p_owner].owner; } void CollisionObject3D::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape3D> &p_shape) { - ERR_FAIL_COND(!shapes.has(p_owner)); ERR_FAIL_COND(p_shape.is_null()); @@ -268,21 +254,21 @@ void CollisionObject3D::shape_owner_add_shape(uint32_t p_owner, const Ref<Shape3 total_subshapes++; } -int CollisionObject3D::shape_owner_get_shape_count(uint32_t p_owner) const { +int CollisionObject3D::shape_owner_get_shape_count(uint32_t p_owner) const { ERR_FAIL_COND_V(!shapes.has(p_owner), 0); return shapes[p_owner].shapes.size(); } -Ref<Shape3D> CollisionObject3D::shape_owner_get_shape(uint32_t p_owner, int p_shape) const { +Ref<Shape3D> CollisionObject3D::shape_owner_get_shape(uint32_t p_owner, int p_shape) const { ERR_FAIL_COND_V(!shapes.has(p_owner), Ref<Shape3D>()); ERR_FAIL_INDEX_V(p_shape, shapes[p_owner].shapes.size(), Ref<Shape3D>()); return shapes[p_owner].shapes[p_shape].shape; } -int CollisionObject3D::shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const { +int CollisionObject3D::shape_owner_get_shape_index(uint32_t p_owner, int p_shape) const { ERR_FAIL_COND_V(!shapes.has(p_owner), -1); ERR_FAIL_INDEX_V(p_shape, shapes[p_owner].shapes.size(), -1); @@ -290,7 +276,6 @@ int CollisionObject3D::shape_owner_get_shape_index(uint32_t p_owner, int p_shape } void CollisionObject3D::shape_owner_remove_shape(uint32_t p_owner, int p_shape) { - ERR_FAIL_COND(!shapes.has(p_owner)); ERR_FAIL_INDEX(p_shape, shapes[p_owner].shapes.size()); @@ -315,7 +300,6 @@ void CollisionObject3D::shape_owner_remove_shape(uint32_t p_owner, int p_shape) } void CollisionObject3D::shape_owner_clear_shapes(uint32_t p_owner) { - ERR_FAIL_COND(!shapes.has(p_owner)); while (shape_owner_get_shape_count(p_owner) > 0) { @@ -324,7 +308,6 @@ void CollisionObject3D::shape_owner_clear_shapes(uint32_t p_owner) { } uint32_t CollisionObject3D::shape_find_owner(int p_shape_index) const { - ERR_FAIL_INDEX_V(p_shape_index, total_subshapes, 0); for (const Map<uint32_t, ShapeData>::Element *E = shapes.front(); E; E = E->next()) { @@ -340,7 +323,6 @@ uint32_t CollisionObject3D::shape_find_owner(int p_shape_index) const { } CollisionObject3D::CollisionObject3D(RID p_rid, bool p_area) { - rid = p_rid; area = p_area; capture_input_on_drag = false; @@ -357,17 +339,14 @@ CollisionObject3D::CollisionObject3D(RID p_rid, bool p_area) { } void CollisionObject3D::set_capture_input_on_drag(bool p_capture) { - capture_input_on_drag = p_capture; } bool CollisionObject3D::get_capture_input_on_drag() const { - return capture_input_on_drag; } String CollisionObject3D::get_configuration_warning() const { - String warning = Node3D::get_configuration_warning(); if (shapes.empty()) { @@ -381,7 +360,6 @@ String CollisionObject3D::get_configuration_warning() const { } CollisionObject3D::CollisionObject3D() { - capture_input_on_drag = false; ray_pickable = true; set_notify_transform(true); @@ -391,6 +369,5 @@ CollisionObject3D::CollisionObject3D() { } CollisionObject3D::~CollisionObject3D() { - PhysicsServer3D::get_singleton()->free(rid); } |