From a30dd094d345fc7bf65bc10486b2797e19054d56 Mon Sep 17 00:00:00 2001 From: Pawel Lampe Date: Sun, 30 Jan 2022 11:30:17 +0100 Subject: Fix transforms involved into navmesh baking Within the context of parsing navigation geometry, this commit: - added missing transform of `MultiMeshInstance` - changed all transforms to global ones so that they don't need to be calculated by hand --- modules/navigation/navigation_mesh_generator.cpp | 23 +++++++++-------------- modules/navigation/navigation_mesh_generator.h | 2 +- 2 files changed, 10 insertions(+), 15 deletions(-) (limited to 'modules') diff --git a/modules/navigation/navigation_mesh_generator.cpp b/modules/navigation/navigation_mesh_generator.cpp index 77fe9cdd19..52d5379e8b 100644 --- a/modules/navigation/navigation_mesh_generator.cpp +++ b/modules/navigation/navigation_mesh_generator.cpp @@ -140,12 +140,12 @@ void NavigationMeshGenerator::_add_faces(const PackedVector3Array &p_faces, cons } } -void NavigationMeshGenerator::_parse_geometry(Transform3D p_accumulated_transform, Node *p_node, Vector &p_vertices, Vector &p_indices, NavigationMesh::ParsedGeometryType p_generate_from, uint32_t p_collision_mask, bool p_recurse_children) { +void NavigationMeshGenerator::_parse_geometry(const Transform3D &p_navmesh_transform, Node *p_node, Vector &p_vertices, Vector &p_indices, NavigationMesh::ParsedGeometryType p_generate_from, uint32_t p_collision_mask, bool p_recurse_children) { if (Object::cast_to(p_node) && p_generate_from != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) { MeshInstance3D *mesh_instance = Object::cast_to(p_node); Ref mesh = mesh_instance->get_mesh(); if (mesh.is_valid()) { - _add_mesh(mesh, p_accumulated_transform * mesh_instance->get_transform(), p_vertices, p_indices); + _add_mesh(mesh, p_navmesh_transform * mesh_instance->get_global_transform(), p_vertices, p_indices); } } @@ -159,7 +159,7 @@ void NavigationMeshGenerator::_parse_geometry(Transform3D p_accumulated_transfor n = multimesh->get_instance_count(); } for (int i = 0; i < n; i++) { - _add_mesh(mesh, p_accumulated_transform * multimesh->get_instance_transform(i), p_vertices, p_indices); + _add_mesh(mesh, p_navmesh_transform * multimesh_instance->get_global_transform() * multimesh->get_instance_transform(i), p_vertices, p_indices); } } } @@ -171,7 +171,7 @@ void NavigationMeshGenerator::_parse_geometry(Transform3D p_accumulated_transfor if (!meshes.is_empty()) { Ref mesh = meshes[1]; if (mesh.is_valid()) { - _add_mesh(mesh, p_accumulated_transform * csg_shape->get_transform(), p_vertices, p_indices); + _add_mesh(mesh, p_navmesh_transform * csg_shape->get_global_transform(), p_vertices, p_indices); } } } @@ -186,7 +186,7 @@ void NavigationMeshGenerator::_parse_geometry(Transform3D p_accumulated_transfor if (Object::cast_to(child)) { CollisionShape3D *col_shape = Object::cast_to(child); - Transform3D transform = p_accumulated_transform * static_body->get_transform() * col_shape->get_transform(); + Transform3D transform = p_navmesh_transform * static_body->get_global_transform() * col_shape->get_transform(); Ref mesh; Ref s = col_shape->get_shape(); @@ -270,11 +270,11 @@ void NavigationMeshGenerator::_parse_geometry(Transform3D p_accumulated_transfor if (gridmap) { if (p_generate_from != NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS) { Array meshes = gridmap->get_meshes(); - Transform3D xform = gridmap->get_transform(); + Transform3D xform = gridmap->get_global_transform(); for (int i = 0; i < meshes.size(); i += 2) { Ref mesh = meshes[i + 1]; if (mesh.is_valid()) { - _add_mesh(mesh, p_accumulated_transform * xform * (Transform3D)meshes[i], p_vertices, p_indices); + _add_mesh(mesh, p_navmesh_transform * xform * (Transform3D)meshes[i], p_vertices, p_indices); } } } @@ -364,14 +364,9 @@ void NavigationMeshGenerator::_parse_geometry(Transform3D p_accumulated_transfor } #endif - if (Object::cast_to(p_node)) { - Node3D *spatial = Object::cast_to(p_node); - p_accumulated_transform = p_accumulated_transform * spatial->get_transform(); - } - if (p_recurse_children) { for (int i = 0; i < p_node->get_child_count(); i++) { - _parse_geometry(p_accumulated_transform, p_node->get_child(i), p_vertices, p_indices, p_generate_from, p_collision_mask, p_recurse_children); + _parse_geometry(p_navmesh_transform, p_node->get_child(i), p_vertices, p_indices, p_generate_from, p_collision_mask, p_recurse_children); } } } @@ -616,7 +611,7 @@ void NavigationMeshGenerator::bake(Ref p_nav_mesh, Node *p_node) p_node->get_tree()->get_nodes_in_group(p_nav_mesh->get_source_group_name(), &parse_nodes); } - Transform3D navmesh_xform = Object::cast_to(p_node)->get_transform().affine_inverse(); + Transform3D navmesh_xform = Object::cast_to(p_node)->get_global_transform().affine_inverse(); for (Node *E : parse_nodes) { NavigationMesh::ParsedGeometryType geometry_type = p_nav_mesh->get_parsed_geometry_type(); uint32_t collision_mask = p_nav_mesh->get_collision_mask(); diff --git a/modules/navigation/navigation_mesh_generator.h b/modules/navigation/navigation_mesh_generator.h index 1ffdd39aee..21f7a4941b 100644 --- a/modules/navigation/navigation_mesh_generator.h +++ b/modules/navigation/navigation_mesh_generator.h @@ -52,7 +52,7 @@ protected: static void _add_vertex(const Vector3 &p_vec3, Vector &p_vertices); static void _add_mesh(const Ref &p_mesh, const Transform3D &p_xform, Vector &p_vertices, Vector &p_indices); static void _add_faces(const PackedVector3Array &p_faces, const Transform3D &p_xform, Vector &p_vertices, Vector &p_indices); - static void _parse_geometry(Transform3D p_accumulated_transform, Node *p_node, Vector &p_vertices, Vector &p_indices, NavigationMesh::ParsedGeometryType p_generate_from, uint32_t p_collision_mask, bool p_recurse_children); + static void _parse_geometry(const Transform3D &p_navmesh_transform, Node *p_node, Vector &p_vertices, Vector &p_indices, NavigationMesh::ParsedGeometryType p_generate_from, uint32_t p_collision_mask, bool p_recurse_children); static void _convert_detail_mesh_to_native_navigation_mesh(const rcPolyMeshDetail *p_detail_mesh, Ref p_nav_mesh); static void _build_recast_navigation_mesh( -- cgit v1.2.3