From 0050a044fa4d536a0382a72618709a57c6e30805 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 21 Aug 2019 10:55:47 +1000 Subject: Cleanup: remove unused derived-mesh API calls --- source/blender/blenkernel/BKE_DerivedMesh.h | 71 -- source/blender/blenkernel/BKE_cdderivedmesh.h | 76 +- source/blender/blenkernel/intern/DerivedMesh.c | 15 - source/blender/blenkernel/intern/cdderivedmesh.c | 872 +--------------------- source/blender/blenkernel/intern/subsurf_ccg.c | 403 ---------- source/blender/editors/uvedit/uvedit_unwrap_ops.c | 2 +- 6 files changed, 6 insertions(+), 1433 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index d215f214a6d..bc115fec35a 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -150,23 +150,6 @@ struct DerivedMesh { /** Calculate vert and face normals */ void (*calcNormals)(DerivedMesh *dm); - /** Calculate loop (split) normals */ - void (*calcLoopNormals)(DerivedMesh *dm, const bool use_split_normals, const float split_angle); - - /** Calculate loop (split) normals, and returns split loop normal spacearr. */ - void (*calcLoopNormalsSpaceArray)(DerivedMesh *dm, - const bool use_split_normals, - const float split_angle, - struct MLoopNorSpaceArray *r_lnors_spacearr); - - void (*calcLoopTangents)(DerivedMesh *dm, - bool calc_active_tangent, - const char (*tangent_names)[MAX_NAME], - int tangent_names_count); - - /** Recalculates mesh tessellation */ - void (*recalcTessellation)(DerivedMesh *dm); - /** Loop tessellation cache (WARNING! Only call inside threading-protected code!) */ void (*recalcLoopTri)(DerivedMesh *dm); /** accessor functions */ @@ -261,51 +244,6 @@ struct DerivedMesh { DMFlagMat *(*getGridFlagMats)(DerivedMesh *dm); unsigned int **(*getGridHidden)(DerivedMesh *dm); - /** Iterate over each mapped vertex in the derived mesh, calling the - * given function with the original vert and the mapped vert's new - * coordinate and normal. For historical reasons the normal can be - * passed as a float or short array, only one should be non-NULL. - */ - void (*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); - - /** Iterate over each mapped edge in the derived mesh, calling the - * given function with the original edge and the mapped edge's new - * coordinates. - */ - void (*foreachMappedEdge)( - DerivedMesh *dm, - void (*func)(void *userData, int index, const float v0co[3], const float v1co[3]), - void *userData); - - /** Iterate over each mapped loop in the derived mesh, calling the given function - * with the original loop index and the mapped loops's new coordinate and normal. - */ - void (*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); - - /** Iterate over each mapped face in the derived mesh, calling the - * given function with the original face and the mapped face's (or - * faces') center and normal. - */ - void (*foreachMappedFaceCenter)( - DerivedMesh *dm, - void (*func)(void *userData, int index, const float cent[3], const float no[3]), - void *userData, - DMForeachFlag flag); - /** Iterate over all vertex points, calling DO_MINMAX with given args. * * Also called in Editmode @@ -319,9 +257,6 @@ struct DerivedMesh { /** Get vertex location, undefined if index is not valid */ void (*getVertCo)(DerivedMesh *dm, int index, float r_co[3]); - /** Fill the array (of length .getNumVerts()) with all vertex locations */ - void (*getVertCos)(DerivedMesh *dm, float (*r_cos)[3]); - /** Get smooth vertex normal, undefined if index is not valid */ void (*getVertNo)(DerivedMesh *dm, int index, float r_no[3]); void (*getPolyNo)(DerivedMesh *dm, int index, float r_no[3]); @@ -330,10 +265,6 @@ struct DerivedMesh { */ const struct MeshElemMap *(*getPolyMap)(struct Object *ob, DerivedMesh *dm); - /** Get the BVH used for paint modes - */ - struct PBVH *(*getPBVH)(struct Object *ob, DerivedMesh *dm); - /** Release reference to the DerivedMesh. This function decides internally * if the DerivedMesh will be freed, or cached for later use. */ void (*release)(DerivedMesh *dm); @@ -446,8 +377,6 @@ DerivedMesh *mesh_create_derived_render(struct Depsgraph *depsgraph, const struct CustomData_MeshMasks *dataMask); /* same as above but wont use render settings */ -DerivedMesh *mesh_create_derived(struct Mesh *me, float (*vertCos)[3]); - struct Mesh *editbmesh_get_eval_cage(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *, diff --git a/source/blender/blenkernel/BKE_cdderivedmesh.h b/source/blender/blenkernel/BKE_cdderivedmesh.h index 08d53bf0e21..50af6c876b4 100644 --- a/source/blender/blenkernel/BKE_cdderivedmesh.h +++ b/source/blender/blenkernel/BKE_cdderivedmesh.h @@ -33,9 +33,7 @@ struct BMEditMesh; struct CustomData_MeshMasks; struct DerivedMesh; -struct MLoopNorSpaceArray; struct Mesh; -struct Object; /* creates a new CDDerivedMesh */ struct DerivedMesh *CDDM_new(int numVerts, int numEdges, int numFaces, int numLoops, int numPolys); @@ -51,79 +49,16 @@ struct DerivedMesh *CDDM_from_mesh_ex(struct Mesh *mesh, eCDAllocType alloctype, const struct CustomData_MeshMasks *mask); -struct DerivedMesh *CDDM_from_bmesh(struct BMesh *bm, const bool use_mdisps); - /* creates a CDDerivedMesh from the given BMEditMesh */ -DerivedMesh *CDDM_from_editbmesh(struct BMEditMesh *em, - const bool use_mdisps, - const bool use_tessface); - -/* creates a CDDerivedMesh from the given curve object */ -struct DerivedMesh *CDDM_from_curve(struct Object *ob); - -/* creates a CDDerivedMesh from the given curve object and specified dispbase */ -/* useful for OrcoDM creation for curves with constructive modifiers */ -DerivedMesh *CDDM_from_curve_displist(struct Object *ob, struct ListBase *dispbase); +DerivedMesh *CDDM_from_editbmesh(struct BMEditMesh *em, const bool use_mdisps); /* Copies the given DerivedMesh with verts, faces & edges stored as * custom element data. */ struct DerivedMesh *CDDM_copy(struct DerivedMesh *dm); -/* creates a CDDerivedMesh with the same layer stack configuration as the - * given DerivedMesh and containing the requested numbers of elements. - * elements are initialized to all zeros - */ -struct DerivedMesh *CDDM_from_template_ex(struct DerivedMesh *source, - int numVerts, - int numEdges, - int numFaces, - int numLoops, - int numPolys, - const struct CustomData_MeshMasks *mask); -struct DerivedMesh *CDDM_from_template(struct DerivedMesh *source, - int numVerts, - int numEdges, - int numFaces, - int numLoops, - int numPolys); - -/* applies vertex coordinates or normals to a CDDerivedMesh. if the MVert - * layer is a referenced layer, it will be duplicate to not overwrite the - * original - */ -void CDDM_apply_vert_coords(struct DerivedMesh *cddm, float (*vertCoords)[3]); -void CDDM_apply_vert_normals(struct DerivedMesh *cddm, short (*vertNormals)[3]); - -/* recalculates vertex and face normals for a CDDerivedMesh - */ -void CDDM_calc_normals_mapping_ex(struct DerivedMesh *dm, const bool only_face_normals); -void CDDM_calc_normals_mapping(struct DerivedMesh *dm); -void CDDM_calc_normals(struct DerivedMesh *dm); - -void CDDM_calc_loop_normals(struct DerivedMesh *dm, - const bool use_split_normals, - const float split_angle); -void CDDM_calc_loop_normals_spacearr(struct DerivedMesh *dm, - const bool use_split_normals, - const float split_angle, - struct MLoopNorSpaceArray *r_lnors_spacearr); - -/* reconstitute face triangulation */ -void CDDM_recalc_tessellation(struct DerivedMesh *dm); -void CDDM_recalc_tessellation_ex(struct DerivedMesh *dm, const bool do_face_nor_cpy); - void CDDM_recalc_looptri(struct DerivedMesh *dm); -/* lowers the number of vertices/edges/faces in a CDDerivedMesh - * the layer data stays the same size - */ -void CDDM_lower_num_verts(struct DerivedMesh *dm, int numVerts); -void CDDM_lower_num_edges(struct DerivedMesh *dm, int numEdges); -void CDDM_lower_num_loops(struct DerivedMesh *dm, int numLoops); -void CDDM_lower_num_polys(struct DerivedMesh *dm, int numPolys); -void CDDM_lower_num_tessfaces(DerivedMesh *dm, int numTessFaces); - /* vertex/edge/face access functions * should always succeed if index is within bounds * note these return pointers - any change modifies the internals of the mesh @@ -145,13 +80,4 @@ struct MFace *CDDM_get_tessfaces(struct DerivedMesh *dm); struct MLoop *CDDM_get_loops(struct DerivedMesh *dm); struct MPoly *CDDM_get_polys(struct DerivedMesh *dm); -/* Assigns news m*** layers to the cddm. Note that you must handle - * freeing the old ones yourself. Also you must ensure dm->num****Data - * is correct.*/ -void CDDM_set_mvert(struct DerivedMesh *dm, struct MVert *mvert); -void CDDM_set_medge(struct DerivedMesh *dm, struct MEdge *medge); -void CDDM_set_mface(struct DerivedMesh *dm, struct MFace *mface); -void CDDM_set_mloop(struct DerivedMesh *dm, struct MLoop *mloop); -void CDDM_set_mpoly(struct DerivedMesh *dm, struct MPoly *mpoly); - #endif diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index 6267c095618..f752542133e 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -819,21 +819,6 @@ void DM_interp_vert_data(DerivedMesh *source, &source->vertData, &dest->vertData, src_indices, weights, NULL, count, dest_index); } -DerivedMesh *mesh_create_derived(Mesh *me, float (*vertCos)[3]) -{ - DerivedMesh *dm = CDDM_from_mesh(me); - - if (!dm) { - return NULL; - } - - if (vertCos) { - CDDM_apply_vert_coords(dm, vertCos); - } - - return dm; -} - static float (*get_editbmesh_orco_verts(BMEditMesh *em))[3] { BMIter iter; diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 28bd9c0cea5..a55b5dc7817 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -173,16 +173,6 @@ static void cdDM_getVertCo(DerivedMesh *dm, int index, float r_co[3]) copy_v3_v3(r_co, cddm->mvert[index].co); } -static void cdDM_getVertCos(DerivedMesh *dm, float (*r_cos)[3]) -{ - MVert *mv = CDDM_get_verts(dm); - int i; - - for (i = 0; i < dm->numVertData; i++, mv++) { - copy_v3_v3(r_cos[i], mv->co); - } -} - static void cdDM_getVertNo(DerivedMesh *dm, int index, float r_no[3]) { CDDerivedMesh *cddm = (CDDerivedMesh *)dm; @@ -203,278 +193,6 @@ static const MeshElemMap *cdDM_getPolyMap(Object *ob, DerivedMesh *dm) return cddm->pmap; } -static bool check_sculpt_object_deformed(Object *object, bool for_construction) -{ - bool deformed = false; - - /* Active modifiers means extra deformation, which can't be handled correct - * on birth of PBVH and sculpt "layer" levels, so use PBVH only for internal brush - * stuff and show final DerivedMesh so user would see actual object shape. - */ - deformed |= object->sculpt->modifiers_active; - - if (for_construction) { - deformed |= object->sculpt->kb != NULL; - } - else { - /* As in case with modifiers, we can't synchronize deformation made against - * PBVH and non-locked keyblock, so also use PBVH only for brushes and - * final DM to give final result to user. - */ - deformed |= object->sculpt->kb && (object->shapeflag & OB_SHAPE_LOCK) == 0; - } - - return deformed; -} - -static bool can_pbvh_draw(Object *ob, DerivedMesh *dm) -{ - CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - Mesh *me = ob->data; - bool deformed = check_sculpt_object_deformed(ob, false); - - if (deformed) { - return false; - } - - return cddm->mvert == me->mvert || ob->sculpt->kb; -} - -static PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm) -{ - CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - - if (!ob) { - cddm->pbvh = NULL; - return NULL; - } - - if (!ob->sculpt) { - return NULL; - } - - if (ob->sculpt->pbvh) { - cddm->pbvh = ob->sculpt->pbvh; - cddm->pbvh_draw = can_pbvh_draw(ob, dm); - } - - /* Sculpting on a BMesh (dynamic-topology) gets a special PBVH */ - if (!cddm->pbvh && ob->sculpt->bm) { - cddm->pbvh = BKE_pbvh_new(); - cddm->pbvh_draw = true; - - BKE_pbvh_build_bmesh(cddm->pbvh, - ob->sculpt->bm, - ob->sculpt->bm_smooth_shading, - ob->sculpt->bm_log, - ob->sculpt->cd_vert_node_offset, - ob->sculpt->cd_face_node_offset); - - pbvh_show_mask_set(cddm->pbvh, ob->sculpt->show_mask); - } - - /* always build pbvh from original mesh, and only use it for drawing if - * this derivedmesh is just original mesh. it's the multires subsurf dm - * that this is actually for, to support a pbvh on a modified mesh */ - if (!cddm->pbvh && 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; - bool deformed; - - cddm->pbvh = BKE_pbvh_new(); - cddm->pbvh_draw = can_pbvh_draw(ob, dm); - - looptri = MEM_malloc_arrayN(looptris_num, sizeof(*looptri), __func__); - - BKE_mesh_recalc_looptri(me->mloop, me->mpoly, me->mvert, me->totloop, me->totpoly, looptri); - - BKE_pbvh_build_mesh(cddm->pbvh, - me->mpoly, - me->mloop, - me->mvert, - me->totvert, - &me->vdata, - &me->ldata, - looptri, - looptris_num); - - pbvh_show_mask_set(cddm->pbvh, ob->sculpt->show_mask); - - deformed = check_sculpt_object_deformed(ob, true); - - if (deformed && ob->derivedDeform) { - DerivedMesh *deformdm = ob->derivedDeform; - float(*vertCos)[3]; - int totvert; - - totvert = deformdm->getNumVerts(deformdm); - vertCos = MEM_malloc_arrayN(totvert, sizeof(float[3]), "cdDM_getPBVH vertCos"); - deformdm->getVertCos(deformdm, vertCos); - BKE_pbvh_apply_vertCos(cddm->pbvh, vertCos, totvert); - MEM_freeN(vertCos); - } - } - - return cddm->pbvh; -} - -static void cdDM_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) -{ - MVert *mv = CDDM_get_verts(dm); - const int *index = DM_get_vert_data_layer(dm, CD_ORIGINDEX); - int i; - - if (index) { - for (i = 0; i < dm->numVertData; i++, mv++) { - const short *no = (flag & DM_FOREACH_USE_NORMAL) ? mv->no : NULL; - const int orig = *index++; - if (orig == ORIGINDEX_NONE) { - continue; - } - func(userData, orig, mv->co, NULL, no); - } - } - else { - for (i = 0; i < dm->numVertData; i++, mv++) { - const short *no = (flag & DM_FOREACH_USE_NORMAL) ? mv->no : NULL; - func(userData, i, mv->co, NULL, no); - } - } -} - -static void cdDM_foreachMappedEdge( - DerivedMesh *dm, - void (*func)(void *userData, int index, const float v0co[3], const float v1co[3]), - void *userData) -{ - CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - MVert *mv = cddm->mvert; - MEdge *med = cddm->medge; - int i, orig, *index = DM_get_edge_data_layer(dm, CD_ORIGINDEX); - - for (i = 0; i < dm->numEdgeData; i++, med++) { - if (index) { - orig = *index++; - if (orig == ORIGINDEX_NONE) { - continue; - } - func(userData, orig, mv[med->v1].co, mv[med->v2].co); - } - else { - func(userData, i, mv[med->v1].co, mv[med->v2].co); - } - } -} - -static void cdDM_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; - - const MVert *mv = CDDM_get_verts(dm); - const MLoop *ml = CDDM_get_loops(dm); - const MPoly *mp = CDDM_get_polys(dm); - const int *v_index = DM_get_vert_data_layer(dm, CD_ORIGINDEX); - const int *f_index = DM_get_poly_data_layer(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 cdDM_foreachMappedFaceCenter( - DerivedMesh *dm, - void (*func)(void *userData, int index, const float cent[3], const float no[3]), - void *userData, - DMForeachFlag flag) -{ - CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - MVert *mvert = cddm->mvert; - MPoly *mp; - MLoop *ml; - int i, orig, *index; - - index = CustomData_get_layer(&dm->polyData, CD_ORIGINDEX); - mp = cddm->mpoly; - for (i = 0; i < dm->numPolyData; i++, mp++) { - float cent[3]; - float *no, _no[3]; - - if (index) { - orig = *index++; - if (orig == ORIGINDEX_NONE) { - continue; - } - } - else { - orig = i; - } - - ml = &cddm->mloop[mp->loopstart]; - BKE_mesh_calc_poly_center(mp, ml, mvert, cent); - - if (flag & DM_FOREACH_USE_NORMAL) { - BKE_mesh_calc_poly_normal(mp, ml, mvert, (no = _no)); - } - else { - no = NULL; - } - - func(userData, orig, cent, no); - } -} - -void CDDM_recalc_tessellation_ex(DerivedMesh *dm, const bool do_face_nor_cpy) -{ - CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - - dm->numTessFaceData = BKE_mesh_recalc_tessellation(&dm->faceData, - &dm->loopData, - &dm->polyData, - cddm->mvert, - dm->numTessFaceData, - dm->numLoopData, - dm->numPolyData, - do_face_nor_cpy); - - cddm->mface = CustomData_get_layer(&dm->faceData, CD_MFACE); - - /* Tessellation recreated faceData, and the active layer indices need to get re-propagated - * from loops and polys to faces */ - CustomData_bmesh_update_active_layers(&dm->faceData, &dm->loopData); -} - -void CDDM_recalc_tessellation(DerivedMesh *dm) -{ - CDDM_recalc_tessellation_ex(dm, true); -} - void CDDM_recalc_looptri(DerivedMesh *dm) { CDDerivedMesh *cddm = (CDDerivedMesh *)dm; @@ -547,25 +265,13 @@ static CDDerivedMesh *cdDM_create(const char *desc) dm->getEdgeDataArray = DM_get_edge_data_layer; dm->getTessFaceDataArray = DM_get_tessface_data_layer; - dm->calcNormals = CDDM_calc_normals; - dm->calcLoopNormals = CDDM_calc_loop_normals; - dm->calcLoopNormalsSpaceArray = CDDM_calc_loop_normals_spacearr; - dm->calcLoopTangents = DM_calc_loop_tangents; - dm->recalcTessellation = CDDM_recalc_tessellation; dm->recalcLoopTri = CDDM_recalc_looptri; - dm->getVertCos = cdDM_getVertCos; dm->getVertCo = cdDM_getVertCo; dm->getVertNo = cdDM_getVertNo; - dm->getPBVH = cdDM_getPBVH; dm->getPolyMap = cdDM_getPolyMap; - dm->foreachMappedVert = cdDM_foreachMappedVert; - dm->foreachMappedEdge = cdDM_foreachMappedEdge; - dm->foreachMappedLoop = cdDM_foreachMappedLoop; - dm->foreachMappedFaceCenter = cdDM_foreachMappedFaceCenter; - dm->release = cdDM_release; return cddm; @@ -664,123 +370,12 @@ DerivedMesh *CDDM_from_mesh_ex(Mesh *mesh, return dm; } -DerivedMesh *CDDM_from_curve(Object *ob) -{ - ListBase disp = {NULL, NULL}; - - if (ob->runtime.curve_cache) { - disp = ob->runtime.curve_cache->disp; - } - - return CDDM_from_curve_displist(ob, &disp); -} - -DerivedMesh *CDDM_from_curve_displist(Object *ob, ListBase *dispbase) -{ - Curve *cu = (Curve *)ob->data; - DerivedMesh *dm; - CDDerivedMesh *cddm; - MVert *allvert; - MEdge *alledge; - MLoop *allloop; - MPoly *allpoly; - MLoopUV *alluv = NULL; - int totvert, totedge, totloop, totpoly; - bool use_orco_uv = (cu->flag & CU_UV_ORCO) != 0; - - if (BKE_mesh_nurbs_displist_to_mdata(ob, - dispbase, - &allvert, - &totvert, - &alledge, - &totedge, - &allloop, - &allpoly, - (use_orco_uv) ? &alluv : NULL, - &totloop, - &totpoly) != 0) { - /* Error initializing mdata. This often happens when curve is empty */ - return CDDM_new(0, 0, 0, 0, 0); - } - - dm = CDDM_new(totvert, totedge, 0, totloop, totpoly); - dm->deformedOnly = 1; - dm->dirty |= DM_DIRTY_NORMALS; - - cddm = (CDDerivedMesh *)dm; - - memcpy(cddm->mvert, allvert, totvert * sizeof(MVert)); - memcpy(cddm->medge, alledge, totedge * sizeof(MEdge)); - memcpy(cddm->mloop, allloop, totloop * sizeof(MLoop)); - memcpy(cddm->mpoly, allpoly, totpoly * sizeof(MPoly)); - - if (alluv) { - const char *uvname = "Orco"; - CustomData_add_layer_named(&cddm->dm.loopData, CD_MLOOPUV, CD_ASSIGN, alluv, totloop, uvname); - } - - MEM_freeN(allvert); - MEM_freeN(alledge); - MEM_freeN(allloop); - MEM_freeN(allpoly); - - return dm; -} - -static void loops_to_customdata_corners( - BMesh *bm, CustomData *facedata, int cdindex, const BMLoop *l3[3], int numCol, int numUV) -{ - const BMLoop *l; - // BMFace *f = l3[0]->f; - MTFace *texface; - MCol *mcol; - MLoopCol *mloopcol; - MLoopUV *mloopuv; - int i, j, hasPCol = CustomData_has_layer(&bm->ldata, CD_PREVIEW_MLOOPCOL); - - for (i = 0; i < numUV; i++) { - texface = CustomData_get_n(facedata, CD_MTFACE, cdindex, i); - - for (j = 0; j < 3; j++) { - l = l3[j]; - mloopuv = CustomData_bmesh_get_n(&bm->ldata, l->head.data, CD_MLOOPUV, i); - copy_v2_v2(texface->uv[j], mloopuv->uv); - } - } - - for (i = 0; i < numCol; i++) { - mcol = CustomData_get_n(facedata, CD_MCOL, cdindex, i); - - for (j = 0; j < 3; j++) { - l = l3[j]; - mloopcol = CustomData_bmesh_get_n(&bm->ldata, l->head.data, CD_MLOOPCOL, i); - MESH_MLOOPCOL_TO_MCOL(mloopcol, &mcol[j]); - } - } - - if (hasPCol) { - mcol = CustomData_get(facedata, cdindex, CD_PREVIEW_MCOL); - - for (j = 0; j < 3; j++) { - l = l3[j]; - mloopcol = CustomData_bmesh_get(&bm->ldata, l->head.data, CD_PREVIEW_MLOOPCOL); - MESH_MLOOPCOL_TO_MCOL(mloopcol, &mcol[j]); - } - } -} - /* TODO(campbell): remove, use BKE_mesh_from_bmesh_for_eval_nomain instead. */ /* used for both editbmesh and bmesh */ -static DerivedMesh *cddm_from_bmesh_ex(struct BMesh *bm, - const bool use_mdisps, - /* EditBMesh vars for use_tessface */ - const bool use_tessface, - const int em_tottri, - const BMLoop *(*em_looptris)[3]) +static DerivedMesh *cddm_from_bmesh_ex(struct BMesh *bm, const bool use_mdisps) { - DerivedMesh *dm = CDDM_new( - bm->totvert, bm->totedge, use_tessface ? em_tottri : 0, bm->totloop, bm->totface); + DerivedMesh *dm = CDDM_new(bm->totvert, bm->totedge, 0, bm->totloop, bm->totface); CDDerivedMesh *cddm = (CDDerivedMesh *)dm; BMIter iter; @@ -789,11 +384,8 @@ static DerivedMesh *cddm_from_bmesh_ex(struct BMesh *bm, BMFace *efa; MVert *mvert = cddm->mvert; MEdge *medge = cddm->medge; - MFace *mface = cddm->mface; MLoop *mloop = cddm->mloop; MPoly *mpoly = cddm->mpoly; - int numCol = CustomData_number_of_layers(&bm->ldata, CD_MLOOPCOL); - int numUV = CustomData_number_of_layers(&bm->ldata, CD_MLOOPUV); int *index, add_orig; CustomData_MeshMasks mask = {0}; unsigned int i, j; @@ -820,11 +412,6 @@ static DerivedMesh *cddm_from_bmesh_ex(struct BMesh *bm, CustomData_merge(&bm->ldata, &dm->loopData, mask.lmask, CD_CALLOC, dm->numLoopData); CustomData_merge(&bm->pdata, &dm->polyData, mask.pmask, CD_CALLOC, dm->numPolyData); - /* add tessellation mface layers */ - if (use_tessface) { - CustomData_from_bmeshpoly(&dm->faceData, &dm->loopData, em_tottri); - } - index = dm->getVertDataArray(dm, CD_ORIGINDEX); BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) { @@ -883,32 +470,6 @@ static DerivedMesh *cddm_from_bmesh_ex(struct BMesh *bm, } bm->elem_index_dirty &= ~BM_EDGE; - /* avoid this where possiblem, takes extra memory */ - if (use_tessface) { - - BM_mesh_elem_index_ensure(bm, BM_FACE); - - index = dm->getTessFaceDataArray(dm, CD_ORIGINDEX); - for (i = 0; i < dm->numTessFaceData; i++) { - MFace *mf = &mface[i]; - const BMLoop **l = em_looptris[i]; - efa = l[0]->f; - - mf->v1 = BM_elem_index_get(l[0]->v); - mf->v2 = BM_elem_index_get(l[1]->v); - mf->v3 = BM_elem_index_get(l[2]->v); - mf->v4 = 0; - mf->mat_nr = efa->mat_nr; - mf->flag = BM_face_flag_to_mflag(efa); - - /* map mfaces to polygons in the same cddm intentionally */ - *index++ = BM_elem_index_get(efa); - - loops_to_customdata_corners(bm, &dm->faceData, i, l, numCol, numUV); - test_index_face(mf, &dm->faceData, i, 3); - } - } - index = CustomData_get_layer(&dm->polyData, CD_ORIGINDEX); j = 0; BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, i) { @@ -948,24 +509,9 @@ static DerivedMesh *cddm_from_bmesh_ex(struct BMesh *bm, return dm; } -struct DerivedMesh *CDDM_from_bmesh(struct BMesh *bm, const bool use_mdisps) +DerivedMesh *CDDM_from_editbmesh(BMEditMesh *em, const bool use_mdisps) { - return cddm_from_bmesh_ex(bm, - use_mdisps, - false, - /* these vars are for editmesh only */ - 0, - NULL); -} - -DerivedMesh *CDDM_from_editbmesh(BMEditMesh *em, const bool use_mdisps, const bool use_tessface) -{ - return cddm_from_bmesh_ex(em->bm, - use_mdisps, - /* editmesh */ - use_tessface, - em->tottri, - (const BMLoop *(*)[3])em->looptris); + return cddm_from_bmesh_ex(em->bm, use_mdisps); } DerivedMesh *CDDM_copy(DerivedMesh *source) @@ -1014,366 +560,11 @@ DerivedMesh *CDDM_copy(DerivedMesh *source) return dm; } -/* note, the CD_ORIGINDEX layers are all 0, so if there is a direct - * relationship between mesh data this needs to be set by the caller. */ -DerivedMesh *CDDM_from_template_ex(DerivedMesh *source, - int numVerts, - int numEdges, - int numTessFaces, - int numLoops, - int numPolys, - const CustomData_MeshMasks *mask) -{ - CDDerivedMesh *cddm = cdDM_create("CDDM_from_template dest"); - DerivedMesh *dm = &cddm->dm; - - /* ensure these are created if they are made on demand */ - source->getVertDataArray(source, CD_ORIGINDEX); - source->getEdgeDataArray(source, CD_ORIGINDEX); - source->getTessFaceDataArray(source, CD_ORIGINDEX); - source->getPolyDataArray(source, CD_ORIGINDEX); - - /* this does a copy of all non mvert/medge/mface layers */ - DM_from_template_ex( - dm, source, DM_TYPE_CDDM, numVerts, numEdges, numTessFaces, numLoops, numPolys, mask); - - /* now add mvert/medge/mface layers */ - CustomData_add_layer(&dm->vertData, CD_MVERT, CD_CALLOC, NULL, numVerts); - CustomData_add_layer(&dm->edgeData, CD_MEDGE, CD_CALLOC, NULL, numEdges); - CustomData_add_layer(&dm->faceData, CD_MFACE, CD_CALLOC, NULL, numTessFaces); - CustomData_add_layer(&dm->loopData, CD_MLOOP, CD_CALLOC, NULL, numLoops); - CustomData_add_layer(&dm->polyData, CD_MPOLY, CD_CALLOC, NULL, numPolys); - - if (!CustomData_get_layer(&dm->vertData, CD_ORIGINDEX)) { - CustomData_add_layer(&dm->vertData, CD_ORIGINDEX, CD_CALLOC, NULL, numVerts); - } - if (!CustomData_get_layer(&dm->edgeData, CD_ORIGINDEX)) { - CustomData_add_layer(&dm->edgeData, CD_ORIGINDEX, CD_CALLOC, NULL, numEdges); - } - if (!CustomData_get_layer(&dm->faceData, CD_ORIGINDEX)) { - CustomData_add_layer(&dm->faceData, CD_ORIGINDEX, CD_CALLOC, NULL, numTessFaces); - } - - cddm->mvert = CustomData_get_layer(&dm->vertData, CD_MVERT); - cddm->medge = CustomData_get_layer(&dm->edgeData, CD_MEDGE); - cddm->mface = CustomData_get_layer(&dm->faceData, CD_MFACE); - cddm->mloop = CustomData_get_layer(&dm->loopData, CD_MLOOP); - cddm->mpoly = CustomData_get_layer(&dm->polyData, CD_MPOLY); - - return dm; -} -DerivedMesh *CDDM_from_template( - DerivedMesh *source, int numVerts, int numEdges, int numTessFaces, int numLoops, int numPolys) -{ - return CDDM_from_template_ex( - source, numVerts, numEdges, numTessFaces, numLoops, numPolys, &CD_MASK_DERIVEDMESH); -} - -void CDDM_apply_vert_coords(DerivedMesh *dm, float (*vertCoords)[3]) -{ - CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - MVert *vert; - int i; - - /* this will just return the pointer if it wasn't a referenced layer */ - vert = CustomData_duplicate_referenced_layer(&dm->vertData, CD_MVERT, dm->numVertData); - cddm->mvert = vert; - - for (i = 0; i < dm->numVertData; ++i, ++vert) { - copy_v3_v3(vert->co, vertCoords[i]); - } - - cddm->dm.dirty |= DM_DIRTY_NORMALS; -} - -void CDDM_apply_vert_normals(DerivedMesh *dm, short (*vertNormals)[3]) -{ - CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - MVert *vert; - int i; - - /* this will just return the pointer if it wasn't a referenced layer */ - vert = CustomData_duplicate_referenced_layer(&dm->vertData, CD_MVERT, dm->numVertData); - cddm->mvert = vert; - - for (i = 0; i < dm->numVertData; ++i, ++vert) { - copy_v3_v3_short(vert->no, vertNormals[i]); - } - - cddm->dm.dirty &= ~DM_DIRTY_NORMALS; -} - -void CDDM_calc_normals_mapping_ex(DerivedMesh *dm, const bool only_face_normals) -{ - CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - float(*face_nors)[3] = NULL; - - if (dm->numVertData == 0) { - cddm->dm.dirty &= ~DM_DIRTY_NORMALS; - return; - } - - /* now we skip calculating vertex normals for referenced layer, - * no need to duplicate verts. - * WATCH THIS, bmesh only change!, - * need to take care of the side effects here - campbell */ -#if 0 - /* we don't want to overwrite any referenced layers */ - cddm->mvert = CustomData_duplicate_referenced_layer(&dm->vertData, CD_MVERT, dm->numVertData); -#endif - -#if 0 - if (dm->numTessFaceData == 0) { - /* No tessellation on this mesh yet, need to calculate one. - * - * Important not to update face normals from polys since it - * interferes with assigning the new normal layer in the following code. - */ - CDDM_recalc_tessellation_ex(dm, false); - } - else { - /* A tessellation already exists, it should always have a CD_ORIGINDEX */ - BLI_assert(CustomData_has_layer(&dm->faceData, CD_ORIGINDEX)); - CustomData_free_layers(&dm->faceData, CD_NORMAL, dm->numTessFaceData); - } -#endif - - face_nors = MEM_malloc_arrayN(dm->numPolyData, sizeof(*face_nors), "face_nors"); - - /* calculate face normals */ - BKE_mesh_calc_normals_poly(cddm->mvert, - NULL, - dm->numVertData, - CDDM_get_loops(dm), - CDDM_get_polys(dm), - dm->numLoopData, - dm->numPolyData, - face_nors, - only_face_normals); - - CustomData_add_layer(&dm->polyData, CD_NORMAL, CD_ASSIGN, face_nors, dm->numPolyData); - - cddm->dm.dirty &= ~DM_DIRTY_NORMALS; -} - -void CDDM_calc_normals_mapping(DerivedMesh *dm) -{ - /* use this to skip calculating normals on original vert's, this may need to be changed */ - const bool only_face_normals = CustomData_is_referenced_layer(&dm->vertData, CD_MVERT); - - CDDM_calc_normals_mapping_ex(dm, only_face_normals); -} - -#if 0 -/* bmesh note: this matches what we have in trunk */ -void CDDM_calc_normals(DerivedMesh *dm) -{ - CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - float(*poly_nors)[3]; - - if (dm->numVertData == 0) { - return; - } - - /* we don't want to overwrite any referenced layers */ - cddm->mvert = CustomData_duplicate_referenced_layer(&dm->vertData, CD_MVERT, dm->numVertData); - - /* fill in if it exists */ - poly_nors = CustomData_get_layer(&dm->polyData, CD_NORMAL); - if (!poly_nors) { - poly_nors = CustomData_add_layer(&dm->polyData, CD_NORMAL, CD_CALLOC, NULL, dm->numPolyData); - } - - BKE_mesh_calc_normals_poly(cddm->mvert, - dm->numVertData, - CDDM_get_loops(dm), - CDDM_get_polys(dm), - dm->numLoopData, - dm->numPolyData, - poly_nors, - false); - - cddm->dm.dirty &= ~DM_DIRTY_NORMALS; -} -#else - -/* poly normal layer is now only for final display */ -void CDDM_calc_normals(DerivedMesh *dm) -{ - CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - - /* we don't want to overwrite any referenced layers */ - cddm->mvert = CustomData_duplicate_referenced_layer(&dm->vertData, CD_MVERT, dm->numVertData); - - BKE_mesh_calc_normals_poly(cddm->mvert, - NULL, - dm->numVertData, - CDDM_get_loops(dm), - CDDM_get_polys(dm), - dm->numLoopData, - dm->numPolyData, - NULL, - false); - - cddm->dm.dirty &= ~DM_DIRTY_NORMALS; -} - -#endif - -void CDDM_calc_loop_normals(DerivedMesh *dm, const bool use_split_normals, const float split_angle) -{ - CDDM_calc_loop_normals_spacearr(dm, use_split_normals, split_angle, NULL); -} - /* #define DEBUG_CLNORS */ #ifdef DEBUG_CLNORS # include "BLI_linklist.h" #endif -void CDDM_calc_loop_normals_spacearr(DerivedMesh *dm, - const bool use_split_normals, - const float split_angle, - MLoopNorSpaceArray *r_lnors_spacearr) -{ - MVert *mverts = dm->getVertArray(dm); - MEdge *medges = dm->getEdgeArray(dm); - MLoop *mloops = dm->getLoopArray(dm); - MPoly *mpolys = dm->getPolyArray(dm); - - CustomData *ldata, *pdata; - - float(*lnors)[3]; - short(*clnor_data)[2]; - float(*pnors)[3]; - - const int numVerts = dm->getNumVerts(dm); - const int numEdges = dm->getNumEdges(dm); - const int numLoops = dm->getNumLoops(dm); - const int numPolys = dm->getNumPolys(dm); - - ldata = dm->getLoopDataLayout(dm); - if (CustomData_has_layer(ldata, CD_NORMAL)) { - lnors = CustomData_get_layer(ldata, CD_NORMAL); - } - else { - lnors = CustomData_add_layer(ldata, CD_NORMAL, CD_CALLOC, NULL, numLoops); - } - - /* Compute poly (always needed) and vert normals. */ - /* Note we can't use DM_ensure_normals, since it won't keep computed poly nors... */ - pdata = dm->getPolyDataLayout(dm); - pnors = CustomData_get_layer(pdata, CD_NORMAL); - if (!pnors) { - pnors = CustomData_add_layer(pdata, CD_NORMAL, CD_CALLOC, NULL, numPolys); - } - BKE_mesh_calc_normals_poly(mverts, - NULL, - numVerts, - mloops, - mpolys, - numLoops, - numPolys, - pnors, - (dm->dirty & DM_DIRTY_NORMALS) ? false : true); - - dm->dirty &= ~DM_DIRTY_NORMALS; - - clnor_data = CustomData_get_layer(ldata, CD_CUSTOMLOOPNORMAL); - - BKE_mesh_normals_loop_split(mverts, - numVerts, - medges, - numEdges, - mloops, - lnors, - numLoops, - mpolys, - (const float(*)[3])pnors, - numPolys, - use_split_normals, - split_angle, - r_lnors_spacearr, - clnor_data, - NULL); -#ifdef DEBUG_CLNORS - if (r_lnors_spacearr) { - int i; - for (i = 0; i < numLoops; i++) { - if (r_lnors_spacearr->lspacearr[i]->ref_alpha != 0.0f) { - LinkNode *loops = r_lnors_spacearr->lspacearr[i]->loops; - printf("Loop %d uses lnor space %p:\n", i, r_lnors_spacearr->lspacearr[i]); - print_v3("\tfinal lnor", lnors[i]); - print_v3("\tauto lnor", r_lnors_spacearr->lspacearr[i]->vec_lnor); - print_v3("\tref_vec", r_lnors_spacearr->lspacearr[i]->vec_ref); - printf("\talpha: %f\n\tbeta: %f\n\tloops: %p\n", - r_lnors_spacearr->lspacearr[i]->ref_alpha, - r_lnors_spacearr->lspacearr[i]->ref_beta, - r_lnors_spacearr->lspacearr[i]->loops); - printf("\t\t(shared with loops"); - while (loops) { - printf(" %d", POINTER_AS_INT(loops->link)); - loops = loops->next; - } - printf(")\n"); - } - else { - printf("Loop %d has no lnor space\n", i); - } - } - } -#endif -} - -void CDDM_lower_num_verts(DerivedMesh *dm, int numVerts) -{ - BLI_assert(numVerts >= 0); - if (numVerts < dm->numVertData) { - CustomData_free_elem(&dm->vertData, numVerts, dm->numVertData - numVerts); - } - - dm->numVertData = numVerts; -} - -void CDDM_lower_num_edges(DerivedMesh *dm, int numEdges) -{ - BLI_assert(numEdges >= 0); - if (numEdges < dm->numEdgeData) { - CustomData_free_elem(&dm->edgeData, numEdges, dm->numEdgeData - numEdges); - } - - dm->numEdgeData = numEdges; -} - -void CDDM_lower_num_tessfaces(DerivedMesh *dm, int numTessFaces) -{ - BLI_assert(numTessFaces >= 0); - if (numTessFaces < dm->numTessFaceData) { - CustomData_free_elem(&dm->faceData, numTessFaces, dm->numTessFaceData - numTessFaces); - } - - dm->numTessFaceData = numTessFaces; -} - -void CDDM_lower_num_loops(DerivedMesh *dm, int numLoops) -{ - BLI_assert(numLoops >= 0); - if (numLoops < dm->numLoopData) { - CustomData_free_elem(&dm->loopData, numLoops, dm->numLoopData - numLoops); - } - - dm->numLoopData = numLoops; -} - -void CDDM_lower_num_polys(DerivedMesh *dm, int numPolys) -{ - BLI_assert(numPolys >= 0); - if (numPolys < dm->numPolyData) { - CustomData_free_elem(&dm->polyData, numPolys, dm->numPolyData - numPolys); - } - - dm->numPolyData = numPolys; -} - /* mesh element access functions */ MVert *CDDM_get_vert(DerivedMesh *dm, int index) @@ -1427,58 +618,3 @@ MPoly *CDDM_get_polys(DerivedMesh *dm) { return ((CDDerivedMesh *)dm)->mpoly; } - -void CDDM_set_mvert(DerivedMesh *dm, MVert *mvert) -{ - CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - - if (!CustomData_has_layer(&dm->vertData, CD_MVERT)) { - CustomData_add_layer(&dm->vertData, CD_MVERT, CD_ASSIGN, mvert, dm->numVertData); - } - - cddm->mvert = mvert; -} - -void CDDM_set_medge(DerivedMesh *dm, MEdge *medge) -{ - CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - - if (!CustomData_has_layer(&dm->edgeData, CD_MEDGE)) { - CustomData_add_layer(&dm->edgeData, CD_MEDGE, CD_ASSIGN, medge, dm->numEdgeData); - } - - cddm->medge = medge; -} - -void CDDM_set_mface(DerivedMesh *dm, MFace *mface) -{ - CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - - if (!CustomData_has_layer(&dm->faceData, CD_MFACE)) { - CustomData_add_layer(&dm->faceData, CD_MFACE, CD_ASSIGN, mface, dm->numTessFaceData); - } - - cddm->mface = mface; -} - -void CDDM_set_mloop(DerivedMesh *dm, MLoop *mloop) -{ - CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - - if (!CustomData_has_layer(&dm->loopData, CD_MLOOP)) { - CustomData_add_layer(&dm->loopData, CD_MLOOP, CD_ASSIGN, mloop, dm->numLoopData); - } - - cddm->mloop = mloop; -} - -void CDDM_set_mpoly(DerivedMesh *dm, MPoly *mpoly) -{ - CDDerivedMesh *cddm = (CDDerivedMesh *)dm; - - if (!CustomData_has_layer(&dm->polyData, CD_MPOLY)) { - CustomData_add_layer(&dm->polyData, CD_MPOLY, CD_ASSIGN, mpoly, dm->numPolyData); - } - - cddm->mpoly = mpoly; -} 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; } diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c index a42a6eba3ff..2d8f40ea5af 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c @@ -524,7 +524,7 @@ static ParamHandle *construct_param_handle_subsurfed(Scene *scene, smd.levels = smd_real->levels; smd.subdivType = smd_real->subdivType; - initialDerived = CDDM_from_editbmesh(em, false, false); + initialDerived = CDDM_from_editbmesh(em, false); derivedMesh = subsurf_make_derived_from_derived( initialDerived, &smd, scene, NULL, SUBSURF_IN_EDIT_MODE); -- cgit v1.2.3