Blender V5.0
geometry_component_instances.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_geometry_set.hh"
6#include "BKE_instances.hh"
7
9
10namespace blender::bke {
11
12/* -------------------------------------------------------------------- */
15
17
19 : GeometryComponent(Type::Instance), instances_(instances), ownership_(ownership)
20{
21}
22
27
29{
30 InstancesComponent *new_component = new InstancesComponent();
31 if (instances_ != nullptr) {
32 new_component->instances_ = new Instances(*instances_);
33 new_component->ownership_ = GeometryOwnershipType::Owned;
34 }
35 return GeometryComponentPtr(new_component);
36}
37
39{
40 BLI_assert(this->is_mutable() || this->is_expired());
41 if (ownership_ == GeometryOwnershipType::Owned) {
42 delete instances_;
43 }
44 instances_ = nullptr;
45}
46
48{
49 if (instances_ != nullptr) {
50 if (instances_->instances_num() > 0) {
51 return false;
52 }
53 }
54 return true;
55}
56
58{
59 if (instances_ != nullptr) {
60 return instances_->owns_direct_data();
61 }
62 return true;
63}
64
66{
67 if (instances_ != nullptr) {
68 instances_->ensure_owns_direct_data();
69 }
70}
71
73{
74 return instances_;
75}
76
78{
79 BLI_assert(this->is_mutable());
80 if (ownership_ == GeometryOwnershipType::ReadOnly) {
81 instances_ = new Instances(*instances_);
83 }
84 return instances_;
85}
86
88{
89 BLI_assert(this->is_mutable());
90 this->clear();
91 instances_ = instances;
92 ownership_ = ownership;
93}
94
96{
97 BLI_assert(this->is_mutable());
98 Instances *instance = instances_;
99 instances_ = nullptr;
100 return instance;
101}
102
104{
105 if (instances_) {
106 instances_->count_memory(memory);
107 }
108}
109
110std::optional<AttributeAccessor> InstancesComponent::attributes() const
111{
113}
114
115std::optional<MutableAttributeAccessor> InstancesComponent::attributes_for_write()
116{
118}
119
121
122} // namespace blender::bke
#define BLI_assert(a)
Definition BLI_assert.h:46
std::optional< MutableAttributeAccessor > attributes_for_write() final
void count_memory(MemoryCounter &memory) const override
GeometryComponentPtr copy() const override
std::optional< AttributeAccessor > attributes() const final
void replace(Instances *instances, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
ImplicitSharingPtr< GeometryComponent > GeometryComponentPtr
const AttributeAccessorFunctions & instance_attribute_accessor_functions()