Geometry Nodes: Optimize curve builtin attribute exists check

Calculating the number of points is overkill here, if there are many splines.
The `exists` check just needs to know if there are any points at all.
This commit is contained in:
Hans Goudey 2021-10-18 12:31:01 -05:00
parent 9a8badc1e4
commit 9f895fbb97
1 changed files with 23 additions and 1 deletions

View File

@ -1055,7 +1055,29 @@ template<typename T> class BuiltinPointAttributeProvider : public BuiltinAttribu
bool exists(const GeometryComponent &component) const final
{
return component.attribute_domain_size(ATTR_DOMAIN_POINT) != 0;
const CurveEval *curve = get_curve_from_component_for_read(component);
if (curve == nullptr) {
return false;
}
Span<SplinePtr> splines = curve->splines();
if (splines.size() == 0) {
return false;
}
bool has_point = false;
for (const SplinePtr &spline : curve->splines()) {
if (spline->size() != 0) {
has_point = true;
break;
}
}
if (!has_point) {
return false;
}
return true;
}
};