Geometry Nodes: Avoid creating cyclic attribute when redundant

The default when there is no cyclic attribute is that none of the curves
are cyclic. In the mesh to curve node, avoid creating the attribute with
just false to save time and memory usage. Also avoid looking up the
attribute twice in the trim node.
This commit is contained in:
Hans Goudey 2023-01-19 15:35:58 -06:00
parent 7db00d4ef7
commit baf69b064b
2 changed files with 10 additions and 5 deletions

View File

@ -30,12 +30,16 @@ bke::CurvesGeometry create_curve_from_vert_indices(
curves.offsets_for_write().last() = vert_indices.size();
curves.fill_curve_types(CURVE_TYPE_POLY);
curves.cyclic_for_write().fill(false);
curves.cyclic_for_write().slice(cyclic_curves).fill(true);
const bke::AttributeAccessor mesh_attributes = mesh.attributes();
bke::MutableAttributeAccessor curves_attributes = curves.attributes_for_write();
if (!cyclic_curves.is_empty()) {
bke::SpanAttributeWriter cyclic = curves_attributes.lookup_or_add_for_write_span<bool>(
"cyclic", ATTR_DOMAIN_CURVE);
cyclic.span.slice(cyclic_curves).fill(true);
cyclic.finish();
}
Set<bke::AttributeIDRef> source_attribute_ids = mesh_attributes.all_ids();
for (const bke::AttributeIDRef &attribute_id : source_attribute_ids) {

View File

@ -1064,8 +1064,9 @@ bke::CurvesGeometry trim_curves(const bke::CurvesGeometry &src_curves,
}
else {
/* Only trimmed curves are no longer cyclic. */
if (dst_curves.attributes().contains("cyclic")) {
dst_curves.cyclic_for_write().fill_indices(selection, false);
if (bke::SpanAttributeWriter cyclic = dst_attributes.lookup_for_write_span<bool>("cyclic")) {
cyclic.span.fill_indices(selection, false);
cyclic.finish();
}
Set<std::string> copy_point_skip;