Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/multires_unsubdivide.cc
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| MultiresUnsubdivideGrid *grid, | MultiresUnsubdivideGrid *grid, | ||||
| BMVert *v, | BMVert *v, | ||||
| BMFace *f, | BMFace *f, | ||||
| int grid_x, | int grid_x, | ||||
| int grid_y) | int grid_y) | ||||
| { | { | ||||
| Mesh *original_mesh = context->original_mesh; | Mesh *original_mesh = context->original_mesh; | ||||
| const MPoly *polys = BKE_mesh_polys(original_mesh); | const MPoly *polys = BKE_mesh_polys(original_mesh); | ||||
| const MLoop *loops = BKE_mesh_loops(original_mesh); | const blender::Span<int> corner_verts = original_mesh->corner_verts(); | ||||
| const MPoly *poly = &polys[BM_elem_index_get(f)]; | const MPoly *poly = &polys[BM_elem_index_get(f)]; | ||||
| const int corner_vertex_index = BM_elem_index_get(v); | const int corner_vertex_index = BM_elem_index_get(v); | ||||
| /* Calculates an offset to write the grids correctly oriented in the main | /* Calculates an offset to write the grids correctly oriented in the main | ||||
| * #MultiresUnsubdivideGrid. */ | * #MultiresUnsubdivideGrid. */ | ||||
| int loop_offset = 0; | int loop_offset = 0; | ||||
| for (int i = 0; i < poly->totloop; i++) { | for (int i = 0; i < poly->totloop; i++) { | ||||
| const int loop_index = poly->loopstart + i; | const int loop_index = poly->loopstart + i; | ||||
| const MLoop *l = &loops[loop_index]; | if (corner_verts[loop_index] == corner_vertex_index) { | ||||
| if (l->v == corner_vertex_index) { | |||||
| loop_offset = i; | loop_offset = i; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| /* Write the 4 grids of the current quad with the right orientation into the face_grid buffer. */ | /* Write the 4 grids of the current quad with the right orientation into the face_grid buffer. */ | ||||
| const int grid_size = BKE_ccg_gridsize(context->num_original_levels); | const int grid_size = BKE_ccg_gridsize(context->num_original_levels); | ||||
| const int face_grid_size = BKE_ccg_gridsize(context->num_original_levels + 1); | const int face_grid_size = BKE_ccg_gridsize(context->num_original_levels + 1); | ||||
| ▲ Show 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Checks the orientation of the loops to flip the x and y axis when extracting the grid if | * Checks the orientation of the loops to flip the x and y axis when extracting the grid if | ||||
| * necessary. | * necessary. | ||||
| */ | */ | ||||
| static bool multires_unsubdivide_flip_grid_x_axis( | static bool multires_unsubdivide_flip_grid_x_axis( | ||||
| const MPoly *polys, const MLoop *loops, int poly, int loop, int v_x) | const MPoly *polys, const int *corner_verts, int poly, int loop, int v_x) | ||||
| { | { | ||||
| const MPoly *p = &polys[poly]; | const MPoly *p = &polys[poly]; | ||||
| const MLoop *l_first = &loops[p->loopstart]; | const int v_first = corner_verts[p->loopstart]; | ||||
| if ((loop == (p->loopstart + (p->totloop - 1))) && l_first->v == v_x) { | if ((loop == (p->loopstart + (p->totloop - 1))) && v_first == v_x) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| int next_l_index = loop + 1; | int next_l_index = loop + 1; | ||||
| if (next_l_index < p->loopstart + p->totloop) { | if (next_l_index < p->loopstart + p->totloop) { | ||||
| const MLoop *l_next = &loops[next_l_index]; | const int v_next = corner_verts[next_l_index]; | ||||
| if (l_next->v == v_x) { | if (v_next == v_x) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| static void multires_unsubdivide_extract_grids(MultiresUnsubdivideContext *context) | static void multires_unsubdivide_extract_grids(MultiresUnsubdivideContext *context) | ||||
| ▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
| BM_mesh_elem_table_ensure(bm_base_mesh, BM_VERT); | BM_mesh_elem_table_ensure(bm_base_mesh, BM_VERT); | ||||
| BM_mesh_elem_table_ensure(bm_base_mesh, BM_FACE); | BM_mesh_elem_table_ensure(bm_base_mesh, BM_FACE); | ||||
| /* Get the data-layer that contains the loops indices. */ | /* Get the data-layer that contains the loops indices. */ | ||||
| const int base_l_offset = CustomData_get_n_offset( | const int base_l_offset = CustomData_get_n_offset( | ||||
| &bm_base_mesh->ldata, CD_PROP_INT32, base_l_layer_index); | &bm_base_mesh->ldata, CD_PROP_INT32, base_l_layer_index); | ||||
| const MPoly *polys = BKE_mesh_polys(base_mesh); | const MPoly *polys = BKE_mesh_polys(base_mesh); | ||||
| const MLoop *loops = BKE_mesh_loops(base_mesh); | const blender::Span<int> corner_verts = base_mesh->corner_verts(); | ||||
| /* Main loop for extracting the grids. Iterates over the base mesh vertices. */ | /* Main loop for extracting the grids. Iterates over the base mesh vertices. */ | ||||
| BM_ITER_MESH (v, &iter, bm_base_mesh, BM_VERTS_OF_MESH) { | BM_ITER_MESH (v, &iter, bm_base_mesh, BM_VERTS_OF_MESH) { | ||||
| /* For each base mesh vertex, get the corresponding #BMVert of the original mesh using the | /* For each base mesh vertex, get the corresponding #BMVert of the original mesh using the | ||||
| * vertex map. */ | * vertex map. */ | ||||
| const int orig_vertex_index = base_to_orig_vmap[BM_elem_index_get(v)]; | const int orig_vertex_index = base_to_orig_vmap[BM_elem_index_get(v)]; | ||||
| BMVert *vert_original = BM_vert_at_index(bm_original_mesh, orig_vertex_index); | BMVert *vert_original = BM_vert_at_index(bm_original_mesh, orig_vertex_index); | ||||
| Show All 21 Lines | |||||
| if (BM_vert_in_face(base_corner_x, base_face) && | if (BM_vert_in_face(base_corner_x, base_face) && | ||||
| BM_vert_in_face(base_corner_y, base_face)) { | BM_vert_in_face(base_corner_y, base_face)) { | ||||
| /* Get the index of the loop. */ | /* Get the index of the loop. */ | ||||
| const int base_mesh_loop_index = BM_ELEM_CD_GET_INT(lb, base_l_offset); | const int base_mesh_loop_index = BM_ELEM_CD_GET_INT(lb, base_l_offset); | ||||
| const int base_mesh_face_index = BM_elem_index_get(base_face); | const int base_mesh_face_index = BM_elem_index_get(base_face); | ||||
| /* Check the orientation of the loops in case that is needed to flip the x and y axis | /* Check the orientation of the loops in case that is needed to flip the x and y axis | ||||
| * when extracting the grid. */ | * when extracting the grid. */ | ||||
| const bool flip_grid = multires_unsubdivide_flip_grid_x_axis( | const bool flip_grid = multires_unsubdivide_flip_grid_x_axis(polys, | ||||
| polys, loops, base_mesh_face_index, base_mesh_loop_index, corner_x_index); | corner_verts.data(), | ||||
| base_mesh_face_index, | |||||
| base_mesh_loop_index, | |||||
| corner_x_index); | |||||
| /* Extract the grid for that loop. */ | /* Extract the grid for that loop. */ | ||||
| context->base_mesh_grids[base_mesh_loop_index].grid_index = base_mesh_loop_index; | context->base_mesh_grids[base_mesh_loop_index].grid_index = base_mesh_loop_index; | ||||
| multires_unsubdivide_extract_single_grid_from_face_edge( | multires_unsubdivide_extract_single_grid_from_face_edge( | ||||
| context, l->f, l->e, !flip_grid, &context->base_mesh_grids[base_mesh_loop_index]); | context, l->f, l->e, !flip_grid, &context->base_mesh_grids[base_mesh_loop_index]); | ||||
| break; | break; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||