[Bf-blender-cvs] [9ba26598c03] refactor-mesh-uv-map-generic: Delete an erroneously created UV attribute .

Martijn Versteegh noreply at git.blender.org
Thu Nov 10 00:08:45 CET 2022


Commit: 9ba26598c03a7f6302b67e0d74dbd181bb85fe07
Author: Martijn Versteegh
Date:   Thu Nov 10 00:04:49 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rB9ba26598c03a7f6302b67e0d74dbd181bb85fe07

Delete an erroneously created UV attribute .

When loading a mesh without UVs from a wavefront obj file which also contains
meshes with UVs, we ended up creating an uninitialized UV layer. Detect when
that happens and delete the invaliud layer. We could also check for UVs
before creating the layer, but as this is probably a rather rare occasion
and checking involves looping over the whole mesh we just detect it after the
fact and delete.

===================================================================

M	source/blender/io/wavefront_obj/importer/obj_import_mesh.cc

===================================================================

diff --git a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc
index 8f034eac62a..f27bbd296e4 100644
--- a/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc
+++ b/source/blender/io/wavefront_obj/importer/obj_import_mesh.cc
@@ -273,6 +273,7 @@ void MeshFromGeometry::create_uv_verts(Mesh *mesh)
       "UVMap", ATTR_DOMAIN_CORNER);
 
   int tot_loop_idx = 0;
+  bool added_uv = false;
 
   for (const PolyElem &curr_face : mesh_geometry_.face_elements_) {
     for (int idx = 0; idx < curr_face.corner_count_; ++idx) {
@@ -280,12 +281,27 @@ void MeshFromGeometry::create_uv_verts(Mesh *mesh)
       if (curr_corner.uv_vert_index >= 0 &&
           curr_corner.uv_vert_index < global_vertices_.uv_vertices.size()) {
         uv_map.span[tot_loop_idx] = global_vertices_.uv_vertices[curr_corner.uv_vert_index];
-        tot_loop_idx++;
+        added_uv = true;
       }
+      else {
+        uv_map.span[tot_loop_idx] = {0.f, 0.f};
+      }
+      tot_loop_idx++;
     }
   }
 
   uv_map.finish();
+
+  /* If we have an object without UVs which resides in the same .obj file
+   * as an object which *does* have UVs we can end up adding and UV layer
+   * filled with zeroes.
+   * We could maybe check before creating this layer but that would need
+   * iterating over the whole mesh to check for UVs and as this is probably
+   * the exception rather than the rule, just delete it afterwards.
+   */
+  if (!added_uv) {
+    attributes.remove("UVMap");
+  }
 }
 
 static Material *get_or_create_material(Main *bmain,



More information about the Bf-blender-cvs mailing list