Changeset View
Changeset View
Standalone View
Standalone View
source/blender/bmesh/intern/bmesh_mesh.c
| Show First 20 Lines • Show All 1,154 Lines • ▼ Show 20 Lines | if (type_flag & BMO_OPTYPE_FLAG_SELECT_FLUSH) { | ||||
| BM_mesh_select_mode_flush(bm); | BM_mesh_select_mode_flush(bm); | ||||
| } | } | ||||
| if ((type_flag & BMO_OPTYPE_FLAG_SELECT_VALIDATE) == 0) { | if ((type_flag & BMO_OPTYPE_FLAG_SELECT_VALIDATE) == 0) { | ||||
| bm->selected = select_history; | bm->selected = select_history; | ||||
| } | } | ||||
| } | } | ||||
| void BM_mesh_elem_index_ensure(BMesh *bm, const char htype) | void BM_mesh_elem_index_ensure_ex(BMesh *bm, const char htype, int elem_offset[4]) | ||||
| { | { | ||||
| const char htype_needed = bm->elem_index_dirty & htype; | const char htype_needed = bm->elem_index_dirty & htype; | ||||
| #ifdef DEBUG | #ifdef DEBUG | ||||
| BM_ELEM_INDEX_VALIDATE(bm, "Should Never Fail!", __func__); | BM_ELEM_INDEX_VALIDATE(bm, "Should Never Fail!", __func__); | ||||
| #endif | #endif | ||||
| if (0 && htype_needed == 0) { | if (0 && htype_needed == 0) { | ||||
| goto finally; | goto finally; | ||||
| } | } | ||||
| if (htype & BM_VERT) { | if (htype & BM_VERT) { | ||||
| if (bm->elem_index_dirty & BM_VERT) { | if (bm->elem_index_dirty & BM_VERT) { | ||||
| BMIter iter; | BMIter iter; | ||||
| BMElem *ele; | BMElem *ele; | ||||
| int index; | int index = elem_offset ? elem_offset[0] : 0; | ||||
| BM_ITER_MESH_INDEX (ele, &iter, bm, BM_VERTS_OF_MESH, index) { | BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) { | ||||
| BM_elem_index_set(ele, index); /* set_ok */ | BM_elem_index_set(ele, index++); /* set_ok */ | ||||
| } | |||||
| if (elem_offset) { | |||||
| elem_offset[0] = index; | |||||
| } | } | ||||
| BLI_assert(index == bm->totvert); | BLI_assert(elem_offset || index == bm->totvert); | ||||
| } | } | ||||
| else { | else { | ||||
| // printf("%s: skipping vert index calc!\n", __func__); | // printf("%s: skipping vert index calc!\n", __func__); | ||||
| } | } | ||||
| } | } | ||||
| if (htype & BM_EDGE) { | if (htype & BM_EDGE) { | ||||
| if (bm->elem_index_dirty & BM_EDGE) { | if (bm->elem_index_dirty & BM_EDGE) { | ||||
| BMIter iter; | BMIter iter; | ||||
| BMElem *ele; | BMElem *ele; | ||||
| int index; | int index = elem_offset ? elem_offset[1] : 0; | ||||
| BM_ITER_MESH_INDEX (ele, &iter, bm, BM_EDGES_OF_MESH, index) { | BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) { | ||||
| BM_elem_index_set(ele, index); /* set_ok */ | BM_elem_index_set(ele, index++); /* set_ok */ | ||||
| } | } | ||||
| BLI_assert(index == bm->totedge); | if (elem_offset) { | ||||
| elem_offset[1] = index; | |||||
| } | |||||
| BLI_assert(elem_offset || index == bm->totedge); | |||||
| } | } | ||||
| else { | else { | ||||
| // printf("%s: skipping edge index calc!\n", __func__); | // printf("%s: skipping edge index calc!\n", __func__); | ||||
| } | } | ||||
| } | } | ||||
| if (htype & (BM_FACE | BM_LOOP)) { | if (htype & (BM_FACE | BM_LOOP)) { | ||||
| if (bm->elem_index_dirty & (BM_FACE | BM_LOOP)) { | if (bm->elem_index_dirty & (BM_FACE | BM_LOOP)) { | ||||
| BMIter iter; | BMIter iter; | ||||
| BMElem *ele; | BMElem *ele; | ||||
| const bool update_face = (htype & BM_FACE) && (bm->elem_index_dirty & BM_FACE); | const bool update_face = (htype & BM_FACE) && (bm->elem_index_dirty & BM_FACE); | ||||
| const bool update_loop = (htype & BM_LOOP) && (bm->elem_index_dirty & BM_LOOP); | const bool update_loop = (htype & BM_LOOP) && (bm->elem_index_dirty & BM_LOOP); | ||||
| int index; | int index_loop = elem_offset ? elem_offset[2] : 0; | ||||
| int index_loop = 0; | int index = elem_offset ? elem_offset[3] : 0; | ||||
| BM_ITER_MESH_INDEX (ele, &iter, bm, BM_FACES_OF_MESH, index) { | BM_ITER_MESH (ele, &iter, bm, BM_FACES_OF_MESH) { | ||||
| if (update_face) { | if (update_face) { | ||||
| BM_elem_index_set(ele, index); /* set_ok */ | BM_elem_index_set(ele, index++); /* set_ok */ | ||||
| } | } | ||||
| if (update_loop) { | if (update_loop) { | ||||
| BMLoop *l_iter, *l_first; | BMLoop *l_iter, *l_first; | ||||
| l_iter = l_first = BM_FACE_FIRST_LOOP((BMFace *)ele); | l_iter = l_first = BM_FACE_FIRST_LOOP((BMFace *)ele); | ||||
| do { | do { | ||||
| BM_elem_index_set(l_iter, index_loop++); /* set_ok */ | BM_elem_index_set(l_iter, index_loop++); /* set_ok */ | ||||
| } while ((l_iter = l_iter->next) != l_first); | } while ((l_iter = l_iter->next) != l_first); | ||||
| } | } | ||||
| } | } | ||||
| BLI_assert(index == bm->totface); | if (elem_offset) { | ||||
| elem_offset[2] = index_loop; | |||||
| elem_offset[3] = index; | |||||
| } | |||||
| BLI_assert(elem_offset || !update_face || index == bm->totface); | |||||
| if (update_loop) { | if (update_loop) { | ||||
| BLI_assert(index_loop == bm->totloop); | BLI_assert(elem_offset || !update_loop || index_loop == bm->totloop); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| // printf("%s: skipping face/loop index calc!\n", __func__); | // printf("%s: skipping face/loop index calc!\n", __func__); | ||||
| } | } | ||||
| } | } | ||||
| finally: | finally: | ||||
| bm->elem_index_dirty &= ~htype; | bm->elem_index_dirty &= ~htype; | ||||
| if (elem_offset) { | |||||
| if (htype & BM_VERT) { | |||||
| if (elem_offset[0] != bm->totvert) { | |||||
| bm->elem_index_dirty |= BM_VERT; | |||||
| } | |||||
| } | |||||
| if (htype & BM_EDGE) { | |||||
| if (elem_offset[1] != bm->totedge) { | |||||
| bm->elem_index_dirty |= BM_EDGE; | |||||
| } | |||||
| } | |||||
| if (htype & BM_LOOP) { | |||||
| if (elem_offset[2] != bm->totloop) { | |||||
| bm->elem_index_dirty |= BM_LOOP; | |||||
| } | |||||
| } | |||||
| if (htype & BM_FACE) { | |||||
| if (elem_offset[3] != bm->totface) { | |||||
| bm->elem_index_dirty |= BM_FACE; | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| void BM_mesh_elem_index_ensure(BMesh *bm, const char htype) | |||||
| { | |||||
| BM_mesh_elem_index_ensure_ex(bm, htype, NULL); | |||||
| } | } | ||||
| /** | /** | ||||
| * Array checking/setting macros | * Array checking/setting macros | ||||
| * | * | ||||
| * Currently vert/edge/loop/face index data is being abused, in a few areas of the code. | * Currently vert/edge/loop/face index data is being abused, in a few areas of the code. | ||||
| * | * | ||||
| ▲ Show 20 Lines • Show All 842 Lines • Show Last 20 Lines | |||||