Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2021-11-02 23:22:16 +0300
committerHans Goudey <h.goudey@me.com>2021-11-02 23:22:49 +0300
commita72ed0bb7fafddd87ccfb0ad7acc8a6e6fe223b0 (patch)
tree3763dff1ca29b1836dcd3d114cfb8c71eee9e68a
parent18392cef17ddb40857fdb2462d8bad50f389029b (diff)
Cleanup: Improve curve point attribute assert
This properly checks the order of point domain attributes on each spline, and avoids the map, which makes the code easier to understand. The assert is also added to realizing instances and the join node. Differential Revision: https://developer.blender.org/D13071
-rw-r--r--source/blender/blenkernel/intern/curve_eval.cc40
-rw-r--r--source/blender/blenkernel/intern/geometry_set_instances.cc1
-rw-r--r--source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc1
3 files changed, 30 insertions, 12 deletions
diff --git a/source/blender/blenkernel/intern/curve_eval.cc b/source/blender/blenkernel/intern/curve_eval.cc
index 0e3da9e0789..bb745d5b20d 100644
--- a/source/blender/blenkernel/intern/curve_eval.cc
+++ b/source/blender/blenkernel/intern/curve_eval.cc
@@ -348,6 +348,7 @@ std::unique_ptr<CurveEval> curve_eval_from_dna_curve(const Curve &dna_curve)
* because attributes are stored on splines rather than in a flat array on the curve:
* - The same set of attributes exists on every spline.
* - Attributes with the same name have the same type on every spline.
+ * - Attributes are in the same order on every spline.
*/
void CurveEval::assert_valid_point_attributes() const
{
@@ -356,25 +357,40 @@ void CurveEval::assert_valid_point_attributes() const
return;
}
const int layer_len = splines_.first()->attributes.data.totlayer;
- Map<AttributeIDRef, AttributeMetaData> map;
+
+ Array<AttributeIDRef> ids_in_order(layer_len);
+ Array<AttributeMetaData> meta_data_in_order(layer_len);
+
+ {
+ int i = 0;
+ splines_.first()->attributes.foreach_attribute(
+ [&](const AttributeIDRef &attribute_id, const AttributeMetaData &meta_data) {
+ ids_in_order[i] = attribute_id;
+ meta_data_in_order[i] = meta_data;
+ i++;
+ return true;
+ },
+ ATTR_DOMAIN_POINT);
+ }
+
for (const SplinePtr &spline : splines_) {
+ /* All splines should have the same number of attributes. */
BLI_assert(spline->attributes.data.totlayer == layer_len);
+
+ int i = 0;
spline->attributes.foreach_attribute(
[&](const AttributeIDRef &attribute_id, const AttributeMetaData &meta_data) {
- map.add_or_modify(
- attribute_id,
- [&](AttributeMetaData *map_data) {
- /* All unique attribute names should be added on the first spline. */
- BLI_assert(spline == splines_.first());
- *map_data = meta_data;
- },
- [&](AttributeMetaData *map_data) {
- /* Attributes on different splines should all have the same type. */
- BLI_assert(meta_data == *map_data);
- });
+ /* Attribute names and IDs should have the same order and exist on all splines. */
+ BLI_assert(attribute_id == ids_in_order[i]);
+
+ /* Attributes with the same ID different splines should all have the same type. */
+ BLI_assert(meta_data == meta_data_in_order[i]);
+
+ i++;
return true;
},
ATTR_DOMAIN_POINT);
}
+
#endif
}
diff --git a/source/blender/blenkernel/intern/geometry_set_instances.cc b/source/blender/blenkernel/intern/geometry_set_instances.cc
index 82fc14e7772..a56c7ffb295 100644
--- a/source/blender/blenkernel/intern/geometry_set_instances.cc
+++ b/source/blender/blenkernel/intern/geometry_set_instances.cc
@@ -569,6 +569,7 @@ static void join_instance_groups_curve(Span<GeometryInstanceGroup> set_groups, G
attributes,
static_cast<GeometryComponent &>(dst_component));
sort_curve_point_attributes(attributes, curve->splines());
+ curve->assert_valid_point_attributes();
}
GeometrySet geometry_set_realize_instances(const GeometrySet &geometry_set)
diff --git a/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc b/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
index 1422bf2e475..110b4a30dc8 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
@@ -469,6 +469,7 @@ static void join_curve_components(MutableSpan<GeometrySet> src_geometry_sets, Ge
dst_curve->attributes.reallocate(dst_curve->splines().size());
join_curve_attributes(info, src_components, *dst_curve);
+ dst_curve->assert_valid_point_attributes();
dst_component.replace(dst_curve);
}