diff options
Diffstat (limited to 'source/blender/alembic/intern/abc_hair.cc')
-rw-r--r-- | source/blender/alembic/intern/abc_hair.cc | 62 |
1 files changed, 28 insertions, 34 deletions
diff --git a/source/blender/alembic/intern/abc_hair.cc b/source/blender/alembic/intern/abc_hair.cc index ed70d36dbee..efe8ea6e79e 100644 --- a/source/blender/alembic/intern/abc_hair.cc +++ b/source/blender/alembic/intern/abc_hair.cc @@ -30,12 +30,15 @@ extern "C" { #include "MEM_guardedalloc.h" +#include "DNA_mesh_types.h" +#include "DNA_meshdata_types.h" #include "DNA_modifier_types.h" #include "BLI_listbase.h" #include "BLI_math_geom.h" -#include "BKE_DerivedMesh.h" +#include "BKE_mesh.h" +#include "BKE_mesh_runtime.h" #include "BKE_object.h" #include "BKE_particle.h" } @@ -49,13 +52,12 @@ using Alembic::AbcGeom::OV2fGeomParam; /* ************************************************************************** */ -AbcHairWriter::AbcHairWriter(Scene *scene, - Object *ob, +AbcHairWriter::AbcHairWriter(Object *ob, AbcTransformWriter *parent, uint32_t time_sampling, ExportSettings &settings, ParticleSystem *psys) - : AbcObjectWriter(scene, ob, time_sampling, settings, parent) + : AbcObjectWriter(ob, time_sampling, settings, parent) , m_uv_warning_shown(false) { m_psys = psys; @@ -69,15 +71,8 @@ void AbcHairWriter::do_write() if (!m_psys) { return; } - - ParticleSystemModifierData *psmd = psys_get_modifier(m_object, m_psys); - - if (!psmd->dm_final) { - return; - } - - DerivedMesh *dm = mesh_create_derived_render(m_scene, m_object, CD_MASK_MESH); - DM_ensure_tessface(dm); + Mesh *mesh = mesh_get_eval_final(m_settings.depsgraph, m_settings.scene, m_object, CD_MASK_MESH); + BKE_mesh_tessface_ensure(mesh); std::vector<Imath::V3f> verts; std::vector<int32_t> hvertices; @@ -87,15 +82,13 @@ void AbcHairWriter::do_write() if (m_psys->pathcache) { ParticleSettings *part = m_psys->part; - write_hair_sample(dm, part, verts, norm_values, uv_values, hvertices); + write_hair_sample(mesh, part, verts, norm_values, uv_values, hvertices); if (m_settings.export_child_hairs && m_psys->childcache) { - write_hair_child_sample(dm, part, verts, norm_values, uv_values, hvertices); + write_hair_child_sample(mesh, part, verts, norm_values, uv_values, hvertices); } } - dm->release(dm); - Alembic::Abc::P3fArraySample iPos(verts); m_sample = OCurvesSchema::Sample(iPos, hvertices); m_sample.setBasis(Alembic::AbcGeom::kNoBasis); @@ -118,7 +111,7 @@ void AbcHairWriter::do_write() m_schema.set(m_sample); } -void AbcHairWriter::write_hair_sample(DerivedMesh *dm, +void AbcHairWriter::write_hair_sample(Mesh *mesh, ParticleSettings *part, std::vector<Imath::V3f> &verts, std::vector<Imath::V3f> &norm_values, @@ -129,9 +122,9 @@ void AbcHairWriter::write_hair_sample(DerivedMesh *dm, float inv_mat[4][4]; 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); + MTFace *mtface = mesh->mtface; + MFace *mface = mesh->mface; + MVert *mverts = mesh->mvert; if ((!mtface || !mface) && !m_uv_warning_shown) { std::fprintf(stderr, "Warning, no UV set found for underlying geometry of %s.\n", @@ -151,11 +144,13 @@ void AbcHairWriter::write_hair_sample(DerivedMesh *dm, /* underlying info for faces-only emission */ path = cache[p]; + /* Write UV and normal vectors */ if (part->from == PART_FROM_FACE && mtface) { const int num = pa->num_dmcache >= 0 ? pa->num_dmcache : pa->num; - if (num < dm->getNumTessFaces(dm)) { - MFace *face = static_cast<MFace *>(dm->getTessFaceData(dm, num, CD_MFACE)); + if (num < mesh->totface) { + /* TODO(Sybren): check whether the NULL check here and if(mface) are actually required */ + MFace *face = mface == NULL ? NULL : &mface[num]; MTFace *tface = mtface + num; if (mface) { @@ -164,14 +159,14 @@ void AbcHairWriter::write_hair_sample(DerivedMesh *dm, psys_interpolate_uvs(tface, face->v4, pa->fuv, r_uv); uv_values.push_back(Imath::V2f(r_uv[0], r_uv[1])); - psys_interpolate_face(mverts, face, tface, NULL, mapfw, vec, normal, NULL, NULL, NULL, NULL); + psys_interpolate_face(mverts, face, tface, NULL, mapfw, vec, normal, NULL, NULL, NULL); copy_yup_from_zup(tmp_nor.getValue(), normal); norm_values.push_back(tmp_nor); } } else { - std::fprintf(stderr, "Particle to faces overflow (%d/%d)\n", num, dm->getNumTessFaces(dm)); + std::fprintf(stderr, "Particle to faces overflow (%d/%d)\n", num, mesh->totface); } } else if (part->from == PART_FROM_VERT && mtface) { @@ -179,8 +174,8 @@ void AbcHairWriter::write_hair_sample(DerivedMesh *dm, const int num = (pa->num_dmcache >= 0) ? pa->num_dmcache : pa->num; /* iterate over all faces to find a corresponding underlying UV */ - for (int n = 0; n < dm->getNumTessFaces(dm); ++n) { - MFace *face = static_cast<MFace *>(dm->getTessFaceData(dm, n, CD_MFACE)); + for (int n = 0; n < mesh->totface; ++n) { + MFace *face = &mface[n]; MTFace *tface = mtface + n; unsigned int vtx[4]; vtx[0] = face->v1; @@ -216,7 +211,7 @@ void AbcHairWriter::write_hair_sample(DerivedMesh *dm, int steps = path->segments + 1; hvertices.push_back(steps); - for (k = 0; k < steps; ++k) { + for (k = 0; k < steps; ++k, ++path) { float vert[3]; copy_v3_v3(vert, path->co); mul_m4_v3(inv_mat, vert); @@ -224,12 +219,11 @@ void AbcHairWriter::write_hair_sample(DerivedMesh *dm, /* Convert Z-up to Y-up. */ verts.push_back(Imath::V3f(vert[0], vert[2], -vert[1])); - ++path; } } } -void AbcHairWriter::write_hair_child_sample(DerivedMesh *dm, +void AbcHairWriter::write_hair_child_sample(Mesh *mesh, ParticleSettings *part, std::vector<Imath::V3f> &verts, std::vector<Imath::V3f> &norm_values, @@ -240,8 +234,8 @@ void AbcHairWriter::write_hair_child_sample(DerivedMesh *dm, float inv_mat[4][4]; invert_m4_m4_safe(inv_mat, m_object->obmat); - MTFace *mtface = static_cast<MTFace *>(CustomData_get_layer(&dm->faceData, CD_MTFACE)); - MVert *mverts = dm->getVertArray(dm); + MTFace *mtface = mesh->mtface; + MVert *mverts = mesh->mvert; ParticleCacheKey **cache = m_psys->childcache; ParticleCacheKey *path; @@ -264,7 +258,7 @@ void AbcHairWriter::write_hair_child_sample(DerivedMesh *dm, continue; } - MFace *face = static_cast<MFace *>(dm->getTessFaceData(dm, num, CD_MFACE)); + MFace *face = &mesh->mface[num]; MTFace *tface = mtface + num; float r_uv[2], tmpnor[3], mapfw[4], vec[3]; @@ -272,7 +266,7 @@ void AbcHairWriter::write_hair_child_sample(DerivedMesh *dm, psys_interpolate_uvs(tface, face->v4, pc->fuv, r_uv); uv_values.push_back(Imath::V2f(r_uv[0], r_uv[1])); - psys_interpolate_face(mverts, face, tface, NULL, mapfw, vec, tmpnor, NULL, NULL, NULL, NULL); + psys_interpolate_face(mverts, face, tface, NULL, mapfw, vec, tmpnor, NULL, NULL, NULL); /* Convert Z-up to Y-up. */ norm_values.push_back(Imath::V3f(tmpnor[0], tmpnor[2], -tmpnor[1])); |