[Bf-blender-cvs] [99c0fc0c217] refactor-mesh-corners-generic: Merge branch 'refactor-mesh-position-generic' into refactor-mesh-corners-generic
Hans Goudey
noreply at git.blender.org
Sat Dec 10 00:05:19 CET 2022
Commit: 99c0fc0c217e48b8b08e3e1d7c9eed6e428cb558
Author: Hans Goudey
Date: Fri Dec 9 17:05:14 2022 -0600
Branches: refactor-mesh-corners-generic
https://developer.blender.org/rB99c0fc0c217e48b8b08e3e1d7c9eed6e428cb558
Merge branch 'refactor-mesh-position-generic' into refactor-mesh-corners-generic
===================================================================
===================================================================
diff --cc source/blender/blenkernel/BKE_mesh.h
index 68dfadec64f,75fe56f1e05..aa39dfb887d
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@@ -493,13 -493,10 +493,11 @@@ void BKE_mesh_ensure_normals_for_displa
* Used when defining an empty custom loop normals data layer,
* to keep same shading as with auto-smooth!
*/
- void BKE_edges_sharp_from_angle_set(const float (*positions)[3],
- int numVerts,
- struct MEdge *medges,
+ void BKE_edges_sharp_from_angle_set(struct MEdge *medges,
int numEdges,
- const struct MLoop *mloops,
- int numLoops,
+ const int *corner_verts,
+ const int *corner_edges,
+ int corners_num,
const struct MPoly *mpolys,
const float (*polynors)[3],
int numPolys,
diff --cc source/blender/blenkernel/intern/mesh.cc
index 24d55d4d9ca,f50d6651170..b40b5afb98f
--- a/source/blender/blenkernel/intern/mesh.cc
+++ b/source/blender/blenkernel/intern/mesh.cc
@@@ -1812,77 -1823,75 +1812,75 @@@ struct SplitFaceNewEdge
int v2;
};
- /* Detect needed new vertices, and update accordingly loops' vertex indices.
- * WARNING! Leaves mesh in invalid state. */
- static int split_faces_prepare_new_verts(Mesh *mesh,
- MLoopNorSpaceArray *lnors_spacearr,
+ /**
+ * Detect necessary new vertices, and update loop vertex indices accordingly.
+ * \warning Leaves mesh in invalid state.
+ * \param lnors_spacearr: Mandatory because trying to do the job in simple way without that data is
+ * doomed to fail, even when only dealing with smooth/flat faces one can find cases that no simple
+ * algorithm can handle properly.
+ */
+ static int split_faces_prepare_new_verts(Mesh &mesh,
+ const MLoopNorSpaceArray &lnors_spacearr,
SplitFaceNewVert **new_verts,
- MemArena *memarena)
+ MemArena &memarena)
{
- /* This is now mandatory, trying to do the job in simple way without that data is doomed to fail,
- * even when only dealing with smooth/flat faces one can find cases that no simple algorithm
- * can handle properly. */
- BLI_assert(lnors_spacearr != nullptr);
-
- const int loops_len = mesh->totloop;
- int verts_len = mesh->totvert;
- MutableSpan<int> corner_verts = mesh->corner_verts_for_write();
- BKE_mesh_vertex_normals_ensure(mesh);
- float(*vert_normals)[3] = BKE_mesh_vertex_normals_for_write(mesh);
+ const int loops_len = mesh.totloop;
+ int verts_len = mesh.totvert;
- MutableSpan<MLoop> loops = mesh.loops_for_write();
++ MutableSpan<int> corner_verts = mesh.corner_verts_for_write();
+ BKE_mesh_vertex_normals_ensure(&mesh);
+ float(*vert_normals)[3] = BKE_mesh_vertex_normals_for_write(&mesh);
BitVector<> verts_used(verts_len, false);
BitVector<> done_loops(loops_len, false);
- MLoopNorSpace **lnor_space = lnors_spacearr->lspacearr;
-
- BLI_assert(lnors_spacearr->data_type == MLNOR_SPACEARR_LOOP_INDEX);
-
- for (int loop_idx = 0; loop_idx < loops_len; loop_idx++, lnor_space++) {
- if (!done_loops[loop_idx]) {
- const int vert_idx = corner_verts[loop_idx];
- const bool vert_used = verts_used[vert_idx];
- /* If vert is already used by another smooth fan, we need a new vert for this one. */
- const int new_vert_idx = vert_used ? verts_len++ : vert_idx;
+ BLI_assert(lnors_spacearr.data_type == MLNOR_SPACEARR_LOOP_INDEX);
- BLI_assert(*lnor_space);
-
- if ((*lnor_space)->flags & MLNOR_SPACE_IS_SINGLE) {
- /* Single loop in this fan... */
- BLI_assert(POINTER_AS_INT((*lnor_space)->loops) == loop_idx);
- done_loops[loop_idx].set();
- if (vert_used) {
- corner_verts[loop_idx] = new_vert_idx;
- }
+ for (int loop_idx = 0; loop_idx < loops_len; loop_idx++) {
+ if (done_loops[loop_idx]) {
+ continue;
+ }
+ const MLoopNorSpace &lnor_space = *lnors_spacearr.lspacearr[loop_idx];
- const int vert_idx = loops[loop_idx].v;
++ const int vert_idx = corner_verts[loop_idx];
+ const bool vert_used = verts_used[vert_idx];
+ /* If vert is already used by another smooth fan, we need a new vert for this one. */
+ const int new_vert_idx = vert_used ? verts_len++ : vert_idx;
+
+ if (lnor_space.flags & MLNOR_SPACE_IS_SINGLE) {
+ /* Single loop in this fan... */
+ BLI_assert(POINTER_AS_INT(lnor_space.loops) == loop_idx);
+ done_loops[loop_idx].set();
+ if (vert_used) {
- loops[loop_idx].v = new_vert_idx;
++ corner_verts[loop_idx] = new_vert_idx;
}
- else {
- for (LinkNode *lnode = (*lnor_space)->loops; lnode; lnode = lnode->next) {
- const int ml_fan_idx = POINTER_AS_INT(lnode->link);
- done_loops[ml_fan_idx].set();
- if (vert_used) {
- corner_verts[ml_fan_idx] = new_vert_idx;
- }
+ }
+ else {
+ for (const LinkNode *lnode = lnor_space.loops; lnode; lnode = lnode->next) {
+ const int ml_fan_idx = POINTER_AS_INT(lnode->link);
+ done_loops[ml_fan_idx].set();
+ if (vert_used) {
- loops[ml_fan_idx].v = new_vert_idx;
++ corner_verts[ml_fan_idx] = new_vert_idx;
}
}
+ }
- if (!vert_used) {
- verts_used[vert_idx].set();
- /* We need to update that vertex's normal here, we won't go over it again. */
- /* This is important! *DO NOT* set vnor to final computed lnor,
- * vnor should always be defined to 'automatic normal' value computed from its polys,
- * not some custom normal.
- * Fortunately, that's the loop normal space's 'lnor' reference vector. ;) */
- copy_v3_v3(vert_normals[vert_idx], (*lnor_space)->vec_lnor);
- }
- else {
- /* Add new vert to list. */
- SplitFaceNewVert *new_vert = (SplitFaceNewVert *)BLI_memarena_alloc(memarena,
- sizeof(*new_vert));
- new_vert->orig_index = vert_idx;
- new_vert->new_index = new_vert_idx;
- new_vert->vnor = (*lnor_space)->vec_lnor; /* See note above. */
- new_vert->next = *new_verts;
- *new_verts = new_vert;
- }
+ if (!vert_used) {
+ verts_used[vert_idx].set();
+ /* We need to update that vertex's normal here, we won't go over it again. */
+ /* This is important! *DO NOT* set vnor to final computed lnor,
+ * vnor should always be defined to 'automatic normal' value computed from its polys,
+ * not some custom normal.
+ * Fortunately, that's the loop normal space's 'lnor' reference vector. ;) */
+ copy_v3_v3(vert_normals[vert_idx], lnor_space.vec_lnor);
+ }
+ else {
+ /* Add new vert to list. */
+ SplitFaceNewVert *new_vert = static_cast<SplitFaceNewVert *>(
+ BLI_memarena_alloc(&memarena, sizeof(*new_vert)));
+ new_vert->orig_index = vert_idx;
+ new_vert->new_index = new_vert_idx;
+ new_vert->vnor = lnor_space.vec_lnor; /* See note above. */
+ new_vert->next = *new_verts;
+ *new_verts = new_vert;
}
}
diff --cc source/blender/blenkernel/intern/mesh_normals.cc
index 866d49d4a60,1cc298039bf..1d6c73944db
--- a/source/blender/blenkernel/intern/mesh_normals.cc
+++ b/source/blender/blenkernel/intern/mesh_normals.cc
@@@ -771,11 -774,10 +772,11 @@@ struct LoopSplitTaskDataCommon
/* Read-only. */
Span<float3> positions;
- MutableSpan<MEdge> edges;
+ Span<MEdge> edges;
- Span<MLoop> loops;
+ Span<int> corner_verts;
+ Span<int> corner_edges;
Span<MPoly> polys;
- int (*edge_to_loops)[2];
+ MutableSpan<int2> edge_to_loops;
Span<int> loop_to_poly;
Span<float3> polynors;
Span<float3> vert_normals;
@@@ -786,46 -788,26 +787,27 @@@
/* See comment about edge_to_loops below. */
#define IS_EDGE_SHARP(_e2l) ELEM((_e2l)[1], INDEX_UNSET, INDEX_INVALID)
- static void mesh_edges_sharp_tag(LoopSplitTaskDataCommon *data,
+ static void mesh_edges_sharp_tag(const Span<MEdge> edges,
+ const Span<MPoly> polys,
- const Span<MLoop> loops,
++ const Span<int> corner_verts,
++ const Span<int> corner_edges,
+ const Span<int> loop_to_poly_map,
+ const Span<float3> poly_normals,
const bool check_angle,
const float split_angle,
- const bool do_sharp_edges_tag)
+ MutableSpan<int2> edge_to_loops,
+ BitVector<> *r_sharp_edges)
{
- MutableSpan<MEdge> edges = data->edges;
- const Span<MPoly> polys = data->polys;
- const Span<int> corner_verts = data->corner_verts;
- const Span<int> corner_edges = data->corner_edges;
- const Span<int> loop_to_poly = data->loop_to_poly;
-
- MutableSpan<float3> loopnors = data->loopnors; /* NOTE: loopnors may be empty here. */
- const Span<float3> polynors = data->polynors;
-
- int(*edge_to_loops)[2] = data->edge_to_loops;
-
- BitVector sharp_edges;
- if (do_sharp_edges_tag) {
- sharp_edges.resize(edges.size(), false);
- }
-
+ using namespace blender;
const float split_angle_cos = check_angle ? cosf(split_angle) : -1.0f;
- for (const int mp_index : polys.index_range()) {
- const MPoly &poly = polys[mp_index];
- int *e2l;
- int ml_curr_index = poly.loopstart;
- const int ml_last_index = (ml_curr_index + poly.totloop) - 1;
-
- for (;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list