Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/geometry/nodes/node_geo_instance_on_points.cc
| Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | b.add_input<decl::Int>("Stable ID") | ||||
| "ID for every instance that is used to identify it over time even when the number of " | "ID for every instance that is used to identify it over time even when the number of " | ||||
| "instances changes. Used for example for motion blur"); | "instances changes. Used for example for motion blur"); | ||||
| b.add_output<decl::Geometry>("Instances"); | b.add_output<decl::Geometry>("Instances"); | ||||
| } | } | ||||
| static void add_instances_from_component(InstancesComponent &dst_component, | static void add_instances_from_component(InstancesComponent &dst_component, | ||||
| const GeometryComponent &src_component, | const GeometryComponent &src_component, | ||||
| const GeometrySet &instance, | |||||
| const GeoNodeExecParams ¶ms) | const GeoNodeExecParams ¶ms) | ||||
| { | { | ||||
| GeometrySet instance = params.get_input<GeometrySet>("Instance"); | |||||
| const AttributeDomain domain = ATTR_DOMAIN_POINT; | const AttributeDomain domain = ATTR_DOMAIN_POINT; | ||||
| const int domain_size = src_component.attribute_domain_size(domain); | const int domain_size = src_component.attribute_domain_size(domain); | ||||
| /* The initial size of the component might be non-zero when this function is called for multiple | /* The initial size of the component might be non-zero when this function is called for multiple | ||||
| * component types. */ | * component types. */ | ||||
| const int start_len = dst_component.instances_amount(); | const int start_len = dst_component.instances_amount(); | ||||
| dst_component.resize(start_len + domain_size); | dst_component.resize(start_len + domain_size); | ||||
| MutableSpan<int> dst_handles = dst_component.instance_reference_handles().slice(start_len, | MutableSpan<int> dst_handles = dst_component.instance_reference_handles().slice(start_len, | ||||
| ▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | if (pick_instance->get_internal_single()) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void geo_node_instance_on_points_exec(GeoNodeExecParams params) | static void geo_node_instance_on_points_exec(GeoNodeExecParams params) | ||||
| { | { | ||||
| GeometrySet geometry_set = params.extract_input<GeometrySet>("Points"); | GeometrySet geometry_set = params.extract_input<GeometrySet>("Points"); | ||||
| GeometrySet geometry_set_out; | GeometrySet instance = params.get_input<GeometrySet>("Instance"); | ||||
| instance.ensure_owns_direct_data(); | |||||
| geometry_set = geometry_set_realize_instances(geometry_set); | |||||
| InstancesComponent &instances = geometry_set_out.get_component_for_write<InstancesComponent>(); | geometry_set.modify_geometry_sets([&](GeometrySet &geometry_set) { | ||||
| InstancesComponent &instances = geometry_set.get_component_for_write<InstancesComponent>(); | |||||
| if (geometry_set.has<MeshComponent>()) { | if (geometry_set.has<MeshComponent>()) { | ||||
| add_instances_from_component( | add_instances_from_component( | ||||
| instances, *geometry_set.get_component_for_read<MeshComponent>(), params); | instances, *geometry_set.get_component_for_read<MeshComponent>(), instance, params); | ||||
| geometry_set.remove(GEO_COMPONENT_TYPE_MESH); | |||||
| } | } | ||||
| if (geometry_set.has<PointCloudComponent>()) { | if (geometry_set.has<PointCloudComponent>()) { | ||||
| add_instances_from_component( | add_instances_from_component(instances, | ||||
| instances, *geometry_set.get_component_for_read<PointCloudComponent>(), params); | *geometry_set.get_component_for_read<PointCloudComponent>(), | ||||
| instance, | |||||
| params); | |||||
| geometry_set.remove(GEO_COMPONENT_TYPE_POINT_CLOUD); | |||||
| } | } | ||||
| if (geometry_set.has<CurveComponent>()) { | if (geometry_set.has<CurveComponent>()) { | ||||
| add_instances_from_component( | add_instances_from_component( | ||||
| instances, *geometry_set.get_component_for_read<CurveComponent>(), params); | instances, *geometry_set.get_component_for_read<CurveComponent>(), instance, params); | ||||
| geometry_set.remove(GEO_COMPONENT_TYPE_CURVE); | |||||
| } | } | ||||
| /* Unused references may have been added above. Remove those now so that other nodes don't | /* Unused references may have been added above. Remove those now so that other nodes don't | ||||
| * process them needlessly. */ | * process them needlessly. */ | ||||
| instances.remove_unused_references(); | instances.remove_unused_references(); | ||||
| }); | |||||
| params.set_output("Instances", std::move(geometry_set_out)); | params.set_output("Instances", std::move(geometry_set)); | ||||
| } | } | ||||
| } // namespace blender::nodes | } // namespace blender::nodes | ||||
| void register_node_type_geo_instance_on_points() | void register_node_type_geo_instance_on_points() | ||||
| { | { | ||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| geo_node_type_base( | geo_node_type_base( | ||||
| &ntype, GEO_NODE_INSTANCE_ON_POINTS, "Instance on Points", NODE_CLASS_GEOMETRY, 0); | &ntype, GEO_NODE_INSTANCE_ON_POINTS, "Instance on Points", NODE_CLASS_GEOMETRY, 0); | ||||
| ntype.declare = blender::nodes::geo_node_instance_on_points_declare; | ntype.declare = blender::nodes::geo_node_instance_on_points_declare; | ||||
| ntype.geometry_node_execute = blender::nodes::geo_node_instance_on_points_exec; | ntype.geometry_node_execute = blender::nodes::geo_node_instance_on_points_exec; | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||