[Bf-blender-cvs] [bcd1a5af896] gsoc-2021-porting-modifiers-to-nodes-solidify: Cleanup
Fabian Schempp
noreply at git.blender.org
Thu Jul 15 11:20:09 CEST 2021
Commit: bcd1a5af896719ee64c6aef94d93c0af52f88e50
Author: Fabian Schempp
Date: Thu Jul 15 11:18:43 2021 +0200
Branches: gsoc-2021-porting-modifiers-to-nodes-solidify
https://developer.blender.org/rBbcd1a5af896719ee64c6aef94d93c0af52f88e50
Cleanup
===================================================================
M source/blender/blenkernel/BKE_solidifiy.h
M source/blender/makesdna/DNA_mesh_types.h
M source/blender/makesrna/intern/rna_nodetree.c
M source/blender/modifiers/intern/MOD_solidify.c
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 c55a225de84..1929f6c45d2 100644
--- a/source/blender/blenkernel/BKE_solidifiy.h
+++ b/source/blender/blenkernel/BKE_solidifiy.h
@@ -28,15 +28,15 @@ typedef struct SolidifyData {
float merge_tolerance;
float bevel_convex;
- float *distance;
+ const float *distance;
} SolidifyData;
struct Mesh *solidify_nonmanifold(const SolidifyData *solidify_data,
- struct Mesh *mesh,
- bool **r_shell_verts,
- bool **r_rim_verts,
- bool **r_shell_faces,
- bool **r_rim_faces);
+ struct Mesh *mesh,
+ bool **r_shell_verts,
+ bool **r_rim_verts,
+ bool **r_shell_faces,
+ bool **r_rim_faces);
#ifdef __cplusplus
}
diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h
index 2a569c8db50..c54c086affd 100644
--- a/source/blender/makesdna/DNA_mesh_types.h
+++ b/source/blender/makesdna/DNA_mesh_types.h
@@ -281,9 +281,9 @@ enum {
/* We can't have both flags enabled at once,
* flags defined in DNA_scene_types.h */
#define ME_EDIT_PAINT_SEL_MODE(_me) \
- (((_me)->editflag & ME_EDIT_PAINT_FACE_SEL) ? SCE_SELECT_FACE : \
- ((_me)->editflag & ME_EDIT_PAINT_VERT_SEL) ? SCE_SELECT_VERTEX : \
- 0)
+ (((_me)->editflag & ME_EDIT_PAINT_FACE_SEL) ? \
+ SCE_SELECT_FACE : \
+ ((_me)->editflag & ME_EDIT_PAINT_VERT_SEL) ? SCE_SELECT_VERTEX : 0)
/* me->flag */
enum {
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index acfc0f0324d..280e6185768 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -9645,7 +9645,8 @@ static void def_geo_solidify(StructRNA *srna)
prop = RNA_def_property(srna, "thickness_mode", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, rna_node_geometry_attribute_input_type_items_float);
- RNA_def_property_ui_text(prop, "Thickness", "Changes the Thickness input between Float and Attribute");
+ RNA_def_property_ui_text(
+ prop, "Thickness", "Changes the Thickness input between Float and Attribute");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update");
prop = RNA_def_property(srna, "nonmanifold_offset_mode", PROP_ENUM, PROP_NONE);
diff --git a/source/blender/modifiers/intern/MOD_solidify.c b/source/blender/modifiers/intern/MOD_solidify.c
index 6140ed5e3d9..11382ca823a 100644
--- a/source/blender/modifiers/intern/MOD_solidify.c
+++ b/source/blender/modifiers/intern/MOD_solidify.c
@@ -86,39 +86,29 @@ static void requiredDataMask(Object *UNUSED(ob),
}
}
-static float *get_distance_factor(Mesh *mesh, Object *ob, const char *name, bool invert)
+static void get_distance_factor(
+ Mesh *mesh, Object *ob, const char *name, bool invert, float *r_selection)
{
int defgrp_index = BKE_object_defgroup_name_index(ob, name);
- MDeformVert *dvert = mesh->dvert;
- float *selection = MEM_callocN(sizeof(float) * (unsigned long)mesh->totvert, __func__);
-
- if (defgrp_index != -1) {
- if (ob->type == OB_LATTICE) {
- dvert = BKE_lattice_deform_verts_get(ob);
- }
- else if (mesh) {
- dvert = mesh->dvert;
- for (int i = 0; i < mesh->totvert; i++) {
- MDeformVert *dv = &dvert[i];
- printf("sel: %i\n", defgrp_index);
- selection[i] = BKE_defvert_find_weight(dv, defgrp_index);
- }
+ if (mesh && defgrp_index != -1) {
+ MDeformVert *dvert = mesh->dvert;
+ for (int i = 0; i < mesh->totvert; i++) {
+ MDeformVert *dv = &dvert[i];
+ r_selection[i] = BKE_defvert_find_weight(dv, defgrp_index);
}
}
else {
for (int i = 0; i < mesh->totvert; i++) {
- selection[i] = 1.0f;
+ r_selection[i] = 1.0f;
}
}
if (invert) {
for (int i = 0; i < mesh->totvert; i++) {
- selection[i] = 1.0f - selection[i];
+ r_selection[i] = 1.0f - r_selection[i];
}
}
-
- return selection;
}
static SolidifyData solidify_data_from_modifier_data(ModifierData *md,
@@ -147,14 +137,16 @@ static SolidifyData solidify_data_from_modifier_data(ModifierData *md,
}
static Mesh *solidify_nonmanifold_modify_mesh(ModifierData *md,
- const ModifierEvalContext *ctx,
- Mesh *mesh,
- const SolidifyModifierData *smd)
+ 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);
+ float *selection = MEM_callocN(sizeof(float) * (uint64_t)mesh->totvert, __func__);
+ get_distance_factor(mesh, ctx->object, smd->defgrp_name, defgrp_invert, selection);
+ solidify_data.distance = selection;
bool *shell_verts = NULL;
bool *rim_verts = NULL;
@@ -224,7 +216,7 @@ static Mesh *solidify_nonmanifold_modify_mesh(ModifierData *md,
}
}
- MEM_freeN(solidify_data.distance);
+ MEM_freeN(selection);
MEM_freeN(shell_verts);
MEM_freeN(rim_verts);
MEM_freeN(shell_faces);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_solidify.cc b/source/blender/nodes/geometry/nodes/node_geo_solidify.cc
index 71f9176fb5a..2ad64dc98a2 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_solidify.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_solidify.cc
@@ -33,8 +33,8 @@
static bNodeSocketTemplate geo_node_solidify_in[] = {
{SOCK_GEOMETRY, N_("Geometry")},
{SOCK_STRING, N_("Thickness")},
- {SOCK_FLOAT, N_("Thickness"), 0.1f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_DISTANCE},
- {SOCK_FLOAT, N_("Clamp"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f},
+ {SOCK_FLOAT, N_("Thickness"), 0.0f, 0.0f, 0.0f, 0.0f, -FLT_MAX, FLT_MAX, PROP_DISTANCE},
+ {SOCK_FLOAT, N_("Clamp"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 2.0f, PROP_FACTOR},
{SOCK_FLOAT, N_("Offset"), -1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, PROP_FACTOR},
{SOCK_BOOLEAN, N_("Fill"), true},
{SOCK_BOOLEAN, N_("Rim"), true},
@@ -50,15 +50,6 @@ static bNodeSocketTemplate geo_node_solidify_out[] = {
namespace blender::nodes {
-static void geo_node_solidify_init(bNodeTree *UNUSED(tree), bNode *node)
-{
- NodeGeometrySolidify *node_storage = (NodeGeometrySolidify *)MEM_callocN(
- sizeof(NodeGeometrySolidify), __func__);
-
- node->storage = node_storage;
- node_storage->thickness_mode = GEO_NODE_ATTRIBUTE_INPUT_FLOAT;
-}
-
static void geo_node_solidify_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiLayoutSetPropSep(layout, true);
@@ -68,6 +59,15 @@ static void geo_node_solidify_layout(uiLayout *layout, bContext *UNUSED(C), Poin
uiItemR(layout, ptr, "nonmanifold_boundary_mode", 0, nullptr, ICON_NONE);
}
+static void geo_node_solidify_init(bNodeTree *UNUSED(tree), bNode *node)
+{
+ NodeGeometrySolidify *node_storage = (NodeGeometrySolidify *)MEM_callocN(
+ sizeof(NodeGeometrySolidify), __func__);
+
+ node->storage = node_storage;
+ node_storage->thickness_mode = GEO_NODE_ATTRIBUTE_INPUT_FLOAT;
+}
+
static void geo_node_solidify_update(bNodeTree *UNUSED(ntree), bNode *node)
{
const NodeGeometrySolidify *node_storage = (NodeGeometrySolidify *)node->storage;
@@ -104,19 +104,12 @@ static void geo_node_solidify_exec(GeoNodeExecParams params)
if (geometry_set.has<MeshComponent>()) {
MeshComponent &mesh_component = geometry_set.get_component_for_write<MeshComponent>();
Mesh *input_mesh = mesh_component.get_for_write();
- Mesh *output_mesh;
- GVArrayPtr thickness = params.get_input_attribute(
- "Thickness", mesh_component, ATTR_DOMAIN_POINT, CD_PROP_FLOAT, nullptr);
- if (!thickness) {
- return;
- }
- float *distance = (float *)MEM_callocN(sizeof(float) * (unsigned long)input_mesh->totvert,
- __func__);
+ const float default_thickness = 0;
+ GVArray_Typed<float> thickness_attribute = params.get_input_attribute<float>(
- for (int i : thickness->typed<float>().index_range()) {
- distance[i] = thickness->typed<float>()[i];
- }
+ "Thickness", mesh_component, ATTR_DOMAIN_POINT, default_thickness);
+ VArray_Span<float> thickness{thickness_attribute};
SolidifyData solidify_node_data = {
self_object,
@@ -129,7 +122,7 @@ static void geo_node_solidify_exec(GeoNodeExecParams params)
flag,
0.01f,
0.0f,
- distance,
+ thickness.data(),
};
bool *shell_verts = nullptr;
@@ -137,10 +130,12 @@ static void geo_node_solidify_exec(GeoNodeExecParams params)
bool *shell_faces = nullptr;
bool *rim_faces = nullptr;
- output_mesh = solidify_nonmanifold(
+ Mesh *output_mesh = solidify_nonmanifold(
&solidify_node_data, input_mesh, &shell_verts, &rim_verts, &shell_faces, &rim_faces);
- geometry_set.replace_mesh(output_mesh);
+ if (output_mesh != input_mesh) {
+ geometry_set.replace_mesh(output_mesh);
+ }
const AttributeDomain result_face_domain = ATTR_DOMAIN_FACE;
@@ -169,7 +164,6 @@ static void geo_node_solidify_exec(GeoNodeExecParams params)
}
}
- MEM_freeN(distance);
MEM_freeN(shell_verts);
MEM_freeN(rim_verts);
MEM_freeN(shell_faces);
More information about the Bf-blender-cvs
mailing list