mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-24 04:46:48 +01:00
Ported from godot4: Remove / Replace old Navigation Debug Visualization
- removes / replaces leftovers from old navigation debug code
- cleanes SceneTree and ProjectSettings from old navigation debug
- smix8
d7f75fab60
This commit is contained in:
parent
b6de23ac8a
commit
25078b1437
@ -529,9 +529,6 @@
|
||||
<member name="debug/shapes/collision/shape_color" type="Color" setter="" getter="" default="Color( 0, 0.6, 0.7, 0.42 )">
|
||||
Color of the collision shapes, visible when "Visible Collision Shapes" is enabled in the Debug menu.
|
||||
</member>
|
||||
<member name="debug/shapes/navigation/disabled_geometry_color" type="Color" setter="" getter="" default="Color( 1, 0.7, 0.1, 0.4 )">
|
||||
Color of the disabled navigation geometry, visible when "Visible Navigation" is enabled in the Debug menu.
|
||||
</member>
|
||||
<member name="debug/shapes/navigation/edge_connection_color" type="Color" setter="" getter="" default="Color(1, 0, 1, 1)">
|
||||
Color to display edge connections between navigation regions, visible when "Visible Navigation" is enabled in the Debug menu.
|
||||
</member>
|
||||
@ -550,9 +547,6 @@
|
||||
<member name="debug/shapes/navigation/enable_geometry_face_random_color" type="bool" setter="" getter="" default="true">
|
||||
If enabled, colorizes each navigation mesh polygon face with a random color when "Visible Navigation" is enabled in the Debug menu.
|
||||
</member>
|
||||
<member name="debug/shapes/navigation/geometry_color" type="Color" setter="" getter="" default="Color( 0.1, 1, 0.7, 0.4 )">
|
||||
Color of the navigation geometry, visible when "Visible Navigation" is enabled in the Debug menu.
|
||||
</member>
|
||||
<member name="debug/shapes/navigation/geometry_edge_color" type="Color" setter="" getter="" default="Color(0.5, 1, 1, 1)">
|
||||
Color to display enabled navigation mesh polygon edges, visible when "Visible Navigation" is enabled in the Debug menu.
|
||||
</member>
|
||||
|
@ -5665,8 +5665,6 @@ void EditorNode::_project_settings_changed() {
|
||||
SceneTree *tree = get_tree();
|
||||
tree->set_debug_collisions_color(GLOBAL_GET("debug/shapes/collision/shape_color"));
|
||||
tree->set_debug_collision_contact_color(GLOBAL_GET("debug/shapes/collision/contact_color"));
|
||||
tree->set_debug_navigation_color(GLOBAL_GET("debug/shapes/navigation/geometry_color"));
|
||||
tree->set_debug_navigation_disabled_color(GLOBAL_GET("debug/shapes/navigation/disabled_geometry_color"));
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
NavigationServer::get_singleton_mut()->set_debug_navigation_edge_connection_color(GLOBAL_GET("debug/shapes/navigation/edge_connection_color"));
|
||||
|
@ -32,8 +32,8 @@
|
||||
|
||||
#include "core/io/marshalls.h"
|
||||
#include "core/object/message_queue.h"
|
||||
#include "scene/3d/light.h"
|
||||
#include "mesh_library.h"
|
||||
#include "scene/3d/light.h"
|
||||
#include "scene/resources/physics_material.h"
|
||||
#include "scene/resources/primitive_meshes.h"
|
||||
#include "scene/resources/surface_tool.h"
|
||||
@ -41,8 +41,8 @@
|
||||
#include "servers/navigation_server.h"
|
||||
#include "servers/rendering_server.h"
|
||||
|
||||
#include "scene/resources/world_3d.h"
|
||||
#include "scene/resources/navigation_mesh.h"
|
||||
#include "scene/resources/world_3d.h"
|
||||
|
||||
bool GridMap::_set(const StringName &p_name, const Variant &p_value) {
|
||||
String name = p_name;
|
||||
@ -576,6 +576,7 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
|
||||
}
|
||||
nm.region = region;
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
// add navigation debugmesh visual instances if debug is enabled
|
||||
SceneTree *st = SceneTree::get_singleton();
|
||||
if (st && st->is_debugging_navigation_hint()) {
|
||||
@ -583,13 +584,13 @@ bool GridMap::_octant_update(const OctantKey &p_key) {
|
||||
RID navmesh_debug_rid = navmesh->get_debug_mesh()->get_rid();
|
||||
nm.navmesh_debug_instance = RS::get_singleton()->instance_create();
|
||||
RS::get_singleton()->instance_set_base(nm.navmesh_debug_instance, navmesh_debug_rid);
|
||||
RS::get_singleton()->mesh_surface_set_material(navmesh_debug_rid, 0, st->get_debug_navigation_material()->get_rid());
|
||||
}
|
||||
if (is_inside_tree()) {
|
||||
RS::get_singleton()->instance_set_scenario(nm.navmesh_debug_instance, get_world_3d()->get_scenario());
|
||||
RS::get_singleton()->instance_set_transform(nm.navmesh_debug_instance, get_global_transform() * nm.xform);
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
}
|
||||
g.navmesh_ids[E->get()] = nm;
|
||||
}
|
||||
|
@ -40,6 +40,10 @@
|
||||
#include "servers/physics_2d_server.h"
|
||||
#include "servers/rendering/rendering_server_canvas_helper.h"
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
#include "servers/navigation_server.h"
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
void TileMap::Quadrant::clear_navpoly() {
|
||||
for (RBMap<PosKey, Quadrant::NavPoly>::Element *E = navpoly_ids.front(); E; E = E->next()) {
|
||||
RID region = E->get().region;
|
||||
@ -370,7 +374,7 @@ void TileMap::update_dirty_quadrants() {
|
||||
|
||||
SceneTree *st = SceneTree::get_singleton();
|
||||
Color debug_collision_color;
|
||||
Color debug_navigation_color;
|
||||
Color debug_navigation_color = Color(0.5, 1.0, 1.0, 1.0);
|
||||
|
||||
bool debug_shapes = false;
|
||||
if (st) {
|
||||
@ -387,7 +391,9 @@ void TileMap::update_dirty_quadrants() {
|
||||
|
||||
bool debug_navigation = st && st->is_debugging_navigation_hint();
|
||||
if (debug_navigation) {
|
||||
debug_navigation_color = st->get_debug_navigation_color();
|
||||
#ifdef DEBUG_ENABLED
|
||||
debug_navigation_color = NavigationServer::get_singleton()->get_debug_navigation_geometry_face_color();
|
||||
#endif // DEBUG_ENABLED
|
||||
}
|
||||
|
||||
while (dirty_quadrant_list.first()) {
|
||||
|
@ -560,6 +560,7 @@ void NavigationMeshInstance::_update_debug_edge_connections_mesh() {
|
||||
}
|
||||
|
||||
Vector<Vector3> vertex_array;
|
||||
//vertex_array.resize(connections_count * 6);
|
||||
|
||||
for (int i = 0; i < connections_count; i++) {
|
||||
Vector3 connection_pathway_start = NavigationServer::get_singleton()->region_get_connection_pathway_start(region, i);
|
||||
|
@ -947,55 +947,6 @@ Color SceneTree::get_debug_collision_contact_color() const {
|
||||
return debug_collision_contact_color;
|
||||
}
|
||||
|
||||
void SceneTree::set_debug_navigation_color(const Color &p_color) {
|
||||
debug_navigation_color = p_color;
|
||||
}
|
||||
|
||||
Color SceneTree::get_debug_navigation_color() const {
|
||||
return debug_navigation_color;
|
||||
}
|
||||
|
||||
void SceneTree::set_debug_navigation_disabled_color(const Color &p_color) {
|
||||
debug_navigation_disabled_color = p_color;
|
||||
}
|
||||
|
||||
Color SceneTree::get_debug_navigation_disabled_color() const {
|
||||
return debug_navigation_disabled_color;
|
||||
}
|
||||
|
||||
Ref<Material> SceneTree::get_debug_navigation_material() {
|
||||
if (navigation_material.is_valid()) {
|
||||
return navigation_material;
|
||||
}
|
||||
|
||||
Ref<SpatialMaterial> line_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
|
||||
line_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
|
||||
line_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
|
||||
line_material->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
|
||||
line_material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
|
||||
line_material->set_albedo(get_debug_navigation_color());
|
||||
|
||||
navigation_material = line_material;
|
||||
|
||||
return navigation_material;
|
||||
}
|
||||
|
||||
Ref<Material> SceneTree::get_debug_navigation_disabled_material() {
|
||||
if (navigation_disabled_material.is_valid()) {
|
||||
return navigation_disabled_material;
|
||||
}
|
||||
|
||||
Ref<SpatialMaterial> line_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
|
||||
line_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
|
||||
line_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
|
||||
line_material->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
|
||||
line_material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
|
||||
line_material->set_albedo(get_debug_navigation_disabled_color());
|
||||
|
||||
navigation_disabled_material = line_material;
|
||||
|
||||
return navigation_disabled_material;
|
||||
}
|
||||
Ref<Material> SceneTree::get_debug_collision_material() {
|
||||
if (collision_material.is_valid()) {
|
||||
return collision_material;
|
||||
@ -2284,8 +2235,6 @@ SceneTree::SceneTree() {
|
||||
#endif
|
||||
debug_collisions_color = GLOBAL_DEF("debug/shapes/collision/shape_color", Color(0.0, 0.6, 0.7, 0.42));
|
||||
debug_collision_contact_color = GLOBAL_DEF("debug/shapes/collision/contact_color", Color(1.0, 0.2, 0.1, 0.8));
|
||||
debug_navigation_color = GLOBAL_DEF("debug/shapes/navigation/geometry_color", Color(0.1, 1.0, 0.7, 0.4));
|
||||
debug_navigation_disabled_color = GLOBAL_DEF("debug/shapes/navigation/disabled_geometry_color", Color(1.0, 0.7, 0.1, 0.4));
|
||||
collision_debug_contacts = GLOBAL_DEF("debug/shapes/collision/max_contacts_displayed", 10000);
|
||||
ProjectSettings::get_singleton()->set_custom_property_info("debug/shapes/collision/max_contacts_displayed", PropertyInfo(Variant::INT, "debug/shapes/collision/max_contacts_displayed", PROPERTY_HINT_RANGE, "0,20000,1")); // No negative
|
||||
|
||||
|
@ -369,14 +369,6 @@ public:
|
||||
void set_debug_collision_contact_color(const Color &p_color);
|
||||
Color get_debug_collision_contact_color() const;
|
||||
|
||||
void set_debug_navigation_color(const Color &p_color);
|
||||
Color get_debug_navigation_color() const;
|
||||
|
||||
void set_debug_navigation_disabled_color(const Color &p_color);
|
||||
Color get_debug_navigation_disabled_color() const;
|
||||
|
||||
Ref<Material> get_debug_navigation_material();
|
||||
Ref<Material> get_debug_navigation_disabled_material();
|
||||
Ref<Material> get_debug_collision_material();
|
||||
Ref<ArrayMesh> get_debug_contact_mesh();
|
||||
|
||||
|
@ -336,94 +336,8 @@ void NavigationMesh::clear_polygons() {
|
||||
polygons.clear();
|
||||
}
|
||||
|
||||
Ref<Mesh> NavigationMesh::get_debug_mesh() {
|
||||
if (debug_mesh.is_valid()) {
|
||||
return debug_mesh;
|
||||
}
|
||||
|
||||
PoolVector<Vector3> vertices = get_vertices();
|
||||
PoolVector<Vector3>::Read vr = vertices.read();
|
||||
List<Face3> faces;
|
||||
for (int i = 0; i < get_polygon_count(); i++) {
|
||||
Vector<int> p = get_polygon(i);
|
||||
|
||||
for (int j = 2; j < p.size(); j++) {
|
||||
Face3 f;
|
||||
f.vertex[0] = vr[p[0]];
|
||||
f.vertex[1] = vr[p[j - 1]];
|
||||
f.vertex[2] = vr[p[j]];
|
||||
|
||||
faces.push_back(f);
|
||||
}
|
||||
}
|
||||
|
||||
RBMap<_EdgeKey, bool> edge_map;
|
||||
PoolVector<Vector3> tmeshfaces;
|
||||
tmeshfaces.resize(faces.size() * 3);
|
||||
|
||||
{
|
||||
PoolVector<Vector3>::Write tw = tmeshfaces.write();
|
||||
int tidx = 0;
|
||||
|
||||
for (List<Face3>::Element *E = faces.front(); E; E = E->next()) {
|
||||
const Face3 &f = E->get();
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
tw[tidx++] = f.vertex[j];
|
||||
_EdgeKey ek;
|
||||
ek.from = f.vertex[j].snapped(Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON));
|
||||
ek.to = f.vertex[(j + 1) % 3].snapped(Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON));
|
||||
if (ek.from < ek.to) {
|
||||
SWAP(ek.from, ek.to);
|
||||
}
|
||||
|
||||
RBMap<_EdgeKey, bool>::Element *F = edge_map.find(ek);
|
||||
|
||||
if (F) {
|
||||
F->get() = false;
|
||||
|
||||
} else {
|
||||
edge_map[ek] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
List<Vector3> lines;
|
||||
|
||||
for (RBMap<_EdgeKey, bool>::Element *E = edge_map.front(); E; E = E->next()) {
|
||||
if (E->get()) {
|
||||
lines.push_back(E->key().from);
|
||||
lines.push_back(E->key().to);
|
||||
}
|
||||
}
|
||||
|
||||
PoolVector<Vector3> varr;
|
||||
varr.resize(lines.size());
|
||||
{
|
||||
PoolVector<Vector3>::Write w = varr.write();
|
||||
int idx = 0;
|
||||
for (List<Vector3>::Element *E = lines.front(); E; E = E->next()) {
|
||||
w[idx++] = E->get();
|
||||
}
|
||||
}
|
||||
|
||||
debug_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
|
||||
|
||||
if (lines.empty()) {
|
||||
return debug_mesh;
|
||||
}
|
||||
|
||||
Array arr;
|
||||
arr.resize(Mesh::ARRAY_MAX);
|
||||
arr[Mesh::ARRAY_VERTEX] = varr;
|
||||
|
||||
debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, arr);
|
||||
|
||||
return debug_mesh;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
Ref<ArrayMesh> NavigationMesh::_get_debug_mesh() {
|
||||
Ref<ArrayMesh> NavigationMesh::get_debug_mesh() {
|
||||
if (debug_mesh.is_valid()) {
|
||||
// Blocks further updates for now, code below is intended for dynamic updates e.g. when settings change.
|
||||
return debug_mesh;
|
||||
|
@ -47,13 +47,6 @@ class NavigationMesh : public Resource {
|
||||
Vector<Polygon> polygons;
|
||||
Ref<ArrayMesh> debug_mesh;
|
||||
|
||||
struct _EdgeKey {
|
||||
Vector3 from;
|
||||
Vector3 to;
|
||||
|
||||
bool operator<(const _EdgeKey &p_with) const { return from == p_with.from ? to < p_with.to : from < p_with.from; }
|
||||
};
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
virtual void _validate_property(PropertyInfo &property) const;
|
||||
@ -195,10 +188,8 @@ public:
|
||||
Vector<int> get_polygon(int p_idx);
|
||||
void clear_polygons();
|
||||
|
||||
Ref<Mesh> get_debug_mesh();
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
Ref<ArrayMesh> _get_debug_mesh();
|
||||
Ref<ArrayMesh> get_debug_mesh();
|
||||
#endif
|
||||
|
||||
NavigationMesh();
|
||||
|
Loading…
Reference in New Issue
Block a user