diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-08-21 03:55:47 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-08-21 04:41:40 +0300 |
commit | 0050a044fa4d536a0382a72618709a57c6e30805 (patch) | |
tree | 2ed2f7fb5b3a0da6ebf318a7e02f5235e7117338 /source/blender/blenkernel/intern/subsurf_ccg.c | |
parent | 48a7f979a5cf2669656d25767c4173fb65bfb67d (diff) |
Cleanup: remove unused derived-mesh API calls
Diffstat (limited to 'source/blender/blenkernel/intern/subsurf_ccg.c')
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 403 |
1 files changed, 0 insertions, 403 deletions
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 3f57ae169ff..77dc438cd04 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -83,8 +83,6 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, int useSubsurfUv, DerivedMesh *dm, bool use_gpu_backend); -static int ccgDM_use_grid_pbvh(CCGDerivedMesh *ccgdm); - /// static void *arena_alloc(CCGAllocatorHDL a, int numBytes) @@ -1580,221 +1578,6 @@ static void ccgDM_copyFinalPolyArray(DerivedMesh *dm, MPoly *mpoly) } } -static void ccgdm_getVertCos(DerivedMesh *dm, float (*cos)[3]) -{ - CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; - CCGSubSurf *ss = ccgdm->ss; - int edgeSize = ccgSubSurf_getEdgeSize(ss); - int gridSize = ccgSubSurf_getGridSize(ss); - int i; - CCGVertIterator vi; - CCGEdgeIterator ei; - CCGFaceIterator fi; - CCGFace **faceMap2; - CCGEdge **edgeMap2; - CCGVert **vertMap2; - int index, totvert, totedge, totface; - - totvert = ccgSubSurf_getNumVerts(ss); - vertMap2 = MEM_mallocN(totvert * sizeof(*vertMap2), "vertmap"); - for (ccgSubSurf_initVertIterator(ss, &vi); !ccgVertIterator_isStopped(&vi); - ccgVertIterator_next(&vi)) { - CCGVert *v = ccgVertIterator_getCurrent(&vi); - - vertMap2[POINTER_AS_INT(ccgSubSurf_getVertVertHandle(v))] = v; - } - - totedge = ccgSubSurf_getNumEdges(ss); - edgeMap2 = MEM_mallocN(totedge * sizeof(*edgeMap2), "edgemap"); - for (ccgSubSurf_initEdgeIterator(ss, &ei), i = 0; !ccgEdgeIterator_isStopped(&ei); - i++, ccgEdgeIterator_next(&ei)) { - CCGEdge *e = ccgEdgeIterator_getCurrent(&ei); - - edgeMap2[POINTER_AS_INT(ccgSubSurf_getEdgeEdgeHandle(e))] = e; - } - - totface = ccgSubSurf_getNumFaces(ss); - faceMap2 = MEM_mallocN(totface * sizeof(*faceMap2), "facemap"); - for (ccgSubSurf_initFaceIterator(ss, &fi); !ccgFaceIterator_isStopped(&fi); - ccgFaceIterator_next(&fi)) { - CCGFace *f = ccgFaceIterator_getCurrent(&fi); - - faceMap2[POINTER_AS_INT(ccgSubSurf_getFaceFaceHandle(f))] = f; - } - - i = 0; - for (index = 0; index < totface; index++) { - CCGFace *f = faceMap2[index]; - int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f); - - copy_v3_v3(cos[i++], ccgSubSurf_getFaceCenterData(f)); - - for (S = 0; S < numVerts; S++) { - for (x = 1; x < gridSize - 1; x++) { - copy_v3_v3(cos[i++], ccgSubSurf_getFaceGridEdgeData(ss, f, S, x)); - } - } - - for (S = 0; S < numVerts; S++) { - for (y = 1; y < gridSize - 1; y++) { - for (x = 1; x < gridSize - 1; x++) { - copy_v3_v3(cos[i++], ccgSubSurf_getFaceGridData(ss, f, S, x, y)); - } - } - } - } - - for (index = 0; index < totedge; index++) { - CCGEdge *e = edgeMap2[index]; - int x; - - for (x = 1; x < edgeSize - 1; x++) { - copy_v3_v3(cos[i++], ccgSubSurf_getEdgeData(ss, e, x)); - } - } - - for (index = 0; index < totvert; index++) { - CCGVert *v = vertMap2[index]; - copy_v3_v3(cos[i++], ccgSubSurf_getVertData(ss, v)); - } - - MEM_freeN(vertMap2); - MEM_freeN(edgeMap2); - MEM_freeN(faceMap2); -} - -static void ccgDM_foreachMappedVert(DerivedMesh *dm, - void (*func)(void *userData, - int index, - const float co[3], - const float no_f[3], - const short no_s[3]), - void *userData, - DMForeachFlag flag) -{ - CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; - CCGVertIterator vi; - CCGKey key; - CCG_key_top_level(&key, ccgdm->ss); - - for (ccgSubSurf_initVertIterator(ccgdm->ss, &vi); !ccgVertIterator_isStopped(&vi); - ccgVertIterator_next(&vi)) { - CCGVert *v = ccgVertIterator_getCurrent(&vi); - const int index = ccgDM_getVertMapIndex(ccgdm->ss, v); - - if (index != -1) { - CCGElem *vd = ccgSubSurf_getVertData(ccgdm->ss, v); - const float *no = (flag & DM_FOREACH_USE_NORMAL) ? CCG_elem_no(&key, vd) : NULL; - func(userData, index, CCG_elem_co(&key, vd), no, NULL); - } - } -} - -static void ccgDM_foreachMappedEdge( - DerivedMesh *dm, - void (*func)(void *userData, int index, const float v0co[3], const float v1co[3]), - void *userData) -{ - CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; - CCGSubSurf *ss = ccgdm->ss; - CCGEdgeIterator ei; - CCGKey key; - int i, edgeSize = ccgSubSurf_getEdgeSize(ss); - - CCG_key_top_level(&key, ss); - - for (ccgSubSurf_initEdgeIterator(ss, &ei); !ccgEdgeIterator_isStopped(&ei); - ccgEdgeIterator_next(&ei)) { - CCGEdge *e = ccgEdgeIterator_getCurrent(&ei); - const int index = ccgDM_getEdgeMapIndex(ss, e); - - if (index != -1) { - CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e); - for (i = 0; i < edgeSize - 1; i++) { - func(userData, - index, - CCG_elem_offset_co(&key, edgeData, i), - CCG_elem_offset_co(&key, edgeData, i + 1)); - } - } - } -} - -static void ccgDM_foreachMappedLoop(DerivedMesh *dm, - void (*func)(void *userData, - int vertex_index, - int face_index, - const float co[3], - const float no[3]), - void *userData, - DMForeachFlag flag) -{ - /* We can't use dm->getLoopDataLayout(dm) here, we want to always access dm->loopData, - * EditDerivedBMesh would return loop data from bmesh itself. */ - const float(*lnors)[3] = (flag & DM_FOREACH_USE_NORMAL) ? DM_get_loop_data_layer(dm, CD_NORMAL) : - NULL; - - MVert *mv = dm->getVertArray(dm); - MLoop *ml = dm->getLoopArray(dm); - MPoly *mp = dm->getPolyArray(dm); - const int *v_index = dm->getVertDataArray(dm, CD_ORIGINDEX); - const int *f_index = dm->getPolyDataArray(dm, CD_ORIGINDEX); - int p_idx, i; - - for (p_idx = 0; p_idx < dm->numPolyData; ++p_idx, ++mp) { - for (i = 0; i < mp->totloop; ++i, ++ml) { - const int v_idx = v_index ? v_index[ml->v] : ml->v; - const int f_idx = f_index ? f_index[p_idx] : p_idx; - const float *no = lnors ? *lnors++ : NULL; - if (!ELEM(ORIGINDEX_NONE, v_idx, f_idx)) { - func(userData, v_idx, f_idx, mv[ml->v].co, no); - } - } - } -} - -static void UNUSED_FUNCTION(ccgdm_pbvh_update)(CCGDerivedMesh *ccgdm) -{ - if (ccgdm->pbvh && ccgDM_use_grid_pbvh(ccgdm)) { - CCGFace **faces; - int totface; - - BKE_pbvh_get_grid_updates(ccgdm->pbvh, 1, (void ***)&faces, &totface); - if (totface) { - ccgSubSurf_updateFromFaces(ccgdm->ss, 0, faces, totface); - ccgSubSurf_updateNormals(ccgdm->ss, faces, totface); - MEM_freeN(faces); - } - } -} - -static void ccgDM_foreachMappedFaceCenter( - DerivedMesh *dm, - void (*func)(void *userData, int index, const float co[3], const float no[3]), - void *userData, - DMForeachFlag flag) -{ - CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; - CCGSubSurf *ss = ccgdm->ss; - CCGKey key; - CCGFaceIterator fi; - - CCG_key_top_level(&key, ss); - - for (ccgSubSurf_initFaceIterator(ss, &fi); !ccgFaceIterator_isStopped(&fi); - ccgFaceIterator_next(&fi)) { - CCGFace *f = ccgFaceIterator_getCurrent(&fi); - const int index = ccgDM_getFaceMapIndex(ss, f); - - if (index != -1) { - /* Face center data normal isn't updated atm. */ - CCGElem *vd = ccgSubSurf_getFaceGridData(ss, f, 0, 0, 0); - const float *no = (flag & DM_FOREACH_USE_NORMAL) ? CCG_elem_no(&key, vd) : NULL; - func(userData, index, CCG_elem_co(&key, vd), no); - } - } -} - static void ccgDM_release(DerivedMesh *dm) { CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; @@ -2222,174 +2005,6 @@ static const MeshElemMap *ccgDM_getPolyMap(Object *ob, DerivedMesh *dm) return ccgdm->pmap; } -static int ccgDM_use_grid_pbvh(CCGDerivedMesh *ccgdm) -{ - MultiresModifierData *mmd = ccgdm->multires.mmd; - - /* both of multires and subsurf modifiers are CCG, but - * grids should only be used when sculpting on multires */ - if (!mmd) { - return 0; - } - - return 1; -} - -static struct PBVH *ccgDM_getPBVH(Object *ob, DerivedMesh *dm) -{ - CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm; - CCGKey key; - int numGrids; - - CCG_key_top_level(&key, ccgdm->ss); - - if (!ob) { - ccgdm->pbvh = NULL; - return NULL; - } - - if (!ob->sculpt) { - return NULL; - } - - bool grid_pbvh = ccgDM_use_grid_pbvh(ccgdm); - if ((ob->mode & OB_MODE_SCULPT) == 0) { - /* In vwpaint, we may use a grid_pbvh for multires/subsurf, under certain conditions. - * More complex cases break 'history' trail back to original vertices, - * in that case we fall back to deformed cage only (i.e. original deformed mesh). */ - VirtualModifierData virtualModifierData; - ModifierData *md = modifiers_getVirtualModifierList(ob, &virtualModifierData); - - grid_pbvh = true; - bool has_one_ccg_modifier = false; - for (; md; md = md->next) { - /* We can only accept to use this ccgdm if: - * - it's the only active ccgdm in the stack. - * - there is no topology-modifying modifier in the stack. - * Otherwise, there is no way to map back to original geometry from grid-generated PBVH. - */ - const ModifierTypeInfo *mti = modifierType_getInfo(md->type); - - if (!modifier_isEnabled(NULL, md, eModifierMode_Realtime)) { - continue; - } - if (ELEM(mti->type, eModifierTypeType_OnlyDeform, eModifierTypeType_NonGeometrical)) { - continue; - } - - if (ELEM(md->type, eModifierType_Subsurf, eModifierType_Multires)) { - if (has_one_ccg_modifier) { - /* We only allow a single active ccg modifier in the stack. */ - grid_pbvh = false; - break; - } - has_one_ccg_modifier = true; - continue; - } - - /* Any other non-deforming modifier makes it impossible to use grid pbvh. */ - grid_pbvh = false; - break; - } - } - - if (ob->sculpt->pbvh) { - /* Note that we have to clean up existing pbvh instead of updating it in case it does not - * match current grid_pbvh status. */ - const PBVHType pbvh_type = BKE_pbvh_type(ob->sculpt->pbvh); - if (grid_pbvh) { - if (pbvh_type == PBVH_GRIDS) { - /* pbvh's grids, gridadj and gridfaces points to data inside ccgdm - * but this can be freed on ccgdm release, this updates the pointers - * when the ccgdm gets remade, the assumption is that the topology - * does not change. */ - ccgdm_create_grids(dm); - BKE_pbvh_grids_update(ob->sculpt->pbvh, - ccgdm->gridData, - (void **)ccgdm->gridFaces, - ccgdm->gridFlagMats, - ccgdm->gridHidden); - } - else { - BKE_pbvh_free(ob->sculpt->pbvh); - ob->sculpt->pbvh = NULL; - } - } - else if (pbvh_type == PBVH_GRIDS) { - BKE_pbvh_free(ob->sculpt->pbvh); - ob->sculpt->pbvh = NULL; - } - - ccgdm->pbvh = ob->sculpt->pbvh; - } - - if (ccgdm->pbvh) { - return ccgdm->pbvh; - } - - /* No pbvh exists yet, we need to create one. only in case of multires - * we build a pbvh over the modified mesh, in other cases the base mesh - * is being sculpted, so we build a pbvh from that. */ - /* Note: vwpaint tries to always build a pbvh over the modified mesh. */ - if (grid_pbvh) { - ccgdm_create_grids(dm); - - numGrids = ccgDM_getNumGrids(dm); - - ob->sculpt->pbvh = ccgdm->pbvh = BKE_pbvh_new(); - BKE_pbvh_build_grids(ccgdm->pbvh, - ccgdm->gridData, - numGrids, - &key, - (void **)ccgdm->gridFaces, - ccgdm->gridFlagMats, - ccgdm->gridHidden); - } - else if (ob->type == OB_MESH) { - Mesh *me = BKE_object_get_original_mesh(ob); - const int looptris_num = poly_to_tri_count(me->totpoly, me->totloop); - MLoopTri *looptri; - - looptri = MEM_mallocN(sizeof(*looptri) * looptris_num, __func__); - - BKE_mesh_recalc_looptri(me->mloop, me->mpoly, me->mvert, me->totloop, me->totpoly, looptri); - - ob->sculpt->pbvh = ccgdm->pbvh = BKE_pbvh_new(); - BKE_pbvh_build_mesh(ccgdm->pbvh, - me->mpoly, - me->mloop, - me->mvert, - me->totvert, - &me->vdata, - &me->ldata, - looptri, - looptris_num); - - if (ob->sculpt->modifiers_active && ob->derivedDeform != NULL) { - DerivedMesh *deformdm = ob->derivedDeform; - float(*vertCos)[3]; - int totvert; - - totvert = deformdm->getNumVerts(deformdm); - vertCos = MEM_malloc_arrayN(totvert, sizeof(float[3]), "ccgDM_getPBVH vertCos"); - deformdm->getVertCos(deformdm, vertCos); - BKE_pbvh_apply_vertCos(ccgdm->pbvh, vertCos, totvert); - MEM_freeN(vertCos); - } - } - - if (ccgdm->pbvh != NULL) { - pbvh_show_mask_set(ccgdm->pbvh, ob->sculpt->show_mask); - } - - return ccgdm->pbvh; -} - -static void ccgDM_recalcTessellation(DerivedMesh *UNUSED(dm)) -{ - /* Nothing to do: CCG handles creating its own tessfaces */ -} - /* WARNING! *MUST* be called in an 'loops_cache_rwlock' protected thread context! */ static void ccgDM_recalcLoopTri(DerivedMesh *dm) { @@ -2425,12 +2040,6 @@ static void ccgDM_recalcLoopTri(DerivedMesh *dm) dm->looptris.array_wip = NULL; } -static void ccgDM_calcNormals(DerivedMesh *dm) -{ - /* Nothing to do: CCG calculates normals during drawing */ - dm->dirty &= ~DM_DIRTY_NORMALS; -} - static void set_default_ccgdm_callbacks(CCGDerivedMesh *ccgdm) { ccgdm->dm.getMinMax = ccgDM_getMinMax; @@ -2471,21 +2080,9 @@ static void set_default_ccgdm_callbacks(CCGDerivedMesh *ccgdm) ccgdm->dm.getGridFlagMats = ccgDM_getGridFlagMats; ccgdm->dm.getGridHidden = ccgDM_getGridHidden; ccgdm->dm.getPolyMap = ccgDM_getPolyMap; - ccgdm->dm.getPBVH = ccgDM_getPBVH; - ccgdm->dm.calcNormals = ccgDM_calcNormals; - ccgdm->dm.calcLoopNormals = CDDM_calc_loop_normals; - ccgdm->dm.calcLoopNormalsSpaceArray = CDDM_calc_loop_normals_spacearr; - ccgdm->dm.calcLoopTangents = DM_calc_loop_tangents; - ccgdm->dm.recalcTessellation = ccgDM_recalcTessellation; ccgdm->dm.recalcLoopTri = ccgDM_recalcLoopTri; - ccgdm->dm.getVertCos = ccgdm_getVertCos; - ccgdm->dm.foreachMappedVert = ccgDM_foreachMappedVert; - ccgdm->dm.foreachMappedEdge = ccgDM_foreachMappedEdge; - ccgdm->dm.foreachMappedLoop = ccgDM_foreachMappedLoop; - ccgdm->dm.foreachMappedFaceCenter = ccgDM_foreachMappedFaceCenter; - ccgdm->dm.release = ccgDM_release; } |