summaryrefslogtreecommitdiff
path: root/scene/3d/ray_cast_3d.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/3d/ray_cast_3d.cpp')
-rw-r--r--scene/3d/ray_cast_3d.cpp50
1 files changed, 25 insertions, 25 deletions
diff --git a/scene/3d/ray_cast_3d.cpp b/scene/3d/ray_cast_3d.cpp
index 811e8a331b..bfe79f15f5 100644
--- a/scene/3d/ray_cast_3d.cpp
+++ b/scene/3d/ray_cast_3d.cpp
@@ -5,8 +5,8 @@
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
+/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -148,14 +148,14 @@ void RayCast3D::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
if (enabled && !Engine::get_singleton()->is_editor_hint()) {
set_physics_process_internal(true);
-
- if (get_tree()->is_debugging_collisions_hint()) {
- _update_debug_shape();
- }
} else {
set_physics_process_internal(false);
}
+ if (get_tree()->is_debugging_collisions_hint()) {
+ _update_debug_shape();
+ }
+
if (Object::cast_to<CollisionObject3D>(get_parent())) {
if (exclude_parent_body) {
exclude.insert(Object::cast_to<CollisionObject3D>(get_parent())->get_rid());
@@ -348,23 +348,32 @@ void RayCast3D::_update_debug_shape() {
}
MeshInstance3D *mi = static_cast<MeshInstance3D *>(debug_shape);
- if (!mi->get_mesh().is_valid()) {
+ Ref<ArrayMesh> mesh = mi->get_mesh();
+ if (!mesh.is_valid()) {
return;
}
- Ref<ArrayMesh> mesh = mi->get_mesh();
- mesh->clear_surfaces();
-
- Array a;
- a.resize(Mesh::ARRAY_MAX);
-
Vector<Vector3> verts;
verts.push_back(Vector3());
verts.push_back(target_position);
- a[Mesh::ARRAY_VERTEX] = verts;
- mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, a);
- mesh->surface_set_material(0, debug_material);
+ if (mesh->get_surface_count() == 0) {
+ Array a;
+ a.resize(Mesh::ARRAY_MAX);
+ a[Mesh::ARRAY_VERTEX] = verts;
+
+ uint32_t flags = Mesh::ARRAY_FLAG_USE_DYNAMIC_UPDATE;
+
+ mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, a, Array(), Dictionary(), flags);
+ mesh->surface_set_material(0, debug_material);
+ } else {
+ Vector<uint8_t> byte_array;
+ int array_size = sizeof(Vector3) * verts.size();
+ byte_array.resize(array_size);
+ copymem(byte_array.ptrw(), verts.ptr(), array_size);
+
+ RS::get_singleton()->mesh_surface_update_region(mesh->get_rid(), 0, 0, byte_array);
+ }
}
void RayCast3D::_clear_debug_shape() {
@@ -383,13 +392,4 @@ void RayCast3D::_clear_debug_shape() {
}
RayCast3D::RayCast3D() {
- enabled = true;
- collided = false;
- against_shape = 0;
- collision_mask = 1;
- target_position = Vector3(0, -1, 0);
- debug_shape = nullptr;
- exclude_parent_body = true;
- collide_with_areas = false;
- collide_with_bodies = true;
}