2
0
Эх сурвалжийг харах

obj: Avoid empty names and meshes

This commit updates the obj importer to properly name imported meshes and
permits it to skip meshes that do not contain geometry. This fixes at
least one crash and several warnings and avoids unnecessary meshes being
generated when importing obj files that do not contain geometry that is
not assigned to a named object (such as when exporting from Blender).
rsjtdrjgfuzkfg 2 жил өмнө
parent
commit
0442a65656

+ 9 - 4
editor/import/resource_importer_obj.cpp

@@ -218,7 +218,8 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_
 	Vector<Vector3> normals;
 	Vector<Vector3> normals;
 	Vector<Vector2> uvs;
 	Vector<Vector2> uvs;
 	Vector<Color> colors;
 	Vector<Color> colors;
-	String name;
+	const String default_name = "Mesh";
+	String name = default_name;
 
 
 	HashMap<String, HashMap<String, Ref<StandardMaterial3D>>> material_map;
 	HashMap<String, HashMap<String, Ref<StandardMaterial3D>>> material_map;
 
 
@@ -395,9 +396,12 @@ static Error _parse_obj(const String &p_path, List<Ref<Mesh>> &r_meshes, bool p_
 
 
 			if (l.begins_with("o ") || f->eof_reached()) {
 			if (l.begins_with("o ") || f->eof_reached()) {
 				if (!p_single_mesh) {
 				if (!p_single_mesh) {
-					mesh->set_name(name);
-					r_meshes.push_back(mesh);
-					mesh.instantiate();
+					if (mesh->get_surface_count() > 0) {
+						mesh->set_name(name);
+						r_meshes.push_back(mesh);
+						mesh.instantiate();
+					}
+					name = default_name;
 					current_group = "";
 					current_group = "";
 					current_material = "";
 					current_material = "";
 				}
 				}
@@ -460,6 +464,7 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, co
 	for (const Ref<Mesh> &m : meshes) {
 	for (const Ref<Mesh> &m : meshes) {
 		Ref<ImporterMesh> mesh;
 		Ref<ImporterMesh> mesh;
 		mesh.instantiate();
 		mesh.instantiate();
+		mesh->set_name(m->get_name());
 		for (int i = 0; i < m->get_surface_count(); i++) {
 		for (int i = 0; i < m->get_surface_count(); i++) {
 			mesh->add_surface(m->surface_get_primitive_type(i), m->surface_get_arrays(i), Array(), Dictionary(), m->surface_get_material(i));
 			mesh->add_surface(m->surface_get_primitive_type(i), m->surface_get_arrays(i), Array(), Dictionary(), m->surface_get_material(i));
 		}
 		}