44 switch (component_type) {
69 const std::optional<AttributeAccessor> attributes = this->
attributes();
70 if (attributes.has_value()) {
71 return attributes->domain_size(domain);
97void GeometryComponent::delete_self()
102void GeometryComponent::delete_data_only()
123 if (!component_ptr) {
127 else if (component_ptr->is_mutable()) {
129 component_ptr->tag_ensured_mutable();
134 component_ptr = component_ptr->copy();
141 if (this->
has(type)) {
149 return components_[size_t(component_type)].get();
155 return component.
has_value() && !component->is_empty();
160 components_[size_t(component_type)].reset();
167 if (!component_types.
contains(component_ptr->type())) {
168 component_ptr.reset();
200 components.
append(component_ptr.get());
208 std::optional<Bounds<float3>> bounds;
210 bounds =
bounds::merge(bounds, pointcloud->bounds_min_max());
219 bounds =
bounds::merge(bounds, curves_id->geometry.wrap().bounds_min_max());
222 bounds =
bounds::merge(bounds, grease_pencil->bounds_min_max_eval());
231 parts.
append(std::to_string(mesh->verts_num) +
" verts");
232 parts.append(std::to_string(mesh->edges_num) +
" edges");
233 parts.append(std::to_string(mesh->faces_num) +
" faces");
234 parts.append(std::to_string(mesh->corners_num) +
" corners");
237 parts.append(std::to_string(curves->geometry.point_num) +
" control points");
238 parts.append(std::to_string(curves->geometry.curve_num) +
" curves");
241 parts.append(std::to_string(grease_pencil->layers().size()) +
" grease pencil layers");
244 parts.append(std::to_string(point_cloud->totpoint) +
" points");
253 parts.append(
"curve edit hints");
256 stream <<
"<GeometrySet: ";
257 for (
const int i : parts.index_range()) {
259 if (i < parts.size() - 1) {
270 component_ptr.reset();
277 if (!component_ptr) {
280 if (component_ptr->owns_direct_data()) {
291 instances->ensure_geometry_instances();
300 if (!component_ptr->owns_direct_data()) {
311 return (component ==
nullptr) ? nullptr : component->
get();
317 return component !=
nullptr && component->
has_mesh();
323 return (component ==
nullptr) ? nullptr : component->
get();
329 return (component ==
nullptr) ? nullptr : component->
get();
335 return (component ==
nullptr) ? nullptr : component->
get();
341 return (component ==
nullptr) ? nullptr : component->
get();
359 return (component ==
nullptr) ? nullptr : component->
get();
371 return component !=
nullptr && component->
get() !=
nullptr &&
378 return component !=
nullptr && component->
has_volume();
384 return component !=
nullptr && component->
has_curves();
456 if (mesh ==
nullptr) {
465 component.
replace(mesh, ownership);
470 if (curves ==
nullptr) {
479 component.
replace(curves, ownership);
484 if (instances ==
nullptr) {
493 component.
replace(instances, ownership);
498 if (pointcloud ==
nullptr) {
507 component.
replace(pointcloud, ownership);
512 if (volume ==
nullptr) {
521 component.
replace(volume, ownership);
527 if (grease_pencil ==
nullptr) {
536 component.
replace(grease_pencil, ownership);
541 MeshComponent *component = this->get_component_ptr<MeshComponent>();
542 return component ==
nullptr ? nullptr : component->
get_for_write();
548 return component ==
nullptr ? nullptr : component->
get_for_write();
553 VolumeComponent *component = this->get_component_ptr<VolumeComponent>();
554 return component ==
nullptr ? nullptr : component->
get_for_write();
559 CurveComponent *component = this->get_component_ptr<CurveComponent>();
560 return component ==
nullptr ? nullptr : component->
get_for_write();
566 return component ==
nullptr ? nullptr : component->
get_for_write();
592 return component ==
nullptr ? nullptr : component->
get_for_write();
600 component->count_memory(shared_memory);
607 const bool include_instances,
611 if (!this->
has(component_type)) {
615 const std::optional<AttributeAccessor> attributes = component.
attributes();
616 if (attributes.has_value()) {
617 attributes->foreach_attribute([&](
const AttributeIter &iter) {
618 callback(iter.
name, {iter.domain, iter.data_type}, component);
640 if (src.sharing_info && src.varray.is_span()) {
662 return component->attributes()->is_builtin(name);
666 return component->attributes()->is_builtin(name);
670 return component->attributes()->is_builtin(name);
674 return component->attributes()->is_builtin(name);
680 return grease_pencil_component->attributes()->is_builtin(name) ||
681 curves_component->attributes()->is_builtin(name);
695 bool include_instances,
705 if (component.
attributes()->is_builtin(attribute_id)) {
706 if (!attribute_is_builtin_on_component_type(dst_component_type, attribute_id)) {
716 if (attribute_filter.
allow_skip(attribute_id)) {
727 attribute_kind->domain = domain;
728 attribute_kind->data_type = meta_data.
data_type;
732 {attribute_kind->domain, domain});
734 {attribute_kind->data_type, meta_data.
data_type});
736 r_attributes.
add_or_modify(attribute_id, add_info, modify_info);
741 const bool include_instances,
742 const bool ignore_empty,
747 if (component->is_empty()) {
753 if (!include_instances) {
757 if (instances ==
nullptr) {
762 instance_geometry_set, include_instances, ignore_empty, r_types);
767 bool ignore_empty)
const
777 r_geometry_sets.
append(&geometry_set);
785 for (
const int handle : instances.references().index_range()) {
786 if (instances.references()[handle].type() == InstanceReference::Type::GeometrySet) {
787 GeometrySet &instance_geometry = instances.geometry_set_from_reference(handle);
797 if (geometry_sets.
size() == 1) {
809 const GeometrySet *geometry_set =
object.runtime->geometry_set_eval;
810 if (geometry_set ==
nullptr) {
Low-level operations for curves.
Low-level operations for grease pencil.
General operations for point clouds.
int BKE_volume_num_grids(const Volume *volume)
std::optional< blender::Bounds< blender::float3 > > BKE_volume_min_max(const Volume *volume)
#define BLI_assert_unreachable()
Object groups, one object can be in many groups at once.
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
auto add_or_modify(const Key &key, const CreateValueF &create_value, const ModifyValueF &modify_value) -> decltype(create_value(nullptr))
constexpr bool contains(const T &value) const
void append(const T &value)
void append_non_duplicates(const T &value)
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
eCustomDataType data_type
GAttributeReader get() const
void replace(Curves *curve, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const Curves * get() const
std::unique_ptr< GizmoEditHints > gizmo_edit_hints_
std::unique_ptr< CurvesEditHints > curves_edit_hints_
int attribute_domain_size(AttrDomain domain) const
virtual std::optional< AttributeAccessor > attributes() const
GeometryComponent(Type type)
virtual std::optional< MutableAttributeAccessor > attributes_for_write()
virtual bool is_empty() const
virtual void count_memory(MemoryCounter &memory) const
virtual void ensure_owns_direct_data()=0
static GeometryComponentPtr create(Type component_type)
bool has_grease_pencil() const
const GreasePencil * get() const
GreasePencil * get_for_write()
void replace(GreasePencil *grease_pencil, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Instances * get_for_write()
const Instances * get() const
void replace(Instances *instances, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
void foreach_referenced_geometry(FunctionRef< void(const GeometrySet &geometry_set)> callback) const
int instances_num() const
void ensure_geometry_instances()
void replace(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
bool add(const StringRef attribute_id, const AttrDomain domain, const eCustomDataType data_type, const AttributeInit &initializer)
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef attribute_id, AttrDomain domain, eCustomDataType data_type)
void replace(PointCloud *pointcloud, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const PointCloud * get() const
bool has_pointcloud() const
PointCloud * get_for_write()
void replace(Volume *volume, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const Volume * get() const
void add_shared(const ImplicitSharingInfo *sharing_info, const FunctionRef< void(MemoryCounter &shared_memory)> count_fn)
DEGForeachIDComponentCallback callback
void copy(const GVArray &src, GMutableSpan dst, int64_t grain_size=4096)
ImplicitSharingPtr< GeometryComponent > GeometryComponentPtr
static void gather_component_types_recursive(const GeometrySet &geometry_set, const bool include_instances, const bool ignore_empty, Vector< GeometryComponent::Type > &r_types)
static void gather_mutable_geometry_sets(GeometrySet &geometry_set, Vector< GeometrySet * > &r_geometry_sets)
bool attribute_is_builtin_on_component_type(const GeometryComponent::Type type, StringRef name)
eCustomDataType attribute_data_type_highest_complexity(Span< eCustomDataType > data_types)
AttrDomain attribute_domain_highest_priority(Span< AttrDomain > domains)
std::ostream & operator<<(std::ostream &stream, const GeometrySet &geometry_set)
bool object_has_geometry_set_instances(const Object &object)
Bounds< T > merge(const Bounds< T > &a, const Bounds< T > &b)
void parallel_for_each(Range &&range, const Function &function)
bool allow_skip(const StringRef name) const
bool owns_direct_data() const
void ensure_owns_all_data()
void replace_volume(Volume *volume, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
void keep_only(Span< GeometryComponent::Type > component_types)
const CurvesEditHints * get_curve_edit_hints() const
GeometrySet & operator=(const GeometrySet &other)
static GeometrySet from_instances(Instances *instances, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
static GeometrySet from_grease_pencil(GreasePencil *grease_pencil, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
bool has_component() const
PointCloud * get_pointcloud_for_write()
static GeometrySet from_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
GizmoEditHints * get_gizmo_edit_hints_for_write()
void replace_instances(Instances *instances, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Instances * get_instances_for_write()
const GreasePencil * get_grease_pencil() const
bool has_pointcloud() const
const Component * get_component() const
Component & get_component_for_write()
const GizmoEditHints * get_gizmo_edit_hints() const
Vector< const GeometryComponent * > get_components() const
const Volume * get_volume() const
static GeometrySet from_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
void gather_attributes_for_propagation(Span< GeometryComponent::Type > component_types, GeometryComponent::Type dst_component_type, bool include_instances, const AttributeFilter &attribute_filter, Map< StringRef, AttributeKind > &r_attributes) const
void replace_pointcloud(PointCloud *pointcloud, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Curves * get_curves_for_write()
void keep_only_during_modify(Span< GeometryComponent::Type > component_types)
bool has_realized_data() const
const Curves * get_curves() const
static GeometrySet from_pointcloud(PointCloud *pointcloud, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const Instances * get_instances() const
bool has_grease_pencil() const
static GeometrySet from_volume(Volume *volume, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
bool has_instances() const
static void propagate_attributes_from_layer_to_instances(const AttributeAccessor src_attributes, MutableAttributeAccessor dst_attributes, const AttributeFilter &attribute_filter)
void ensure_owns_direct_data()
void replace_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
CurvesEditHints * get_curve_edit_hints_for_write()
void count_memory(MemoryCounter &memory) const
const PointCloud * get_pointcloud() const
const Mesh * get_mesh() const
void replace_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
GreasePencil * get_grease_pencil_for_write()
std::optional< Bounds< float3 > > compute_boundbox_without_instances() const
Volume * get_volume_for_write()
void remove_geometry_during_modify()
void attribute_foreach(Span< GeometryComponent::Type > component_types, bool include_instances, AttributeForeachCallback callback) const
Mesh * get_mesh_for_write()
void add(const GeometryComponent &component)
void replace_grease_pencil(GreasePencil *grease_pencil, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)