diff options
Diffstat (limited to 'scene/resources/importer_mesh.cpp')
| -rw-r--r-- | scene/resources/importer_mesh.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/scene/resources/importer_mesh.cpp b/scene/resources/importer_mesh.cpp index a65a75d878..f479ae1e1b 100644 --- a/scene/resources/importer_mesh.cpp +++ b/scene/resources/importer_mesh.cpp @@ -475,6 +475,14 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli if (new_index_count == 0 || (new_index_count >= (index_count * 0.75f))) { break; } + if (new_index_count > 5000000) { + // This limit theoretically shouldn't be needed, but it's here + // as an ad-hoc fix to prevent a crash with complex meshes. + // The crash still happens with limit of 6000000, but 5000000 works. + // In the future, identify what's causing that crash and fix it. + WARN_PRINT("Mesh LOD generation failed for mesh " + get_name() + " surface " + itos(i) + ", mesh is too complex. Some automatic LODs were not generated."); + break; + } new_indices.resize(new_index_count); @@ -1225,6 +1233,7 @@ Error ImporterMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform, for (int i = 0; i < lightmap_surfaces.size(); i++) { Ref<SurfaceTool> st; st.instantiate(); + st->set_skin_weight_count((lightmap_surfaces[i].format & Mesh::ARRAY_FLAG_USE_8_BONE_WEIGHTS) ? SurfaceTool::SKIN_8_WEIGHTS : SurfaceTool::SKIN_4_WEIGHTS); st->begin(Mesh::PRIMITIVE_TRIANGLES); st->set_material(lightmap_surfaces[i].material); st->set_meta("name", lightmap_surfaces[i].name); @@ -1292,7 +1301,15 @@ Error ImporterMesh::lightmap_unwrap_cached(const Transform3D &p_base_transform, Ref<SurfaceTool> &tool = surfaces_tools[i]; tool->index(); Array arrays = tool->commit_to_arrays(); - add_surface(tool->get_primitive_type(), arrays, Array(), Dictionary(), tool->get_material(), tool->get_meta("name"), lightmap_surfaces[i].format); + + uint64_t format = lightmap_surfaces[i].format; + if (tool->get_skin_weight_count() == SurfaceTool::SKIN_8_WEIGHTS) { + format |= RS::ARRAY_FLAG_USE_8_BONE_WEIGHTS; + } else { + format &= ~RS::ARRAY_FLAG_USE_8_BONE_WEIGHTS; + } + + add_surface(tool->get_primitive_type(), arrays, Array(), Dictionary(), tool->get_material(), tool->get_meta("name"), format); } set_lightmap_size_hint(Size2(size_x, size_y)); |
