1
1

Geometry Nodes: instance on points in instances

For consistency with other nodes, we also want to process
all instances in the Points input independently. This allows
for more efficient instancing of many objects but also leads
to nested instancing. All instances are processed in their
local space, so that instances don't have to be realized.

Differential Revision: https://developer.blender.org/D12660
This commit is contained in:
2021-09-29 10:08:40 +02:00
parent 8cbec0beb2
commit f51bef75f4

View File

@@ -163,28 +163,31 @@ static void add_instances_from_component(InstancesComponent &dst_component,
static void geo_node_instance_on_points_exec(GeoNodeExecParams params)
{
GeometrySet geometry_set = params.extract_input<GeometrySet>("Points");
GeometrySet geometry_set_out;
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>()) {
add_instances_from_component(
instances, *geometry_set.get_component_for_read<MeshComponent>(), params);
}
if (geometry_set.has<PointCloudComponent>()) {
add_instances_from_component(
instances, *geometry_set.get_component_for_read<PointCloudComponent>(), params);
}
if (geometry_set.has<CurveComponent>()) {
add_instances_from_component(
instances, *geometry_set.get_component_for_read<CurveComponent>(), params);
}
if (geometry_set.has<MeshComponent>()) {
add_instances_from_component(
instances, *geometry_set.get_component_for_read<MeshComponent>(), params);
geometry_set.remove(GEO_COMPONENT_TYPE_MESH);
}
if (geometry_set.has<PointCloudComponent>()) {
add_instances_from_component(
instances, *geometry_set.get_component_for_read<PointCloudComponent>(), params);
geometry_set.remove(GEO_COMPONENT_TYPE_POINT_CLOUD);
}
if (geometry_set.has<CurveComponent>()) {
add_instances_from_component(
instances, *geometry_set.get_component_for_read<CurveComponent>(), params);
geometry_set.remove(GEO_COMPONENT_TYPE_CURVE);
}
/* Unused references may have been added above. Remove those now so that other nodes don't
* process them needlessly. */
instances.remove_unused_references();
});
/* Unused references may have been added above. Remove those now so that other nodes don't
* process them needlessly. */
instances.remove_unused_references();
params.set_output("Instances", std::move(geometry_set_out));
params.set_output("Instances", std::move(geometry_set));
}
} // namespace blender::nodes