Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/mesh_normals.cc
| Show First 20 Lines • Show All 300 Lines • ▼ Show 20 Lines | static void mesh_calc_normals_poly_and_vertex_finalize_fn( | ||||
| float *no = data->vnors[vidx]; | float *no = data->vnors[vidx]; | ||||
| if (UNLIKELY(normalize_v3(no) == 0.0f)) { | if (UNLIKELY(normalize_v3(no) == 0.0f)) { | ||||
| /* Following Mesh convention; we use vertex coordinate itself for normal in this case. */ | /* Following Mesh convention; we use vertex coordinate itself for normal in this case. */ | ||||
| normalize_v3_v3(no, mv->co); | normalize_v3_v3(no, mv->co); | ||||
| } | } | ||||
| } | } | ||||
| static void mesh_calc_normals_poly_and_vertex(const MVert *mvert, | void BKE_mesh_calc_normals_poly_and_vertex(const MVert *mvert, | ||||
| const int mvert_len, | const int mvert_len, | ||||
| const MLoop *mloop, | const MLoop *mloop, | ||||
| const int UNUSED(mloop_len), | const int UNUSED(mloop_len), | ||||
| const MPoly *mpoly, | const MPoly *mpoly, | ||||
| const int mpoly_len, | const int mpoly_len, | ||||
| float (*r_poly_normals)[3], | float (*r_poly_normals)[3], | ||||
| float (*r_vert_normals)[3]) | float (*r_vert_normals)[3]) | ||||
| { | { | ||||
| TaskParallelSettings settings; | TaskParallelSettings settings; | ||||
| BLI_parallel_range_settings_defaults(&settings); | BLI_parallel_range_settings_defaults(&settings); | ||||
| settings.min_iter_per_thread = 1024; | settings.min_iter_per_thread = 1024; | ||||
| memset(r_vert_normals, 0, sizeof(*r_vert_normals) * (size_t)mvert_len); | memset(r_vert_normals, 0, sizeof(*r_vert_normals) * (size_t)mvert_len); | ||||
| MeshCalcNormalsData_PolyAndVertex data = {}; | MeshCalcNormalsData_PolyAndVertex data = {}; | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | const float (*BKE_mesh_vertex_normals_ensure(const Mesh *mesh))[3] | ||||
| /* Isolate task because a mutex is locked and computing normals is multi-threaded. */ | /* Isolate task because a mutex is locked and computing normals is multi-threaded. */ | ||||
| blender::threading::isolate_task([&]() { | blender::threading::isolate_task([&]() { | ||||
| Mesh &mesh_mutable = *const_cast<Mesh *>(mesh); | Mesh &mesh_mutable = *const_cast<Mesh *>(mesh); | ||||
| vert_normals = BKE_mesh_vertex_normals_for_write(&mesh_mutable); | vert_normals = BKE_mesh_vertex_normals_for_write(&mesh_mutable); | ||||
| poly_normals = BKE_mesh_poly_normals_for_write(&mesh_mutable); | poly_normals = BKE_mesh_poly_normals_for_write(&mesh_mutable); | ||||
| mesh_calc_normals_poly_and_vertex(mesh_mutable.mvert, | BKE_mesh_calc_normals_poly_and_vertex(mesh_mutable.mvert, | ||||
| mesh_mutable.totvert, | mesh_mutable.totvert, | ||||
| mesh_mutable.mloop, | mesh_mutable.mloop, | ||||
| mesh_mutable.totloop, | mesh_mutable.totloop, | ||||
| mesh_mutable.mpoly, | mesh_mutable.mpoly, | ||||
| mesh_mutable.totpoly, | mesh_mutable.totpoly, | ||||
| poly_normals, | poly_normals, | ||||
| vert_normals); | vert_normals); | ||||
| BKE_mesh_vertex_normals_clear_dirty(&mesh_mutable); | BKE_mesh_vertex_normals_clear_dirty(&mesh_mutable); | ||||
| BKE_mesh_poly_normals_clear_dirty(&mesh_mutable); | BKE_mesh_poly_normals_clear_dirty(&mesh_mutable); | ||||
| }); | }); | ||||
| BLI_mutex_unlock(normals_mutex); | BLI_mutex_unlock(normals_mutex); | ||||
| return vert_normals; | return vert_normals; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 992 Lines • Show Last 20 Lines | |||||