[Bf-blender-cvs] [9bfd8525fca] refactor-mesh-sharp-face-generic: More progress
Hans Goudey
noreply at git.blender.org
Thu Jan 5 18:50:54 CET 2023
Commit: 9bfd8525fcadf62880a5f39ae87ffe8bbf7129dc
Author: Hans Goudey
Date: Thu Jan 5 11:32:05 2023 -0500
Branches: refactor-mesh-sharp-face-generic
https://developer.blender.org/rB9bfd8525fcadf62880a5f39ae87ffe8bbf7129dc
More progress
===================================================================
M source/blender/blenkernel/BKE_DerivedMesh.h
M source/blender/blenkernel/BKE_mesh.h
M source/blender/blenkernel/intern/data_transfer.cc
M source/blender/blenkernel/intern/mesh_normals.cc
M source/blender/blenkernel/intern/pbvh.c
M source/blender/bmesh/intern/bmesh_construct.c
M source/blender/bmesh/intern/bmesh_construct.h
M source/blender/bmesh/intern/bmesh_mesh_convert.cc
M source/blender/draw/intern/draw_pbvh.cc
M source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.cc
M source/blender/io/alembic/exporter/abc_writer_mesh.cc
M source/blender/render/intern/bake.cc
M source/blender/render/intern/multires_bake.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h
index cb9c4256e33..8b60fa7ee7a 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -75,7 +75,7 @@ struct Scene;
/* keep in sync with MFace/MPoly types */
typedef struct DMFlagMat {
short mat_nr;
- char flag;
+ bool sharp;
} DMFlagMat;
typedef enum DerivedMeshType {
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index 066d302fdd1..0727cb71b85 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -475,6 +475,8 @@ void BKE_mesh_ensure_normals_for_display(struct Mesh *mesh);
*
* Used when defining an empty custom loop normals data layer,
* to keep same shading as with auto-smooth!
+ *
+ * \param sharp_faces: Optional array used to mark specific faces as sharp.
*/
void BKE_edges_sharp_from_angle_set(struct MEdge *medges,
int numEdges,
@@ -482,6 +484,7 @@ void BKE_edges_sharp_from_angle_set(struct MEdge *medges,
int numLoops,
const struct MPoly *mpolys,
const float (*poly_normals)[3],
+ const bool *sharp_faces,
int numPolys,
float split_angle);
@@ -596,6 +599,7 @@ void BKE_lnor_space_custom_normal_to_data(const MLoopNorSpace *lnor_space,
* (splitting edges).
*
* \param loop_to_poly_map: Optional pre-created map from loops to their polygon.
+ * \param sharp_faces: Optional array used to mark specific faces as sharp.
*/
void BKE_mesh_normals_loop_split(const struct MVert *mverts,
const float (*vert_normals)[3],
@@ -607,6 +611,7 @@ void BKE_mesh_normals_loop_split(const struct MVert *mverts,
int numLoops,
const struct MPoly *mpolys,
const float (*poly_normals)[3],
+ const bool *sharp_faces,
int numPolys,
bool use_split_normals,
float split_angle,
@@ -624,6 +629,7 @@ void BKE_mesh_normals_loop_custom_set(const struct MVert *mverts,
int numLoops,
const struct MPoly *mpolys,
const float (*poly_normals)[3],
+ const bool *sharp_faces,
int numPolys,
short (*r_clnors_data)[2]);
void BKE_mesh_normals_loop_custom_from_verts_set(const struct MVert *mverts,
@@ -636,6 +642,7 @@ void BKE_mesh_normals_loop_custom_from_verts_set(const struct MVert *mverts,
int numLoops,
const struct MPoly *mpolys,
const float (*poly_normals)[3],
+ const bool *sharp_faces,
int numPolys,
short (*r_clnors_data)[2]);
diff --git a/source/blender/blenkernel/intern/data_transfer.cc b/source/blender/blenkernel/intern/data_transfer.cc
index 4220d106095..0bf66fdcead 100644
--- a/source/blender/blenkernel/intern/data_transfer.cc
+++ b/source/blender/blenkernel/intern/data_transfer.cc
@@ -297,6 +297,8 @@ static void data_transfer_dtdata_type_preprocess(Mesh *me_src,
num_loops_dst,
polys_dst,
BKE_mesh_poly_normals_ensure(me_dst),
+ static_cast<const bool *>(CustomData_get_layer_named(
+ &me_dst->pdata, CD_PROP_BOOL, "sharp_face")),
num_polys_dst,
use_split_nors_dst,
split_angle_dst,
@@ -352,6 +354,8 @@ static void data_transfer_dtdata_type_postprocess(Object * /*ob_src*/,
num_loops_dst,
polys_dst,
poly_nors_dst,
+ static_cast<const bool *>(CustomData_get_layer_named(
+ &me_dst->pdata, CD_PROP_BOOL, "sharp_face")),
num_polys_dst,
custom_nors_dst);
}
@@ -1056,26 +1060,20 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map,
return true;
}
if (r_map && cddata_type == CD_FAKE_SHARP) {
- const size_t elem_size = sizeof(*((MPoly *)nullptr));
- const size_t data_size = sizeof(((MPoly *)nullptr)->flag);
- const size_t data_offset = offsetof(MPoly, flag);
- const uint64_t data_flag = ME_SMOOTH;
-
- data_transfer_layersmapping_add_item(r_map,
- cddata_type,
- mix_mode,
- mix_factor,
- mix_weights,
- BKE_mesh_polys(me_src),
- BKE_mesh_polys_for_write(me_dst),
- me_src->totpoly,
- me_dst->totpoly,
- elem_size,
- data_size,
- data_offset,
- data_flag,
- nullptr,
- interp_data);
+ if (!CustomData_get_layer_named(&me_dst->pdata, CD_PROP_BOOL, "sharp_face")) {
+ CustomData_add_layer_named(
+ &me_dst->pdata, CD_PROP_BOOL, CD_SET_DEFAULT, nullptr, me_dst->totpoly, "sharp_face");
+ }
+ data_transfer_layersmapping_add_item_cd(
+ r_map,
+ CD_PROP_BOOL,
+ mix_mode,
+ mix_factor,
+ mix_weights,
+ CustomData_get_layer_named(&me_src->pdata, CD_PROP_BOOL, "sharp_face"),
+ CustomData_get_layer_named(&me_dst->pdata, CD_PROP_BOOL, "sharp_face"),
+ interp,
+ interp_data);
return true;
}
diff --git a/source/blender/blenkernel/intern/mesh_normals.cc b/source/blender/blenkernel/intern/mesh_normals.cc
index 7d486a99406..f0bd91a5044 100644
--- a/source/blender/blenkernel/intern/mesh_normals.cc
+++ b/source/blender/blenkernel/intern/mesh_normals.cc
@@ -838,6 +838,7 @@ static void mesh_edges_sharp_tag(const Span<MEdge> edges,
const Span<MLoop> loops,
const Span<int> loop_to_poly_map,
const Span<float3> poly_normals,
+ const Span<bool> sharp_faces,
const bool check_angle,
const float split_angle,
MutableSpan<int2> edge_to_loops,
@@ -845,6 +846,9 @@ static void mesh_edges_sharp_tag(const Span<MEdge> edges,
{
using namespace blender;
const float split_angle_cos = check_angle ? cosf(split_angle) : -1.0f;
+ auto face_is_smooth = [&](const int poly_i) {
+ return sharp_faces.is_empty() || !sharp_faces[poly_i];
+ };
for (const int poly_i : polys.index_range()) {
const MPoly &poly = polys[poly_i];
@@ -859,7 +863,7 @@ static void mesh_edges_sharp_tag(const Span<MEdge> edges,
/* 'Empty' edge until now, set e2l[0] (and e2l[1] to INDEX_UNSET to tag it as unset). */
e2l[0] = loop_index;
/* We have to check this here too, else we might miss some flat faces!!! */
- e2l[1] = (poly.flag & ME_SMOOTH) ? INDEX_UNSET : INDEX_INVALID;
+ e2l[1] = (face_is_smooth(poly_i)) ? INDEX_UNSET : INDEX_INVALID;
}
else if (e2l[1] == INDEX_UNSET) {
const bool is_angle_sharp = (check_angle &&
@@ -871,7 +875,7 @@ static void mesh_edges_sharp_tag(const Span<MEdge> edges,
* or both poly have opposed (flipped) normals, i.e. both loops on the same edge share the
* same vertex, or angle between both its polys' normals is above split_angle value.
*/
- if (!(poly.flag & ME_SMOOTH) || (edges[edge_i].flag & ME_SHARP) ||
+ if (!face_is_smooth(poly_i) || (edges[edge_i].flag & ME_SHARP) ||
vert_i == loops[e2l[0]].v || is_angle_sharp) {
/* NOTE: we are sure that loop != 0 here ;). */
e2l[1] = INDEX_INVALID;
@@ -907,6 +911,7 @@ void BKE_edges_sharp_from_angle_set(MEdge *medges,
const int numLoops,
const MPoly *mpolys,
const float (*poly_normals)[3],
+ const bool *sharp_faces,
const int numPolys,
const float split_angle)
{
@@ -930,6 +935,7 @@ void BKE_edges_sharp_from_angle_set(MEdge *medges,
{mloops, numLoops},
loop_to_poly,
{reinterpret_cast<const float3 *>(poly_normals), numPolys},
+ Span(sharp_faces, sharp_faces ? numPolys : 0),
true,
split_angle,
edge_to_loops,
@@ -1501,6 +1507,7 @@ void BKE_mesh_normals_loop_split(const MVert *mverts,
const int numLoops,
const MPoly *mpolys,
const float (*poly_normals)[3],
+ const bool *sharp_faces,
con
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list