Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_proximity.cc
| Show All 23 Lines | |||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "UI_resources.h" | #include "UI_resources.h" | ||||
| #include "node_geometry_util.hh" | #include "node_geometry_util.hh" | ||||
| namespace blender::nodes::node_geo_proximity_cc { | namespace blender::nodes::node_geo_proximity_cc { | ||||
| static void geo_node_proximity_declare(NodeDeclarationBuilder &b) | static void node_declare(NodeDeclarationBuilder &b) | ||||
| { | { | ||||
| b.add_input<decl::Geometry>(N_("Target")) | b.add_input<decl::Geometry>(N_("Target")) | ||||
| .only_realized_data() | .only_realized_data() | ||||
| .supported_type({GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_POINT_CLOUD}); | .supported_type({GEO_COMPONENT_TYPE_MESH, GEO_COMPONENT_TYPE_POINT_CLOUD}); | ||||
| b.add_input<decl::Vector>(N_("Source Position")).implicit_field(); | b.add_input<decl::Vector>(N_("Source Position")).implicit_field(); | ||||
| b.add_output<decl::Vector>(N_("Position")).dependent_field(); | b.add_output<decl::Vector>(N_("Position")).dependent_field(); | ||||
| b.add_output<decl::Float>(N_("Distance")).dependent_field(); | b.add_output<decl::Float>(N_("Distance")).dependent_field(); | ||||
| } | } | ||||
| static void geo_node_proximity_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) | static void node_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr) | ||||
| { | { | ||||
| uiItemR(layout, ptr, "target_element", 0, "", ICON_NONE); | uiItemR(layout, ptr, "target_element", 0, "", ICON_NONE); | ||||
| } | } | ||||
| static void geo_proximity_init(bNodeTree *UNUSED(ntree), bNode *node) | static void geo_proximity_init(bNodeTree *UNUSED(ntree), bNode *node) | ||||
| { | { | ||||
| NodeGeometryProximity *node_storage = (NodeGeometryProximity *)MEM_callocN( | NodeGeometryProximity *node_storage = (NodeGeometryProximity *)MEM_callocN( | ||||
| sizeof(NodeGeometryProximity), __func__); | sizeof(NodeGeometryProximity), __func__); | ||||
| ▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | if (params.single_output_is_required(2, "Distance")) { | ||||
| const int j = mask[i]; | const int j = mask[i]; | ||||
| distances[j] = std::sqrt(distances[j]); | distances[j] = std::sqrt(distances[j]); | ||||
| } | } | ||||
| }); | }); | ||||
| } | } | ||||
| } | } | ||||
| }; | }; | ||||
| static void geo_node_proximity_exec(GeoNodeExecParams params) | static void node_geo_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| GeometrySet geometry_set_target = params.extract_input<GeometrySet>("Target"); | GeometrySet geometry_set_target = params.extract_input<GeometrySet>("Target"); | ||||
| geometry_set_target.ensure_owns_direct_data(); | geometry_set_target.ensure_owns_direct_data(); | ||||
| auto return_default = [&]() { | auto return_default = [&]() { | ||||
| params.set_output("Position", fn::make_constant_field<float3>({0.0f, 0.0f, 0.0f})); | params.set_output("Position", fn::make_constant_field<float3>({0.0f, 0.0f, 0.0f})); | ||||
| params.set_output("Distance", fn::make_constant_field<float>(0.0f)); | params.set_output("Distance", fn::make_constant_field<float>(0.0f)); | ||||
| }; | }; | ||||
| Show All 22 Lines | void register_node_type_geo_proximity() | ||||
| namespace file_ns = blender::nodes::node_geo_proximity_cc; | namespace file_ns = blender::nodes::node_geo_proximity_cc; | ||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| geo_node_type_base(&ntype, GEO_NODE_PROXIMITY, "Geometry Proximity", NODE_CLASS_GEOMETRY, 0); | geo_node_type_base(&ntype, GEO_NODE_PROXIMITY, "Geometry Proximity", NODE_CLASS_GEOMETRY, 0); | ||||
| node_type_init(&ntype, file_ns::geo_proximity_init); | node_type_init(&ntype, file_ns::geo_proximity_init); | ||||
| node_type_storage( | node_type_storage( | ||||
| &ntype, "NodeGeometryProximity", node_free_standard_storage, node_copy_standard_storage); | &ntype, "NodeGeometryProximity", node_free_standard_storage, node_copy_standard_storage); | ||||
| ntype.declare = file_ns::geo_node_proximity_declare; | ntype.declare = file_ns::node_declare; | ||||
| ntype.geometry_node_execute = file_ns::geo_node_proximity_exec; | ntype.geometry_node_execute = file_ns::node_geo_exec; | ||||
| ntype.draw_buttons = file_ns::geo_node_proximity_layout; | ntype.draw_buttons = file_ns::node_layout; | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||