Blender V5.3
GEO_realize_instances_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "BLI_array_utils.hh"
6
7#include "BKE_curves.hh"
8#include "BKE_geometry_set.hh"
9#include "BKE_gtest_base.hh"
10#include "BKE_instances.hh"
11#include "BKE_lib_id.hh"
12
13#include "DNA_curves_types.h"
14
16
17#include "testing/testing.h"
18
19namespace blender {
20
21using namespace blender::bke;
22
23namespace geometry::tests {
24
26
28{
29 BLI_assert(!offsets.is_empty());
30 const int curves_num = offsets.size() - 1;
31 const int points_num = offsets.last();
32
33 curves.resize(points_num, curves_num);
34 curves.offsets_for_write().copy_from(offsets);
35 curves.update_curve_types();
36
37 /* Attribute storing original indices to test point remapping. */
38 SpanAttributeWriter<int> test_indices_writer =
39 curves.attributes_for_write().lookup_or_add_for_write_span<int>(
41 array_utils::fill_index_range(test_indices_writer.span);
42 test_indices_writer.finish();
43}
44
45/* Regression test for builtin curve attributes:
46 * The attribute can be added with arbitrary type/domain on instances,
47 * but is built-in and restricted on curves, which will not allow writing it
48 * to the realized curves geometry. #142163 */
49TEST_F(RealizeInstancesTest, InstanceAttributeToBuiltinCurvesAttribute)
50{
51 Curves *curves_id = BKE_id_new_nomain<Curves>("TestCurves");
52 create_test_curves(curves_id->geometry.wrap(), {0, 3});
53 bke::GeometrySet curves_geometry = GeometrySet::from_curves(curves_id);
54
55 auto instances = std::make_unique<Instances>(2);
56 const int handle = instances->add_reference(bke::InstanceReference{curves_geometry});
57 /* The issue only occurs with 2 or more instances. In case of a single instance the code takes a
58 * special path that does not run cause this problem. */
59 instances->reference_handles_for_write().fill(handle);
60 instances->transforms_for_write().fill(float4x4::identity());
61 /* This attribute will be converted to the point domain, where it is invalid on curves. */
62 instances->attributes_for_write().add<float>(
64 bke::GeometrySet instances_geometry = GeometrySet::from_instances(std::move(instances));
65
67 options.realize_instance_attributes = true;
68 GeometrySet realized_geometry_set =
69 geometry::realize_instances(instances_geometry, options).geometry;
70}
71
72} // namespace geometry::tests
73} // namespace blender
Low-level operations for curves.
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr const T & last(const int64_t n=0) const
Definition BLI_span.hh:329
constexpr bool is_empty() const
Definition BLI_span.hh:264
CCL_NAMESPACE_BEGIN struct Options options
void fill_index_range(MutableSpan< T > span, const T start=0)
TEST_F(MergeCurvesTest, NoConnections)
static bke::CurvesGeometry create_test_curves(Span< int > offsets, Span< bool > cyclic)
RealizeInstancesResult realize_instances(bke::GeometrySet geometry_set, const RealizeInstancesOptions &options)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void * BKE_id_new_nomain(short type, const char *name)
Definition lib_id.cc:1617
static GeometrySet from_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
static GeometrySet from_instances(std::unique_ptr< Instances > instances)