Commit: 0b55947ad931ceb6d082d7603ec0967dc50a6543
Author: Kévin Dietrich
Date: Thu Jun 16 15:17:46 2016 +0200
Branches: alembic_basic_io
https://developer.blender.org/rB0b55947ad931ceb6d082d7603ec0967dc50a6543
Fix crashing accessing normals out-of-bounds.
Normals in Alembic can either be per-face or per-vertex, so read the
normals according to their scope. Face normals are not read at the
moment since I couldn't figure out how to read the data and there are
some other annoying crashes that need to be fixed beforehand.
===================================================================
M source/blender/alembic/intern/abc_mesh.cc
M source/blender/alembic/intern/abc_mesh.h
M source/blender/alembic/intern/abc_util.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 86f5560..8652bb4 100644
--- a/source/blender/alembic/intern/abc_mesh.cc
+++ b/source/blender/alembic/intern/abc_mesh.cc
@@ -919,8 +919,16 @@ 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,
- face_indices, face_counts, uvsamp_vals);
+ const IN3fGeomParam normals = m_schema.valid() ?
m_schema.getNormalsParam() : IN3fGeomParam();
+ N3fArraySamplePtr normal_vals;
+
+ if (normals.valid()) {
+ IN3fGeomParam::Sample normsamp = normals.getExpandedValue();
+ normal_vals = normsamp.getVals();
+ }
+
+ read_mpolys(mesh->mpoly, mesh->mloop, mesh->mloopuv, &mesh->pdata,
+ face_indices, face_counts, uvsamp_vals, normal_vals);
const ICompoundProperty &arb_geom_params = (m_schema.valid() ?
m_schema.getArbGeomParams()
:
m_subd_schema.getArbGeomParams());
@@ -1017,14 +1025,30 @@ void read_mverts(MVert *mverts,
}
}
-void read_mpolys(MPoly *mpolys, MLoop *mloops, MLoopUV *mloopuvs,
+void read_mpolys(MPoly *mpolys, MLoop *mloops, MLoopUV *mloopuvs, CustomData
*pdata,
const Alembic::AbcGeom::Int32ArraySamplePtr &face_indices,
const Alembic::AbcGeom::Int32ArraySamplePtr &face_counts,
- const Alembic::AbcGeom::V2fArraySamplePtr &uvs)
+ const Alembic::AbcGeom::V2fArraySamplePtr &uvs,
+ const Alembic::AbcGeom::N3fArraySamplePtr &/*normals*/)
{
int loopcount = 0;
unsigned int vert_index;
+#if 0
+ float (*pnors)[3];
+
+ if (normals) {
+ pnors = (float (*)[3])CustomData_get_layer(pdata, CD_NORMAL);
+
+ if (!pnors) {
+ pnors = (float (*)[3])CustomData_add_layer(pdata,
CD_NORMAL, CD_CALLOC, NULL, face_counts->size());
+ }
+ }
+
+ 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];
@@ -1045,6 +1069,14 @@ void read_mpolys(MPoly *mpolys, MLoop *mloops, MLoopUV
*mloopuvs,
loopuv.uv[0] = (*uvs)[vert_index][0];
loopuv.uv[1] = (*uvs)[vert_index][1];
}
+
+#if 0
+ /* TODO: figure this out. */
+ if (normals && pnors) {
+ nor = (*normals)[vert_index];
+ copy_yup_zup(pnors[i], nor.getValue());
+ }
+#endif
}
}
}
diff --git a/source/blender/alembic/intern/abc_mesh.h
b/source/blender/alembic/intern/abc_mesh.h
index d7d1803..656e38a 100644
--- a/source/blender/alembic/intern/abc_mesh.h
+++ b/source/blender/alembic/intern/abc_mesh.h
@@ -126,10 +126,11 @@ void read_mverts(MVert *mverts,
const Alembic::AbcGeom::P3fArraySamplePtr &positions,
const Alembic::AbcGeom::N3fArraySamplePtr &normals);
-void read_mpolys(MPoly *mpolys, MLoop *mloops, MLoopUV *mloopuvs,
+void read_mpolys(MPoly *mpolys, MLoop *mloops, MLoopUV *mloopuvs, CustomData
*pdata,
const Alembic::AbcGeom::Int32ArraySamplePtr &face_indices,
const Alembic::AbcGeom::Int32ArraySamplePtr &face_counts,
- const Alembic::AbcGeom::V2fArraySamplePtr &uvs =
Alembic::AbcGeom::V2fArraySamplePtr());
+ const Alembic::AbcGeom::V2fArraySamplePtr &uvs,
+ const Alembic::AbcGeom::N3fArraySamplePtr &normals);
void read_uvs(MPoly *mpolys, MLoop *mloops, MLoopUV *mloopuvs, size_t
face_count,
const Alembic::AbcGeom::V2fArraySamplePtr &uvs,
diff --git a/source/blender/alembic/intern/abc_util.h
b/source/blender/alembic/intern/abc_util.h
index c87ff58..345b71e 100644
--- a/source/blender/alembic/intern/abc_util.h
+++ b/source/blender/alembic/intern/abc_util.h
@@ -92,14 +92,14 @@ void get_min_max_time(const Schema &schema, chrono_t &min,
chrono_t &max)
/* Copy from Y-up to Z-up. */
-ABC_INLINE void copy_yup_zup(float zup[3], float yup[3])
+ABC_INLINE void copy_yup_zup(float zup[3], const float yup[3])
{
zup[0] = yup[0];
zup[1] = -yup[2];
zup[2] = yup[1];
}
-ABC_INLINE void copy_yup_zup(short zup[3], short yup[3])
+ABC_INLINE void copy_yup_zup(short zup[3], const short yup[3])
{
zup[0] = yup[0];
zup[1] = -yup[2];
@@ -108,14 +108,14 @@ ABC_INLINE void copy_yup_zup(short zup[3], short yup[3])
/* Copy from Z-up to Y-up. */
-ABC_INLINE void copy_zup_yup(float yup[3], float zup[3])
+ABC_INLINE void copy_zup_yup(float yup[3], const float zup[3])
{
yup[0] = zup[0];
yup[1] = zup[2];
yup[2] = -zup[1];
}
-ABC_INLINE void copy_zup_yup(short yup[3], short zup[3])
+ABC_INLINE void copy_zup_yup(short yup[3], const short zup[3])
{
yup[0] = zup[0];
yup[1] = zup[2];
diff --git a/source/blender/alembic/intern/alembic_capi.cc
b/source/blender/alembic/intern/alembic_capi.cc
index 21bfa42..1a1322c 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -719,25 +719,32 @@ static DerivedMesh *read_mesh_sample(DerivedMesh *dm,
const IObject &iobject, co
IV2fGeomParam::Sample::samp_ptr_type uvsamp_vals;
if (uv.valid()) {
- IV2fGeomParam::Sample uvsamp = uv.getExpandedValue();
+ IV2fGeomParam::Sample uvsamp = uv.getExpandedValue(sample_sel);
uvsamp_vals = uvsamp.getVals();
}
- N3fArraySamplePtr normal_vals;
+ N3fArraySamplePtr vertex_normals, poly_normals;
const IN3fGeomParam normals = schema.getNormalsParam();
if (normals.valid()) {
- IN3fGeomParam::Sample normsamp = normals.getExpandedValue();
- normal_vals = normsamp.getVals();
+ IN3fGeomParam::Sample normsamp =
normals.getExpandedValue(sample_sel);
+
+ if (normals.getScope() == Alembic::AbcGeom::kFacevaryingScope) {
+ poly_normals = normsamp.getVals();
+ }
+ else {
+ vertex_normals = normsamp.getVals();
+ }
}
MVert *mverts = dm->getVertArray(dm);
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);
- read_mverts(mverts, positions, normal_vals);
- read_mpolys(mpolys, mloops, mloopuvs, face_indices, face_counts,
uvsamp_vals);
+ read_mverts(mverts, positions, vertex_normals);
+ read_mpolys(mpolys, mloops, mloopuvs, pdata, face_indices, face_counts,
uvsamp_vals, poly_normals);
CDDM_calc_edges(dm);
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