Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mesh.cc
| Show First 20 Lines • Show All 1,842 Lines • ▼ Show 20 Lines | MVert *mv = (MVert *)CustomData_duplicate_referenced_layer( | ||||
| &mesh->vdata, CD_MVERT, mesh->totvert); | &mesh->vdata, CD_MVERT, mesh->totvert); | ||||
| mesh->mvert = mv; | mesh->mvert = mv; | ||||
| for (int i = 0; i < mesh->totvert; i++, mv++) { | for (int i = 0; i < mesh->totvert; i++, mv++) { | ||||
| mul_v3_m4v3(mv->co, mat, vert_coords[i]); | mul_v3_m4v3(mv->co, mat, vert_coords[i]); | ||||
| } | } | ||||
| BKE_mesh_tag_coords_changed(mesh); | BKE_mesh_tag_coords_changed(mesh); | ||||
| } | } | ||||
| void BKE_mesh_calc_normals_split_ex(Mesh *mesh, MLoopNorSpaceArray *r_lnors_spacearr) | static float (*ensure_corner_normal_layer(Mesh &mesh))[3] | ||||
| { | { | ||||
| float(*r_loopnors)[3]; | float(*r_loopnors)[3]; | ||||
| if (CustomData_has_layer(&mesh.ldata, CD_NORMAL)) { | |||||
| r_loopnors = (float(*)[3])CustomData_get_layer(&mesh.ldata, CD_NORMAL); | |||||
| memset(r_loopnors, 0, sizeof(float[3]) * mesh.totloop); | |||||
| } | |||||
| else { | |||||
| r_loopnors = (float(*)[3])CustomData_add_layer( | |||||
| &mesh.ldata, CD_NORMAL, CD_CALLOC, nullptr, mesh.totloop); | |||||
| CustomData_set_layer_flag(&mesh.ldata, CD_NORMAL, CD_FLAG_TEMPORARY); | |||||
| } | |||||
| return r_loopnors; | |||||
| } | |||||
| void BKE_mesh_calc_normals_split_ex(Mesh *mesh, | |||||
| MLoopNorSpaceArray *r_lnors_spacearr, | |||||
| float (*r_corner_normals)[3]) | |||||
| { | |||||
| short(*clnors)[2] = nullptr; | short(*clnors)[2] = nullptr; | ||||
| /* Note that we enforce computing clnors when the clnor space array is requested by caller here. | /* Note that we enforce computing clnors when the clnor space array is requested by caller here. | ||||
| * However, we obviously only use the auto-smooth angle threshold | * However, we obviously only use the auto-smooth angle threshold | ||||
| * only in case auto-smooth is enabled. */ | * only in case auto-smooth is enabled. */ | ||||
| const bool use_split_normals = (r_lnors_spacearr != nullptr) || | const bool use_split_normals = (r_lnors_spacearr != nullptr) || | ||||
| ((mesh->flag & ME_AUTOSMOOTH) != 0); | ((mesh->flag & ME_AUTOSMOOTH) != 0); | ||||
| const float split_angle = (mesh->flag & ME_AUTOSMOOTH) != 0 ? mesh->smoothresh : (float)M_PI; | const float split_angle = (mesh->flag & ME_AUTOSMOOTH) != 0 ? mesh->smoothresh : (float)M_PI; | ||||
| if (CustomData_has_layer(&mesh->ldata, CD_NORMAL)) { | |||||
| r_loopnors = (float(*)[3])CustomData_get_layer(&mesh->ldata, CD_NORMAL); | |||||
| memset(r_loopnors, 0, sizeof(float[3]) * mesh->totloop); | |||||
| } | |||||
| else { | |||||
| r_loopnors = (float(*)[3])CustomData_add_layer( | |||||
| &mesh->ldata, CD_NORMAL, CD_CALLOC, nullptr, mesh->totloop); | |||||
| CustomData_set_layer_flag(&mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); | |||||
| } | |||||
| /* may be nullptr */ | /* may be nullptr */ | ||||
| clnors = (short(*)[2])CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL); | clnors = (short(*)[2])CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL); | ||||
| BKE_mesh_normals_loop_split(mesh->mvert, | BKE_mesh_normals_loop_split(mesh->mvert, | ||||
| BKE_mesh_vertex_normals_ensure(mesh), | BKE_mesh_vertex_normals_ensure(mesh), | ||||
| mesh->totvert, | mesh->totvert, | ||||
| mesh->medge, | mesh->medge, | ||||
| mesh->totedge, | mesh->totedge, | ||||
| mesh->mloop, | mesh->mloop, | ||||
| r_loopnors, | r_corner_normals, | ||||
| mesh->totloop, | mesh->totloop, | ||||
| mesh->mpoly, | mesh->mpoly, | ||||
| BKE_mesh_poly_normals_ensure(mesh), | BKE_mesh_poly_normals_ensure(mesh), | ||||
| mesh->totpoly, | mesh->totpoly, | ||||
| use_split_normals, | use_split_normals, | ||||
| split_angle, | split_angle, | ||||
| r_lnors_spacearr, | r_lnors_spacearr, | ||||
| clnors, | clnors, | ||||
| nullptr); | nullptr); | ||||
| BKE_mesh_assert_normals_dirty_or_calculated(mesh); | BKE_mesh_assert_normals_dirty_or_calculated(mesh); | ||||
| } | } | ||||
| void BKE_mesh_calc_normals_split(Mesh *mesh) | void BKE_mesh_calc_normals_split(Mesh *mesh) | ||||
| { | { | ||||
| BKE_mesh_calc_normals_split_ex(mesh, nullptr); | BKE_mesh_calc_normals_split_ex(mesh, nullptr, ensure_corner_normal_layer(*mesh)); | ||||
| } | } | ||||
| /* Split faces helper functions. */ | /* Split faces helper functions. */ | ||||
| struct SplitFaceNewVert { | struct SplitFaceNewVert { | ||||
| struct SplitFaceNewVert *next; | struct SplitFaceNewVert *next; | ||||
| int new_index; | int new_index; | ||||
| int orig_index; | int orig_index; | ||||
| ▲ Show 20 Lines • Show All 202 Lines • ▼ Show 20 Lines | void BKE_mesh_split_faces(Mesh *mesh, bool free_loop_normals) | ||||
| if (num_polys == 0) { | if (num_polys == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| BKE_mesh_tessface_clear(mesh); | BKE_mesh_tessface_clear(mesh); | ||||
| MLoopNorSpaceArray lnors_spacearr = {nullptr}; | MLoopNorSpaceArray lnors_spacearr = {nullptr}; | ||||
| /* Compute loop normals and loop normal spaces (a.k.a. smooth fans of faces around vertices). */ | /* Compute loop normals and loop normal spaces (a.k.a. smooth fans of faces around vertices). */ | ||||
| BKE_mesh_calc_normals_split_ex(mesh, &lnors_spacearr); | BKE_mesh_calc_normals_split_ex(mesh, &lnors_spacearr, ensure_corner_normal_layer(*mesh)); | ||||
| /* Stealing memarena from loop normals space array. */ | /* Stealing memarena from loop normals space array. */ | ||||
| MemArena *memarena = lnors_spacearr.mem; | MemArena *memarena = lnors_spacearr.mem; | ||||
| SplitFaceNewVert *new_verts = nullptr; | SplitFaceNewVert *new_verts = nullptr; | ||||
| SplitFaceNewEdge *new_edges = nullptr; | SplitFaceNewEdge *new_edges = nullptr; | ||||
| /* Ensure we own the layers, we need to do this before split_faces_prepare_new_verts as it will | /* Ensure we own the layers, we need to do this before split_faces_prepare_new_verts as it will | ||||
| * directly assign new indices to existing edges and loops. */ | * directly assign new indices to existing edges and loops. */ | ||||
| ▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines | |||||