From 6ed15c5a41130b55cb57a43a8a9470a91d38c3d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 26 Apr 2017 15:31:03 +0200 Subject: Alembic export: support simple child hairs (Fix T51144) Simple child hairs don't have a face index number assigned, so the call to dm->getTessFaceData(dm, num, CD_MFACE) would cause a crash. To work around this, UV and normal vectors are copied from the parent hair. I've also removed an unnecessary call to dm->getTessFaceArray(dm); Reviewers: kevindietrich Differential Revision: https://developer.blender.org/D2638 --- source/blender/alembic/intern/abc_hair.cc | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'source/blender/alembic') diff --git a/source/blender/alembic/intern/abc_hair.cc b/source/blender/alembic/intern/abc_hair.cc index 9a974273a46..2d42c532c9b 100644 --- a/source/blender/alembic/intern/abc_hair.cc +++ b/source/blender/alembic/intern/abc_hair.cc @@ -241,7 +241,6 @@ void AbcHairWriter::write_hair_child_sample(DerivedMesh *dm, invert_m4_m4_safe(inv_mat, m_object->obmat); MTFace *mtface = static_cast(CustomData_get_layer(&dm->faceData, CD_MTFACE)); - MFace *mface = dm->getTessFaceArray(dm); MVert *mverts = dm->getVertArray(dm); ParticleCacheKey **cache = m_psys->childcache; @@ -253,12 +252,25 @@ void AbcHairWriter::write_hair_child_sample(DerivedMesh *dm, path = cache[p]; if (part->from == PART_FROM_FACE) { - const int num = pc->num; + if (part->childtype == PART_CHILD_PARTICLES || !mtface) { + /* Face index is unknown for these particles, so just take info + * from the parent. */ + uv_values.push_back(uv_values[pc->parent]); + norm_values.push_back(norm_values[pc->parent]); + } + else { + const int num = pc->num; + if (num < 0) { + ABC_LOG(m_settings.logger) + << "Warning, child particle of hair system " << m_psys->name + << " has unknown face index of geometry of "<< (m_object->id.name + 2) + << ", skipping child hair." << std::endl; + continue; + } - MFace *face = static_cast(dm->getTessFaceData(dm, num, CD_MFACE)); - MTFace *tface = mtface + num; + MFace *face = static_cast(dm->getTessFaceData(dm, num, CD_MFACE)); + MTFace *tface = mtface + num; - if (mface && mtface) { float r_uv[2], tmpnor[3], mapfw[4], vec[3]; psys_interpolate_uvs(tface, face->v4, pc->fuv, r_uv); @@ -270,6 +282,14 @@ void AbcHairWriter::write_hair_child_sample(DerivedMesh *dm, norm_values.push_back(Imath::V3f(tmpnor[0], tmpnor[2], -tmpnor[1])); } } + else { + ABC_LOG(m_settings.logger) + << "Unknown particle type " << part->from + << " for child hair of system " << m_psys->name + << std::endl; + uv_values.push_back(uv_values[pc->parent]); + norm_values.push_back(norm_values[pc->parent]); + } int steps = path->segments + 1; hvertices.push_back(steps); -- cgit v1.2.3