Commit: b97910717e68a59b48f24c514ac7c1c6f5197004 Author: Hans Goudey Date: Sun Sep 5 11:02:10 2021 -0500 Branches: temp-vert-normals-cleanup https://developer.blender.org/rBb97910717e68a59b48f24c514ac7c1c6f5197004
More changes and fixes to pass normals around separately from MVert =================================================================== M source/blender/blenkernel/BKE_mesh.h M source/blender/blenkernel/BKE_mesh_remap.h M source/blender/blenkernel/BKE_pbvh.h M source/blender/blenkernel/intern/data_transfer.c M source/blender/blenkernel/intern/key.c M source/blender/blenkernel/intern/mesh.c M source/blender/blenkernel/intern/mesh_mirror.c M source/blender/blenkernel/intern/mesh_normals.cc M source/blender/blenkernel/intern/mesh_remap.c M source/blender/blenkernel/intern/pbvh.c M source/blender/bmesh/intern/bmesh_mesh_convert.c M source/blender/draw/intern/draw_cache_extract_mesh_render_data.c M source/blender/draw/intern/mesh_extractors/extract_mesh.h M source/blender/editors/physics/particle_edit.c M source/blender/editors/sculpt_paint/paint_image_proj.c M source/blender/editors/sculpt_paint/paint_vertex.c M source/blender/editors/sculpt_paint/sculpt.c M source/blender/editors/sculpt_paint/sculpt_intern.h M source/blender/editors/transform/transform_snap_object.c M source/blender/gpu/GPU_buffers.h M source/blender/gpu/intern/gpu_buffers.c M source/blender/modifiers/intern/MOD_normal_edit.c M source/blender/modifiers/intern/MOD_weighted_normal.c M source/blender/render/intern/bake.c M source/blender/render/intern/multires_bake.c M source/blender/render/intern/texture_pointdensity.c =================================================================== diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h index b0583cc570d..6dd31a12b9f 100644 --- a/source/blender/blenkernel/BKE_mesh.h +++ b/source/blender/blenkernel/BKE_mesh.h @@ -292,8 +292,8 @@ void BKE_mesh_calc_normals_poly_and_vertex(struct MVert *mvert, float (*r_poly_normals)[3], float (*r_vert_normals)[3]); void BKE_mesh_calc_normals(struct Mesh *me); -const float (*BKE_mesh_ensure_vertex_normals(const Mesh *mesh))[3]; -const float (*BKE_mesh_ensure_face_normals(const Mesh *mesh))[3]; +const float (*BKE_mesh_ensure_vertex_normals(const struct Mesh *mesh))[3]; +const float (*BKE_mesh_ensure_face_normals(const struct Mesh *mesh))[3]; void BKE_mesh_ensure_normals_for_display(struct Mesh *mesh); void BKE_mesh_calc_normals_looptri(struct MVert *mverts, int numVerts, @@ -412,6 +412,7 @@ void BKE_mesh_normals_loop_split(const struct MVert *mverts, const int numLoops, struct MPoly *mpolys, const float (*polynors)[3], + const float (*vert_normals)[3], const int numPolys, const bool use_split_normals, const float split_angle, @@ -420,6 +421,7 @@ void BKE_mesh_normals_loop_split(const struct MVert *mverts, int *r_loop_to_poly); void BKE_mesh_normals_loop_custom_set(const struct MVert *mverts, + const float (*vert_normals)[3], const int numVerts, struct MEdge *medges, const int numEdges, diff --git a/source/blender/blenkernel/BKE_mesh_remap.h b/source/blender/blenkernel/BKE_mesh_remap.h index 7f8f028c26b..d31fc3bdfaa 100644 --- a/source/blender/blenkernel/BKE_mesh_remap.h +++ b/source/blender/blenkernel/BKE_mesh_remap.h @@ -198,6 +198,7 @@ void BKE_mesh_remap_calc_loops_from_mesh(const int mode, const float max_dist, const float ray_radius, struct MVert *verts_dst, + const float (*vert_normals_dst)[3], const int numverts_dst, struct MEdge *edges_dst, const int numedges_dst, diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h index 54a6e27fdb3..65afe13d2cb 100644 --- a/source/blender/blenkernel/BKE_pbvh.h +++ b/source/blender/blenkernel/BKE_pbvh.h @@ -373,7 +373,7 @@ typedef struct PBVHVertexIter { struct MVert *mvert; struct BMVert *bm_vert; float *co; - float *no; + const float *no; float *fno; float *mask; float *col; diff --git a/source/blender/blenkernel/intern/data_transfer.c b/source/blender/blenkernel/intern/data_transfer.c index b83621e8b79..72040c28cce 100644 --- a/source/blender/blenkernel/intern/data_transfer.c +++ b/source/blender/blenkernel/intern/data_transfer.c @@ -288,26 +288,9 @@ static void data_transfer_dtdata_type_preprocess(Mesh *me_src, BLI_assert(CustomData_get_layer(&me_src->pdata, CD_NORMAL) != NULL); (void)me_src; - float(*poly_nors_dst)[3]; float(*loop_nors_dst)[3]; short(*custom_nors_dst)[2] = CustomData_get_layer(ldata_dst, CD_CUSTOMLOOPNORMAL); - /* Cache poly nors into a temp CDLayer. */ - poly_nors_dst = CustomData_get_layer(pdata_dst, CD_NORMAL); - const bool do_poly_nors_dst = (poly_nors_dst == NULL); - if (do_poly_nors_dst) { - poly_nors_dst = CustomData_add_layer(pdata_dst, CD_NORMAL, CD_CALLOC, NULL, num_polys_dst); - CustomData_set_layer_flag(pdata_dst, CD_NORMAL, CD_FLAG_TEMPORARY); - } - if (dirty_nors_dst || do_poly_nors_dst) { - BKE_mesh_calc_normals_poly(verts_dst, - num_verts_dst, - loops_dst, - num_loops_dst, - polys_dst, - num_polys_dst, - poly_nors_dst); - } /* Cache loop nors into a temp CDLayer. */ loop_nors_dst = CustomData_get_layer(ldata_dst, CD_NORMAL); const bool do_loop_nors_dst = (loop_nors_dst == NULL); @@ -324,7 +307,8 @@ static void data_transfer_dtdata_type_preprocess(Mesh *me_src, loop_nors_dst, num_loops_dst, polys_dst, - (const float(*)[3])poly_nors_dst, + BKE_mesh_ensure_face_normals(me_dst), + BKE_mesh_ensure_vertex_normals(me_dst), num_polys_dst, use_split_nors_dst, split_angle_dst, @@ -372,6 +356,7 @@ static void data_transfer_dtdata_type_postprocess(Object *UNUSED(ob_src), /* Note loop_nors_dst contains our custom normals as transferred from source... */ BKE_mesh_normals_loop_custom_set(verts_dst, + BKE_mesh_ensure_vertex_normals(me_dst), num_verts_dst, edges_dst, num_edges_dst, @@ -1696,6 +1681,7 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph, max_distance, ray_radius, verts_dst, + BKE_mesh_ensure_vertex_normals(me_dst), num_verts_dst, edges_dst, num_edges_dst, diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index f79058dcf21..edc15d6e97a 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -2280,8 +2280,14 @@ void BKE_keyblock_mesh_calc_normals(struct KeyBlock *kb, r_polynors = MEM_mallocN(sizeof(float[3]) * me.totpoly, __func__); free_polynors = true; } - BKE_mesh_calc_normals_poly_and_vertex( - me.mvert, me.totvert, me.mloop, me.totloop, me.mpoly, me.totpoly, r_polynors, r_vertnors); + + const float(*vert_normals)[3] = BKE_mesh_ensure_vertex_normals(mesh); + if (r_vertnors) { + memcpy(r_vertnors, vert_normals, sizeof(float[3]) * me.totvert); + } + + const float(*face_normals)[3] = BKE_mesh_ensure_face_normals(mesh); + memcpy(r_polynors, face_normals, sizeof(float[3]) * me.totpoly); if (r_loopnors) { short(*clnors)[2] = CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL); /* May be NULL. */ @@ -2294,7 +2300,8 @@ void BKE_keyblock_mesh_calc_normals(struct KeyBlock *kb, r_loopnors, me.totloop, me.mpoly, - r_polynors, + face_normals, + vert_normals, me.totpoly, (me.flag & ME_AUTOSMOOTH) != 0, me.smoothresh, diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 2efe0d77d87..08c8250ab48 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -1896,9 +1896,7 @@ void BKE_mesh_vert_normals_apply(Mesh *mesh, const short (*vert_normals)[3]) void BKE_mesh_calc_normals_split_ex(Mesh *mesh, MLoopNorSpaceArray *r_lnors_spacearr) { float(*r_loopnors)[3]; - float(*polynors)[3]; short(*clnors)[2] = NULL; - bool free_polynors = false; /* Note that we enforce computing clnors when the clnor space array is requested by caller here. * However, we obviously only use the autosmooth angle threshold @@ -1918,25 +1916,6 @@ void BKE_mesh_calc_normals_split_ex(Mesh *mesh, MLoopNorSpaceArray *r_lnors_spac /* may be NULL */ clnors = CustomData_get_layer(&mesh->ldata, CD_CUSTOMLOOPNORMAL); - if (CustomData_has_layer(&mesh->pdata, CD_NORMAL)) { - /* This assume that layer is always up to date, not sure this is the case - * (esp. in Edit mode?)... */ - polynors = CustomData_get_layer(&mesh->pdata, CD_NORMAL); - free_polynors = false; - } - else { - polynors = MEM_malloc_arrayN(mesh->totpoly, sizeof(float[3]), __func__); - BKE_mesh_calc_normals_poly_and_vertex(mesh->mvert, - mesh->totvert, - mesh->mloop, - mesh->totloop, - mesh->mpoly, - mesh->totpoly, - polynors, - NULL); - free_polynors = true; - } - BKE_mesh_normals_loop_split(mesh->mvert, mesh->totvert, mesh->medge, @@ -1945,7 +1924,8 @@ void BKE_mesh_calc_normals_split_ex(Mesh *mesh, MLoopNorSpaceArray *r_lnors_spac r_loopnors, mesh->totloop, mesh->mpoly, - (const float(*)[3])polynors, + BKE_mesh_ensure_face_normals(mesh), + BKE_mesh_ensure_vertex_normals(mesh), mesh->totpoly, use_split_normals, split_angle, @@ -1953,10 +1933,6 @@ void BKE_mesh_calc_normals_split_ex(Mesh *mesh, MLoopNorSpaceArray *r_lnors_spac @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs