Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_instances_to_points.cc
| Show All 11 Lines | |||||
| * You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
| * along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| */ | */ | ||||
| #include "BKE_pointcloud.h" | #include "BKE_pointcloud.h" | ||||
| #include "DNA_pointcloud_types.h" | #include "DNA_pointcloud_types.h" | ||||
| #include "BKE_attribute_math.hh" | |||||
| #include "node_geometry_util.hh" | #include "node_geometry_util.hh" | ||||
| namespace blender::nodes::node_geo_instances_to_points_cc { | namespace blender::nodes::node_geo_instances_to_points_cc { | ||||
| static void node_declare(NodeDeclarationBuilder &b) | static void node_declare(NodeDeclarationBuilder &b) | ||||
| { | { | ||||
| b.add_input<decl::Geometry>(N_("Instances")).only_instances(); | b.add_input<decl::Geometry>(N_("Instances")).only_instances(); | ||||
| b.add_input<decl::Bool>(N_("Selection")).default_value(true).hide_value().supports_field(); | b.add_input<decl::Bool>(N_("Selection")).default_value(true).hide_value().supports_field(); | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | static void convert_instances_to_points(GeometrySet &geometry_set, | ||||
| evaluator.add(std::move(position_field)); | evaluator.add(std::move(position_field)); | ||||
| evaluator.add(std::move(radius_field)); | evaluator.add(std::move(radius_field)); | ||||
| evaluator.evaluate(); | evaluator.evaluate(); | ||||
| const VArray<float3> &positions = evaluator.get_evaluated<float3>(0); | const VArray<float3> &positions = evaluator.get_evaluated<float3>(0); | ||||
| copy_attribute_to_points(positions, selection, {(float3 *)pointcloud->co, pointcloud->totpoint}); | copy_attribute_to_points(positions, selection, {(float3 *)pointcloud->co, pointcloud->totpoint}); | ||||
| const VArray<float> &radii = evaluator.get_evaluated<float>(1); | const VArray<float> &radii = evaluator.get_evaluated<float>(1); | ||||
| copy_attribute_to_points(radii, selection, {pointcloud->radius, pointcloud->totpoint}); | copy_attribute_to_points(radii, selection, {pointcloud->radius, pointcloud->totpoint}); | ||||
| if (!instances.instance_ids().is_empty()) { | /* Copy dynamic attributes to the points. */ | ||||
| OutputAttribute_Typed<int> id_attribute = points.attribute_try_get_for_output<int>( | instances.attribute_foreach([&](const AttributeIDRef &id, const AttributeMetaData &meta_data) { | ||||
| "id", ATTR_DOMAIN_POINT, CD_PROP_INT32); | GVArray src = instances.attribute_get_for_read( | ||||
| MutableSpan<int> ids = id_attribute.as_span(); | id, ATTR_DOMAIN_INSTANCE, meta_data.data_type, nullptr); | ||||
| for (const int i : selection.index_range()) { | OutputAttribute dst = points.attribute_try_get_for_output_only( | ||||
| ids[i] = instances.instance_ids()[selection[i]]; | id, ATTR_DOMAIN_POINT, meta_data.data_type); | ||||
| } | attribute_math::convert_to_static_type(meta_data.data_type, [&](auto dummy) { | ||||
| id_attribute.save(); | using T = decltype(dummy); | ||||
| } | copy_attribute_to_points(src.typed<T>(), selection, dst.as_span().typed<T>()); | ||||
| }); | |||||
| dst.save(); | |||||
| return true; | |||||
| }); | |||||
| } | } | ||||
| static void node_geo_exec(GeoNodeExecParams params) | static void node_geo_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| GeometrySet geometry_set = params.extract_input<GeometrySet>("Instances"); | GeometrySet geometry_set = params.extract_input<GeometrySet>("Instances"); | ||||
| if (geometry_set.has_instances()) { | if (geometry_set.has_instances()) { | ||||
| convert_instances_to_points(geometry_set, | convert_instances_to_points(geometry_set, | ||||
| Show All 25 Lines | |||||