[Bf-blender-cvs] [12c34a9] alembic_basic_io: Add support to read loop/poly normals.
Kévin Dietrich
noreply at git.blender.org
Fri Jun 17 18:09:49 CEST 2016
Commit: 12c34a9fea2b27d5bc33db19194ba6e183b7cd97
Author: Kévin Dietrich
Date: Fri Jun 17 11:43:58 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB12c34a9fea2b27d5bc33db19194ba6e183b7cd97
Add support to read loop/poly normals.
===================================================================
M source/blender/alembic/intern/abc_mesh.cc
M source/blender/alembic/intern/abc_mesh.h
M source/blender/alembic/intern/alembic_capi.cc
===================================================================
diff --git a/source/blender/alembic/intern/abc_mesh.cc b/source/blender/alembic/intern/abc_mesh.cc
index 5d743e1..f88013d 100644
--- a/source/blender/alembic/intern/abc_mesh.cc
+++ b/source/blender/alembic/intern/abc_mesh.cc
@@ -953,7 +953,7 @@ void AbcMeshReader::readPolyDataSample(Mesh *mesh,
ED_mesh_uv_texture_add(mesh, Alembic::Abc::GetSourceName(uv.getMetaData()).c_str(), true);
}
- read_mpolys(mesh->mpoly, mesh->mloop, mesh->mloopuv, &mesh->pdata,
+ read_mpolys(mesh->mpoly, mesh->mloop, mesh->mloopuv, &mesh->ldata,
face_indices, face_counts, uvs, uvs_indices, normals);
const ICompoundProperty &arb_geom_params = (m_schema.valid() ? m_schema.getArbGeomParams()
@@ -1051,61 +1051,56 @@ void read_mverts(MVert *mverts,
}
}
-void read_mpolys(MPoly *mpolys, MLoop *mloops, MLoopUV *mloopuvs, CustomData */*pdata*/,
+void read_mpolys(MPoly *mpolys, MLoop *mloops, MLoopUV *mloopuvs, CustomData *ldata,
const Alembic::AbcGeom::Int32ArraySamplePtr &face_indices,
const Alembic::AbcGeom::Int32ArraySamplePtr &face_counts,
const Alembic::AbcGeom::V2fArraySamplePtr &uvs,
const Alembic::AbcGeom::UInt32ArraySamplePtr &uvs_indices,
- const Alembic::AbcGeom::N3fArraySamplePtr &/*normals*/)
+ const Alembic::AbcGeom::N3fArraySamplePtr &normals)
{
- int loopcount = 0;
- unsigned int vert_index;
-
-#if 0
- float (*pnors)[3];
+ float (*pnors)[3] = NULL;
if (normals) {
- pnors = (float (*)[3])CustomData_get_layer(pdata, CD_NORMAL);
+ pnors = (float (*)[3])CustomData_get_layer(ldata, CD_NORMAL);
if (!pnors) {
- pnors = (float (*)[3])CustomData_add_layer(pdata, CD_NORMAL, CD_CALLOC, NULL, face_counts->size());
+ pnors = (float (*)[3])CustomData_add_layer(ldata, CD_NORMAL, CD_CALLOC, NULL, normals->size());
}
}
+ const bool do_normals = (normals && pnors);
+ const bool do_uvs = (mloopuvs && uvs && uvs_indices);
+ unsigned int loop_index = 0;
+ unsigned int rev_loop_index = 0;
+ unsigned int uv_index = 0;
Imath::V3f nor;
- float no[3];
-#endif
for (int i = 0; i < face_counts->size(); ++i) {
- int face_size = (*face_counts)[i];
- MPoly &poly = mpolys[i];
+ const int face_size = (*face_counts)[i];
- poly.loopstart = loopcount;
+ MPoly &poly = mpolys[i];
+ poly.loopstart = loop_index;
poly.totloop = face_size;
- /* TODO: reverse. */
- int rev_loop = loopcount;
- for (int f = face_size; f-- ; ++loopcount) {
- MLoop &loop = mloops[rev_loop + f];
+ /* NOTE: Alembic data is stored in the reverse order. */
+ rev_loop_index = loop_index + (face_size - 1);
- vert_index = (*face_indices)[loopcount];
- loop.v = vert_index;
+ for (int f = 0; f < face_size; ++f, ++loop_index, --rev_loop_index) {
+ MLoop &loop = mloops[rev_loop_index];
+ loop.v = (*face_indices)[loop_index];
- if (mloopuvs && uvs && uvs_indices) {
- MLoopUV &loopuv = mloopuvs[rev_loop + f];
-
- vert_index = (*uvs_indices)[loopcount];
- loopuv.uv[0] = (*uvs)[vert_index][0];
- loopuv.uv[1] = (*uvs)[vert_index][1];
+ if (do_normals) {
+ nor = (*normals)[loop_index];
+ copy_yup_zup(pnors[rev_loop_index], nor.getValue());
}
-#if 0
- /* TODO: figure this out. */
- if (normals && pnors) {
- nor = (*normals)[vert_index];
- copy_yup_zup(pnors[i], nor.getValue());
+ if (do_uvs) {
+ MLoopUV &loopuv = mloopuvs[rev_loop_index];
+
+ uv_index = (*uvs_indices)[loop_index];
+ loopuv.uv[0] = (*uvs)[uv_index][0];
+ loopuv.uv[1] = (*uvs)[uv_index][1];
}
-#endif
}
}
}
diff --git a/source/blender/alembic/intern/abc_mesh.h b/source/blender/alembic/intern/abc_mesh.h
index 69b35e6..926feb3 100644
--- a/source/blender/alembic/intern/abc_mesh.h
+++ b/source/blender/alembic/intern/abc_mesh.h
@@ -127,7 +127,7 @@ void read_mverts(MVert *mverts,
const Alembic::AbcGeom::P3fArraySamplePtr &positions,
const Alembic::AbcGeom::N3fArraySamplePtr &normals);
-void read_mpolys(MPoly *mpolys, MLoop *mloops, MLoopUV *mloopuvs, CustomData *pdata,
+void read_mpolys(MPoly *mpolys, MLoop *mloops, MLoopUV *mloopuvs, CustomData *ldata,
const Alembic::AbcGeom::Int32ArraySamplePtr &face_indices,
const Alembic::AbcGeom::Int32ArraySamplePtr &face_counts,
const Alembic::AbcGeom::V2fArraySamplePtr &uvs,
diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc
index 7bc1c38..93bd21b 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -747,7 +747,7 @@ 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->getPolyDataLayout(dm);
+ CustomData *pdata = dm->getLoopDataLayout(dm);
read_mverts(mverts, positions, vertex_normals);
read_mpolys(mpolys, mloops, mloopuvs, pdata, face_indices, face_counts, uvs, uvs_indices, poly_normals);
More information about the Bf-blender-cvs
mailing list