37 switch (component_type) {
63 if (attributes.has_value()) {
90void GeometryComponent::delete_self()
95void GeometryComponent::delete_data_only()
116 if (!component_ptr) {
120 else if (component_ptr->is_mutable()) {
122 component_ptr->tag_ensured_mutable();
127 component_ptr = component_ptr->copy();
134 if (this->
has(type)) {
142 return components_[size_t(component_type)].get();
148 return component.
has_value() && !component->is_empty();
153 components_[size_t(component_type)].
reset();
160 if (!component_types.
contains(component_ptr->type())) {
161 component_ptr.reset();
193 components.
append(component_ptr.get());
200 const bool use_radius,
const bool use_subdiv)
const
202 std::optional<Bounds<float3>>
bounds;
208 if (use_subdiv &&
mesh->runtime->mesh_eval) {
230 if (!geometry_set.
name.empty()) {
231 parts.
append(fmt::format(
"\"{}\"", geometry_set.
name));
234 parts.
append(std::to_string(
mesh->verts_num) +
" verts");
235 parts.
append(std::to_string(
mesh->edges_num) +
" edges");
236 parts.
append(std::to_string(
mesh->faces_num) +
" faces");
237 parts.
append(std::to_string(
mesh->corners_num) +
" corners");
238 if (
mesh->runtime->subsurf_runtime_data) {
239 const int resolution =
mesh->runtime->subsurf_runtime_data->resolution;
242 const int level = log2_floor(resolution - 1);
243 parts.
append(std::to_string(level) +
" subdiv levels");
246 parts.
append(std::to_string(resolution) +
" subdiv resolution");
251 parts.
append(std::to_string(
curves->geometry.point_num) +
" control points");
252 parts.
append(std::to_string(
curves->geometry.curve_num) +
" curves");
255 parts.
append(std::to_string(grease_pencil->layers().size()) +
" Grease Pencil layers");
258 parts.
append(std::to_string(pointcloud->totpoint) +
" points");
267 parts.
append(
"curve edit hints");
270 stream <<
"<GeometrySet: ";
273 if (
i < parts.size() - 1) {
284 component_ptr.reset();
291 if (!component_ptr) {
294 if (component_ptr->owns_direct_data()) {
305 instances->ensure_geometry_instances();
314 if (!component_ptr->owns_direct_data()) {
324 for (
const int i :
IndexRange(this->components_.size())) {
325 if (components_[
i]) {
334 return (component ==
nullptr) ?
nullptr : component->
get();
340 return component !=
nullptr && component->
has_mesh();
346 return (component ==
nullptr) ?
nullptr : component->
get();
352 return (component ==
nullptr) ?
nullptr : component->
get();
358 return (component ==
nullptr) ?
nullptr : component->
get();
364 return (component ==
nullptr) ?
nullptr : component->
get();
388 return (component ==
nullptr) ?
nullptr : component->
get();
400 return component !=
nullptr && component->
get() !=
nullptr &&
407 return component !=
nullptr && component->
has_volume();
413 return component !=
nullptr && component->
has_curves();
485 if (
mesh ==
nullptr) {
513 if (instances ==
nullptr) {
522 component.
replace(instances, ownership);
527 if (pointcloud ==
nullptr) {
536 component.
replace(pointcloud, ownership);
541 if (volume ==
nullptr) {
550 component.
replace(volume, ownership);
556 if (grease_pencil ==
nullptr) {
565 component.
replace(grease_pencil, ownership);
570 MeshComponent *component = this->get_component_ptr<MeshComponent>();
582 VolumeComponent *component = this->get_component_ptr<VolumeComponent>();
588 CurveComponent *component = this->get_component_ptr<CurveComponent>();
639 component->count_memory(shared_memory);
646 const bool include_instances,
650 if (!this->
has(component_type)) {
654 const std::optional<AttributeAccessor> attributes = component.
attributes();
655 if (attributes.has_value()) {
656 attributes->foreach_attribute([&](
const AttributeIter &iter) {
657 callback(iter.
name, {iter.domain, iter.data_type}, component);
667 callback(iter.
name, {iter.domain, iter.data_type}, component);
676 instance_geometry_set.
attribute_foreach(component_types, include_instances, callback);
687 return component->attributes()->is_builtin(name);
691 return component->attributes()->is_builtin(name);
695 return component->attributes()->is_builtin(name);
699 return component->attributes()->is_builtin(name);
705 return grease_pencil_component->attributes()->is_builtin(name) ||
706 curves_component->attributes()->is_builtin(name);
720 bool include_instances,
730 if (component.
attributes()->is_builtin(attribute_id)) {
741 if (attribute_filter.
allow_skip(attribute_id)) {
752 attribute_kind->domain = domain;
753 attribute_kind->data_type = meta_data.
data_type;
757 {attribute_kind->domain, domain});
759 {attribute_kind->data_type, meta_data.
data_type});
761 r_attributes.
add_or_modify(attribute_id, add_info, modify_info);
766 const bool include_instances,
767 const bool ignore_empty,
772 if (component->is_empty()) {
778 if (!include_instances) {
782 if (instances ==
nullptr) {
787 instance_geometry_set, include_instances, ignore_empty, r_types);
792 bool ignore_empty)
const
802 r_geometry_sets.
append(&geometry_set);
810 for (
const int handle : instances.
references().index_range()) {
822 if (geometry_sets.
size() == 1) {
824 callback(*geometry_sets.
first());
828 [&](
GeometrySet *geometry_set) { callback(*geometry_set); });
834 const GeometrySet *geometry_set =
object.runtime->geometry_set_eval;
835 if (geometry_set ==
nullptr) {
Low-level operations for curves.
Low-level operations for grease pencil.
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()
MINLINE int is_power_of_2_i(int n)
Object is a sort of wrapper for general info.
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)
IndexRange index_range() const
void append_non_duplicates(const T &value)
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
void replace(Curves *curve, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
const Curves * get() const
std::unique_ptr< GreasePencilEditHints > grease_pencil_edit_hints_
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)
GeometrySet & geometry_set_from_reference(int reference_index)
Span< InstanceReference > references() const
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)
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)
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)
void ensure_no_shared_components()
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
FunctionRef< void(StringRef attribute_id, const AttributeMetaData &meta_data, const GeometryComponent &component)> AttributeForeachCallback
Vector< const GeometryComponent * > get_components() const
const Volume * get_volume() const
std::optional< Bounds< float3 > > compute_boundbox_without_instances(bool use_radius=true, bool use_subdiv=false) const
static GeometrySet from_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
bool has(const GeometryComponent::Type component_type) 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
void ensure_owns_direct_data()
GreasePencilEditHints * get_grease_pencil_edit_hints_for_write()
void replace_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
CurvesEditHints * get_curve_edit_hints_for_write()
void gather_attributes_for_propagation(Span< GeometryComponent::Type > component_types, GeometryComponent::Type dst_component_type, bool include_instances, const AttributeFilter &attribute_filter, Map< StringRef, AttributeDomainAndType > &r_attributes) const
void count_memory(MemoryCounter &memory) const
const GreasePencilEditHints * get_grease_pencil_edit_hints() const
const PointCloud * get_pointcloud() const
const Mesh * get_mesh() const
void modify_geometry_sets(ForeachSubGeometryCallback callback)
void replace_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
GreasePencil * get_grease_pencil_for_write()
Vector< GeometryComponent::Type > gather_component_types(bool include_instances, bool ignore_empty) 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()
FunctionRef< void(GeometrySet &geometry_set)> ForeachSubGeometryCallback
void add(const GeometryComponent &component)
void replace_grease_pencil(GreasePencil *grease_pencil, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)