Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-09-09 16:29:07 +0300
committerHans Goudey <h.goudey@me.com>2022-09-09 16:29:47 +0300
commit291c313f80b4cccc8fcce3035584caeaa654844f (patch)
treecdc3469c825babf773c3c2cc9de678d193bec9db /source/blender/modifiers
parent21f2bacad977d3fd83d9e4730f2a14dc9932f043 (diff)
Mesh: Move bevel weight out of MVert and MEdge
As described in T95966, the goal is to move to a "struct of arrays" approach rather than gathering an arbitrary set of data in hard-coded structs. This has performance benefits, but also code complexity benefits (this patch removes plenty of code, though the boilerplate for the new operators outweighs that here). To mirror the internal change, the options for storing mesh bevel weights are converted into operators that add or remove the layer, like for some other layers. The most complex change is to the solidify modifier, where bevel weights had special handling. Other than that, most changes are removing clearing of the weights, boilerplate for the add/remove operators, and removing the manual transfer of bevel weights in bmesh - mesh conversion. Eventually bevel weights can become a fully generic attribute, but for now this patch aims to avoid most functional changes. Bevel weights are still written and read from the mesh in the old way, so neither forward nor backward compatibility are affected. As described in T95965, writing in the old format will be done until 4.0. Differential Revision: https://developer.blender.org/D14077
Diffstat (limited to 'source/blender/modifiers')
-rw-r--r--source/blender/modifiers/intern/MOD_array.c2
-rw-r--r--source/blender/modifiers/intern/MOD_bevel.c4
-rw-r--r--source/blender/modifiers/intern/MOD_solidify_extrude.c56
-rw-r--r--source/blender/modifiers/intern/MOD_solidify_nonmanifold.c71
4 files changed, 75 insertions, 58 deletions
diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c
index 5ac6bfea879..7feff30968f 100644
--- a/source/blender/modifiers/intern/MOD_array.c
+++ b/source/blender/modifiers/intern/MOD_array.c
@@ -294,7 +294,7 @@ static void mesh_merge_transform(Mesh *result,
for (i = 0; i < cap_nverts; i++, mv++) {
mul_m4_v3(cap_offset, mv->co);
/* Reset MVert flags for caps */
- mv->flag = mv->bweight = 0;
+ mv->flag = 0;
}
/* We have to correct normals too, if we do not tag them as dirty later! */
diff --git a/source/blender/modifiers/intern/MOD_bevel.c b/source/blender/modifiers/intern/MOD_bevel.c
index ee9a2856ab0..668843188ab 100644
--- a/source/blender/modifiers/intern/MOD_bevel.c
+++ b/source/blender/modifiers/intern/MOD_bevel.c
@@ -74,6 +74,10 @@ static void requiredDataMask(Object *UNUSED(ob),
if (bmd->defgrp_name[0] != '\0') {
r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
}
+ if (bmd->lim_flags & MOD_BEVEL_WEIGHT) {
+ r_cddata_masks->vmask |= CD_MASK_BWEIGHT;
+ r_cddata_masks->emask |= CD_MASK_BWEIGHT;
+ }
}
/*
diff --git a/source/blender/modifiers/intern/MOD_solidify_extrude.c b/source/blender/modifiers/intern/MOD_solidify_extrude.c
index 343aa3920d9..1456254c31f 100644
--- a/source/blender/modifiers/intern/MOD_solidify_extrude.c
+++ b/source/blender/modifiers/intern/MOD_solidify_extrude.c
@@ -340,11 +340,6 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
MPoly *mpoly = BKE_mesh_polys_for_write(result);
MLoop *mloop = BKE_mesh_loops_for_write(result);
- if (do_bevel_convex) {
- /* Make sure bweight is enabled. */
- result->cd_flag |= ME_CDFLAG_EDGE_BWEIGHT;
- }
-
if (do_shell) {
CustomData_copy_data(&mesh->vdata, &result->vdata, 0, 0, (int)verts_num);
CustomData_copy_data(&mesh->vdata, &result->vdata, 0, (int)verts_num, (int)verts_num);
@@ -392,6 +387,12 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
CustomData_copy_data(&mesh->pdata, &result->pdata, 0, 0, (int)polys_num);
}
+ float *result_edge_bweight = NULL;
+ if (do_bevel_convex) {
+ result_edge_bweight = CustomData_add_layer(
+ &result->edata, CD_BWEIGHT, CD_SET_DEFAULT, NULL, result->totedge);
+ }
+
/* initializes: (i_end, do_shell_align, mv). */
#define INIT_VERT_ARRAY_OFFSETS(test) \
if (((ofs_new >= ofs_orig) == do_flip) == test) { \
@@ -671,20 +672,18 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
for (uint i = 0; i < edges_num; i++) {
if (edge_users[i] == INVALID_PAIR) {
float angle = edge_angs[i];
- medge[i].bweight = (char)clamp_i(
- (int)medge[i].bweight + (int)((angle < M_PI ? clamp_f(bevel_convex, 0.0f, 1.0f) :
- clamp_f(bevel_convex, -1.0f, 0.0f)) *
- 255),
- 0,
- 255);
+ result_edge_bweight[i] = clamp_f(result_edge_bweight[i] +
+ (angle < M_PI ? clamp_f(bevel_convex, 0.0f, 1.0f) :
+ clamp_f(bevel_convex, -1.0f, 0.0f)),
+ 0.0f,
+ 1.0f);
if (do_shell) {
- medge[i + edges_num].bweight = (char)clamp_i(
- (int)medge[i + edges_num].bweight +
- (int)((angle > M_PI ? clamp_f(bevel_convex, 0.0f, 1.0f) :
- clamp_f(bevel_convex, -1.0f, 0.0f)) *
- 255),
+ result_edge_bweight[i + edges_num] = clamp_f(
+ result_edge_bweight[i + edges_num] + (angle > M_PI ?
+ clamp_f(bevel_convex, 0.0f, 1.0f) :
+ clamp_f(bevel_convex, -1.0f, 0.0f)),
0,
- 255);
+ 1.0f);
}
}
}
@@ -900,20 +899,17 @@ Mesh *MOD_solidify_extrude_modifyMesh(ModifierData *md, const ModifierEvalContex
for (i = 0; i < edges_num; i++) {
if (edge_users[i] == INVALID_PAIR) {
float angle = edge_angs[i];
- medge[i].bweight = (char)clamp_i(
- (int)medge[i].bweight + (int)((angle < M_PI ? clamp_f(bevel_convex, 0, 1) :
- clamp_f(bevel_convex, -1, 0)) *
- 255),
- 0,
- 255);
+ result_edge_bweight[i] = clamp_f(result_edge_bweight[i] +
+ (angle < M_PI ? clamp_f(bevel_convex, 0.0f, 1.0f) :
+ clamp_f(bevel_convex, -1.0f, 0.0f)),
+ 0.0f,
+ 1.0f);
if (do_shell) {
- medge[i + edges_num].bweight = (char)clamp_i(
- (int)medge[i + edges_num].bweight +
- (int)((angle > M_PI ? clamp_f(bevel_convex, 0, 1) :
- clamp_f(bevel_convex, -1, 0)) *
- 255),
- 0,
- 255);
+ result_edge_bweight[i + edges_num] = clamp_f(
+ result_edge_bweight[i + edges_num] +
+ (angle > M_PI ? clamp_f(bevel_convex, 0, 1) : clamp_f(bevel_convex, -1, 0)),
+ 0.0f,
+ 1.0f);
}
}
}
diff --git a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
index e73df0d1c12..d3aff5c58c5 100644
--- a/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
+++ b/source/blender/modifiers/intern/MOD_solidify_nonmanifold.c
@@ -189,6 +189,10 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
const MPoly *orig_mpoly = BKE_mesh_polys(mesh);
const MLoop *orig_mloop = BKE_mesh_loops(mesh);
+ /* 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);
+
uint new_verts_num = 0;
uint new_edges_num = 0;
uint new_loops_num = 0;
@@ -1965,9 +1969,10 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
int *origindex_edge = CustomData_get_layer(&result->edata, CD_ORIGINDEX);
int *origindex_poly = CustomData_get_layer(&result->pdata, CD_ORIGINDEX);
- if (bevel_convex != 0.0f || (result->cd_flag & ME_CDFLAG_VERT_BWEIGHT) != 0) {
- /* make sure bweight is enabled */
- result->cd_flag |= ME_CDFLAG_EDGE_BWEIGHT;
+ float *result_edge_bweight = CustomData_get_layer(&result->edata, CD_BWEIGHT);
+ if (bevel_convex != 0.0f || orig_vert_bweight != NULL) {
+ result_edge_bweight = CustomData_add_layer(
+ &result->edata, CD_BWEIGHT, CD_SET_DEFAULT, NULL, result->totedge);
}
/* Checks that result has dvert data. */
@@ -2038,17 +2043,18 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
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;
- medge[insert].bweight = orig_medge[(*l)->old_edge].bweight;
+ if (result_edge_bweight) {
+ result_edge_bweight[insert] = orig_edge_bweight[(*l)->old_edge];
+ }
if (bevel_convex != 0.0f && (*l)->faces[1] != NULL) {
- medge[insert].bweight = (char)clamp_i(
- (int)medge[insert].bweight + (int)(((*l)->angle > M_PI + FLT_EPSILON ?
- clamp_f(bevel_convex, 0.0f, 1.0f) :
- ((*l)->angle < M_PI - FLT_EPSILON ?
- clamp_f(bevel_convex, -1.0f, 0.0f) :
- 0)) *
- 255),
- 0,
- 255);
+ result_edge_bweight[insert] = clamp_f(
+ result_edge_bweight[insert] +
+ ((*l)->angle > M_PI + FLT_EPSILON ?
+ clamp_f(bevel_convex, 0.0f, 1.0f) :
+ ((*l)->angle < M_PI - FLT_EPSILON ? clamp_f(bevel_convex, -1.0f, 0.0f) :
+ 0)),
+ 0.0f,
+ 1.0f);
}
(*l)->new_edge = insert;
}
@@ -2113,13 +2119,14 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
EdgeGroup *last_g = NULL;
EdgeGroup *first_g = NULL;
char mv_crease = vertex_crease ? (char)(vertex_crease[i] * 255.0f) : 0;
+ 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;
- char max_bweight;
- char last_max_bweight = 0;
- char first_max_bweight = 0;
+ float max_bweight;
+ float last_max_bweight = 0.0f;
+ float first_max_bweight = 0.0f;
short flag;
short last_flag = 0;
short first_flag = 0;
@@ -2142,20 +2149,24 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
max_crease = ed->crease;
}
if (g->edges[k]->new_edge != MOD_SOLIDIFY_EMPTY_TAG) {
- char bweight = medge[g->edges[k]->new_edge].bweight;
- if (bweight > max_bweight) {
- max_bweight = bweight;
+ if (result_edge_bweight) {
+ float bweight = result_edge_bweight[g->edges[k]->new_edge];
+ if (bweight > max_bweight) {
+ max_bweight = bweight;
+ }
}
}
flag |= ed->flag;
}
}
- const char bweight_open_edge = min_cc(
- orig_medge[g->edges[0]->old_edge].bweight,
- orig_medge[g->edges[g->edges_len - 1]->old_edge].bweight);
+ const float bweight_open_edge =
+ orig_edge_bweight ?
+ min_ff(orig_edge_bweight[g->edges[0]->old_edge],
+ orig_edge_bweight[g->edges[g->edges_len - 1]->old_edge]) :
+ 0.0f;
if (bweight_open_edge > 0) {
- max_bweight = min_cc(bweight_open_edge, max_bweight);
+ max_bweight = min_ff(bweight_open_edge, max_bweight);
}
else {
if (bevel_convex < 0.0f) {
@@ -2183,8 +2194,11 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
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));
- medge[edge_index++].bweight = max_cc(mv->bweight,
- min_cc(last_max_bweight, max_bweight));
+ if (result_edge_bweight) {
+ result_edge_bweight[edge_index] = max_ff(mv_bweight,
+ min_ff(last_max_bweight, max_bweight));
+ }
+ edge_index++;
}
last_g = g;
last_max_crease = max_crease;
@@ -2212,8 +2226,11 @@ Mesh *MOD_solidify_nonmanifold_modifyMesh(ModifierData *md,
((last_flag | first_flag) & (ME_SEAM | ME_SHARP));
medge[edge_index].crease = max_cc(mv_crease,
min_cc(last_max_crease, first_max_crease));
- medge[edge_index++].bweight = max_cc(mv->bweight,
- min_cc(last_max_bweight, first_max_bweight));
+ if (result_edge_bweight) {
+ result_edge_bweight[edge_index] = max_ff(
+ mv_bweight, min_ff(last_max_bweight, first_max_bweight));
+ }
+ edge_index++;
/* Loop data. */
int *loops = MEM_malloc_arrayN(j, sizeof(*loops), "loops in solidify");