Alembic export: support simple child hairs (Fix T51144)
authorSybren A. Stüvel <sybren@stuvel.eu>
Wed, 26 Apr 2017 13:31:03 +0000 (15:31 +0200)
committerSybren A. Stüvel <sybren@stuvel.eu>
Wed, 26 Apr 2017 13:31:03 +0000 (15:31 +0200)
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

index 9a974273a46bc4054c470b267fb105df927393de..2d42c532c9bce0dd7a5eb3b1e5c0ba4b0cc283e6 100644 (file)
@@ -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<MTFace *>(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<MFace *>(dm->getTessFaceData(dm, num, CD_MFACE));
-                       MTFace *tface = mtface + num;
+                               MFace *face = static_cast<MFace *>(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);