Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/subdiv_converter_mesh.cc
| Show All 31 Lines | |||||
| #define BUGGY_SIMPLE_SCHEME_WORKAROUND 1 | #define BUGGY_SIMPLE_SCHEME_WORKAROUND 1 | ||||
| struct ConverterStorage { | struct ConverterStorage { | ||||
| SubdivSettings settings; | SubdivSettings settings; | ||||
| const Mesh *mesh; | const Mesh *mesh; | ||||
| const float (*vert_positions)[3]; | const float (*vert_positions)[3]; | ||||
| const MEdge *edges; | const MEdge *edges; | ||||
| const MPoly *polys; | const MPoly *polys; | ||||
| const MLoop *loops; | const int *corner_verts; | ||||
| const int *corner_edges; | |||||
| /* CustomData layer for vertex sharpnesses. */ | /* CustomData layer for vertex sharpnesses. */ | ||||
| const float *cd_vertex_crease; | const float *cd_vertex_crease; | ||||
| /* CustomData layer for edge sharpness. */ | /* CustomData layer for edge sharpness. */ | ||||
| const float *cd_edge_crease; | const float *cd_edge_crease; | ||||
| /* Indexed by loop index, value denotes index of face-varying vertex | /* Indexed by loop index, value denotes index of face-varying vertex | ||||
| * which corresponds to the UV coordinate. | * which corresponds to the UV coordinate. | ||||
| */ | */ | ||||
| ▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | |||||
| } | } | ||||
| static void get_face_vertices(const OpenSubdiv_Converter *converter, | static void get_face_vertices(const OpenSubdiv_Converter *converter, | ||||
| int manifold_face_index, | int manifold_face_index, | ||||
| int *manifold_face_vertices) | int *manifold_face_vertices) | ||||
| { | { | ||||
| ConverterStorage *storage = static_cast<ConverterStorage *>(converter->user_data); | ConverterStorage *storage = static_cast<ConverterStorage *>(converter->user_data); | ||||
| const MPoly *poly = &storage->polys[manifold_face_index]; | const MPoly *poly = &storage->polys[manifold_face_index]; | ||||
| const MLoop *mloop = storage->loops; | for (int i = 0; i < poly->totloop; i++) { | ||||
| for (int corner = 0; corner < poly->totloop; corner++) { | const int vert = storage->corner_verts[poly->loopstart + i]; | ||||
| manifold_face_vertices[corner] = | manifold_face_vertices[i] = storage->manifold_vertex_index[vert]; | ||||
| storage->manifold_vertex_index[mloop[poly->loopstart + corner].v]; | |||||
| } | } | ||||
| } | } | ||||
| static void get_edge_vertices(const OpenSubdiv_Converter *converter, | static void get_edge_vertices(const OpenSubdiv_Converter *converter, | ||||
| int manifold_edge_index, | int manifold_edge_index, | ||||
| int *manifold_edge_vertices) | int *manifold_edge_vertices) | ||||
| { | { | ||||
| ConverterStorage *storage = static_cast<ConverterStorage *>(converter->user_data); | ConverterStorage *storage = static_cast<ConverterStorage *>(converter->user_data); | ||||
| ▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | static void precalc_uv_layer(const OpenSubdiv_Converter *converter, const int layer_index) | ||||
| if (storage->loop_uv_indices == NULL) { | if (storage->loop_uv_indices == NULL) { | ||||
| storage->loop_uv_indices = static_cast<int *>( | storage->loop_uv_indices = static_cast<int *>( | ||||
| MEM_malloc_arrayN(mesh->totloop, sizeof(int), "loop uv vertex index")); | MEM_malloc_arrayN(mesh->totloop, sizeof(int), "loop uv vertex index")); | ||||
| } | } | ||||
| UvVertMap *uv_vert_map = BKE_mesh_uv_vert_map_create( | UvVertMap *uv_vert_map = BKE_mesh_uv_vert_map_create( | ||||
| storage->polys, | storage->polys, | ||||
| (const bool *)CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, ".hide_poly"), | (const bool *)CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, ".hide_poly"), | ||||
| (const bool *)CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, ".select_poly"), | (const bool *)CustomData_get_layer_named(&mesh->pdata, CD_PROP_BOOL, ".select_poly"), | ||||
| storage->loops, | storage->corner_verts, | ||||
| mloopuv, | mloopuv, | ||||
| num_poly, | num_poly, | ||||
| num_vert, | num_vert, | ||||
| limit, | limit, | ||||
| false, | false, | ||||
| true); | true); | ||||
| /* NOTE: First UV vertex is supposed to be always marked as separate. */ | /* NOTE: First UV vertex is supposed to be always marked as separate. */ | ||||
| storage->num_uv_coordinates = -1; | storage->num_uv_coordinates = -1; | ||||
| ▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | static void initialize_manifold_index_array(const BLI_bitmap *used_map, | ||||
| } | } | ||||
| *r_num_manifold_elements = num_elements - offset; | *r_num_manifold_elements = num_elements - offset; | ||||
| } | } | ||||
| static void initialize_manifold_indices(ConverterStorage *storage) | static void initialize_manifold_indices(ConverterStorage *storage) | ||||
| { | { | ||||
| const Mesh *mesh = storage->mesh; | const Mesh *mesh = storage->mesh; | ||||
| const MEdge *medge = storage->edges; | const MEdge *medge = storage->edges; | ||||
| const MLoop *mloop = storage->loops; | |||||
| const MPoly *mpoly = storage->polys; | const MPoly *mpoly = storage->polys; | ||||
| /* Set bits of elements which are not loose. */ | /* Set bits of elements which are not loose. */ | ||||
| BLI_bitmap *vert_used_map = BLI_BITMAP_NEW(mesh->totvert, "vert used map"); | BLI_bitmap *vert_used_map = BLI_BITMAP_NEW(mesh->totvert, "vert used map"); | ||||
| BLI_bitmap *edge_used_map = BLI_BITMAP_NEW(mesh->totedge, "edge used map"); | BLI_bitmap *edge_used_map = BLI_BITMAP_NEW(mesh->totedge, "edge used map"); | ||||
| for (int poly_index = 0; poly_index < mesh->totpoly; poly_index++) { | for (int poly_index = 0; poly_index < mesh->totpoly; poly_index++) { | ||||
| const MPoly *poly = &mpoly[poly_index]; | const MPoly *poly = &mpoly[poly_index]; | ||||
| for (int corner = 0; corner < poly->totloop; corner++) { | for (int i = 0; i < poly->totloop; i++) { | ||||
| const MLoop *loop = &mloop[poly->loopstart + corner]; | const int corner = poly->loopstart + i; | ||||
| BLI_BITMAP_ENABLE(vert_used_map, loop->v); | BLI_BITMAP_ENABLE(vert_used_map, storage->corner_verts[corner]); | ||||
| BLI_BITMAP_ENABLE(edge_used_map, loop->e); | BLI_BITMAP_ENABLE(edge_used_map, storage->corner_edges[corner]); | ||||
| } | } | ||||
| } | } | ||||
| initialize_manifold_index_array(vert_used_map, | initialize_manifold_index_array(vert_used_map, | ||||
| mesh->totvert, | mesh->totvert, | ||||
| &storage->manifold_vertex_index, | &storage->manifold_vertex_index, | ||||
| &storage->manifold_vertex_index_reverse, | &storage->manifold_vertex_index_reverse, | ||||
| &storage->num_manifold_vertices); | &storage->num_manifold_vertices); | ||||
| initialize_manifold_index_array(edge_used_map, | initialize_manifold_index_array(edge_used_map, | ||||
| Show All 21 Lines | |||||
| { | { | ||||
| ConverterStorage *user_data = static_cast<ConverterStorage *>( | ConverterStorage *user_data = static_cast<ConverterStorage *>( | ||||
| MEM_mallocN(sizeof(ConverterStorage), __func__)); | MEM_mallocN(sizeof(ConverterStorage), __func__)); | ||||
| user_data->settings = *settings; | user_data->settings = *settings; | ||||
| user_data->mesh = mesh; | user_data->mesh = mesh; | ||||
| user_data->vert_positions = BKE_mesh_vert_positions(mesh); | user_data->vert_positions = BKE_mesh_vert_positions(mesh); | ||||
| user_data->edges = BKE_mesh_edges(mesh); | user_data->edges = BKE_mesh_edges(mesh); | ||||
| user_data->polys = BKE_mesh_polys(mesh); | user_data->polys = BKE_mesh_polys(mesh); | ||||
| user_data->loops = BKE_mesh_loops(mesh); | user_data->corner_verts = mesh->corner_verts().data(); | ||||
| user_data->corner_edges = mesh->corner_edges().data(); | |||||
| user_data->cd_vertex_crease = static_cast<const float *>( | user_data->cd_vertex_crease = static_cast<const float *>( | ||||
| CustomData_get_layer(&mesh->vdata, CD_CREASE)); | CustomData_get_layer(&mesh->vdata, CD_CREASE)); | ||||
| user_data->cd_edge_crease = static_cast<const float *>( | user_data->cd_edge_crease = static_cast<const float *>( | ||||
| CustomData_get_layer(&mesh->edata, CD_CREASE)); | CustomData_get_layer(&mesh->edata, CD_CREASE)); | ||||
| user_data->loop_uv_indices = NULL; | user_data->loop_uv_indices = NULL; | ||||
| initialize_manifold_indices(user_data); | initialize_manifold_indices(user_data); | ||||
| converter->user_data = user_data; | converter->user_data = user_data; | ||||
| } | } | ||||
| void BKE_subdiv_converter_init_for_mesh(OpenSubdiv_Converter *converter, | void BKE_subdiv_converter_init_for_mesh(OpenSubdiv_Converter *converter, | ||||
| const SubdivSettings *settings, | const SubdivSettings *settings, | ||||
| const Mesh *mesh) | const Mesh *mesh) | ||||
| { | { | ||||
| init_functions(converter); | init_functions(converter); | ||||
| init_user_data(converter, settings, mesh); | init_user_data(converter, settings, mesh); | ||||
| } | } | ||||