[Bf-blender-cvs] [60e0c9b993f] temp-vert-normals-cleanup: Cleanup
Hans Goudey
noreply at git.blender.org
Sun Nov 7 06:57:00 CET 2021
Commit: 60e0c9b993fba3cf61ffb1c835f62cb02594d999
Author: Hans Goudey
Date: Sun Nov 7 00:56:54 2021 -0500
Branches: temp-vert-normals-cleanup
https://developer.blender.org/rB60e0c9b993fba3cf61ffb1c835f62cb02594d999
Cleanup
===================================================================
M source/blender/blenkernel/intern/customdata.c
M source/blender/blenkernel/intern/fluid.c
M source/blender/blenkernel/intern/mesh_normals.cc
===================================================================
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index f8967681ed5..4ec6f31a92d 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1523,7 +1523,6 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
NULL,
NULL,
NULL,
- /* TODO: Should normal interpolation be removed? Normals are generally just recalculated. */
layerInterp_normal,
NULL,
NULL,
diff --git a/source/blender/blenkernel/intern/fluid.c b/source/blender/blenkernel/intern/fluid.c
index cbde7f9cba1..b5da3a4ff69 100644
--- a/source/blender/blenkernel/intern/fluid.c
+++ b/source/blender/blenkernel/intern/fluid.c
@@ -1054,7 +1054,7 @@ static void obstacles_from_mesh(Object *coll_ob,
/* Transform mesh vertices to domain grid space for fast lookups */
BKE_mesh_ensure_vertex_normals(me);
- float(*vert_normals)[3] = (float(*)[3])CustomData_get_layer(&me->vdata, CD_NORMAL);
+ float(*vert_normals)[3] = BKE_mesh_vertex_normals_for_write(me);
for (i = 0; i < numverts; i++) {
float co[3];
@@ -2140,7 +2140,7 @@ static void emit_from_mesh(
/* Transform mesh vertices to domain grid space for fast lookups */
BKE_mesh_ensure_vertex_normals(me);
- float(*vert_normals)[3] = (float(*)[3])CustomData_get_layer(&me->vdata, CD_NORMAL);
+ float(*vert_normals)[3] = BKE_mesh_vertex_normals_for_write(me);
for (i = 0; i < numverts; i++) {
/* Vertex position. */
mul_m4_v3(flow_ob->obmat, mvert[i].co);
@@ -3408,7 +3408,6 @@ static Mesh *create_liquid_geometry(FluidDomainSettings *fds,
# endif
}
- BKE_mesh_normals_tag_dirty(me);
BKE_mesh_calc_edges(me, false, false);
return me;
diff --git a/source/blender/blenkernel/intern/mesh_normals.cc b/source/blender/blenkernel/intern/mesh_normals.cc
index 08e1b985038..e92c7dd3836 100644
--- a/source/blender/blenkernel/intern/mesh_normals.cc
+++ b/source/blender/blenkernel/intern/mesh_normals.cc
@@ -121,9 +121,8 @@ void BKE_mesh_normals_tag_dirty(Mesh *mesh)
}
/**
- * For manual calculation of vertex normals, make sure the vertex normal data layer exists and
- * return it. Clears the dirty flag for vertex normals, since this is meant to be used when
- * manually setting normals.
+ * Make sure the vertex normal data layer exists and return it.
+ * Used for manually assigning vertex normals. Clears the dirty flag.
*/
float (*BKE_mesh_vertex_normals_for_write(Mesh *mesh))[3]
{
@@ -133,9 +132,8 @@ float (*BKE_mesh_vertex_normals_for_write(Mesh *mesh))[3]
}
/**
- * For manual calculation of face normals, make sure the face normal data layer exists and
- * return it. Clears the dirty flag for face normals, since this is meant to be used when
- * manually setting normals.
+ * Make sure the face normal data layer exists and return it.
+ * Used for manually assigning face normals. Clears the dirty flag.
*/
float (*BKE_mesh_face_normals_for_write(Mesh *mesh))[3]
{
@@ -280,6 +278,10 @@ const float (*BKE_mesh_ensure_vertex_normals(const Mesh *mesh))[3]
return (const float(*)[3])CustomData_get_layer(&mesh->vdata, CD_NORMAL);
}
+ if (mesh->totvert == 0) {
+ return nullptr;
+ }
+
ThreadMutex *normals_mutex = (ThreadMutex *)mesh->runtime.normals_mutex;
BLI_mutex_lock(normals_mutex);
if (!(mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL ||
@@ -294,10 +296,6 @@ const float (*BKE_mesh_ensure_vertex_normals(const Mesh *mesh))[3]
me.runtime.cd_dirty_vert &= ~CD_MASK_NORMAL;
me.runtime.cd_dirty_poly &= ~CD_MASK_NORMAL;
- // if (mesh->totvert == 0) {
- // return nullptr;
- // }
-
MutableSpan<float3> vert_normals{(float3 *)BKE_mesh_vertex_normals_for_write(&me), me.totvert};
MutableSpan<float3> poly_normals{(float3 *)BKE_mesh_face_normals_for_write(&me), me.totpoly};
mesh_calc_normals_poly_and_vertex({me.mvert, me.totvert},
@@ -320,6 +318,10 @@ const float (*BKE_mesh_ensure_face_normals(const Mesh *mesh))[3]
return (const float(*)[3])CustomData_get_layer(&mesh->pdata, CD_NORMAL);
}
+ if (mesh->totpoly == 0) {
+ return nullptr;
+ }
+
ThreadMutex *normals_mutex = (ThreadMutex *)mesh->runtime.normals_mutex;
BLI_mutex_lock(normals_mutex);
if (!(mesh->runtime.cd_dirty_poly & CD_MASK_NORMAL)) {
@@ -331,9 +333,6 @@ const float (*BKE_mesh_ensure_face_normals(const Mesh *mesh))[3]
Mesh &me = *const_cast<Mesh *>(mesh);
/* Clear the dirty flag, since the normals have been calculated. */
me.runtime.cd_dirty_poly &= ~CD_MASK_NORMAL;
- // if (mesh->totpoly == 0) {
- // return nullptr;
- // }
float(*poly_normals)[3] = BKE_mesh_face_normals_for_write(&me);
BKE_mesh_calc_normals_poly(
@@ -383,7 +382,8 @@ void BKE_mesh_assert_normals_dirty_or_calculated(const Mesh *mesh)
if (!CustomData_has_layer(&mesh->vdata, CD_NORMAL)) {
Mesh *me = const_cast<Mesh *>(mesh);
MEM_freeN(me);
- /* Cause a use after free, to quickly tell where the offending mesh was allocated. */
+ /* Cause a use after free, to quickly tell where the offending mesh was allocated.
+ * TODO: Remove. */
MEM_freeN(me);
}
BLI_assert(CustomData_has_layer(&mesh->vdata, CD_NORMAL));
@@ -393,7 +393,8 @@ void BKE_mesh_assert_normals_dirty_or_calculated(const Mesh *mesh)
if (!CustomData_has_layer(&mesh->pdata, CD_NORMAL)) {
Mesh *me = const_cast<Mesh *>(mesh);
MEM_freeN(me);
- /* Cause a use after free, to quickly tell where the offending mesh was allocated. */
+ /* Cause a use after free, to quickly tell where the offending mesh was allocated.
+ * TODO: Remove. */
MEM_freeN(me);
}
BLI_assert(CustomData_has_layer(&mesh->vdata, CD_NORMAL));
More information about the Bf-blender-cvs
mailing list