Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/key.cc
| Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | |||||
| if (r_vert_normals == nullptr && r_poly_normals == nullptr && r_loop_normals == nullptr) { | if (r_vert_normals == nullptr && r_poly_normals == nullptr && r_loop_normals == nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| float(*positions)[3] = static_cast<float(*)[3]>(MEM_dupallocN(BKE_mesh_vert_positions(mesh))); | float(*positions)[3] = static_cast<float(*)[3]>(MEM_dupallocN(BKE_mesh_vert_positions(mesh))); | ||||
| BKE_keyblock_convert_to_mesh(kb, positions, mesh->totvert); | BKE_keyblock_convert_to_mesh(kb, positions, mesh->totvert); | ||||
| const MEdge *edges = BKE_mesh_edges(mesh); | const MEdge *edges = BKE_mesh_edges(mesh); | ||||
| const MPoly *polys = BKE_mesh_polys(mesh); | const MPoly *polys = BKE_mesh_polys(mesh); | ||||
| const MLoop *loops = BKE_mesh_loops(mesh); | const blender::Span<int> corner_verts = mesh->corner_verts(); | ||||
| const blender::Span<int> corner_edges = mesh->corner_edges(); | |||||
| const bool loop_normals_needed = r_loop_normals != nullptr; | const bool loop_normals_needed = r_loop_normals != nullptr; | ||||
| const bool vert_normals_needed = r_vert_normals != nullptr || loop_normals_needed; | const bool vert_normals_needed = r_vert_normals != nullptr || loop_normals_needed; | ||||
| const bool poly_normals_needed = r_poly_normals != nullptr || vert_normals_needed || | const bool poly_normals_needed = r_poly_normals != nullptr || vert_normals_needed || | ||||
| loop_normals_needed; | loop_normals_needed; | ||||
| float(*vert_normals)[3] = r_vert_normals; | float(*vert_normals)[3] = r_vert_normals; | ||||
| float(*poly_normals)[3] = r_poly_normals; | float(*poly_normals)[3] = r_poly_normals; | ||||
| bool free_vert_normals = false; | bool free_vert_normals = false; | ||||
| bool free_poly_normals = false; | bool free_poly_normals = false; | ||||
| if (vert_normals_needed && r_vert_normals == nullptr) { | if (vert_normals_needed && r_vert_normals == nullptr) { | ||||
| vert_normals = static_cast<float(*)[3]>( | vert_normals = static_cast<float(*)[3]>( | ||||
| MEM_malloc_arrayN(mesh->totvert, sizeof(float[3]), __func__)); | MEM_malloc_arrayN(mesh->totvert, sizeof(float[3]), __func__)); | ||||
| free_vert_normals = true; | free_vert_normals = true; | ||||
| } | } | ||||
| if (poly_normals_needed && r_poly_normals == nullptr) { | if (poly_normals_needed && r_poly_normals == nullptr) { | ||||
| poly_normals = static_cast<float(*)[3]>( | poly_normals = static_cast<float(*)[3]>( | ||||
| MEM_malloc_arrayN(mesh->totpoly, sizeof(float[3]), __func__)); | MEM_malloc_arrayN(mesh->totpoly, sizeof(float[3]), __func__)); | ||||
| free_poly_normals = true; | free_poly_normals = true; | ||||
| } | } | ||||
| if (poly_normals_needed) { | if (poly_normals_needed) { | ||||
| BKE_mesh_calc_normals_poly( | BKE_mesh_calc_normals_poly(positions, | ||||
| positions, mesh->totvert, loops, mesh->totloop, polys, mesh->totpoly, poly_normals); | mesh->totvert, | ||||
| corner_verts.data(), | |||||
| mesh->totloop, | |||||
| polys, | |||||
| mesh->totpoly, | |||||
| poly_normals); | |||||
| } | } | ||||
| if (vert_normals_needed) { | if (vert_normals_needed) { | ||||
| BKE_mesh_calc_normals_poly_and_vertex(positions, | BKE_mesh_calc_normals_poly_and_vertex(positions, | ||||
| mesh->totvert, | mesh->totvert, | ||||
| loops, | corner_verts.data(), | ||||
| mesh->totloop, | mesh->totloop, | ||||
| polys, | polys, | ||||
| mesh->totpoly, | mesh->totpoly, | ||||
| poly_normals, | poly_normals, | ||||
| vert_normals); | vert_normals); | ||||
| } | } | ||||
| if (loop_normals_needed) { | if (loop_normals_needed) { | ||||
| short(*clnors)[2] = static_cast<short(*)[2]>(CustomData_get_layer_for_write( | short(*clnors)[2] = static_cast<short(*)[2]>(CustomData_get_layer_for_write( | ||||
| &mesh->ldata, CD_CUSTOMLOOPNORMAL, mesh->totloop)); /* May be nullptr. */ | &mesh->ldata, CD_CUSTOMLOOPNORMAL, mesh->totloop)); /* May be nullptr. */ | ||||
| const bool *sharp_edges = static_cast<const bool *>( | const bool *sharp_edges = static_cast<const bool *>( | ||||
| CustomData_get_layer_named(&mesh->edata, CD_PROP_BOOL, "sharp_edge")); | CustomData_get_layer_named(&mesh->edata, CD_PROP_BOOL, "sharp_edge")); | ||||
| BKE_mesh_normals_loop_split(positions, | BKE_mesh_normals_loop_split(positions, | ||||
| vert_normals, | vert_normals, | ||||
| mesh->totvert, | mesh->totvert, | ||||
| edges, | edges, | ||||
| mesh->totedge, | mesh->totedge, | ||||
| loops, | corner_verts.data(), | ||||
| corner_edges.data(), | |||||
| r_loop_normals, | r_loop_normals, | ||||
| mesh->totloop, | mesh->totloop, | ||||
| polys, | polys, | ||||
| poly_normals, | poly_normals, | ||||
| mesh->totpoly, | mesh->totpoly, | ||||
| (mesh->flag & ME_AUTOSMOOTH) != 0, | (mesh->flag & ME_AUTOSMOOTH) != 0, | ||||
| mesh->smoothresh, | mesh->smoothresh, | ||||
| sharp_edges, | sharp_edges, | ||||
| ▲ Show 20 Lines • Show All 92 Lines • Show Last 20 Lines | |||||