Commit: 0d45e091babb722659cd0d262f0f67e5ae3d5d95
Author: Kévin Dietrich
Date:   Mon Jun 20 16:35:55 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB0d45e091babb722659cd0d262f0f67e5ae3d5d95

Add support to stream vertex colors for dynamic meshes.

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

M       source/blender/alembic/intern/abc_customdata.cc
M       source/blender/alembic/intern/abc_customdata.h
M       source/blender/alembic/intern/abc_mesh.cc
M       source/blender/alembic/intern/alembic_capi.cc

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

diff --git a/source/blender/alembic/intern/abc_customdata.cc 
b/source/blender/alembic/intern/abc_customdata.cc
index 8fdc173..c7b568b 100644
--- a/source/blender/alembic/intern/abc_customdata.cc
+++ b/source/blender/alembic/intern/abc_customdata.cc
@@ -225,7 +225,8 @@ using Alembic::AbcGeom::IC4fGeomParam;
 using Alembic::AbcGeom::IV2fGeomParam;
 
 static void read_mcols(const CDStreamConfig &config, void *data,
-                       const C3fArraySamplePtr &c3f_ptr, const 
C4fArraySamplePtr &c4f_ptr)
+                       const C3fArraySamplePtr &c3f_ptr, const 
C4fArraySamplePtr &c4f_ptr,
+                       const Alembic::Abc::ISampleSelector &iss)
 {
        MCol *cfaces = static_cast<MCol *>(data);
        MPoly *polys = config.mpoly;
@@ -269,7 +270,8 @@ static void read_mcols(const CDStreamConfig &config, void 
*data,
 
 static void read_uvs(const CDStreamConfig &config, void *data,
                      const Alembic::AbcGeom::V2fArraySamplePtr &uvs,
-                     const Alembic::AbcGeom::UInt32ArraySamplePtr &indices)
+                     const Alembic::AbcGeom::UInt32ArraySamplePtr &indices,
+                     const Alembic::Abc::ISampleSelector &iss)
 {
        MPoly *mpolys = config.mpoly;
        MLoopUV *mloopuvs = static_cast<MLoopUV *>(data);
@@ -291,10 +293,12 @@ static void read_uvs(const CDStreamConfig &config, void 
*data,
        }
 }
 
-static void read_custom_data_ex(const ICompoundProperty &prop, const 
PropertyHeader &prop_header, const CDStreamConfig &config, CustomData *data, 
int data_type)
+static void read_custom_data_ex(const ICompoundProperty &prop,
+                                const PropertyHeader &prop_header,
+                                const CDStreamConfig &config,
+                                const Alembic::Abc::ISampleSelector &iss,
+                                int data_type)
 {
-       Alembic::Abc::ISampleSelector iss = Alembic::Abc::ISampleSelector(0.0f);
-
        void *cd_data = config.add_customdata_cb(config.user_data,
                                                 prop_header.getName().c_str(),
                                                 data_type);
@@ -318,18 +322,18 @@ static void read_custom_data_ex(const ICompoundProperty 
&prop, const PropertyHea
                        c4f_ptr = sample.getVals();
                }
 
-               read_mcols(config, cd_data, c3f_ptr, c4f_ptr);
+               read_mcols(config, cd_data, c3f_ptr, c4f_ptr, iss);
        }
        else if (data_type == CD_MLOOPUV) {
                IV2fGeomParam uv_param(prop, prop_header.getName());
                IV2fGeomParam::Sample sample;
                uv_param.getIndexed(sample, iss);
 
-               read_uvs(config, cd_data, sample.getVals(), 
sample.getIndices());
+               read_uvs(config, cd_data, sample.getVals(), 
sample.getIndices(), iss);
        }
 }
 
-void read_custom_data(const ICompoundProperty &prop, const CDStreamConfig 
&config, CustomData *data)
+void read_custom_data(const ICompoundProperty &prop, const CDStreamConfig 
&config, const Alembic::Abc::ISampleSelector &iss)
 {
        if (!prop.valid()) {
                return;
@@ -349,7 +353,7 @@ void read_custom_data(const ICompoundProperty &prop, const 
CDStreamConfig &confi
                                continue;
                        }
 
-                       read_custom_data_ex(prop, prop_header, config, data, 
CD_MLOOPUV);
+                       read_custom_data_ex(prop, prop_header, config, iss, 
CD_MLOOPUV);
                        continue;
                }
 
@@ -359,7 +363,7 @@ void read_custom_data(const ICompoundProperty &prop, const 
CDStreamConfig &confi
                                continue;
                        }
 
-                       read_custom_data_ex(prop, prop_header, config, data, 
CD_MLOOPCOL);
+                       read_custom_data_ex(prop, prop_header, config, iss, 
CD_MLOOPCOL);
                        continue;
                }
 
@@ -369,7 +373,7 @@ void read_custom_data(const ICompoundProperty &prop, const 
CDStreamConfig &confi
                                continue;
                        }
 
-                       read_custom_data_ex(prop, prop_header, config, data, 
CD_MLOOPCOL);
+                       read_custom_data_ex(prop, prop_header, config, iss, 
CD_MLOOPCOL);
                        continue;
                }
        }
diff --git a/source/blender/alembic/intern/abc_customdata.h 
b/source/blender/alembic/intern/abc_customdata.h
index 49a01a8..b1e2293 100644
--- a/source/blender/alembic/intern/abc_customdata.h
+++ b/source/blender/alembic/intern/abc_customdata.h
@@ -79,4 +79,4 @@ void write_custom_data(const OCompoundProperty &prop,
 
 void read_custom_data(const ICompoundProperty &prop,
                       const CDStreamConfig &config,
-                      CustomData *data);
+                      const Alembic::Abc::ISampleSelector &iss);
diff --git a/source/blender/alembic/intern/abc_mesh.cc 
b/source/blender/alembic/intern/abc_mesh.cc
index b3e7fdd..6d337eb 100644
--- a/source/blender/alembic/intern/abc_mesh.cc
+++ b/source/blender/alembic/intern/abc_mesh.cc
@@ -953,7 +953,16 @@ void AbcMeshReader::readPolyDataSample(Mesh *mesh,
                uvs = uvsamp.getVals();
                uvs_indices = uvsamp.getIndices();
 
-               ED_mesh_uv_texture_add(mesh, 
Alembic::Abc::GetSourceName(uv.getMetaData()).c_str(), true);
+               std::string name = 
Alembic::Abc::GetSourceName(uv.getMetaData());
+
+               /* According to the convention, primary UVs should have had 
their name
+                * set using Alembic::Abc::SetSourceName, but you can't expect 
everyone
+                * to follow it! :) */
+               if (name.empty()) {
+                       name = uv.getName();
+               }
+
+               ED_mesh_uv_texture_add(mesh, name.c_str(), true);
        }
 
        read_mpolys(mesh->mpoly, mesh->mloop, mesh->mloopuv, &mesh->ldata,
@@ -970,7 +979,7 @@ void AbcMeshReader::readPolyDataSample(Mesh *mesh,
        config.user_data = mesh;
        config.add_customdata_cb = add_customdata_cb;
 
-       read_custom_data(arb_geom_params, config, &mesh->ldata);
+       read_custom_data(arb_geom_params, config, ISampleSelector(0.0f));
 }
 
 void AbcMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, size_t 
poly_start,
diff --git a/source/blender/alembic/intern/alembic_capi.cc 
b/source/blender/alembic/intern/alembic_capi.cc
index 40359c3..4a85e24 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -702,6 +702,28 @@ void ABC_get_transform(Object *ob, const char *filepath, 
const char *object_path
 
 /* ***************************************** */
 
+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);
+               }
+       }
+
+       return cd_ptr;
+}
+
 static DerivedMesh *read_mesh_sample(DerivedMesh *dm, const IObject &iobject, 
const float time)
 {
        IPolyMesh mesh(iobject, kWrapExisting);
@@ -713,8 +735,10 @@ static DerivedMesh *read_mesh_sample(DerivedMesh *dm, 
const IObject &iobject, co
        const Alembic::Abc::Int32ArraySamplePtr &face_indices = 
sample.getFaceIndices();
        const Alembic::Abc::Int32ArraySamplePtr &face_counts = 
sample.getFaceCounts();
 
+       bool new_dm = false;
        if (dm->getNumVerts(dm) != positions->size()) {
                dm = CDDM_new(positions->size(), 0, 0, face_indices->size(), 
face_counts->size());
+               new_dm = true;
        }
 
        const IV2fGeomParam uv = schema.getUVsParam();
@@ -722,7 +746,8 @@ static DerivedMesh *read_mesh_sample(DerivedMesh *dm, const 
IObject &iobject, co
        Alembic::Abc::UInt32ArraySamplePtr uvs_indices;
 
        if (uv.valid()) {
-               IV2fGeomParam::Sample uvsamp = uv.getExpandedValue(sample_sel);
+               IV2fGeomParam::Sample uvsamp;
+               uv.getIndexed(uvsamp, sample_sel);
                uvs = uvsamp.getVals();
                uvs_indices = uvsamp.getIndices();
        }
@@ -747,12 +772,45 @@ static DerivedMesh *read_mesh_sample(DerivedMesh *dm, 
const IObject &iobject, co
        MPoly *mpolys = dm->getPolyArray(dm);
        MLoop *mloops = dm->getLoopArray(dm);
        MLoopUV *mloopuvs = static_cast<MLoopUV 
*>(CustomData_get(&dm->loopData, 0, CD_MLOOPUV));
-       CustomData *pdata = dm->getLoopDataLayout(dm);
+
+       if (!mloopuvs && uvs) {
+               std::string name = 
Alembic::Abc::GetSourceName(uv.getMetaData());
+
+               /* According to the convention, primary UVs should have had 
their name
+                * set using Alembic::Abc::SetSourceName, but you can't expect 
everyone
+                * to follow it! :) */
+               if (name.empty()) {
+                       name = uv.getName();
+               }
+
+               void *ptr = 
CustomData_add_layer_named(dm->getLoopDataLayout(dm),
+                                                      CD_MLOOPUV,
+                                                      CD_DEFAULT,
+                                                      NULL,
+                                                      dm->getNumLoops(dm),
+                                                      name.c_str());
+
+               mloopuvs = static_cast<MLoopUV *>(ptr);
+       }
+
+       CustomData *ldata = dm->getLoopDataLayout(dm);
 
        read_mverts(mverts, positions, vertex_normals);
-       read_mpolys(mpolys, mloops, mloopuvs, pdata, face_indices, face_counts, 
uvs, uvs_indices, poly_normals);
+       read_mpolys(mpolys, mloops, mloopuvs, ldata, face_indices, face_counts, 
uvs, uvs_indices, poly_normals);
+
+       CDStreamConfig config;
+       config.user_data = dm;
+       config.mloop = dm->getLoopArray(dm);
+       config.mpoly = dm->getPolyArray(dm);
+       config.totloop = dm->getNumLoops(dm);
+       config.totpoly = dm->getNumPolys(dm);
+       config.add_customdata_cb = add_customdata_cb;
 
-       CDDM_calc_edges(dm);
+       read_custom_data(schema.getArbGeomParams(), config, sample_sel);
+
+       if (new_dm) {
+               CDDM_calc_edges(dm);
+       }
 
        if (!normals.valid()) {
                dm->dirty = 
static_cast<DMDirtyFlag>(static_cast<int>(dm->dirty) | 
static_cast<int>(DM_DIRTY_NORMALS));

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to