diff options
author | Hans Goudey <h.goudey@me.com> | 2022-09-23 17:02:05 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-09-23 17:02:28 +0300 |
commit | a8a454287a27d408668f8adc6fe1b3aa988de1ac (patch) | |
tree | a0c55182e620598bb92542562d2fc134091a2c08 /source/blender/modifiers | |
parent | b197cd5821f1dfaa5168d31984dd8014f5252456 (diff) |
Mesh: Move edge crease out of MEdge
This is very similar to D14077. There are two differences though.
First is that vertex creases are already stored in a separate layer,
and second is that we can now completely remove use of `Mesh.cd_flag`,
since that information is now inherent to whether the layers exist.
There are two functional differences here:
* Operators are used to add and remove layers instead of a property.
* The "crease" attribute can be created and removed by geometry nodes.
The second change should make various geometry nodes slightly faster,
since the "crease" attribute was always processed before. Creases are
now interpolated generically in the CustomData API too, which should
help maintain the values across edits better.
Meshes get an `edge_creases` RNA property like the existing vertex
property, to provide more efficient access to the data in Cycles.
One test failure is expected, where different rounding between float
the old char storage means that 5 additional points are scattered in
a geometry nodes test.
Differential Revision: https://developer.blender.org/D15927
Diffstat (limited to 'source/blender/modifiers')
-rw-r--r-- | source/blender/modifiers/intern/MOD_screw.c | 3 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_solidify_extrude.c | 23 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_solidify_nonmanifold.c | 50 |
3 files changed, 47 insertions, 29 deletions
diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c index 6a46edef9a2..71ffe91f364 100644 --- a/source/blender/modifiers/intern/MOD_screw.c +++ b/source/blender/modifiers/intern/MOD_screw.c @@ -444,7 +444,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * for (i = 0; i < totedge; i++, med_orig++, med_new++) { med_new->v1 = med_orig->v1; med_new->v2 = med_orig->v2; - med_new->crease = med_orig->crease; med_new->flag = med_orig->flag & ~ME_LOOSEEDGE; /* Tag #MVert as not loose. */ @@ -1064,7 +1063,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * med_new->v1 = i1; med_new->v2 = i2; med_new->flag = med_new_firstloop->flag; - med_new->crease = med_new_firstloop->crease; med_new++; } i1 += totvert; @@ -1092,7 +1090,6 @@ static Mesh *modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh * med_new->v1 = i1; med_new->v2 = i2; med_new->flag = med_new_firstloop->flag & ~ME_LOOSEEDGE; - med_new->crease = med_new_firstloop->crease; med_new++; } diff --git a/source/blender/modifiers/intern/MOD_solidify_extrude.c b/source/blender/modifiers/intern/MOD_solidify_extrude.c index 1456254c31f..f1758b91a91 100644 --- a/source/blender/modifiers/intern/MOD_solidify_extrude.c +++ b/source/blender/modifiers/intern/MOD_solidify_extrude.c @@ -1024,16 +1024,17 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex NULL; float nor[3]; #endif - const uchar crease_rim = smd->crease_rim * 255.0f; - const uchar crease_outer = smd->crease_outer * 255.0f; - const uchar crease_inner = smd->crease_inner * 255.0f; + const float crease_rim = smd->crease_rim; + const float crease_outer = smd->crease_outer; + const float crease_inner = smd->crease_inner; int *origindex_edge; int *orig_ed; uint j; + float *result_edge_crease = NULL; if (crease_rim || crease_outer || crease_inner) { - result->cd_flag |= ME_CDFLAG_EDGE_CREASE; + result_edge_crease = (float *)CustomData_get_layer(&result->edata, CD_CREASE); } /* add faces & edges */ @@ -1051,7 +1052,7 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex } if (crease_rim) { - ed->crease = crease_rim; + result_edge_crease[ed - medge] = crease_rim; } } @@ -1140,16 +1141,16 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex } if (crease_outer) { /* crease += crease_outer; without wrapping */ - char *cr = &(ed->crease); - int tcr = *cr + crease_outer; - *cr = tcr > 255 ? 255 : tcr; + float *cr = &(result_edge_crease[ed - medge]); + float tcr = *cr + crease_outer; + *cr = tcr > 1.0f ? 1.0f : tcr; } if (crease_inner) { /* crease += crease_inner; without wrapping */ - char *cr = &(medge[edges_num + (do_shell ? eidx : i)].crease); - int tcr = *cr + crease_inner; - *cr = tcr > 255 ? 255 : tcr; + float *cr = &(result_edge_crease[edges_num + (do_shell ? eidx : i)]); + float tcr = *cr + crease_inner; + *cr = tcr > 1.0f ? 1.0f : tcr; } #ifdef SOLIDIFY_SIDE_NORMALS diff --git a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c index d3aff5c58c5..b9b80f3668c 100644 --- a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c +++ b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c @@ -192,6 +192,7 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, /* These might be null. */ const float *orig_vert_bweight = CustomData_get_layer(&mesh->vdata, CD_BWEIGHT); const float *orig_edge_bweight = CustomData_get_layer(&mesh->edata, CD_BWEIGHT); + const float *orig_edge_crease = CustomData_get_layer(&mesh->edata, CD_CREASE); uint new_verts_num = 0; uint new_edges_num = 0; @@ -1984,12 +1985,13 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, /* Get vertex crease layer and ensure edge creases are active if vertex creases are found, since * they will introduce edge creases in the used custom interpolation method. */ const float *vertex_crease = CustomData_get_layer(&mesh->vdata, CD_CREASE); + float *result_edge_crease = NULL; if (vertex_crease) { - result->cd_flag |= ME_CDFLAG_EDGE_CREASE; + result_edge_crease = (float *)CustomData_add_layer( + &result->edata, CD_CREASE, CD_SET_DEFAULT, NULL, result->totedge); /* delete all vertex creases in the result if a rim is used. */ if (do_rim) { CustomData_free_layers(&result->vdata, CD_CREASE, result->totvert); - result->cd_flag &= (char)(~ME_CDFLAG_VERT_CREASE); } } @@ -2042,7 +2044,10 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, medge[insert].v1 = v1; medge[insert].v2 = v2; medge[insert].flag = orig_medge[(*l)->old_edge].flag | ME_EDGEDRAW | ME_EDGERENDER; - medge[insert].crease = orig_medge[(*l)->old_edge].crease; + if (result_edge_crease) { + result_edge_crease[insert] = orig_edge_crease ? orig_edge_crease[(*l)->old_edge] : + 0.0f; + } if (result_edge_bweight) { result_edge_bweight[insert] = orig_edge_bweight[(*l)->old_edge]; } @@ -2118,12 +2123,12 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, EdgeGroup *g2 = gs; EdgeGroup *last_g = NULL; EdgeGroup *first_g = NULL; - char mv_crease = vertex_crease ? (char)(vertex_crease[i] * 255.0f) : 0; + float mv_crease = vertex_crease ? vertex_crease[i] : 0.0f; float mv_bweight = orig_vert_bweight ? orig_vert_bweight[i] : 0.0f; /* Data calculation cache. */ - char max_crease; - char last_max_crease = 0; - char first_max_crease = 0; + float max_crease; + float last_max_crease = 0.0f; + float first_max_crease = 0.0f; float max_bweight; float last_max_bweight = 0.0f; float first_max_bweight = 0.0f; @@ -2139,14 +2144,24 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, BLI_assert(g->edges_len >= 2); if (g->edges_len == 2) { - max_crease = min_cc(orig_medge[g->edges[0]->old_edge].crease, - orig_medge[g->edges[1]->old_edge].crease); + if (result_edge_crease) { + if (orig_edge_crease) { + max_crease = min_ff(orig_edge_crease[g->edges[0]->old_edge], + orig_edge_crease[g->edges[1]->old_edge]); + } + else { + max_crease = 0.0f; + } + } } else { for (uint k = 1; k < g->edges_len - 1; k++) { - const MEdge *ed = orig_medge + g->edges[k]->old_edge; - if (ed->crease > max_crease) { - max_crease = ed->crease; + const uint orig_edge_index = g->edges[k]->old_edge; + const MEdge *ed = &orig_medge[orig_edge_index]; + if (result_edge_crease) { + if (orig_edge_crease && orig_edge_crease[orig_edge_index] > max_crease) { + max_crease = orig_edge_crease[orig_edge_index]; + } } if (g->edges[k]->new_edge != MOD_SOLIDIFY_EMPTY_TAG) { if (result_edge_bweight) { @@ -2193,7 +2208,10 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, medge[edge_index].v2 = g->new_vert; medge[edge_index].flag = ME_EDGEDRAW | ME_EDGERENDER | ((last_flag | flag) & (ME_SEAM | ME_SHARP)); - medge[edge_index].crease = max_cc(mv_crease, min_cc(last_max_crease, max_crease)); + if (result_edge_crease) { + result_edge_crease[edge_index] = max_ff(mv_crease, + min_ff(last_max_crease, max_crease)); + } if (result_edge_bweight) { result_edge_bweight[edge_index] = max_ff(mv_bweight, min_ff(last_max_bweight, max_bweight)); @@ -2224,8 +2242,10 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md, medge[edge_index].v2 = first_g->new_vert; medge[edge_index].flag = ME_EDGEDRAW | ME_EDGERENDER | ((last_flag | first_flag) & (ME_SEAM | ME_SHARP)); - medge[edge_index].crease = max_cc(mv_crease, - min_cc(last_max_crease, first_max_crease)); + if (result_edge_crease) { + result_edge_crease[edge_index] = max_ff(mv_crease, + min_ff(last_max_crease, first_max_crease)); + } if (result_edge_bweight) { result_edge_bweight[edge_index] = max_ff( mv_bweight, min_ff(last_max_bweight, first_max_bweight)); |