diff options
Diffstat (limited to 'scene/3d')
-rw-r--r-- | scene/3d/area.cpp | 4 | ||||
-rw-r--r-- | scene/3d/camera.cpp | 9 | ||||
-rw-r--r-- | scene/3d/gi_probe.cpp | 2 | ||||
-rw-r--r-- | scene/3d/light.cpp | 8 | ||||
-rw-r--r-- | scene/3d/light.h | 4 | ||||
-rw-r--r-- | scene/3d/navigation.h | 6 | ||||
-rw-r--r-- | scene/3d/particles.cpp | 42 | ||||
-rw-r--r-- | scene/3d/particles.h | 2 | ||||
-rw-r--r-- | scene/3d/physics_body.cpp | 122 | ||||
-rw-r--r-- | scene/3d/physics_body.h | 27 | ||||
-rw-r--r-- | scene/3d/ray_cast.cpp | 35 | ||||
-rw-r--r-- | scene/3d/ray_cast.h | 4 | ||||
-rw-r--r-- | scene/3d/spatial.cpp | 4 | ||||
-rw-r--r-- | scene/3d/vehicle_body.cpp | 20 |
14 files changed, 219 insertions, 70 deletions
diff --git a/scene/3d/area.cpp b/scene/3d/area.cpp index 266bc5e381..422aa556f9 100644 --- a/scene/3d/area.cpp +++ b/scene/3d/area.cpp @@ -737,8 +737,8 @@ void Area::_bind_methods() { BIND_ENUM_CONSTANT(SPACE_OVERRIDE_REPLACE_COMBINE); } -Area::Area() - : CollisionObject(PhysicsServer::get_singleton()->area_create(), true) { +Area::Area() : + CollisionObject(PhysicsServer::get_singleton()->area_create(), true) { space_override = SPACE_OVERRIDE_DISABLED; set_gravity(9.8); diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index abc4a03498..af210fff1c 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -191,11 +191,12 @@ void Camera::_update_camera() { get_viewport()->_camera_transform_changed_notify(); */ - if (is_inside_tree() && is_current()) { - get_viewport()->_camera_transform_changed_notify(); - } + if (!is_inside_tree() || get_tree()->is_node_being_edited(this) || !is_current()) + return; + + get_viewport()->_camera_transform_changed_notify(); - if (is_current() && get_world().is_valid()) { + if (get_world().is_valid()) { get_world()->_update_camera(this); } } diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp index 2754d56a05..8e2f87738a 100644 --- a/scene/3d/gi_probe.cpp +++ b/scene/3d/gi_probe.cpp @@ -410,7 +410,7 @@ static bool planeBoxOverlap(Vector3 normal, float d, Vector3 maxbox) { rad = fa * boxhalfsize.x + fb * boxhalfsize.z; \ if (min > rad || max < -rad) return false; -/*======================== Z-tests ========================*/ + /*======================== Z-tests ========================*/ #define AXISTEST_Z12(a, b, fa, fb) \ p1 = a * v1.x - b * v1.y; \ diff --git a/scene/3d/light.cpp b/scene/3d/light.cpp index 126c07f0be..1fc4e932e8 100644 --- a/scene/3d/light.cpp +++ b/scene/3d/light.cpp @@ -367,8 +367,8 @@ void DirectionalLight::_bind_methods() { BIND_ENUM_CONSTANT(SHADOW_DEPTH_RANGE_OPTIMIZED); } -DirectionalLight::DirectionalLight() - : Light(VisualServer::LIGHT_DIRECTIONAL) { +DirectionalLight::DirectionalLight() : + Light(VisualServer::LIGHT_DIRECTIONAL) { set_param(PARAM_SHADOW_NORMAL_BIAS, 0.8); set_param(PARAM_SHADOW_BIAS, 0.1); @@ -422,8 +422,8 @@ void OmniLight::_bind_methods() { BIND_ENUM_CONSTANT(SHADOW_DETAIL_HORIZONTAL); } -OmniLight::OmniLight() - : Light(VisualServer::LIGHT_OMNI) { +OmniLight::OmniLight() : + Light(VisualServer::LIGHT_OMNI) { set_shadow_mode(SHADOW_CUBE); set_shadow_detail(SHADOW_DETAIL_HORIZONTAL); diff --git a/scene/3d/light.h b/scene/3d/light.h index 8514b429ec..33e62214b1 100644 --- a/scene/3d/light.h +++ b/scene/3d/light.h @@ -208,8 +208,8 @@ protected: static void _bind_methods(); public: - SpotLight() - : Light(VisualServer::LIGHT_SPOT) {} + SpotLight() : + Light(VisualServer::LIGHT_SPOT) {} }; #endif diff --git a/scene/3d/navigation.h b/scene/3d/navigation.h index 010d16dedd..d9a38f7b00 100644 --- a/scene/3d/navigation.h +++ b/scene/3d/navigation.h @@ -58,9 +58,9 @@ class Navigation : public Spatial { return (a.key == p_key.a.key) ? (b.key < p_key.b.key) : (a.key < p_key.a.key); }; - EdgeKey(const Point &p_a = Point(), const Point &p_b = Point()) - : a(p_a), - b(p_b) { + EdgeKey(const Point &p_a = Point(), const Point &p_b = Point()) : + a(p_a), + b(p_b) { if (a.key > b.key) { SWAP(a, b); } diff --git a/scene/3d/particles.cpp b/scene/3d/particles.cpp index 2a032f5d96..c137b7e8ff 100644 --- a/scene/3d/particles.cpp +++ b/scene/3d/particles.cpp @@ -703,10 +703,13 @@ void ParticlesMaterial::_update_shader() { else code += " float tex_linear_velocity = 0.0;\n"; - if (tex_parameters[PARAM_ORBIT_VELOCITY].is_valid()) - code += " float tex_orbit_velocity = textureLod(orbit_velocity_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; - else - code += " float tex_orbit_velocity = 0.0;\n"; + if (flags[FLAG_DISABLE_Z]) { + + if (tex_parameters[PARAM_ORBIT_VELOCITY].is_valid()) + code += " float tex_orbit_velocity = textureLod(orbit_velocity_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; + else + code += " float tex_orbit_velocity = 0.0;\n"; + } if (tex_parameters[PARAM_ANGULAR_VELOCITY].is_valid()) code += " float tex_angular_velocity = textureLod(angular_velocity_texture,vec2(CUSTOM.y,0.0),0.0).r;\n"; @@ -756,7 +759,7 @@ void ParticlesMaterial::_update_shader() { code += " //apply linear acceleration\n"; code += " force += length(VELOCITY) > 0.0 ? normalize(VELOCITY) * (linear_accel+tex_linear_accel)*mix(1.0,rand_from_seed(alt_seed),linear_accel_random) : vec3(0.0);\n"; code += " //apply radial acceleration\n"; - code += " vec3 org = vec3(0.0);\n"; + code += " vec3 org = EMISSION_TRANSFORM[3].xyz;\n"; code += " vec3 diff = pos-org;\n"; code += " force += length(diff) > 0.0 ? normalize(diff) * (radial_accel+tex_radial_accel)*mix(1.0,rand_from_seed(alt_seed),radial_accel_random) : vec3(0.0);\n"; code += " //apply tangential acceleration;\n"; @@ -769,6 +772,18 @@ void ParticlesMaterial::_update_shader() { } code += " //apply attractor forces\n"; code += " VELOCITY += force * DELTA;\n"; + code += " //orbit velocity\n"; + if (flags[FLAG_DISABLE_Z]) { + + code += " float orbit_amount = (orbit_velocity+tex_orbit_velocity)*mix(1.0,rand_from_seed(alt_seed),orbit_velocity_random);\n"; + code += " if (orbit_amount!=0.0) {\n"; + code += " float ang = orbit_amount * DELTA * 3.1416 * 2.0;\n"; + code += " mat2 rot = mat2(vec2(cos(ang),-sin(ang)),vec2(sin(ang),cos(ang)));\n"; + code += " TRANSFORM[3].xy-=diff.xy;\n"; + code += " TRANSFORM[3].xy+=rot * diff.xy;\n"; + code += " }\n"; + } + if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid()) { code += " VELOCITY = normalize(VELOCITY)*tex_linear_velocity;\n"; } @@ -869,6 +884,7 @@ void ParticlesMaterial::_update_shader() { } //scale by scale code += " float base_scale = mix(scale*tex_scale,1.0,scale_random*scale_rand);\n"; + code += " if (base_scale==0.0) base_scale=0.000001;\n"; if (trail_size_modifier.is_valid()) { code += " if (trail_divisor > 1) { base_scale *= textureLod(trail_size_modifier,vec2(float(int(NUMBER)%trail_divisor)/float(trail_divisor-1),0.0),0.0).r; } \n"; } @@ -1173,6 +1189,9 @@ void ParticlesMaterial::set_flag(Flags p_flag, bool p_enable) { ERR_FAIL_INDEX(p_flag, FLAG_MAX); flags[p_flag] = p_enable; _queue_shader_change(); + if (p_flag==FLAG_DISABLE_Z) { + _change_notify(); + } } bool ParticlesMaterial::get_flag(Flags p_flag) const { @@ -1358,6 +1377,15 @@ void ParticlesMaterial::_validate_property(PropertyInfo &property) const { if (property.name == "emission_point_count" && (emission_shape != EMISSION_SHAPE_POINTS && emission_shape != EMISSION_SHAPE_DIRECTED_POINTS)) { property.usage = 0; } + + if (property.name.begins_with("orbit_") && !flags[FLAG_DISABLE_Z]) { + property.usage=0; + } +} + +Shader::Mode ParticlesMaterial::get_shader_mode() const { + + return Shader::MODE_PARTICLES; } void ParticlesMaterial::_bind_methods() { @@ -1517,8 +1545,8 @@ void ParticlesMaterial::_bind_methods() { BIND_ENUM_CONSTANT(EMISSION_SHAPE_DIRECTED_POINTS); } -ParticlesMaterial::ParticlesMaterial() - : element(this) { +ParticlesMaterial::ParticlesMaterial() : + element(this) { set_spread(45); set_flatness(0); diff --git a/scene/3d/particles.h b/scene/3d/particles.h index 30080360bb..5b8121e937 100644 --- a/scene/3d/particles.h +++ b/scene/3d/particles.h @@ -390,6 +390,8 @@ public: RID get_shader_rid() const; + virtual Shader::Mode get_shader_mode() const; + ParticlesMaterial(); ~ParticlesMaterial(); }; diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index 4e06b272e2..8c9f59e267 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -166,8 +166,8 @@ void PhysicsBody::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); } -PhysicsBody::PhysicsBody(PhysicsServer::BodyMode p_mode) - : CollisionObject(PhysicsServer::get_singleton()->body_create(p_mode), false) { +PhysicsBody::PhysicsBody(PhysicsServer::BodyMode p_mode) : + CollisionObject(PhysicsServer::get_singleton()->body_create(p_mode), false) { collision_layer = 1; collision_mask = 1; @@ -241,8 +241,8 @@ void StaticBody::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "constant_angular_velocity"), "set_constant_angular_velocity", "get_constant_angular_velocity"); } -StaticBody::StaticBody() - : PhysicsBody(PhysicsServer::BODY_MODE_STATIC) { +StaticBody::StaticBody() : + PhysicsBody(PhysicsServer::BODY_MODE_STATIC) { bounce = 0; friction = 1; @@ -734,15 +734,31 @@ bool RigidBody::is_contact_monitor_enabled() const { return contact_monitor != NULL; } -void RigidBody::set_axis_lock(AxisLock p_lock) { +void RigidBody::set_axis_lock_x(bool p_lock) { + RigidBody::locked_axis[0] = p_lock; + PhysicsServer::get_singleton()->body_set_axis_lock(get_rid(), 0, locked_axis[0]); +} + +void RigidBody::set_axis_lock_y(bool p_lock) { + RigidBody::locked_axis[1] = p_lock; + PhysicsServer::get_singleton()->body_set_axis_lock(get_rid(), 1, locked_axis[1]); +} + +void RigidBody::set_axis_lock_z(bool p_lock) { + RigidBody::locked_axis[2] = p_lock; + PhysicsServer::get_singleton()->body_set_axis_lock(get_rid(), 2, locked_axis[2]); +} - axis_lock = p_lock; - PhysicsServer::get_singleton()->body_set_axis_lock(get_rid(), PhysicsServer::BodyAxisLock(axis_lock)); +bool RigidBody::get_axis_lock_x() const { + return RigidBody::locked_axis[0]; } -RigidBody::AxisLock RigidBody::get_axis_lock() const { +bool RigidBody::get_axis_lock_y() const { + return RigidBody::locked_axis[1]; +} - return axis_lock; +bool RigidBody::get_axis_lock_z() const { + return RigidBody::locked_axis[2]; } Array RigidBody::get_colliding_bodies() const { @@ -837,8 +853,12 @@ void RigidBody::_bind_methods() { ClassDB::bind_method(D_METHOD("_body_enter_tree"), &RigidBody::_body_enter_tree); ClassDB::bind_method(D_METHOD("_body_exit_tree"), &RigidBody::_body_exit_tree); - ClassDB::bind_method(D_METHOD("set_axis_lock", "axis_lock"), &RigidBody::set_axis_lock); - ClassDB::bind_method(D_METHOD("get_axis_lock"), &RigidBody::get_axis_lock); + ClassDB::bind_method(D_METHOD("set_axis_lock_x", "axis_lock_x"), &RigidBody::set_axis_lock_x); + ClassDB::bind_method(D_METHOD("set_axis_lock_y", "axis_lock_y"), &RigidBody::set_axis_lock_y); + ClassDB::bind_method(D_METHOD("set_axis_lock_z", "axis_lock_z"), &RigidBody::set_axis_lock_z); + ClassDB::bind_method(D_METHOD("get_axis_lock_x"), &RigidBody::get_axis_lock_x); + ClassDB::bind_method(D_METHOD("get_axis_lock_y"), &RigidBody::get_axis_lock_y); + ClassDB::bind_method(D_METHOD("get_axis_lock_z"), &RigidBody::get_axis_lock_z); ClassDB::bind_method(D_METHOD("get_colliding_bodies"), &RigidBody::get_colliding_bodies); @@ -856,7 +876,10 @@ void RigidBody::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "contact_monitor"), "set_contact_monitor", "is_contact_monitor_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sleeping"), "set_sleeping", "is_sleeping"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "can_sleep"), "set_can_sleep", "is_able_to_sleep"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "axis_lock", PROPERTY_HINT_ENUM, "Disabled,Lock X,Lock Y,Lock Z"), "set_axis_lock", "get_axis_lock"); + ADD_GROUP("Axis Lock", "axis_lock_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "axis_lock_x"), "set_axis_lock_x", "get_axis_lock_x"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "axis_lock_y"), "set_axis_lock_y", "get_axis_lock_y"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "axis_lock_z"), "set_axis_lock_z", "get_axis_lock_z"); ADD_GROUP("Linear", "linear_"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "linear_velocity"), "set_linear_velocity", "get_linear_velocity"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "linear_damp", PROPERTY_HINT_RANGE, "-1,128,0.01"), "set_linear_damp", "get_linear_damp"); @@ -874,15 +897,10 @@ void RigidBody::_bind_methods() { BIND_ENUM_CONSTANT(MODE_STATIC); BIND_ENUM_CONSTANT(MODE_CHARACTER); BIND_ENUM_CONSTANT(MODE_KINEMATIC); - - BIND_ENUM_CONSTANT(AXIS_LOCK_DISABLED); - BIND_ENUM_CONSTANT(AXIS_LOCK_X); - BIND_ENUM_CONSTANT(AXIS_LOCK_Y); - BIND_ENUM_CONSTANT(AXIS_LOCK_Z); } -RigidBody::RigidBody() - : PhysicsBody(PhysicsServer::BODY_MODE_RIGID) { +RigidBody::RigidBody() : + PhysicsBody(PhysicsServer::BODY_MODE_RIGID) { mode = MODE_RIGID; @@ -904,8 +922,6 @@ RigidBody::RigidBody() contact_monitor = NULL; can_sleep = true; - axis_lock = AXIS_LOCK_DISABLED; - PhysicsServer::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed"); } @@ -952,6 +968,12 @@ bool KinematicBody::move_and_collide(const Vector3 &p_motion, Collision &r_colli r_collision.local_shape = result.collision_local_shape; } + for (int i = 0; i < 3; i++) { + if (locked_axis[i]) { + result.motion[i] = 0; + } + } + gt.origin += result.motion; set_global_transform(gt); @@ -960,9 +982,16 @@ bool KinematicBody::move_and_collide(const Vector3 &p_motion, Collision &r_colli Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Vector3 &p_floor_direction, float p_slope_stop_min_velocity, int p_max_slides, float p_floor_max_angle) { - Vector3 motion = (floor_velocity + p_linear_velocity) * get_physics_process_delta_time(); Vector3 lv = p_linear_velocity; + for (int i = 0; i < 3; i++) { + if (locked_axis[i]) { + lv[i] = 0; + } + } + + Vector3 motion = (floor_velocity + lv) * get_physics_process_delta_time(); + on_floor = false; on_ceiling = false; on_wall = false; @@ -1008,6 +1037,12 @@ Vector3 KinematicBody::move_and_slide(const Vector3 &p_linear_velocity, const Ve motion = motion.slide(n); lv = lv.slide(n); + for (int i = 0; i < 3; i++) { + if (locked_axis[i]) { + lv[i] = 0; + } + } + colliders.push_back(collision); } else { @@ -1047,6 +1082,33 @@ bool KinematicBody::test_move(const Transform &p_from, const Vector3 &p_motion) return PhysicsServer::get_singleton()->body_test_motion(get_rid(), p_from, p_motion); } +void KinematicBody::set_axis_lock_x(bool p_lock) { + KinematicBody::locked_axis[0] = p_lock; + PhysicsServer::get_singleton()->body_set_axis_lock(get_rid(), 0, locked_axis[0]); +} + +void KinematicBody::set_axis_lock_y(bool p_lock) { + KinematicBody::locked_axis[1] = p_lock; + PhysicsServer::get_singleton()->body_set_axis_lock(get_rid(), 1, locked_axis[1]); +} + +void KinematicBody::set_axis_lock_z(bool p_lock) { + KinematicBody::locked_axis[2] = p_lock; + PhysicsServer::get_singleton()->body_set_axis_lock(get_rid(), 2, locked_axis[2]); +} + +bool KinematicBody::get_axis_lock_x() const { + return KinematicBody::locked_axis[0]; +} + +bool KinematicBody::get_axis_lock_y() const { + return KinematicBody::locked_axis[1]; +} + +bool KinematicBody::get_axis_lock_z() const { + return KinematicBody::locked_axis[2]; +} + void KinematicBody::set_safe_margin(float p_margin) { margin = p_margin; @@ -1095,17 +1157,29 @@ void KinematicBody::_bind_methods() { ClassDB::bind_method(D_METHOD("is_on_wall"), &KinematicBody::is_on_wall); ClassDB::bind_method(D_METHOD("get_floor_velocity"), &KinematicBody::get_floor_velocity); + ClassDB::bind_method(D_METHOD("set_axis_lock_x", "axis_lock_x"), &KinematicBody::set_axis_lock_x); + ClassDB::bind_method(D_METHOD("set_axis_lock_y", "axis_lock_y"), &KinematicBody::set_axis_lock_y); + ClassDB::bind_method(D_METHOD("set_axis_lock_z", "axis_lock_z"), &KinematicBody::set_axis_lock_z); + ClassDB::bind_method(D_METHOD("get_axis_lock_x"), &KinematicBody::get_axis_lock_x); + ClassDB::bind_method(D_METHOD("get_axis_lock_y"), &KinematicBody::get_axis_lock_y); + ClassDB::bind_method(D_METHOD("get_axis_lock_z"), &KinematicBody::get_axis_lock_z); + ClassDB::bind_method(D_METHOD("set_safe_margin", "pixels"), &KinematicBody::set_safe_margin); ClassDB::bind_method(D_METHOD("get_safe_margin"), &KinematicBody::get_safe_margin); ClassDB::bind_method(D_METHOD("get_slide_count"), &KinematicBody::get_slide_count); ClassDB::bind_method(D_METHOD("get_slide_collision", "slide_idx"), &KinematicBody::_get_slide_collision); + ADD_GROUP("Axis Lock", "axis_lock_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "axis_lock_x"), "set_axis_lock_x", "get_axis_lock_x"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "axis_lock_y"), "set_axis_lock_y", "get_axis_lock_y"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "axis_lock_z"), "set_axis_lock_z", "get_axis_lock_z"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "collision/safe_margin", PROPERTY_HINT_RANGE, "0.001,256,0.001"), "set_safe_margin", "get_safe_margin"); } -KinematicBody::KinematicBody() - : PhysicsBody(PhysicsServer::BODY_MODE_KINEMATIC) { +KinematicBody::KinematicBody() : + PhysicsBody(PhysicsServer::BODY_MODE_KINEMATIC) { margin = 0.001; diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body.h index f88b3860dc..57b120ef63 100644 --- a/scene/3d/physics_body.h +++ b/scene/3d/physics_body.h @@ -114,13 +114,6 @@ public: MODE_KINEMATIC, }; - enum AxisLock { - AXIS_LOCK_DISABLED, - AXIS_LOCK_X, - AXIS_LOCK_Y, - AXIS_LOCK_Z, - }; - private: bool can_sleep; PhysicsDirectBodyState *state; @@ -139,7 +132,7 @@ private: bool sleeping; bool ccd; - AxisLock axis_lock; + bool locked_axis[3] = { false, false, false }; int max_contacts_reported; @@ -245,8 +238,12 @@ public: void set_use_continuous_collision_detection(bool p_enable); bool is_using_continuous_collision_detection() const; - void set_axis_lock(AxisLock p_lock); - AxisLock get_axis_lock() const; + void set_axis_lock_x(bool p_lock); + void set_axis_lock_y(bool p_lock); + void set_axis_lock_z(bool p_lock); + bool get_axis_lock_x() const; + bool get_axis_lock_y() const; + bool get_axis_lock_z() const; Array get_colliding_bodies() const; @@ -259,7 +256,6 @@ public: }; VARIANT_ENUM_CAST(RigidBody::Mode); -VARIANT_ENUM_CAST(RigidBody::AxisLock); class KinematicCollision; @@ -281,6 +277,8 @@ public: }; private: + bool locked_axis[3] = { false, false, false }; + float margin; Vector3 floor_velocity; @@ -303,6 +301,13 @@ public: bool move_and_collide(const Vector3 &p_motion, Collision &r_collision); bool test_move(const Transform &p_from, const Vector3 &p_motion); + void set_axis_lock_x(bool p_lock); + void set_axis_lock_y(bool p_lock); + void set_axis_lock_z(bool p_lock); + bool get_axis_lock_x() const; + bool get_axis_lock_y() const; + bool get_axis_lock_z() const; + void set_safe_margin(float p_margin); float get_safe_margin() const; diff --git a/scene/3d/ray_cast.cpp b/scene/3d/ray_cast.cpp index aebdcaf183..faeb18691a 100644 --- a/scene/3d/ray_cast.cpp +++ b/scene/3d/ray_cast.cpp @@ -119,6 +119,29 @@ bool RayCast::is_enabled() const { return enabled; } +void RayCast::set_exclude_parent_body(bool p_exclude_parent_body) { + + if (exclude_parent_body == p_exclude_parent_body) + return; + + exclude_parent_body = p_exclude_parent_body; + + if (!is_inside_tree()) + return; + + if (Object::cast_to<CollisionObject>(get_parent())) { + if (exclude_parent_body) + exclude.insert(Object::cast_to<CollisionObject>(get_parent())->get_rid()); + else + exclude.erase(Object::cast_to<CollisionObject>(get_parent())->get_rid()); + } +} + +bool RayCast::get_exclude_parent_body() const { + + return exclude_parent_body; +} + void RayCast::_notification(int p_what) { switch (p_what) { @@ -133,6 +156,13 @@ void RayCast::_notification(int p_what) { } else set_physics_process(false); + if (Object::cast_to<CollisionObject>(get_parent())) { + if (exclude_parent_body) + exclude.insert(Object::cast_to<CollisionObject>(get_parent())->get_rid()); + else + exclude.erase(Object::cast_to<CollisionObject>(get_parent())->get_rid()); + } + } break; case NOTIFICATION_EXIT_TREE: { @@ -256,7 +286,11 @@ void RayCast::_bind_methods() { ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &RayCast::set_collision_mask_bit); ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &RayCast::get_collision_mask_bit); + ClassDB::bind_method(D_METHOD("set_exclude_parent_body", "mask"), &RayCast::set_exclude_parent_body); + ClassDB::bind_method(D_METHOD("get_exclude_parent_body"), &RayCast::get_exclude_parent_body); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "exclude_parent"), "set_exclude_parent_body", "get_exclude_parent_body"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "cast_to"), "set_cast_to", "get_cast_to"); ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask"); } @@ -332,4 +366,5 @@ RayCast::RayCast() { collision_mask = 1; cast_to = Vector3(0, -1, 0); debug_shape = NULL; + exclude_parent_body = true; } diff --git a/scene/3d/ray_cast.h b/scene/3d/ray_cast.h index ca94580271..9fb1a1be67 100644 --- a/scene/3d/ray_cast.h +++ b/scene/3d/ray_cast.h @@ -48,6 +48,7 @@ class RayCast : public Spatial { Set<RID> exclude; uint32_t collision_mask; + bool exclude_parent_body; Node *debug_shape; Ref<Material> debug_material; @@ -74,6 +75,9 @@ public: void set_collision_mask_bit(int p_bit, bool p_value); bool get_collision_mask_bit(int p_bit) const; + void set_exclude_parent_body(bool p_exclude_parent_body); + bool get_exclude_parent_body() const; + void force_raycast_update(); bool is_colliding() const; Object *get_collider() const; diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index 588aa2881a..d9f88ac693 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -756,8 +756,8 @@ void Spatial::_bind_methods() { ADD_SIGNAL(MethodInfo("visibility_changed")); } -Spatial::Spatial() - : xform_change(this) { +Spatial::Spatial() : + xform_change(this) { data.dirty = DIRTY_NONE; data.children_lock = 0; diff --git a/scene/3d/vehicle_body.cpp b/scene/3d/vehicle_body.cpp index a072572142..2e3e179a7b 100644 --- a/scene/3d/vehicle_body.cpp +++ b/scene/3d/vehicle_body.cpp @@ -54,8 +54,8 @@ public: const Vector3 &inertiaInvA, const real_t massInvA, const Vector3 &inertiaInvB, - const real_t massInvB) - : m_linearJointAxis(jointAxis) { + const real_t massInvB) : + m_linearJointAxis(jointAxis) { m_aJ = world2A.xform(rel_pos1.cross(m_linearJointAxis)); m_bJ = world2B.xform(rel_pos2.cross(-m_linearJointAxis)); m_0MinvJt = inertiaInvA * m_aJ; @@ -593,12 +593,12 @@ void VehicleBody::_resolve_single_bilateral(PhysicsDirectBodyState *s, const Vec #endif } -VehicleBody::btVehicleWheelContactPoint::btVehicleWheelContactPoint(PhysicsDirectBodyState *s, PhysicsBody *body1, const Vector3 &frictionPosWorld, const Vector3 &frictionDirectionWorld, real_t maxImpulse) - : m_s(s), - m_body1(body1), - m_frictionPositionWorld(frictionPosWorld), - m_frictionDirectionWorld(frictionDirectionWorld), - m_maxImpulse(maxImpulse) { +VehicleBody::btVehicleWheelContactPoint::btVehicleWheelContactPoint(PhysicsDirectBodyState *s, PhysicsBody *body1, const Vector3 &frictionPosWorld, const Vector3 &frictionDirectionWorld, real_t maxImpulse) : + m_s(s), + m_body1(body1), + m_frictionPositionWorld(frictionPosWorld), + m_frictionDirectionWorld(frictionDirectionWorld), + m_maxImpulse(maxImpulse) { float denom0 = 0; float denom1 = 0; @@ -969,8 +969,8 @@ void VehicleBody::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "friction", PROPERTY_HINT_RANGE, "0.01,1,0.01"), "set_friction", "get_friction"); } -VehicleBody::VehicleBody() - : PhysicsBody(PhysicsServer::BODY_MODE_RIGID) { +VehicleBody::VehicleBody() : + PhysicsBody(PhysicsServer::BODY_MODE_RIGID) { m_pitchControl = 0; m_currentVehicleSpeedKmHour = real_t(0.); |