[Bf-blender-cvs] [172a976273f] refactor-mesh-corner-normals-lazy: Mesh: Start refactor of lazy face corner normals
Hans Goudey
noreply at git.blender.org
Tue Nov 29 19:35:41 CET 2022
Commit: 172a976273f0e7144eed60c19c3e72357c74b0f6
Author: Hans Goudey
Date: Fri Nov 11 18:44:37 2022 -0600
Branches: refactor-mesh-corner-normals-lazy
https://developer.blender.org/rB172a976273f0e7144eed60c19c3e72357c74b0f6
Mesh: Start refactor of lazy face corner normals
===================================================================
M source/blender/blenkernel/BKE_mesh.h
M source/blender/blenkernel/BKE_mesh_types.h
M source/blender/blenkernel/intern/DerivedMesh.cc
M source/blender/blenkernel/intern/data_transfer.c
M source/blender/blenkernel/intern/mesh.cc
M source/blender/blenkernel/intern/mesh_iterators.cc
M source/blender/blenkernel/intern/mesh_normals.cc
M source/blender/blenkernel/intern/mesh_remap.c
M source/blender/blenkernel/intern/mesh_tangent.cc
M source/blender/blenkernel/intern/mesh_wrapper.cc
M source/blender/blenkernel/intern/shrinkwrap.cc
M source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_pos_nor.cc
M source/blender/editors/sculpt_paint/curves_sculpt_add.cc
M source/blender/editors/sculpt_paint/curves_sculpt_density.cc
M source/blender/editors/sculpt_paint/curves_sculpt_puff.cc
M source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
M source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
M source/blender/io/alembic/exporter/abc_writer_mesh.cc
M source/blender/io/collada/GeometryExporter.cpp
M source/blender/io/usd/intern/usd_writer_mesh.cc
M source/blender/io/wavefront_obj/exporter/obj_export_mesh.cc
M source/blender/io/wavefront_obj/exporter/obj_export_mesh.hh
M source/blender/io/wavefront_obj/tests/obj_importer_tests.cc
M source/blender/makesrna/intern/rna_mesh.c
M source/blender/makesrna/intern/rna_mesh_api.c
M source/blender/modifiers/intern/MOD_displace.c
M source/blender/modifiers/intern/MOD_multires.cc
M source/blender/modifiers/intern/MOD_subsurf.cc
M source/blender/modifiers/intern/MOD_triangulate.c
M source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc
M source/blender/render/intern/bake.c
M source/blender/render/intern/multires_bake.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 8f6786d4113..30e39749df4 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -372,6 +372,8 @@ const float (*BKE_mesh_vertex_normals_ensure(const struct Mesh *mesh))[3];
*/
const float (*BKE_mesh_poly_normals_ensure(const struct Mesh *mesh))[3];
+const float (*BKE_mesh_corner_normals_ensure(const struct Mesh *mesh))[3];
+
/**
* Tag mesh vertex and face normals to be recalculated when/if they are needed later.
*
@@ -434,6 +436,8 @@ void BKE_mesh_vertex_normals_clear_dirty(struct Mesh *mesh);
*/
void BKE_mesh_poly_normals_clear_dirty(struct Mesh *mesh);
+void BKE_mesh_corner_normals_clear_dirty(struct Mesh *mesh);
+
/**
* Return true if the mesh vertex normals either are not stored or are dirty.
* This can be used to help decide whether to transfer them when copying a mesh.
@@ -446,6 +450,8 @@ bool BKE_mesh_vertex_normals_are_dirty(const struct Mesh *mesh);
*/
bool BKE_mesh_poly_normals_are_dirty(const struct Mesh *mesh);
+bool BKE_mesh_corner_normals_are_dirty(const struct Mesh *mesh);
+
/**
* Calculate face normals directly into a result array.
*
@@ -690,7 +696,6 @@ void BKE_mesh_normals_loop_to_vertex(int numVerts,
*/
bool BKE_mesh_has_custom_loop_normals(struct Mesh *me);
-void BKE_mesh_calc_normals_split(struct Mesh *mesh);
/**
* Compute 'split' (aka loop, or per face corner's) normals.
*
diff --git a/source/blender/blenkernel/BKE_mesh_types.h b/source/blender/blenkernel/BKE_mesh_types.h
index 80f61086052..65d1e0fcb13 100644
--- a/source/blender/blenkernel/BKE_mesh_types.h
+++ b/source/blender/blenkernel/BKE_mesh_types.h
@@ -141,8 +141,10 @@ struct MeshRuntime {
*/
bool vert_normals_dirty = false;
bool poly_normals_dirty = false;
+ bool corner_normals_dirty = false;
float (*vert_normals)[3] = nullptr;
float (*poly_normals)[3] = nullptr;
+ float (*corner_normals)[3] = nullptr;
/**
* A #BLI_bitmap containing tags for the center vertices of subdivided polygons, set by the
diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc b/source/blender/blenkernel/intern/DerivedMesh.cc
index bfdfc447baf..a7e398adcfa 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.cc
+++ b/source/blender/blenkernel/intern/DerivedMesh.cc
@@ -547,7 +547,7 @@ static void mesh_calc_modifier_final_normals(const Mesh *mesh_input,
/* Compute loop normals (NOTE: will compute poly and vert normals as well, if needed!). In case
* of deferred CPU subdivision, this will be computed when the wrapper is generated. */
if (!subsurf_runtime_data || subsurf_runtime_data->resolution == 0) {
- BKE_mesh_calc_normals_split(mesh_final);
+ BKE_mesh_corner_normals_ensure(mesh_final);
}
}
else {
@@ -560,12 +560,7 @@ static void mesh_calc_modifier_final_normals(const Mesh *mesh_input,
BKE_mesh_ensure_normals_for_display(mesh_final);
}
- /* Some modifiers, like data-transfer, may generate those data as temp layer,
- * we do not want to keep them, as they are used by display code when available
- * (i.e. even if auto-smooth is disabled). */
- if (CustomData_has_layer(&mesh_final->ldata, CD_NORMAL)) {
- CustomData_free_layers(&mesh_final->ldata, CD_NORMAL, mesh_final->totloop);
- }
+
}
}
@@ -1216,18 +1211,12 @@ static void editbmesh_calc_modifier_final_normals(Mesh *mesh_final,
/* Compute loop normals. In case of deferred CPU subdivision, this will be computed when the
* wrapper is generated. */
if (!subsurf_runtime_data || subsurf_runtime_data->resolution == 0) {
- BKE_mesh_calc_normals_split(mesh_final);
+ BKE_mesh_corner_normals_ensure(mesh_final);
}
}
else {
/* Same as mesh_calc_modifiers. If using loop normals, poly nors have already been computed. */
BKE_mesh_ensure_normals_for_display(mesh_final);
-
- /* Some modifiers, like data-transfer, may generate those data, we do not want to keep them,
- * as they are used by display code when available (i.e. even if autosmooth is disabled). */
- if (CustomData_has_layer(&mesh_final->ldata, CD_NORMAL)) {
- CustomData_free_layers(&mesh_final->ldata, CD_NORMAL, mesh_final->totloop);
- }
}
}
diff --git a/source/blender/blenkernel/intern/data_transfer.c b/source/blender/blenkernel/intern/data_transfer.c
index e6afca11b40..b5ad92c2705 100644
--- a/source/blender/blenkernel/intern/data_transfer.c
+++ b/source/blender/blenkernel/intern/data_transfer.c
@@ -247,65 +247,6 @@ int BKE_object_data_transfer_dttype_to_srcdst_index(const int dtdata_type)
/* ********** */
-/* Generic pre/post processing, only used by custom loop normals currently. */
-
-static void data_transfer_dtdata_type_preprocess(Mesh *me_src,
- Mesh *me_dst,
- const int dtdata_type,
- const bool dirty_nors_dst)
-{
- if (dtdata_type == DT_TYPE_LNOR) {
- /* Compute custom normals into regular loop normals, which will be used for the transfer. */
-
- const MVert *verts_dst = BKE_mesh_verts(me_dst);
- const int num_verts_dst = me_dst->totvert;
- const MEdge *edges_dst = BKE_mesh_edges(me_dst);
- const int num_edges_dst = me_dst->totedge;
- const MPoly *polys_dst = BKE_mesh_polys(me_dst);
- const int num_polys_dst = me_dst->totpoly;
- const MLoop *loops_dst = BKE_mesh_loops(me_dst);
- const int num_loops_dst = me_dst->totloop;
- CustomData *ldata_dst = &me_dst->ldata;
-
- const bool use_split_nors_dst = (me_dst->flag & ME_AUTOSMOOTH) != 0;
- const float split_angle_dst = me_dst->smoothresh;
-
- /* This should be ensured by cddata_masks we pass to code generating/giving us me_src now. */
- BLI_assert(CustomData_get_layer(&me_src->ldata, CD_NORMAL) != NULL);
- (void)me_src;
-
- float(*loop_nors_dst)[3];
- short(*custom_nors_dst)[2] = CustomData_get_layer(ldata_dst, CD_CUSTOMLOOPNORMAL);
-
- /* 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);
- if (do_loop_nors_dst) {
- loop_nors_dst = CustomData_add_layer(
- ldata_dst, CD_NORMAL, CD_SET_DEFAULT, NULL, num_loops_dst);
- CustomData_set_layer_flag(ldata_dst, CD_NORMAL, CD_FLAG_TEMPORARY);
- }
- if (dirty_nors_dst || do_loop_nors_dst) {
- BKE_mesh_normals_loop_split(verts_dst,
- BKE_mesh_vertex_normals_ensure(me_dst),
- num_verts_dst,
- edges_dst,
- num_edges_dst,
- loops_dst,
- loop_nors_dst,
- num_loops_dst,
- polys_dst,
- BKE_mesh_poly_normals_ensure(me_dst),
- num_polys_dst,
- use_split_nors_dst,
- split_angle_dst,
- NULL,
- custom_nors_dst,
- NULL);
- }
- }
-}
-
static void data_transfer_dtdata_type_postprocess(Object *UNUSED(ob_src),
Object *UNUSED(ob_dst),
Mesh *UNUSED(me_src),
@@ -330,7 +271,6 @@ static void data_transfer_dtdata_type_postprocess(Object *UNUSED(ob_src),
CustomData *ldata_dst = &me_dst->ldata;
const float(*poly_nors_dst)[3] = BKE_mesh_poly_normals_ensure(me_dst);
- float(*loop_nors_dst)[3] = CustomData_get_layer(ldata_dst, CD_NORMAL);
short(*custom_nors_dst)[2] = CustomData_get_layer(ldata_dst, CD_CUSTOMLOOPNORMAL);
if (!custom_nors_dst) {
@@ -345,7 +285,7 @@ static void data_transfer_dtdata_type_postprocess(Object *UNUSED(ob_src),
edges_dst,
num_edges_dst,
loops_dst,
- loop_nors_dst,
+ BKE_mesh_corner_normals_ensure(me_dst),
num_loops_dst,
polys_dst,
poly_nors_dst,
@@ -1323,8 +1263,6 @@ bool BKE_object_data_transfer_ex(struct Depsgraph *depsgraph,
continue;
}
- data_transfer_dtdata_type_preprocess(me_src, me_dst, dtdata_type, dirty_nors_dst);
-
cddata_type = BKE_object_data_transfer_dttype_to_cdtype(dtdata_type);
fromto_idx = BKE_object_data_transfer_dttype_to_srcdst_index(dtdata_type);
diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc
index 2d613f24a0a..5b5d504a743 100644
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@ -1567,20 +1567,6 @@ void BKE_mesh_transform(Mesh *me, const float mat[4][4], bool do_keys)
}
}
- /* don't update normals, caller can do this explicitly.
- * We do update loop normals though, those may not be auto-generated
- * (see e.g. STL import script)! */
- float(*lnors)[3] = (float(*)[3])CustomData_duplicate_referenced_layer(
- &me->ldata, CD_NORMAL, me->totloop);
- if (lnors) {
- float m3[3][3];
-
- copy_m3_m4(m3, mat);
- normalize_m3(m3);
- for (int i = 0; i < me->totloop; i++, lnors++) {
- mul_m3_v3(m3, *lnors);
- }
- }
BKE_mesh_tag_coords_changed(me);
}
@@ -1836,10 +1822,6 @@ void BKE_mesh_calc_normals_split_ex(Mesh *mesh,
BKE_mesh_assert_normals_dirty_or_calculated(mesh);
}
-void BKE_mesh_calc_normals_split(Mesh *mesh)
-{
- BKE_mesh_calc_normals_split_ex(mesh, nullptr, ensure_corner_normal_layer(*mesh));
-}
/* Split faces helper functions. */
diff --git a/source/blender/blenkernel/intern/mesh_iterators.cc b/source/blender/blenkernel/intern/mesh_iterators.cc
index a99e9b2348d..4ec97caaa29 100644
--- a/source/
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list