forked from blender/blender
davidhaver-WIP-realize-depth #3
@ -236,6 +236,11 @@ struct GeometrySet {
|
|||||||
const AttributeMetaData &meta_data,
|
const AttributeMetaData &meta_data,
|
||||||
const GeometryComponent &component)>;
|
const GeometryComponent &component)>;
|
||||||
|
|
||||||
|
void attribute_foreach(Span<GeometryComponent::Type> component_types,
|
||||||
|
bool include_instances,
|
||||||
|
const VArray<int> instance_depth,
|
||||||
|
AttributeForeachCallback callback) const;
|
||||||
|
|
||||||
void attribute_foreach(Span<GeometryComponent::Type> component_types,
|
void attribute_foreach(Span<GeometryComponent::Type> component_types,
|
||||||
bool include_instances,
|
bool include_instances,
|
||||||
AttributeForeachCallback callback) const;
|
AttributeForeachCallback callback) const;
|
||||||
@ -245,9 +250,16 @@ struct GeometrySet {
|
|||||||
MutableAttributeAccessor dst_attributes,
|
MutableAttributeAccessor dst_attributes,
|
||||||
const AnonymousAttributePropagationInfo &propagation_info);
|
const AnonymousAttributePropagationInfo &propagation_info);
|
||||||
|
|
||||||
|
void gather_attributes_for_propagation(Span<GeometryComponent::Type> component_types, //old variation.
|
||||||
|
GeometryComponent::Type dst_component_type,
|
||||||
|
bool include_instances,
|
||||||
|
const AnonymousAttributePropagationInfo &propagation_info,
|
||||||
|
Map<AttributeIDRef, AttributeKind> &r_attributes) const;
|
||||||
|
|
||||||
void gather_attributes_for_propagation(Span<GeometryComponent::Type> component_types,
|
void gather_attributes_for_propagation(Span<GeometryComponent::Type> component_types,
|
||||||
GeometryComponent::Type dst_component_type,
|
GeometryComponent::Type dst_component_type,
|
||||||
bool include_instances,
|
bool include_instances,
|
||||||
|
const VArray<int> instance_depth,
|
||||||
const AnonymousAttributePropagationInfo &propagation_info,
|
const AnonymousAttributePropagationInfo &propagation_info,
|
||||||
Map<AttributeIDRef, AttributeKind> &r_attributes) const;
|
Map<AttributeIDRef, AttributeKind> &r_attributes) const;
|
||||||
|
|
||||||
|
@ -573,6 +573,42 @@ GreasePencil *GeometrySet::get_grease_pencil_for_write()
|
|||||||
return component == nullptr ? nullptr : component->get_for_write();
|
return component == nullptr ? nullptr : component->get_for_write();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeometrySet::attribute_foreach(const Span<GeometryComponent::Type> component_types,
|
||||||
|
const bool include_instances,
|
||||||
|
const VArray<int> instance_depth,
|
||||||
|
const AttributeForeachCallback callback) const
|
||||||
|
{
|
||||||
|
for (const GeometryComponent::Type component_type : component_types) {
|
||||||
|
if (!this->has(component_type)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const GeometryComponent &component = *this->get_component(component_type);
|
||||||
|
const std::optional<AttributeAccessor> attributes = component.attributes();
|
||||||
|
if (attributes.has_value()) {
|
||||||
|
attributes->for_all(
|
||||||
|
[&](const AttributeIDRef &attribute_id, const AttributeMetaData &meta_data) {
|
||||||
|
callback(attribute_id, meta_data, component);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (include_instances && this->has_instances()) {
|
||||||
|
const Instances &instances = *this->get_instances();
|
||||||
|
|
||||||
|
// instances.foreach_referenced_geometry([&](const GeometrySet &instance_geometry_set) {
|
||||||
|
// });
|
||||||
|
BLI_assert(instances.instances_num() == instance_depth.size());
|
||||||
|
size_t index = 0;
|
||||||
|
instances.foreach_referenced_geometry([&](const GeometrySet &instance_geometry_set) {
|
||||||
|
if (instance_depth[index] > 0){
|
||||||
|
const VArray<int> intsnace_depth_tmp = VArray<int>::ForSingle(instance_depth[index]-1, instances.instances_num());
|
||||||
|
instance_geometry_set.attribute_foreach(component_types, include_instances, intsnace_depth_tmp, callback);
|
||||||
|
}
|
||||||
|
index ++;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void GeometrySet::attribute_foreach(const Span<GeometryComponent::Type> component_types,
|
void GeometrySet::attribute_foreach(const Span<GeometryComponent::Type> component_types,
|
||||||
const bool include_instances,
|
const bool include_instances,
|
||||||
const AttributeForeachCallback callback) const
|
const AttributeForeachCallback callback) const
|
||||||
@ -678,6 +714,60 @@ void GeometrySet::gather_attributes_for_propagation(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GeometrySet::gather_attributes_for_propagation(
|
||||||
|
const Span<GeometryComponent::Type> component_types,
|
||||||
|
const GeometryComponent::Type dst_component_type,
|
||||||
|
bool include_instances,
|
||||||
|
const VArray<int> instance_depth,
|
||||||
|
const AnonymousAttributePropagationInfo &propagation_info,
|
||||||
|
Map<AttributeIDRef, AttributeKind> &r_attributes) const
|
||||||
|
{
|
||||||
|
/* Only needed right now to check if an attribute is built-in on this component type.
|
||||||
|
* TODO: Get rid of the dummy component. */
|
||||||
|
const GeometryComponentPtr dummy_component = GeometryComponent::create(dst_component_type);
|
||||||
|
this->attribute_foreach(
|
||||||
|
component_types,
|
||||||
|
include_instances,
|
||||||
|
instance_depth,
|
||||||
|
[&](const AttributeIDRef &attribute_id,
|
||||||
|
const AttributeMetaData &meta_data,
|
||||||
|
const GeometryComponent &component) {
|
||||||
|
if (component.attributes()->is_builtin(attribute_id)) {
|
||||||
|
if (!dummy_component->attributes()->is_builtin(attribute_id)) {
|
||||||
|
/* Don't propagate built-in attributes that are not built-in on the destination
|
||||||
|
* component. */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (meta_data.data_type == CD_PROP_STRING) {
|
||||||
|
/* Propagating string attributes is not supported yet. */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (attribute_id.is_anonymous() &&
|
||||||
|
!propagation_info.propagate(attribute_id.anonymous_id())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
AttrDomain domain = meta_data.domain;
|
||||||
|
if (dst_component_type != GeometryComponent::Type::Instance &&
|
||||||
|
domain == AttrDomain::Instance) {
|
||||||
|
domain = AttrDomain::Point;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto add_info = [&](AttributeKind *attribute_kind) {
|
||||||
|
attribute_kind->domain = domain;
|
||||||
|
attribute_kind->data_type = meta_data.data_type;
|
||||||
|
};
|
||||||
|
auto modify_info = [&](AttributeKind *attribute_kind) {
|
||||||
|
attribute_kind->domain = bke::attribute_domain_highest_priority(
|
||||||
|
{attribute_kind->domain, domain});
|
||||||
|
attribute_kind->data_type = bke::attribute_data_type_highest_complexity(
|
||||||
|
{attribute_kind->data_type, meta_data.data_type});
|
||||||
|
};
|
||||||
|
r_attributes.add_or_modify(attribute_id, add_info, modify_info);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
static void gather_component_types_recursive(const GeometrySet &geometry_set,
|
static void gather_component_types_recursive(const GeometrySet &geometry_set,
|
||||||
const bool include_instances,
|
const bool include_instances,
|
||||||
const bool ignore_empty,
|
const bool ignore_empty,
|
||||||
|
@ -739,6 +739,7 @@ static OrderedAttributes gather_generic_instance_attributes_to_propagate(
|
|||||||
in_geometry_set.gather_attributes_for_propagation(src_component_types,
|
in_geometry_set.gather_attributes_for_propagation(src_component_types,
|
||||||
bke::GeometryComponent::Type::Instance,
|
bke::GeometryComponent::Type::Instance,
|
||||||
true,
|
true,
|
||||||
|
options.depths,
|
||||||
options.propagation_info,
|
options.propagation_info,
|
||||||
attributes_to_propagate);
|
attributes_to_propagate);
|
||||||
attributes_to_propagate.remove("position");
|
attributes_to_propagate.remove("position");
|
||||||
@ -768,6 +769,7 @@ static OrderedAttributes gather_generic_pointcloud_attributes_to_propagate(
|
|||||||
in_geometry_set.gather_attributes_for_propagation(src_component_types,
|
in_geometry_set.gather_attributes_for_propagation(src_component_types,
|
||||||
bke::GeometryComponent::Type::PointCloud,
|
bke::GeometryComponent::Type::PointCloud,
|
||||||
true,
|
true,
|
||||||
|
options.depths,
|
||||||
options.propagation_info,
|
options.propagation_info,
|
||||||
attributes_to_propagate);
|
attributes_to_propagate);
|
||||||
attributes_to_propagate.remove("position");
|
attributes_to_propagate.remove("position");
|
||||||
@ -1053,6 +1055,7 @@ static OrderedAttributes gather_generic_mesh_attributes_to_propagate(
|
|||||||
bool &r_create_id,
|
bool &r_create_id,
|
||||||
bool &r_create_material_index)
|
bool &r_create_material_index)
|
||||||
{
|
{
|
||||||
|
options.depths;
|
||||||
Vector<bke::GeometryComponent::Type> src_component_types;
|
Vector<bke::GeometryComponent::Type> src_component_types;
|
||||||
src_component_types.append(bke::GeometryComponent::Type::Mesh);
|
src_component_types.append(bke::GeometryComponent::Type::Mesh);
|
||||||
if (options.realize_instance_attributes) {
|
if (options.realize_instance_attributes) {
|
||||||
@ -1063,6 +1066,7 @@ static OrderedAttributes gather_generic_mesh_attributes_to_propagate(
|
|||||||
in_geometry_set.gather_attributes_for_propagation(src_component_types,
|
in_geometry_set.gather_attributes_for_propagation(src_component_types,
|
||||||
bke::GeometryComponent::Type::Mesh,
|
bke::GeometryComponent::Type::Mesh,
|
||||||
true,
|
true,
|
||||||
|
options.depths,
|
||||||
options.propagation_info,
|
options.propagation_info,
|
||||||
attributes_to_propagate);
|
attributes_to_propagate);
|
||||||
attributes_to_propagate.remove("position");
|
attributes_to_propagate.remove("position");
|
||||||
@ -1410,6 +1414,7 @@ static OrderedAttributes gather_generic_curve_attributes_to_propagate(
|
|||||||
in_geometry_set.gather_attributes_for_propagation(src_component_types,
|
in_geometry_set.gather_attributes_for_propagation(src_component_types,
|
||||||
bke::GeometryComponent::Type::Curve,
|
bke::GeometryComponent::Type::Curve,
|
||||||
true,
|
true,
|
||||||
|
options.depths,
|
||||||
options.propagation_info,
|
options.propagation_info,
|
||||||
attributes_to_propagate);
|
attributes_to_propagate);
|
||||||
attributes_to_propagate.remove("position");
|
attributes_to_propagate.remove("position");
|
||||||
|
Loading…
Reference in New Issue
Block a user