[Bf-blender-cvs] [db94d030bca] blender-v3.4-release: Fix T102502: Collada import sets incorrect material indices

Hans Goudey noreply at git.blender.org
Tue Nov 15 00:53:16 CET 2022


Commit: db94d030bca977ad2004101ce502510de5414242
Author: Hans Goudey
Date:   Mon Nov 14 17:52:50 2022 -0600
Branches: blender-v3.4-release
https://developer.blender.org/rBdb94d030bca977ad2004101ce502510de5414242

Fix T102502: Collada import sets incorrect material indices

The weird code dealing with `MeshPrimitive` didn't increment the
material indices pointer for geometry types besides triangle fans.
Also use a proper accessor to avoid adding a duplicate material
indices attribute, just in case this code is used on existing meshes.

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

M	source/blender/io/collada/MeshImporter.cpp

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

diff --git a/source/blender/io/collada/MeshImporter.cpp b/source/blender/io/collada/MeshImporter.cpp
index 6d7593afb8b..006d320e854 100644
--- a/source/blender/io/collada/MeshImporter.cpp
+++ b/source/blender/io/collada/MeshImporter.cpp
@@ -621,8 +621,7 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
 
   MaterialIdPrimitiveArrayMap mat_prim_map;
 
-  int *material_indices = (int *)CustomData_add_layer_named(
-      &me->pdata, CD_PROP_INT32, CD_SET_DEFAULT, nullptr, me->totpoly, "material_index");
+  int *material_indices = BKE_mesh_material_indices_for_write(me);
 
   COLLADAFW::MeshPrimitiveArray &prim_arr = collada_mesh->getMeshPrimitives();
   COLLADAFW::MeshVertexData &nor = collada_mesh->getNormals();
@@ -775,6 +774,9 @@ void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh,
         }
 
         mpoly++;
+        if (material_indices) {
+          material_indices++;
+        }
         mloop += vcount;
         loop_index += vcount;
         start_index += vcount;



More information about the Bf-blender-cvs mailing list