Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartijn Versteegh <blender@aaltjegron.nl>2022-11-10 02:04:49 +0300
committerMartijn Versteegh <blender@aaltjegron.nl>2022-11-10 02:04:49 +0300
commit9ba26598c03a7f6302b67e0d74dbd181bb85fe07 (patch)
treecd3b97dce348a2f9daeab8edfe4c5cd59c5edbc4
parent4706b4fe2d884f9886597332baed1278595f1d68 (diff)
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.
-rw-r--r--source/blender/io/wavefront_obj/importer/obj_import_mesh.cc18
1 files changed, 17 insertions, 1 deletions
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,