Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mesh_iterators.cc
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| void (*func)(void *userData, | void (*func)(void *userData, | ||||
| int vertex_index, | int vertex_index, | ||||
| int face_index, | int face_index, | ||||
| const float co[3], | const float co[3], | ||||
| const float no[3]), | const float no[3]), | ||||
| void *userData, | void *userData, | ||||
| MeshForeachFlag flag) | MeshForeachFlag flag) | ||||
| { | { | ||||
| using namespace blender; | |||||
| /* We can't use `dm->getLoopDataLayout(dm)` here, | /* We can't use `dm->getLoopDataLayout(dm)` here, | ||||
| * we want to always access `dm->loopData`, `EditDerivedBMesh` would | * we want to always access `dm->loopData`, `EditDerivedBMesh` would | ||||
| * return loop data from BMesh itself. */ | * return loop data from BMesh itself. */ | ||||
| if (mesh->edit_mesh != nullptr && mesh->runtime->edit_data) { | if (mesh->edit_mesh != nullptr && mesh->runtime->edit_data) { | ||||
| BMEditMesh *em = mesh->edit_mesh; | BMEditMesh *em = mesh->edit_mesh; | ||||
| BMesh *bm = em->bm; | BMesh *bm = em->bm; | ||||
| BMIter iter; | BMIter iter; | ||||
| BMFace *efa; | BMFace *efa; | ||||
| Show All 24 Lines | |||||
| } | } | ||||
| else { | else { | ||||
| const float(*loop_normals)[3] = (flag & MESH_FOREACH_USE_NORMAL) ? | const float(*loop_normals)[3] = (flag & MESH_FOREACH_USE_NORMAL) ? | ||||
| static_cast<const float(*)[3]>( | static_cast<const float(*)[3]>( | ||||
| CustomData_get_layer(&mesh->ldata, CD_NORMAL)) : | CustomData_get_layer(&mesh->ldata, CD_NORMAL)) : | ||||
| nullptr; | nullptr; | ||||
| const float(*positions)[3] = BKE_mesh_vert_positions(mesh); | const float(*positions)[3] = BKE_mesh_vert_positions(mesh); | ||||
| const MLoop *ml = BKE_mesh_loops(mesh); | const Span<int> corner_verts = mesh->corner_verts(); | ||||
| const MPoly *mp = BKE_mesh_polys(mesh); | const MPoly *mp = BKE_mesh_polys(mesh); | ||||
| const int *v_index = static_cast<const int *>( | const int *v_index = static_cast<const int *>( | ||||
| CustomData_get_layer(&mesh->vdata, CD_ORIGINDEX)); | CustomData_get_layer(&mesh->vdata, CD_ORIGINDEX)); | ||||
| const int *f_index = static_cast<const int *>( | const int *f_index = static_cast<const int *>( | ||||
| CustomData_get_layer(&mesh->pdata, CD_ORIGINDEX)); | CustomData_get_layer(&mesh->pdata, CD_ORIGINDEX)); | ||||
| int p_idx, i; | int p_idx, i; | ||||
| if (v_index || f_index) { | if (v_index || f_index) { | ||||
| for (p_idx = 0; p_idx < mesh->totpoly; p_idx++, mp++) { | for (p_idx = 0; p_idx < mesh->totpoly; p_idx++, mp++) { | ||||
| for (i = 0; i < mp->totloop; i++, ml++) { | for (i = 0; i < mp->totloop; i++) { | ||||
| const int v_idx = v_index ? v_index[ml->v] : ml->v; | const int vert = corner_verts[i]; | ||||
| const int v_idx = v_index ? v_index[vert] : vert; | |||||
| const int f_idx = f_index ? f_index[p_idx] : p_idx; | const int f_idx = f_index ? f_index[p_idx] : p_idx; | ||||
| const float *no = loop_normals ? *loop_normals++ : nullptr; | const float *no = loop_normals ? *loop_normals++ : nullptr; | ||||
| if (ELEM(ORIGINDEX_NONE, v_idx, f_idx)) { | if (ELEM(ORIGINDEX_NONE, v_idx, f_idx)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| func(userData, v_idx, f_idx, positions[ml->v], no); | func(userData, v_idx, f_idx, positions[vert], no); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| for (p_idx = 0; p_idx < mesh->totpoly; p_idx++, mp++) { | for (p_idx = 0; p_idx < mesh->totpoly; p_idx++, mp++) { | ||||
| for (i = 0; i < mp->totloop; i++, ml++) { | for (i = 0; i < mp->totloop; i++) { | ||||
| const int v_idx = ml->v; | const int vert = corner_verts[i]; | ||||
| const int f_idx = p_idx; | const int f_idx = p_idx; | ||||
| const float *no = loop_normals ? *loop_normals++ : nullptr; | const float *no = loop_normals ? *loop_normals++ : nullptr; | ||||
| func(userData, v_idx, f_idx, positions[ml->v], no); | func(userData, vert, f_idx, positions[vert], no); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void BKE_mesh_foreach_mapped_face_center( | void BKE_mesh_foreach_mapped_face_center( | ||||
| Mesh *mesh, | Mesh *mesh, | ||||
| void (*func)(void *userData, int index, const float cent[3], const float no[3]), | void (*func)(void *userData, int index, const float cent[3], const float no[3]), | ||||
| void *userData, | void *userData, | ||||
| MeshForeachFlag flag) | MeshForeachFlag flag) | ||||
| { | { | ||||
| using namespace blender; | |||||
| if (mesh->edit_mesh != nullptr && mesh->runtime->edit_data != nullptr) { | if (mesh->edit_mesh != nullptr && mesh->runtime->edit_data != nullptr) { | ||||
| BMEditMesh *em = mesh->edit_mesh; | BMEditMesh *em = mesh->edit_mesh; | ||||
| BMesh *bm = em->bm; | BMesh *bm = em->bm; | ||||
| const float(*polyCos)[3]; | const float(*polyCos)[3]; | ||||
| const float(*polyNos)[3]; | const float(*polyNos)[3]; | ||||
| BMFace *efa; | BMFace *efa; | ||||
| BMIter iter; | BMIter iter; | ||||
| int i; | int i; | ||||
| Show All 20 Lines | |||||
| const float *no = (flag & MESH_FOREACH_USE_NORMAL) ? efa->no : nullptr; | const float *no = (flag & MESH_FOREACH_USE_NORMAL) ? efa->no : nullptr; | ||||
| func(userData, i, polyCos[i], no); | func(userData, i, polyCos[i], no); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| const float(*positions)[3] = BKE_mesh_vert_positions(mesh); | const float(*positions)[3] = BKE_mesh_vert_positions(mesh); | ||||
| const MPoly *mp = BKE_mesh_polys(mesh); | const MPoly *mp = BKE_mesh_polys(mesh); | ||||
| const MLoop *loops = BKE_mesh_loops(mesh); | const Span<int> corner_verts = mesh->corner_verts(); | ||||
| const MLoop *ml; | |||||
| float _no_buf[3]; | float _no_buf[3]; | ||||
| float *no = (flag & MESH_FOREACH_USE_NORMAL) ? _no_buf : nullptr; | float *no = (flag & MESH_FOREACH_USE_NORMAL) ? _no_buf : nullptr; | ||||
| const int *index = static_cast<const int *>(CustomData_get_layer(&mesh->pdata, CD_ORIGINDEX)); | const int *index = static_cast<const int *>(CustomData_get_layer(&mesh->pdata, CD_ORIGINDEX)); | ||||
| if (index) { | if (index) { | ||||
| for (int i = 0; i < mesh->totpoly; i++, mp++) { | for (int i = 0; i < mesh->totpoly; i++, mp++) { | ||||
| const int orig = *index++; | const int orig = *index++; | ||||
| if (orig == ORIGINDEX_NONE) { | if (orig == ORIGINDEX_NONE) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| float cent[3]; | float cent[3]; | ||||
| ml = &loops[mp->loopstart]; | BKE_mesh_calc_poly_center(mp, &corner_verts[mp->loopstart], positions, cent); | ||||
| BKE_mesh_calc_poly_center(mp, ml, positions, cent); | |||||
| if (flag & MESH_FOREACH_USE_NORMAL) { | if (flag & MESH_FOREACH_USE_NORMAL) { | ||||
| BKE_mesh_calc_poly_normal(mp, ml, positions, no); | BKE_mesh_calc_poly_normal(mp, &corner_verts[mp->loopstart], positions, no); | ||||
| } | } | ||||
| func(userData, orig, cent, no); | func(userData, orig, cent, no); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| for (int i = 0; i < mesh->totpoly; i++, mp++) { | for (int i = 0; i < mesh->totpoly; i++, mp++) { | ||||
| float cent[3]; | float cent[3]; | ||||
| ml = &loops[mp->loopstart]; | BKE_mesh_calc_poly_center(mp, &corner_verts[mp->loopstart], positions, cent); | ||||
| BKE_mesh_calc_poly_center(mp, ml, positions, cent); | |||||
| if (flag & MESH_FOREACH_USE_NORMAL) { | if (flag & MESH_FOREACH_USE_NORMAL) { | ||||
| BKE_mesh_calc_poly_normal(mp, ml, positions, no); | BKE_mesh_calc_poly_normal(mp, &corner_verts[mp->loopstart], positions, no); | ||||
| } | } | ||||
| func(userData, i, cent, no); | func(userData, i, cent, no); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void BKE_mesh_foreach_mapped_subdiv_face_center( | void BKE_mesh_foreach_mapped_subdiv_face_center( | ||||
| Mesh *mesh, | Mesh *mesh, | ||||
| void (*func)(void *userData, int index, const float cent[3], const float no[3]), | void (*func)(void *userData, int index, const float cent[3], const float no[3]), | ||||
| void *userData, | void *userData, | ||||
| MeshForeachFlag flag) | MeshForeachFlag flag) | ||||
| { | { | ||||
| const float(*positions)[3] = BKE_mesh_vert_positions(mesh); | const float(*positions)[3] = BKE_mesh_vert_positions(mesh); | ||||
| const MPoly *mp = BKE_mesh_polys(mesh); | const MPoly *mp = BKE_mesh_polys(mesh); | ||||
| const MLoop *loops = BKE_mesh_loops(mesh); | const blender::Span<int> corner_verts = mesh->corner_verts(); | ||||
| const MLoop *ml; | |||||
| const float(*vert_normals)[3] = (flag & MESH_FOREACH_USE_NORMAL) ? | const float(*vert_normals)[3] = (flag & MESH_FOREACH_USE_NORMAL) ? | ||||
| BKE_mesh_vertex_normals_ensure(mesh) : | BKE_mesh_vertex_normals_ensure(mesh) : | ||||
| nullptr; | nullptr; | ||||
| const int *index = static_cast<const int *>(CustomData_get_layer(&mesh->pdata, CD_ORIGINDEX)); | const int *index = static_cast<const int *>(CustomData_get_layer(&mesh->pdata, CD_ORIGINDEX)); | ||||
| const BLI_bitmap *facedot_tags = mesh->runtime->subsurf_face_dot_tags; | const BLI_bitmap *facedot_tags = mesh->runtime->subsurf_face_dot_tags; | ||||
| BLI_assert(facedot_tags != nullptr); | BLI_assert(facedot_tags != nullptr); | ||||
| if (index) { | if (index) { | ||||
| for (int i = 0; i < mesh->totpoly; i++, mp++) { | for (int i = 0; i < mesh->totpoly; i++, mp++) { | ||||
| const int orig = *index++; | const int orig = *index++; | ||||
| if (orig == ORIGINDEX_NONE) { | if (orig == ORIGINDEX_NONE) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| ml = &loops[mp->loopstart]; | for (int j = 0; j < mp->totloop; j++) { | ||||
| for (int j = 0; j < mp->totloop; j++, ml++) { | const int vert = corner_verts[mp->loopstart + j]; | ||||
| if (BLI_BITMAP_TEST(facedot_tags, ml->v)) { | if (BLI_BITMAP_TEST(facedot_tags, vert)) { | ||||
| func(userData, | func(userData, | ||||
| orig, | orig, | ||||
| positions[ml->v], | positions[vert], | ||||
| (flag & MESH_FOREACH_USE_NORMAL) ? vert_normals[ml->v] : nullptr); | (flag & MESH_FOREACH_USE_NORMAL) ? vert_normals[vert] : nullptr); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| for (int i = 0; i < mesh->totpoly; i++, mp++) { | for (int i = 0; i < mesh->totpoly; i++, mp++) { | ||||
| ml = &loops[mp->loopstart]; | for (int j = 0; j < mp->totloop; j++) { | ||||
| for (int j = 0; j < mp->totloop; j++, ml++) { | const int vert = corner_verts[mp->loopstart + j]; | ||||
| if (BLI_BITMAP_TEST(facedot_tags, ml->v)) { | if (BLI_BITMAP_TEST(facedot_tags, vert)) { | ||||
| func(userData, | func(userData, | ||||
| i, | i, | ||||
| positions[ml->v], | positions[vert], | ||||
| (flag & MESH_FOREACH_USE_NORMAL) ? vert_normals[ml->v] : nullptr); | (flag & MESH_FOREACH_USE_NORMAL) ? vert_normals[vert] : nullptr); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Helpers based on above foreach loopers> */ | /* Helpers based on above foreach loopers> */ | ||||
| Show All 30 Lines | |||||