diff options
Diffstat (limited to 'source/blender/blenkernel/intern/editderivedmesh.c')
-rw-r--r-- | source/blender/blenkernel/intern/editderivedmesh.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index 58f25179c5c..b8fade6e4cd 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -242,6 +242,47 @@ static void emDM_recalcTessellation(DerivedMesh *UNUSED(dm)) /* do nothing */ } +static void emDM_recalcLoopTri(DerivedMesh *UNUSED(dm)) +{ + /* Nothing to do: emDM tessellation is known, + * allocate and fill in with emDM_getLoopTriArray */ +} + +static const MLoopTri *emDM_getLoopTriArray(DerivedMesh *dm) +{ + if (dm->looptris.array) { + BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num); + } + else { + EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm; + BMLoop *(*looptris)[3] = bmdm->em->looptris; + MLoopTri *mlooptri; + const int tottri = bmdm->em->tottri; + int i; + + DM_ensure_looptri_data(dm); + mlooptri = dm->looptris.array; + + BLI_assert(poly_to_tri_count(dm->numPolyData, dm->numLoopData) == dm->looptris.num); + BLI_assert(tottri == dm->looptris.num); + + BM_mesh_elem_index_ensure(bmdm->em->bm, BM_FACE | BM_LOOP); + + for (i = 0; i < tottri; i++) { + BMLoop **ltri = looptris[i]; + MLoopTri *lt = &mlooptri[i]; + + ARRAY_SET_ITEMS( + lt->tri, + BM_elem_index_get(ltri[0]), + BM_elem_index_get(ltri[1]), + BM_elem_index_get(ltri[2])); + lt->poly = BM_elem_index_get(ltri[0]->f); + } + } + return dm->looptris.array; +} + static void emDM_foreachMappedVert( DerivedMesh *dm, void (*func)(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3]), @@ -1794,6 +1835,8 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em, bmdm->dm.getNumLoops = emDM_getNumLoops; bmdm->dm.getNumPolys = emDM_getNumPolys; + bmdm->dm.getLoopTriArray = emDM_getLoopTriArray; + bmdm->dm.getVert = emDM_getVert; bmdm->dm.getVertCo = emDM_getVertCo; bmdm->dm.getVertNo = emDM_getVertNo; @@ -1812,6 +1855,7 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em, bmdm->dm.calcLoopNormals = emDM_calcLoopNormals; bmdm->dm.calcLoopNormalsSpaceArray = emDM_calcLoopNormalsSpaceArray; bmdm->dm.recalcTessellation = emDM_recalcTessellation; + bmdm->dm.recalcLoopTri = emDM_recalcLoopTri; bmdm->dm.foreachMappedVert = emDM_foreachMappedVert; bmdm->dm.foreachMappedLoop = emDM_foreachMappedLoop; |