Page MenuHome
Paste P2729

Instance copying
ActivePublic

Authored by Hans Goudey (HooglyBoogly) on Jan 13 2022, 6:12 AM.
Array<int> offsets(selection.size() + 1);
int dst_size = 0;
for (const int i_selection : selection.index_range()) {
offsets[i_selection] = dst_size;
dst_size += std::max(0, counts[selection[i_selection]]);
}
if (dst_size == 0) {
geometry_set.clear();
return;
}
InstancesComponent dst_instances;
dst_instances.resize(dst_size);
for (const int i_selection : selection.index_range()) {
const int count = offsets[i_selection + 1] - offsets[i_selection];
if (count == 0) {
continue;
}
const int old_handle = src_instances.instance_reference_handles()[i_selection];
const InstanceReference reference = src_instances.references()[old_handle];
const int new_handle = dst_instances.add_reference(reference);
const float4x4 transform = src_instances.instance_transforms()[i_selection];
dst_instances.instance_transforms().slice(offsets[i_selection], count).fill(transform);
dst_instances.instance_reference_handles().slice(offsets[i_selection], count).fill(new_handle);
}

Event Timeline