1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-10 13:00:37 +00:00

import: Fix uv2 by avoiding premature ImporterMesh::get_mesh()

Implements create_convex_shape in ImpoterMesh.
Note: ImporterMeshInstance3D::get_mesh() is safe.
The only dangerous function with side effects is ImpoterMesh::get_mesh()
This commit is contained in:
Lyuma
2023-02-23 11:07:48 +01:00
parent 19c9fd6926
commit 51a4fe1d53
5 changed files with 82 additions and 6 deletions

View File

@@ -444,9 +444,45 @@ void SceneImportSettings::_update_view_gizmos() {
collider_view->set_visible(show_collider_view);
if (generate_collider) {
// This collider_view doesn't have a mesh so we need to generate a new one.
Ref<ImporterMesh> mesh;
mesh.instantiate();
// ResourceImporterScene::get_collision_shapes() expects ImporterMesh, not Mesh.
// TODO: Duplicate code with EditorSceneFormatImporterESCN::import_scene()
// Consider making a utility function to convert from Mesh to ImporterMesh.
Ref<Mesh> mesh_3d_mesh = mesh_node->get_mesh();
Ref<ArrayMesh> array_mesh_3d_mesh = mesh_3d_mesh;
if (array_mesh_3d_mesh.is_valid()) {
// For the MeshInstance3D nodes, we need to convert the ArrayMesh to an ImporterMesh specially.
mesh->set_name(array_mesh_3d_mesh->get_name());
for (int32_t blend_i = 0; blend_i < array_mesh_3d_mesh->get_blend_shape_count(); blend_i++) {
mesh->add_blend_shape(array_mesh_3d_mesh->get_blend_shape_name(blend_i));
}
for (int32_t surface_i = 0; surface_i < array_mesh_3d_mesh->get_surface_count(); surface_i++) {
mesh->add_surface(array_mesh_3d_mesh->surface_get_primitive_type(surface_i),
array_mesh_3d_mesh->surface_get_arrays(surface_i),
array_mesh_3d_mesh->surface_get_blend_shape_arrays(surface_i),
array_mesh_3d_mesh->surface_get_lods(surface_i),
array_mesh_3d_mesh->surface_get_material(surface_i),
array_mesh_3d_mesh->surface_get_name(surface_i),
array_mesh_3d_mesh->surface_get_format(surface_i));
}
mesh->set_blend_shape_mode(array_mesh_3d_mesh->get_blend_shape_mode());
} else if (mesh_3d_mesh.is_valid()) {
// For the MeshInstance3D nodes, we need to convert the Mesh to an ImporterMesh specially.
mesh->set_name(mesh_3d_mesh->get_name());
for (int32_t surface_i = 0; surface_i < mesh_3d_mesh->get_surface_count(); surface_i++) {
mesh->add_surface(mesh_3d_mesh->surface_get_primitive_type(surface_i),
mesh_3d_mesh->surface_get_arrays(surface_i),
Array(),
mesh_3d_mesh->surface_get_lods(surface_i),
mesh_3d_mesh->surface_get_material(surface_i),
mesh_3d_mesh->surface_get_material(surface_i).is_valid() ? mesh_3d_mesh->surface_get_material(surface_i)->get_name() : String(),
mesh_3d_mesh->surface_get_format(surface_i));
}
}
// Generate the mesh collider.
Vector<Ref<Shape3D>> shapes = ResourceImporterScene::get_collision_shapes(mesh_node->get_mesh(), e.value.settings, 1.0);
Vector<Ref<Shape3D>> shapes = ResourceImporterScene::get_collision_shapes(mesh, e.value.settings, 1.0);
const Transform3D transform = ResourceImporterScene::get_collision_shapes_transform(e.value.settings);
Ref<ArrayMesh> collider_view_mesh;