Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_trace_image.cc
- This file was added.
| /* SPDX-License-Identifier: GPL-2.0-or-later */ | |||||
| #include "UI_interface.h" | |||||
| #include "UI_resources.h" | |||||
| #include "BKE_curves.hh" | |||||
| #include "BKE_geometry_set.hh" | |||||
| #include "BKE_image.h" | |||||
| #include "node_geometry_util.hh" | |||||
| #include "GEO_trace_image.hh" | |||||
| namespace blender::nodes::neo_geo_trace_image_cc { | |||||
| NODE_STORAGE_FUNCS(NodeGeometryTraceImage) | |||||
| static void node_declare(NodeDeclarationBuilder &b) | |||||
| { | |||||
| b.add_input<decl::Image>(N_("Image")); | |||||
| b.add_input<decl::Int>(N_("Resolution")).default_value(5).min(1).max(10); | |||||
| b.add_input<decl::Float>(N_("Scale")).default_value(1.0f).min(0.0f); | |||||
| b.add_input<decl::Float>(N_("Color Threshold")).default_value(0.5f).min(0.0f).max(1.0f); | |||||
| b.add_output<decl::Geometry>(N_("Curve")); | |||||
| } | |||||
| static void node_init(bNodeTree *UNUSED(tree), bNode *node) | |||||
| { | |||||
| NodeGeometryTraceImage *data = MEM_cnew<NodeGeometryTraceImage>(__func__); | |||||
| data->turn_policy = GEO_NODE_TRACE_IMAGE_TURN_POLICY_BLACK; | |||||
| node->storage = data; | |||||
| } | |||||
| static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) | |||||
| { | |||||
| uiItemR(layout, ptr, "turn_policy", 0, IFACE_("Turn Policy"), ICON_NONE); | |||||
| } | |||||
HooglyBoogly: I don't know if this is just a WIP patch thing, but I think it's worth refactoring this a bit… | |||||
| static void node_geo_exec(GeoNodeExecParams params) | |||||
| { | |||||
| const NodeGeometryTraceImage &storage = node_storage(params.node()); | |||||
| const GeometryNodeTraceImageTurnPolicy turn_policy = GeometryNodeTraceImageTurnPolicy( | |||||
| storage.turn_policy); | |||||
| Image *image = params.get_input<Image *>("Image"); | |||||
| if (image == nullptr) { | |||||
| params.set_output("Curve", GeometrySet()); | |||||
| return; | |||||
| } | |||||
| float scale = params.get_input<float>("Scale"); | |||||
| int resolution = std::max(3, params.get_input<int>("Resolution")); | |||||
| float threshold = params.get_input<float>("Color Threshold"); | |||||
| Curves *curves = geometry::trace_image(image, turn_policy, threshold, resolution, scale); | |||||
| params.set_output("Curve", GeometrySet::create_with_curves(curves)); | |||||
| } | |||||
| } // namespace blender::nodes::neo_geo_trace_image_cc | |||||
| void register_node_type_geo_trace_image() | |||||
| { | |||||
| namespace file_ns = blender::nodes::neo_geo_trace_image_cc; | |||||
| static bNodeType ntype; | |||||
| geo_node_type_base(&ntype, GEO_NODE_TRACE_IMAGE, "Trace Image", NODE_CLASS_GEOMETRY); | |||||
| ntype.declare = file_ns::node_declare; | |||||
| ntype.initfunc = file_ns::node_init; | |||||
| ntype.geometry_node_execute = file_ns::node_geo_exec; | |||||
| ntype.draw_buttons = file_ns::node_layout; | |||||
| node_type_size(&ntype, 280, 120, 700); | |||||
| node_type_storage( | |||||
| &ntype, "NodeGeometryTraceImage", node_free_standard_storage, node_copy_standard_storage); | |||||
| nodeRegisterType(&ntype); | |||||
| } | |||||
Done Inline ActionsMaybe it would be simpler to do the scale and offset in separate passes afterwards, so they don't need to be passed around this deep. HooglyBoogly: Maybe it would be simpler to do the scale and offset in separate passes afterwards, so they… | |||||
Done Inline ActionsIt looks like this is just evaluating a Bezier spline. In that case, it's probably preferable to create a Bezier output directly, for more artistic control later on. Maybe I'm misinterpreting this code. HooglyBoogly: It looks like this is just evaluating a Bezier spline. In that case, it's probably preferable… | |||||
Done Inline ActionsSome of these macros aren't used at all. Maybe they weren't used where you copied them from either. HooglyBoogly: Some of these macros aren't used at all. Maybe they weren't used where you copied them from… | |||||
Done Inline ActionsKeep these three functions at the top, like other files. HooglyBoogly: Keep these three functions at the top, like other files. | |||||
I don't know if this is just a WIP patch thing, but I think it's worth refactoring this a bit further. A couple options:
I think the first option is probably better, though it would involve changing grease pencil code too.