MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / get_nav_array_debug_mesh

Function get_nav_array_debug_mesh

exporters/scene_exporter.cpp:1405–1471  ·  view source on GitHub ↗

disabled in debug builds, so we have to copy-and-paste it here.

Source from the content-addressed store, hash-verified

1403
1404// disabled in debug builds, so we have to copy-and-paste it here.
1405Ref<ArrayMesh> get_nav_array_debug_mesh(const Ref<NavigationMesh> navmesh) {
1406 Ref<ArrayMesh> debug_mesh;
1407 debug_mesh.instantiate();
1408 Vector<Vector3> vertices = navmesh->get_vertices();
1409
1410 if (vertices.is_empty()) {
1411 return debug_mesh;
1412 }
1413
1414 int polygon_count = navmesh->get_polygon_count();
1415
1416 if (polygon_count < 1) {
1417 // no face, no play
1418 return debug_mesh;
1419 }
1420
1421 // build geometry face surface
1422 Vector<Vector3> face_vertex_array;
1423 face_vertex_array.resize(polygon_count * 3);
1424
1425 for (int i = 0; i < polygon_count; i++) {
1426 Vector<int> polygon = navmesh->get_polygon(i);
1427
1428 face_vertex_array.push_back(vertices[polygon[0]]);
1429 face_vertex_array.push_back(vertices[polygon[1]]);
1430 face_vertex_array.push_back(vertices[polygon[2]]);
1431 }
1432
1433 Array face_mesh_array;
1434 face_mesh_array.resize(Mesh::ARRAY_MAX);
1435 face_mesh_array[Mesh::ARRAY_VERTEX] = face_vertex_array;
1436
1437 // if enabled add vertex colors to colorize each face individually
1438 static constexpr bool enabled_geometry_face_random_color = false;
1439 static const Color debug_navigation_geometry_face_color = Color(0.5, 1.0, 1.0, 0.4);
1440 if (enabled_geometry_face_random_color) {
1441 Color polygon_color = debug_navigation_geometry_face_color;
1442
1443 Vector<Color> face_color_array;
1444 face_color_array.resize(polygon_count * 3);
1445
1446 for (int i = 0; i < polygon_count; i++) {
1447 polygon_color = debug_navigation_geometry_face_color * (Color(Math::randf(), Math::randf(), Math::randf()));
1448
1449 face_color_array.push_back(polygon_color);
1450 face_color_array.push_back(polygon_color);
1451 face_color_array.push_back(polygon_color);
1452 }
1453 face_mesh_array[Mesh::ARRAY_COLOR] = face_color_array;
1454 }
1455
1456 debug_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, face_mesh_array);
1457 Ref<StandardMaterial3D> face_material;
1458 face_material = Ref<StandardMaterial3D>(memnew(StandardMaterial3D));
1459 face_material->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
1460 face_material->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
1461 face_material->set_albedo(debug_navigation_geometry_face_color);
1462 face_material->set_cull_mode(StandardMaterial3D::CULL_DISABLED);

Callers 1

Calls 4

push_backMethod · 0.80
surface_set_materialMethod · 0.80
resizeMethod · 0.45

Tested by

no test coverage detected