Blender V5.3
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
8
9#include "BKE_geometry_set.hh"
10#include "BKE_instances.hh"
11
12namespace blender::bke {
13
14/* -------------------------------------------------------------------- */
17
19
21 : GeometryComponent(Type::Instance), instances_(instances), ownership_(ownership)
22{
23}
24
29
31{
32 InstancesComponent *new_component = new InstancesComponent();
33 if (instances_ != nullptr) {
34 new_component->instances_ = new Instances(*instances_);
35 new_component->ownership_ = GeometryOwnershipType::Owned;
36 }
37 return GeometryComponentPtr(new_component);
38}
39
41{
42 BLI_assert(this->is_mutable() || this->is_expired());
43 if (ownership_ == GeometryOwnershipType::Owned) {
44 delete instances_;
45 }
46 instances_ = nullptr;
47}
48
50{
51 if (instances_ != nullptr) {
52 if (instances_->instances_num() > 0) {
53 return false;
54 }
55 }
56 return true;
57}
58
60{
61 if (instances_ != nullptr) {
62 return instances_->owns_direct_data();
63 }
64 return true;
65}
66
68{
69 if (instances_ != nullptr) {
70 instances_->ensure_owns_direct_data();
71 }
72}
73
75{
76 return instances_;
77}
78
80{
81 BLI_assert(this->is_mutable());
82 if (ownership_ == GeometryOwnershipType::ReadOnly) {
83 instances_ = new Instances(*instances_);
85 }
86 return instances_;
87}
88
90{
91 BLI_assert(this->is_mutable());
92 this->clear();
93 instances_ = instances;
94 ownership_ = ownership;
95}
96
98{
99 BLI_assert(this->is_mutable());
100 Instances *instance = instances_;
101 instances_ = nullptr;
102 return instance;
103}
104
106{
107 if (instances_) {
108 instances_->count_memory(memory);
109 }
110}
111
112std::optional<AttributeAccessor> InstancesComponent::attributes() const
113{
115}
116
117std::optional<MutableAttributeAccessor> InstancesComponent::attributes_for_write()
118{
120}
121
123
124} // namespace blender::bke
AttributeAccessor(const void *owner, const AttributeAccessorFunctions &fn)
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)
MutableAttributeAccessor(void *owner, const AttributeAccessorFunctions &fn)
A running instance of the engine.
ImplicitSharingPtr< GeometryComponent > GeometryComponentPtr
const AttributeAccessorFunctions & instance_attribute_accessor_functions()
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)