Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_points_to_vertices.cc
| Show All 10 Lines | |||||
| namespace blender::nodes::node_geo_points_to_vertices_cc { | namespace blender::nodes::node_geo_points_to_vertices_cc { | ||||
| using blender::Array; | using blender::Array; | ||||
| static void node_declare(NodeDeclarationBuilder &b) | static void node_declare(NodeDeclarationBuilder &b) | ||||
| { | { | ||||
| b.add_input<decl::Geometry>(N_("Points")).supported_type(GEO_COMPONENT_TYPE_POINT_CLOUD); | b.add_input<decl::Geometry>(N_("Points")).supported_type(GEO_COMPONENT_TYPE_POINT_CLOUD); | ||||
| b.add_input<decl::Bool>(N_("Selection")).default_value(true).supports_field().hide_value(); | b.add_input<decl::Bool>(N_("Selection")).default_value(true).field_on_all().hide_value(); | ||||
| b.add_output<decl::Geometry>(N_("Mesh")); | b.add_output<decl::Geometry>(N_("Mesh")).propagate_all(); | ||||
| } | } | ||||
| /* One improvement would be to move the attribute arrays directly to the mesh when possible. */ | /* One improvement would be to move the attribute arrays directly to the mesh when possible. */ | ||||
| static void geometry_set_points_to_vertices(GeometrySet &geometry_set, | static void geometry_set_points_to_vertices( | ||||
| Field<bool> &selection_field) | GeometrySet &geometry_set, | ||||
| Field<bool> &selection_field, | |||||
| const AnonymousAttributePropagationInfo &propagation_info) | |||||
| { | { | ||||
| const PointCloud *points = geometry_set.get_pointcloud_for_read(); | const PointCloud *points = geometry_set.get_pointcloud_for_read(); | ||||
| if (points == nullptr) { | if (points == nullptr) { | ||||
| geometry_set.remove_geometry_during_modify(); | geometry_set.remove_geometry_during_modify(); | ||||
| return; | return; | ||||
| } | } | ||||
| if (points->totpoint == 0) { | if (points->totpoint == 0) { | ||||
| geometry_set.remove_geometry_during_modify(); | geometry_set.remove_geometry_during_modify(); | ||||
| return; | return; | ||||
| } | } | ||||
| bke::PointCloudFieldContext field_context{*points}; | bke::PointCloudFieldContext field_context{*points}; | ||||
| fn::FieldEvaluator selection_evaluator{field_context, points->totpoint}; | fn::FieldEvaluator selection_evaluator{field_context, points->totpoint}; | ||||
| selection_evaluator.add(selection_field); | selection_evaluator.add(selection_field); | ||||
| selection_evaluator.evaluate(); | selection_evaluator.evaluate(); | ||||
| const IndexMask selection = selection_evaluator.get_evaluated_as_mask(0); | const IndexMask selection = selection_evaluator.get_evaluated_as_mask(0); | ||||
| Map<AttributeIDRef, AttributeKind> attributes; | Map<AttributeIDRef, AttributeKind> attributes; | ||||
| geometry_set.gather_attributes_for_propagation( | geometry_set.gather_attributes_for_propagation({GEO_COMPONENT_TYPE_POINT_CLOUD}, | ||||
| {GEO_COMPONENT_TYPE_POINT_CLOUD}, GEO_COMPONENT_TYPE_MESH, false, attributes); | GEO_COMPONENT_TYPE_MESH, | ||||
| false, | |||||
| propagation_info, | |||||
| attributes); | |||||
| Mesh *mesh = BKE_mesh_new_nomain(selection.size(), 0, 0, 0, 0); | Mesh *mesh = BKE_mesh_new_nomain(selection.size(), 0, 0, 0, 0); | ||||
| geometry_set.replace_mesh(mesh); | geometry_set.replace_mesh(mesh); | ||||
| const AttributeAccessor src_attributes = points->attributes(); | const AttributeAccessor src_attributes = points->attributes(); | ||||
| MutableAttributeAccessor dst_attributes = mesh->attributes_for_write(); | MutableAttributeAccessor dst_attributes = mesh->attributes_for_write(); | ||||
| for (Map<AttributeIDRef, AttributeKind>::Item entry : attributes.items()) { | for (Map<AttributeIDRef, AttributeKind>::Item entry : attributes.items()) { | ||||
| Show All 14 Lines | |||||
| } | } | ||||
| static void node_geo_exec(GeoNodeExecParams params) | static void node_geo_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| GeometrySet geometry_set = params.extract_input<GeometrySet>("Points"); | GeometrySet geometry_set = params.extract_input<GeometrySet>("Points"); | ||||
| Field<bool> selection_field = params.extract_input<Field<bool>>("Selection"); | Field<bool> selection_field = params.extract_input<Field<bool>>("Selection"); | ||||
| geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { | geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { | ||||
| geometry_set_points_to_vertices(geometry_set, selection_field); | geometry_set_points_to_vertices( | ||||
| geometry_set, selection_field, params.get_output_propagation_info("Mesh")); | |||||
| }); | }); | ||||
| params.set_output("Mesh", std::move(geometry_set)); | params.set_output("Mesh", std::move(geometry_set)); | ||||
| } | } | ||||
| } // namespace blender::nodes::node_geo_points_to_vertices_cc | } // namespace blender::nodes::node_geo_points_to_vertices_cc | ||||
| void register_node_type_geo_points_to_vertices() | void register_node_type_geo_points_to_vertices() | ||||
| Show All 11 Lines | |||||