diff options
Diffstat (limited to 'scene/3d')
-rw-r--r-- | scene/3d/audio_stream_player_3d.cpp | 2 | ||||
-rw-r--r-- | scene/3d/camera_3d.cpp | 2 | ||||
-rw-r--r-- | scene/3d/gpu_particles_collision_3d.cpp | 2 | ||||
-rw-r--r-- | scene/3d/light_3d.cpp | 2 | ||||
-rw-r--r-- | scene/3d/lightmap_gi.cpp | 10 | ||||
-rw-r--r-- | scene/3d/mesh_instance_3d.cpp | 4 | ||||
-rw-r--r-- | scene/3d/occluder_instance_3d.cpp | 4 | ||||
-rw-r--r-- | scene/3d/physics_body_3d.cpp | 67 | ||||
-rw-r--r-- | scene/3d/physics_body_3d.h | 2 | ||||
-rw-r--r-- | scene/3d/ray_cast_3d.cpp | 2 | ||||
-rw-r--r-- | scene/3d/reflection_probe.h | 2 | ||||
-rw-r--r-- | scene/3d/remote_transform_3d.cpp | 2 | ||||
-rw-r--r-- | scene/3d/skeleton_3d.cpp | 4 | ||||
-rw-r--r-- | scene/3d/soft_body_3d.cpp | 2 | ||||
-rw-r--r-- | scene/3d/voxel_gi.cpp | 6 | ||||
-rw-r--r-- | scene/3d/voxelizer.cpp | 6 | ||||
-rw-r--r-- | scene/3d/world_environment.cpp | 2 | ||||
-rw-r--r-- | scene/3d/xr_nodes.cpp | 6 |
18 files changed, 83 insertions, 44 deletions
diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 9640043031..e05f37c73c 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -997,7 +997,7 @@ void AudioStreamPlayer3D::_bind_methods() { } AudioStreamPlayer3D::AudioStreamPlayer3D() { - velocity_tracker.instance(); + velocity_tracker.instantiate(); AudioServer::get_singleton()->connect("bus_layout_changed", callable_mp(this, &AudioStreamPlayer3D::_bus_layout_changed)); set_disable_scale(true); } diff --git a/scene/3d/camera_3d.cpp b/scene/3d/camera_3d.cpp index 62bbebe6e7..32006d5e7f 100644 --- a/scene/3d/camera_3d.cpp +++ b/scene/3d/camera_3d.cpp @@ -661,7 +661,7 @@ Camera3D::Camera3D() { set_perspective(75.0, 0.05, 4000.0); RenderingServer::get_singleton()->camera_set_cull_mask(camera, layers); //active=false; - velocity_tracker.instance(); + velocity_tracker.instantiate(); set_notify_transform(true); set_disable_scale(true); } diff --git a/scene/3d/gpu_particles_collision_3d.cpp b/scene/3d/gpu_particles_collision_3d.cpp index 322bc60fce..c1e71b9565 100644 --- a/scene/3d/gpu_particles_collision_3d.cpp +++ b/scene/3d/gpu_particles_collision_3d.cpp @@ -495,7 +495,7 @@ Ref<Image> GPUParticlesCollisionSDF::bake() { _compute_sdf(¶ms); Ref<Image> ret; - ret.instance(); + ret.instantiate(); ret->create(sdf_size.x, sdf_size.y * sdf_size.z, false, Image::FORMAT_RF, data); ret->convert(Image::FORMAT_RH); //convert to half, save space ret->set_meta("depth", sdf_size.z); //hack, make sure to add to the docs of this function diff --git a/scene/3d/light_3d.cpp b/scene/3d/light_3d.cpp index d45749d36b..37881c3332 100644 --- a/scene/3d/light_3d.cpp +++ b/scene/3d/light_3d.cpp @@ -353,7 +353,7 @@ Light3D::Light3D(RenderingServer::LightType p_type) { } Light3D::Light3D() { - ERR_PRINT("Light3D should not be instanced directly; use the DirectionalLight3D, OmniLight3D or SpotLight3D subtypes instead."); + ERR_PRINT("Light3D should not be instantiated directly; use the DirectionalLight3D, OmniLight3D or SpotLight3D subtypes instead."); } Light3D::~Light3D() { diff --git a/scene/3d/lightmap_gi.cpp b/scene/3d/lightmap_gi.cpp index a3f681e53c..74b4269169 100644 --- a/scene/3d/lightmap_gi.cpp +++ b/scene/3d/lightmap_gi.cpp @@ -717,7 +717,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa w_albedo[i + 3] = 255; } - md.albedo_on_uv2.instance(); + md.albedo_on_uv2.instantiate(); md.albedo_on_uv2->create(lightmap_size.width, lightmap_size.height, false, Image::FORMAT_RGBA8, albedom); } @@ -940,7 +940,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa } break; case ENVIRONMENT_MODE_CUSTOM_COLOR: { - environment_image.instance(); + environment_image.instantiate(); environment_image->create(128, 64, false, Image::FORMAT_RGBAF); Color c = environment_custom_color; c.r *= environment_custom_energy; @@ -972,7 +972,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa } //we assume they are all the same, so let's create a large one for saving Ref<Image> large_image; - large_image.instance(); + large_image.instantiate(); large_image->create(images[0]->get_width(), images[0]->get_height() * images.size(), false, images[0]->get_format()); @@ -984,7 +984,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa Ref<ConfigFile> config; - config.instance(); + config.instantiate(); if (FileAccess::exists(base_path + ".import")) { config->load(base_path + ".import"); } @@ -1017,7 +1017,7 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa set_light_data(Ref<LightmapGIData>()); //clear data->clear(); } else { - data.instance(); + data.instantiate(); } data->set_light_texture(texture); diff --git a/scene/3d/mesh_instance_3d.cpp b/scene/3d/mesh_instance_3d.cpp index c495f68890..08dec232ab 100644 --- a/scene/3d/mesh_instance_3d.cpp +++ b/scene/3d/mesh_instance_3d.cpp @@ -405,14 +405,14 @@ void MeshInstance3D::create_debug_tangents() { if (lines.size()) { Ref<StandardMaterial3D> sm; - sm.instance(); + sm.instantiate(); sm->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); sm->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); sm->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); Ref<ArrayMesh> am; - am.instance(); + am.instantiate(); Array a; a.resize(Mesh::ARRAY_MAX); a[Mesh::ARRAY_VERTEX] = lines; diff --git a/scene/3d/occluder_instance_3d.cpp b/scene/3d/occluder_instance_3d.cpp index 429e1d4b98..b0b9668fd2 100644 --- a/scene/3d/occluder_instance_3d.cpp +++ b/scene/3d/occluder_instance_3d.cpp @@ -114,7 +114,7 @@ Ref<ArrayMesh> Occluder3D::get_debug_mesh() const { arrays[Mesh::ARRAY_VERTEX] = vertices; arrays[Mesh::ARRAY_INDEX] = indices; - debug_mesh.instance(); + debug_mesh.instantiate(); debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, arrays); return debug_mesh; } @@ -303,7 +303,7 @@ OccluderInstance3D::BakeError OccluderInstance3D::bake(Node *p_from_node, String if (get_occluder().is_valid()) { occ = get_occluder(); } else { - occ.instance(); + occ.instantiate(); occ->set_path(p_occluder_path); } diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp index 28a0c72fe3..7c9245cd3e 100644 --- a/scene/3d/physics_body_3d.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -106,7 +106,7 @@ Ref<KinematicCollision3D> PhysicsBody3D::_move(const Vector3 &p_motion, bool p_i PhysicsServer3D::MotionResult result; if (move_and_collide(p_motion, p_infinite_inertia, result, p_margin, p_exclude_raycast_shapes, p_test_only)) { if (motion_cache.is_null()) { - motion_cache.instance(); + motion_cache.instantiate(); motion_cache->owner = this; } @@ -118,10 +118,43 @@ Ref<KinematicCollision3D> PhysicsBody3D::_move(const Vector3 &p_motion, bool p_i return Ref<KinematicCollision3D>(); } -bool PhysicsBody3D::move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer3D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes, bool p_test_only) { +bool PhysicsBody3D::move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer3D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes, bool p_test_only, bool p_cancel_sliding) { Transform3D gt = get_global_transform(); bool colliding = PhysicsServer3D::get_singleton()->body_test_motion(get_rid(), gt, p_motion, p_infinite_inertia, p_margin, &r_result, p_exclude_raycast_shapes); + // Restore direction of motion to be along original motion, + // in order to avoid sliding due to recovery, + // but only if collision depth is low enough to avoid tunneling. + real_t motion_length = p_motion.length(); + if (motion_length > CMP_EPSILON) { + real_t precision = CMP_EPSILON; + + if (colliding && p_cancel_sliding) { + // Can't just use margin as a threshold because collision depth is calculated on unsafe motion, + // so even in normal resting cases the depth can be a bit more than the margin. + precision += motion_length * (r_result.collision_unsafe_fraction - r_result.collision_safe_fraction); + + if (r_result.collision_depth > (real_t)p_margin + precision) { + p_cancel_sliding = false; + } + } + + if (p_cancel_sliding) { + // Check depth of recovery. + Vector3 motion_normal = p_motion / motion_length; + real_t dot = r_result.motion.dot(motion_normal); + Vector3 recovery = r_result.motion - motion_normal * dot; + real_t recovery_length = recovery.length(); + // Fixes cases where canceling slide causes the motion to go too deep into the ground, + // Becauses we're only taking rest information into account and not general recovery. + if (recovery_length < (real_t)p_margin + precision) { + // Apply adjustment to motion. + r_result.motion = motion_normal * dot; + r_result.remainder = p_motion - r_result.motion; + } + } + } + for (int i = 0; i < 3; i++) { if (locked_axis & (1 << i)) { r_result.motion[i] = 0; @@ -978,15 +1011,16 @@ void CharacterBody3D::move_and_slide() { floor_normal = Vector3(); floor_velocity = Vector3(); - int slide_count = max_slides; - while (slide_count) { + // No sliding on first attempt to keep motion stable when possible. + bool sliding_enabled = false; + for (int iteration = 0; iteration < max_slides; ++iteration) { PhysicsServer3D::MotionResult result; bool found_collision = false; for (int i = 0; i < 2; ++i) { bool collided; if (i == 0) { //collide - collided = move_and_collide(motion, infinite_inertia, result, margin); + collided = move_and_collide(motion, infinite_inertia, result, margin, true, false, !sliding_enabled); if (!collided) { motion = Vector3(); //clear because no collision happened and motion completed } @@ -1002,7 +1036,6 @@ void CharacterBody3D::move_and_slide() { found_collision = true; motion_results.push_back(result); - motion = result.remainder; if (up_direction == Vector3()) { //all is a wall @@ -1016,7 +1049,7 @@ void CharacterBody3D::move_and_slide() { floor_velocity = result.collider_velocity; if (stop_on_slope) { - if ((body_velocity_normal + up_direction).length() < 0.01 && result.motion.length() < 1) { + if ((body_velocity_normal + up_direction).length() < 0.01) { Transform3D gt = get_global_transform(); gt.origin -= result.motion.slide(up_direction); set_global_transform(gt); @@ -1031,22 +1064,26 @@ void CharacterBody3D::move_and_slide() { } } - motion = motion.slide(result.collision_normal); - linear_velocity = linear_velocity.slide(result.collision_normal); + if (sliding_enabled || !on_floor) { + motion = result.remainder.slide(result.collision_normal); + linear_velocity = linear_velocity.slide(result.collision_normal); - for (int j = 0; j < 3; j++) { - if (locked_axis & (1 << j)) { - linear_velocity[j] = 0.0; + for (int j = 0; j < 3; j++) { + if (locked_axis & (1 << j)) { + linear_velocity[j] = 0.0; + } } + } else { + motion = result.remainder; } } + + sliding_enabled = true; } if (!found_collision || motion == Vector3()) { break; } - - --slide_count; } if (!was_on_floor || snap == Vector3()) { @@ -1168,7 +1205,7 @@ Ref<KinematicCollision3D> CharacterBody3D::_get_slide_collision(int p_bounce) { } if (slide_colliders[p_bounce].is_null()) { - slide_colliders.write[p_bounce].instance(); + slide_colliders.write[p_bounce].instantiate(); slide_colliders.write[p_bounce]->owner = this; } diff --git a/scene/3d/physics_body_3d.h b/scene/3d/physics_body_3d.h index 7d7adf1624..bc4556494d 100644 --- a/scene/3d/physics_body_3d.h +++ b/scene/3d/physics_body_3d.h @@ -53,7 +53,7 @@ protected: Ref<KinematicCollision3D> _move(const Vector3 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, bool p_test_only = false, real_t p_margin = 0.001); public: - bool move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer3D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes = true, bool p_test_only = false); + bool move_and_collide(const Vector3 &p_motion, bool p_infinite_inertia, PhysicsServer3D::MotionResult &r_result, real_t p_margin, bool p_exclude_raycast_shapes = true, bool p_test_only = false, bool p_cancel_sliding = true); bool test_move(const Transform3D &p_from, const Vector3 &p_motion, bool p_infinite_inertia = true, bool p_exclude_raycast_shapes = true, const Ref<KinematicCollision3D> &r_collision = Ref<KinematicCollision3D>(), real_t p_margin = 0.001); void set_axis_lock(PhysicsServer3D::BodyAxis p_axis, bool p_lock); diff --git a/scene/3d/ray_cast_3d.cpp b/scene/3d/ray_cast_3d.cpp index db841101e5..dfab3d4a17 100644 --- a/scene/3d/ray_cast_3d.cpp +++ b/scene/3d/ray_cast_3d.cpp @@ -419,6 +419,8 @@ void RayCast3D::_update_debug_shape_material(bool p_check_collision) { debug_material = material; material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); + // Use double-sided rendering so that the RayCast can be seen if the camera is inside. + material->set_cull_mode(BaseMaterial3D::CULL_DISABLED); material->set_transparency(BaseMaterial3D::TRANSPARENCY_ALPHA); } diff --git a/scene/3d/reflection_probe.h b/scene/3d/reflection_probe.h index 15c2da3ae0..4bf20c89c5 100644 --- a/scene/3d/reflection_probe.h +++ b/scene/3d/reflection_probe.h @@ -55,7 +55,7 @@ private: RID probe; float intensity = 1.0; float max_distance = 0.0; - Vector3 extents = Vector3(1, 1, 1); + Vector3 extents = Vector3(10, 10, 10); Vector3 origin_offset = Vector3(0, 0, 0); bool box_projection = false; bool enable_shadows = false; diff --git a/scene/3d/remote_transform_3d.cpp b/scene/3d/remote_transform_3d.cpp index a7b3a6f1ec..d5fb1fa6ab 100644 --- a/scene/3d/remote_transform_3d.cpp +++ b/scene/3d/remote_transform_3d.cpp @@ -34,7 +34,7 @@ void RemoteTransform3D::_update_cache() { cache = ObjectID(); if (has_node(remote_node)) { Node *node = get_node(remote_node); - if (!node || this == node || node->is_a_parent_of(this) || this->is_a_parent_of(node)) { + if (!node || this == node || node->is_ancestor_of(this) || this->is_ancestor_of(node)) { return; } diff --git a/scene/3d/skeleton_3d.cpp b/scene/3d/skeleton_3d.cpp index f9d613a4bb..fa3b16935c 100644 --- a/scene/3d/skeleton_3d.cpp +++ b/scene/3d/skeleton_3d.cpp @@ -797,7 +797,7 @@ Ref<SkinReference> Skeleton3D::register_skin(const Ref<Skin> &p_skin) { //when skeletons did not support skins. It is also used by gizmo //to display the skeleton. - skin.instance(); + skin.instantiate(); skin->set_bind_count(bones.size()); _update_process_order(); //just in case @@ -826,7 +826,7 @@ Ref<SkinReference> Skeleton3D::register_skin(const Ref<Skin> &p_skin) { ERR_FAIL_COND_V(skin.is_null(), Ref<SkinReference>()); Ref<SkinReference> skin_ref; - skin_ref.instance(); + skin_ref.instantiate(); skin_ref->skeleton_node = this; skin_ref->bind_count = 0; diff --git a/scene/3d/soft_body_3d.cpp b/scene/3d/soft_body_3d.cpp index df5474d03e..9592fe5849 100644 --- a/scene/3d/soft_body_3d.cpp +++ b/scene/3d/soft_body_3d.cpp @@ -465,7 +465,7 @@ void SoftBody3D::become_mesh_owner() { surface_format |= Mesh::ARRAY_FLAG_USE_DYNAMIC_UPDATE; Ref<ArrayMesh> soft_mesh; - soft_mesh.instance(); + soft_mesh.instantiate(); soft_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, surface_arrays, surface_blend_arrays, surface_lods, surface_format); soft_mesh->surface_set_material(0, mesh->surface_get_material(0)); diff --git a/scene/3d/voxel_gi.cpp b/scene/3d/voxel_gi.cpp index e00be9204c..5558930df8 100644 --- a/scene/3d/voxel_gi.cpp +++ b/scene/3d/voxel_gi.cpp @@ -55,7 +55,7 @@ void VoxelGIData::_set_data(const Dictionary &p_data) { } else if (p_data.has("octree_df_png")) { Vector<uint8_t> octree_df_png = p_data["octree_df_png"]; Ref<Image> img; - img.instance(); + img.instantiate(); Error err = img->load_png_from_buffer(octree_df_png); ERR_FAIL_COND(err != OK); ERR_FAIL_COND(img->get_format() != Image::FORMAT_L8); @@ -76,7 +76,7 @@ Dictionary VoxelGIData::_get_data() const { d["octree_data"] = get_data_cells(); if (otsize != Vector3i()) { Ref<Image> img; - img.instance(); + img.instantiate(); img->create(otsize.x * otsize.y, otsize.z, false, Image::FORMAT_L8, get_distance_field()); Vector<uint8_t> df_png = img->save_png_to_buffer(); ERR_FAIL_COND_V(df_png.size() == 0, Dictionary()); @@ -467,7 +467,7 @@ void VoxelGI::bake(Node *p_from_node, bool p_create_visual_debug) { Ref<VoxelGIData> probe_data = get_probe_data(); if (probe_data.is_null()) { - probe_data.instance(); + probe_data.instantiate(); } if (bake_step_function) { diff --git a/scene/3d/voxelizer.cpp b/scene/3d/voxelizer.cpp index ee0c3fe9b6..12f055c01d 100644 --- a/scene/3d/voxelizer.cpp +++ b/scene/3d/voxelizer.cpp @@ -931,14 +931,14 @@ void Voxelizer::_debug_mesh(int p_idx, int p_level, const AABB &p_aabb, Ref<Mult Ref<MultiMesh> Voxelizer::create_debug_multimesh() { Ref<MultiMesh> mm; - mm.instance(); + mm.instantiate(); mm->set_transform_format(MultiMesh::TRANSFORM_3D); mm->set_use_colors(true); mm->set_instance_count(leaf_voxel_count); Ref<ArrayMesh> mesh; - mesh.instance(); + mesh.instantiate(); { Array arr; @@ -985,7 +985,7 @@ Ref<MultiMesh> Voxelizer::create_debug_multimesh() { { Ref<StandardMaterial3D> fsm; - fsm.instance(); + fsm.instantiate(); fsm->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true); fsm->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true); fsm->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED); diff --git a/scene/3d/world_environment.cpp b/scene/3d/world_environment.cpp index 829ecc5ec2..352bef072f 100644 --- a/scene/3d/world_environment.cpp +++ b/scene/3d/world_environment.cpp @@ -145,7 +145,7 @@ TypedArray<String> WorldEnvironment::get_configuration_warnings() const { } if (camera_effects.is_valid() && get_viewport()->find_world_3d()->get_camera_effects() != camera_effects) { - warnings.push_back(TTR("Only one WorldEnvironment is allowed per scene (or set of instanced scenes).")); + warnings.push_back(TTR("Only one WorldEnvironment is allowed per scene (or set of instantiated scenes).")); } return warnings; diff --git a/scene/3d/xr_nodes.cpp b/scene/3d/xr_nodes.cpp index 4f2c816934..a91e712b0b 100644 --- a/scene/3d/xr_nodes.cpp +++ b/scene/3d/xr_nodes.cpp @@ -204,7 +204,7 @@ void XRController3D::_notification(int p_what) { // check button states for (int i = 0; i < 16; i++) { bool was_pressed = (button_states & mask) == mask; - bool is_pressed = Input::get_singleton()->is_joy_button_pressed(joy_id, i); + bool is_pressed = Input::get_singleton()->is_joy_button_pressed(joy_id, (JoyButton)i); if (!was_pressed && is_pressed) { emit_signal("button_pressed", i); @@ -304,7 +304,7 @@ bool XRController3D::is_button_pressed(int p_button) const { return false; }; - return Input::get_singleton()->is_joy_button_pressed(joy_id, p_button); + return Input::get_singleton()->is_joy_button_pressed(joy_id, (JoyButton)p_button); }; float XRController3D::get_joystick_axis(int p_axis) const { @@ -313,7 +313,7 @@ float XRController3D::get_joystick_axis(int p_axis) const { return 0.0; }; - return Input::get_singleton()->get_joy_axis(joy_id, p_axis); + return Input::get_singleton()->get_joy_axis(joy_id, (JoyAxis)p_axis); }; real_t XRController3D::get_rumble() const { |