GPv3: Reverse Curve node #113702

Manually merged
Dalai Felinto merged 55 commits from dfelinto/blender:grease-nodes-reverted-node into main 2023-10-16 11:54:19 +02:00
1 changed files with 40 additions and 17 deletions
Showing only changes of commit a93238a922 - Show all commits

View File

@ -5,6 +5,7 @@
#include "BLI_task.hh"
#include "BKE_curves.hh"
#include "BKE_grease_pencil.hh"
#include "node_geometry_util.hh"
@ -12,36 +13,58 @@ namespace blender::nodes::node_geo_curve_reverse_cc {
static void node_declare(NodeDeclarationBuilder &b)
{
b.add_input<decl::Geometry>("Curve").supported_type(GeometryComponent::Type::Curve);
b.add_input<decl::Geometry>("Curve").supported_type(
{GeometryComponent::Type::Curve, GeometryComponent::Type::GreasePencil});
b.add_input<decl::Bool>("Selection").default_value(true).hide_value().field_on_all();
b.add_output<decl::Geometry>("Curve").propagate_all();
}
static void reverse_curve(bke::CurvesGeometry &curves,
const fn::FieldContext &field_context,
const Field<bool> &selection_field)
{
fn::FieldEvaluator selection_evaluator{field_context, curves.curves_num()};
selection_evaluator.add(selection_field);
selection_evaluator.evaluate();
const IndexMask selection = selection_evaluator.get_evaluated_as_mask(0);
if (selection.is_empty()) {
dfelinto marked this conversation as resolved
Review

An empty line between a declaration and a null/empty check isn't usually helpful IMO, tiny thing but might be nicer without it? :)

An empty line between a declaration and a null/empty check isn't usually helpful IMO, tiny thing but might be nicer without it? :)
return;
}
curves.reverse_curves(selection);
}
static void reverse_grease_pencil(GreasePencil &grease_pencil, const Field<bool> &selection_field)
{
using namespace blender::bke::greasepencil;
for (const int layer_index : grease_pencil.layers().index_range()) {
Drawing *drawing = get_eval_grease_pencil_layer_drawing_for_write(grease_pencil, layer_index);
if (drawing == nullptr) {
continue;
}
bke::CurvesGeometry &curves = drawing->strokes_for_write();
const bke::GreasePencilLayerFieldContext field_context(
grease_pencil, ATTR_DOMAIN_CURVE, layer_index);
reverse_curve(curves, field_context, selection_field);
drawing->tag_topology_changed();
}
}
static void node_geo_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.extract_input<GeometrySet>("Curve");
Field<bool> selection_field = params.extract_input<Field<bool>>("Selection");
GeometryComponentEditData::remember_deformed_positions_if_necessary(geometry_set);
geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) {
if (!geometry_set.has_curves()) {
return;
if (Curves *curves_id = geometry_set.get_curves_for_write()) {
bke::CurvesGeometry &curves = curves_id->geometry.wrap();
const bke::CurvesFieldContext field_context{curves, ATTR_DOMAIN_CURVE};
reverse_curve(curves, field_context, selection_field);
}
const Curves &src_curves_id = *geometry_set.get_curves();
const bke::CurvesGeometry &src_curves = src_curves_id.geometry.wrap();
const bke::CurvesFieldContext field_context{src_curves, ATTR_DOMAIN_CURVE};
fn::FieldEvaluator selection_evaluator{field_context, src_curves.curves_num()};
selection_evaluator.add(params.get_input<Field<bool>>("Selection"));
selection_evaluator.evaluate();
const IndexMask selection = selection_evaluator.get_evaluated_as_mask(0);
if (selection.is_empty()) {
return;
if (geometry_set.has_grease_pencil()) {
reverse_grease_pencil(*geometry_set.get_grease_pencil_for_write(), selection_field);
}
Curves &curves_id = *geometry_set.get_curves_for_write();
bke::CurvesGeometry &curves = curves_id.geometry.wrap();
curves.reverse_curves(selection);
});
params.set_output("Curve", std::move(geometry_set));