Fix T50227: Alembic uv export/load issue
authorSybren A. Stüvel <sybren@stuvel.eu>
Wed, 12 Apr 2017 14:33:40 +0000 (16:33 +0200)
committerSybren A. Stüvel <sybren@stuvel.eu>
Wed, 12 Apr 2017 14:33:47 +0000 (16:33 +0200)
Previously only a CD_MLOOPUV custom data layer was created. Now we also
create the accompanying CD_MTEXPOLY layer too.

source/blender/alembic/intern/abc_mesh.cc

index 5a57e43326a5d40abb4a5ceb0210d9bad4acb69e..79b891dbcd4ed7a4c2a7e8c72d55b8a9108dd382 100644 (file)
@@ -897,19 +897,31 @@ static void *add_customdata_cb(void *user_data, const char *name, int data_type)
 {
        DerivedMesh *dm = static_cast<DerivedMesh *>(user_data);
        CustomDataType cd_data_type = static_cast<CustomDataType>(data_type);
-       void *cd_ptr = NULL;
-
-       if (ELEM(cd_data_type, CD_MLOOPUV, CD_MLOOPCOL)) {
-               cd_ptr = CustomData_get_layer_named(dm->getLoopDataLayout(dm), cd_data_type, name);
-
-               if (cd_ptr == NULL) {
-                       cd_ptr = CustomData_add_layer_named(dm->getLoopDataLayout(dm),
-                                                           cd_data_type,
-                                                           CD_DEFAULT,
-                                                           NULL,
-                                                           dm->getNumLoops(dm),
-                                                           name);
-               }
+       void *cd_ptr;
+       CustomData *loopdata;
+       int numloops;
+
+       /* unsupported custom data type -- don't do anything. */
+       if (!ELEM(cd_data_type, CD_MLOOPUV, CD_MLOOPCOL)) {
+               return NULL;
+       }
+
+       loopdata = dm->getLoopDataLayout(dm);
+       cd_ptr = CustomData_get_layer_named(loopdata, cd_data_type, name);
+       if (cd_ptr != NULL) {
+               /* layer already exists, so just return it. */
+               return cd_ptr;
+       }
+
+       /* create a new layer, taking care to construct the hopefully-soon-to-be-removed
+        * CD_MTEXPOLY layer too, with the same name. */
+       numloops = dm->getNumLoops(dm);
+       cd_ptr = CustomData_add_layer_named(loopdata, cd_data_type, CD_DEFAULT,
+                                           NULL, numloops, name);
+       if (cd_data_type == CD_MLOOPUV) {
+               CustomData_add_layer_named(dm->getPolyDataLayout(dm),
+                                          CD_MTEXPOLY, CD_DEFAULT,
+                                          NULL, numloops, name);
        }
 
        return cd_ptr;