[Bf-blender-cvs] [328406cf608] gsoc-2021-porting-modifiers-to-nodes-solidify: generalized material offset for solidify_modifier
Fabian Schempp
noreply at git.blender.org
Fri Jun 18 21:15:48 CEST 2021
Commit: 328406cf608c6c45338760ecace19e48a7793d31
Author: Fabian Schempp
Date: Fri Jun 18 21:14:59 2021 +0200
Branches: gsoc-2021-porting-modifiers-to-nodes-solidify
https://developer.blender.org/rB328406cf608c6c45338760ecace19e48a7793d31
generalized material offset for solidify_modifier
===================================================================
M source/blender/blenkernel/BKE_solidifiy.h
M source/blender/blenkernel/intern/solidify_nonmanifold.c
M source/blender/modifiers/intern/MOD_solidify.c
M source/blender/modifiers/intern/MOD_solidify_util.h
M source/blender/nodes/geometry/nodes/node_geo_solidify.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_solidifiy.h b/source/blender/blenkernel/BKE_solidifiy.h
index 8c79e6ef7db..c6a902c9def 100644
--- a/source/blender/blenkernel/BKE_solidifiy.h
+++ b/source/blender/blenkernel/BKE_solidifiy.h
@@ -44,7 +44,9 @@ typedef struct SolidifyData {
Mesh *solidify_nonmanifold(const SolidifyData *solidify_data,
Mesh *mesh,
bool **r_shell_verts,
- bool **r_rim_verts);
+ bool **r_rim_verts,
+ bool **r_shell_faces,
+ bool **r_rim_faces);
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/intern/solidify_nonmanifold.c b/source/blender/blenkernel/intern/solidify_nonmanifold.c
index a72ee14a08b..b381403babd 100644
--- a/source/blender/blenkernel/intern/solidify_nonmanifold.c
+++ b/source/blender/blenkernel/intern/solidify_nonmanifold.c
@@ -135,7 +135,9 @@ static int comp_float_int_pair(const void *a, const void *b)
Mesh *solidify_nonmanifold(const SolidifyData *solidify_data,
Mesh *mesh,
bool **r_shell_verts,
- bool **r_rim_verts)
+ bool **r_rim_verts,
+ bool **r_shell_faces,
+ bool **r_rim_faces)
{
Mesh *result;
@@ -152,12 +154,6 @@ Mesh *solidify_nonmanifold(const SolidifyData *solidify_data,
return mesh;
}
- /* Only use material offsets if we have 2 or more materials. */
- const short mat_nrs = solidify_data->object->totcol > 1 ? solidify_data->object->totcol : 1;
- const short mat_nr_max = mat_nrs - 1;
- const short mat_ofs = mat_nrs > 1 ? solidify_data->mat_ofs : 0;
- const short mat_ofs_rim = mat_nrs > 1 ? solidify_data->mat_ofs_rim : 0;
-
float(*poly_nors)[3] = NULL;
const float ofs_front = (solidify_data->offset_fac + 1.0f) * 0.5f * solidify_data->offset;
@@ -1920,6 +1916,21 @@ Mesh *solidify_nonmanifold(const SolidifyData *solidify_data,
(*r_rim_verts)[i] = false;
}
+ *r_shell_faces = MEM_malloc_arrayN(
+ (size_t)result->totpoly, sizeof(bool), "shell faces selection in solidify");
+
+ for (int i = 0; i < result->totpoly; i++) {
+ (*r_shell_faces)[i] = false;
+ }
+
+ *r_rim_faces = MEM_malloc_arrayN(
+ (size_t)result->totpoly, sizeof(bool), "rim faces selection in solidify");
+
+ for (int i = 0; i < result->totpoly; i++) {
+ (*r_rim_faces)[i] = false;
+ }
+
+
/* Make_new_verts. */
{
gs_ptr = orig_vert_groups_arr;
@@ -2146,50 +2157,17 @@ Mesh *solidify_nonmanifold(const SolidifyData *solidify_data,
/* Loop data. */
int *loops = MEM_malloc_arrayN(j, sizeof(*loops), "loops in solidify");
- /* The #mat_nr is from consensus. */
- short most_mat_nr = 0;
- uint most_mat_nr_face = 0;
- uint most_mat_nr_count = 0;
- for (short l = 0; l < mat_nrs; l++) {
- uint count = 0;
- uint face = 0;
- uint k = 0;
- for (EdgeGroup *g3 = g2; g3->valid && k < j; g3++) {
- if ((do_rim && !g3->is_orig_closed) || (do_shell && g3->split)) {
- /* Check both far ends in terms of faces of an edge group. */
- if (g3->edges[0]->faces[0]->face->mat_nr == l) {
- face = g3->edges[0]->faces[0]->index;
- count++;
- }
- NewEdgeRef *le = g3->edges[g3->edges_len - 1];
- if (le->faces[1] && le->faces[1]->face->mat_nr == l) {
- face = le->faces[1]->index;
- count++;
- }
- else if (!le->faces[1] && le->faces[0]->face->mat_nr == l) {
- face = le->faces[0]->index;
- count++;
- }
- k++;
- }
- }
- if (count > most_mat_nr_count) {
- most_mat_nr = l;
- most_mat_nr_face = face;
- most_mat_nr_count = count;
- }
- }
- CustomData_copy_data(
- &mesh->pdata, &result->pdata, (int)most_mat_nr_face, (int)poly_index, 1);
+
if (origindex_poly) {
origindex_poly[poly_index] = ORIGINDEX_NONE;
}
mpoly[poly_index].loopstart = (int)loop_index;
mpoly[poly_index].totloop = (int)j;
- mpoly[poly_index].mat_nr = most_mat_nr +
- (g->is_orig_closed || !do_rim ? 0 : mat_ofs_rim);
- CLAMP(mpoly[poly_index].mat_nr, 0, mat_nr_max);
- mpoly[poly_index].flag = orig_mpoly[most_mat_nr_face].flag;
+
+ if(g->is_orig_closed || !do_rim){
+ (*r_rim_faces)[poly_index] = true;
+ }
+
poly_index++;
for (uint k = 0; g2->valid && k < j; g2++) {
@@ -2261,8 +2239,8 @@ Mesh *solidify_nonmanifold(const SolidifyData *solidify_data,
&mesh->pdata, &result->pdata, (int)(*new_edges)->faces[0]->index, (int)poly_index, 1);
mpoly[poly_index].loopstart = (int)loop_index;
mpoly[poly_index].totloop = 4 - (int)(v1_singularity || v2_singularity);
- mpoly[poly_index].mat_nr = face->mat_nr + mat_ofs_rim;
- CLAMP(mpoly[poly_index].mat_nr, 0, mat_nr_max);
+
+ (*r_rim_faces)[poly_index] = true;
mpoly[poly_index].flag = face->flag;
poly_index++;
@@ -2442,8 +2420,10 @@ Mesh *solidify_nonmanifold(const SolidifyData *solidify_data,
CustomData_copy_data(&mesh->pdata, &result->pdata, (int)(i / 2), (int)poly_index, 1);
mpoly[poly_index].loopstart = (int)loop_index;
mpoly[poly_index].totloop = (int)k;
- mpoly[poly_index].mat_nr = fr->face->mat_nr + (fr->reversed != do_flip ? mat_ofs : 0);
- CLAMP(mpoly[poly_index].mat_nr, 0, mat_nr_max);
+
+ if(fr->reversed != do_flip){
+ (*r_shell_faces)[poly_index] = true;
+ }
mpoly[poly_index].flag = fr->face->flag;
if (fr->reversed != do_flip) {
for (int l = (int)k - 1; l >= 0; l--) {
@@ -2473,27 +2453,28 @@ Mesh *solidify_nonmanifold(const SolidifyData *solidify_data,
MEM_freeN(face_verts);
MEM_freeN(face_edges);
}
- if (edge_index != numNewEdges) {
+ /* Haven't found a good way to generalize this. */
+ //if (edge_index != numNewEdges) {
/*BKE_modifier_set_error(ctx->object,
md,
"Internal Error: edges array wrong size: %u instead of %u",
numNewEdges,
edge_index);*/
- }
- if (poly_index != numNewPolys) {
+ //}
+ //if (poly_index != numNewPolys) {
/*BKE_modifier_set_error(ctx->object,
md,
"Internal Error: polys array wrong size: %u instead of %u",
numNewPolys,f
poly_index);*/
- }
- if (loop_index != numNewLoops) {
+ //}
+ //if (loop_index != numNewLoops) {
/*BKE_modifier_set_error(ctx->object,
md,
"Internal Error: loops array wrong size: %u instead of %u",
numNewLoops,
loop_index);*/
- }
+ //}
BLI_assert(edge_index == numNewEdges);
BLI_assert(poly_index == numNewPolys);
BLI_assert(loop_index == numNewLoops);
diff --git a/source/blender/modifiers/intern/MOD_solidify.c b/source/blender/modifiers/intern/MOD_solidify.c
index 6baa35e8067..0c02823791c 100644
--- a/source/blender/modifiers/intern/MOD_solidify.c
+++ b/source/blender/modifiers/intern/MOD_solidify.c
@@ -161,6 +161,94 @@ static const SolidifyData solidify_data_from_modifier_data(ModifierData *md,
return solidify_data;
}
+static Mesh *MOD_solidify_nonmanifold(ModifierData *md,
+ const ModifierEvalContext *ctx,
+ Mesh *mesh,
+ const SolidifyModifierData *smd)
+{
+ SolidifyData solidify_data = solidify_data_from_modifier_data(md, ctx);
+
+ const bool defgrp_invert = (solidify_data.flag & MOD_SOLIDIFY_VGROUP_INV) != 0;
+ solidify_data.distance = get_distance_factor(
+ mesh, ctx->object, smd->defgrp_name, defgrp_invert);
+
+ bool *shell_verts = NULL;
+ bool *rim_verts = NULL;
+ bool *shell_faces = NULL;
+ bool *rim_faces = NULL;
+
+ Mesh *output_mesh = solidify_nonmanifold(&solidify_data, mesh, &shell_verts, &rim_verts, &shell_faces, &rim_faces);
+
+ const int shell_defgrp_index = BKE_object_defgroup_name_index(ctx->object,
+ smd->shell_defgrp_name);
+ const int rim_defgrp_index = BKE_object_defgroup_name_index(ctx->object,
+ smd->rim_defgrp_name);
+
+ MDeformVert *dvert;
+ if (shell_defgrp_index != -1 || rim_defgrp_index != -1) {
+ dvert = CustomData_duplicate_referenced_layer(
+ &output_mesh->vdata, CD_MDEFORMVERT, output_mesh->totvert);
+ /* If no vertices were ever added to an object's vgroup, dvert might be NULL. */
+ if (dvert == NULL) {
+ /* Add a valid data layer! */
+ dvert = CustomData_add_layer(
+ &output_mesh->vdata, CD_MDEFORMVERT, CD_CALLOC, NULL, output_mesh->totvert);
+ }
+ output_mesh->dvert = dvert;
+ if ((solidify_data.flag & MOD_SOLIDIFY_SHELL) && shell_defgrp_index != -1) {
+ for (int i = 0; i < output_mesh->totvert; i++) {
+ BKE_defvert_ensure_index(&output_mesh->dvert[i], shell_defgrp_index)->weight =
+ shell_verts[i];
+ }
+ }
+ if ((solidify_data.flag & MOD_SOLIDIFY_RIM) && rim_defgrp_index != -1) {
+ for (int i = 0; i < output_mesh->totvert; i++) {
+ BKE_defvert_ensure_index(&output_mesh->dvert[i], rim_defgrp_index)->weight =
+ rim_verts[i];
+ }
+ }
+ }
+
+ /*
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list