BKE: Utilities to create curves and point clouds without attributes #120368
|
@ -41,15 +41,20 @@ components_supported_reordering()
|
|||
return supported_types_and_domains;
|
||||
}
|
||||
|
||||
static void reorder_attributes_group_to_group(const bke::AttributeAccessor src_attributes,
|
||||
const bke::AttrDomain domain,
|
||||
const OffsetIndices<int> src_offsets,
|
||||
const OffsetIndices<int> dst_offsets,
|
||||
const Span<int> old_by_new_map,
|
||||
bke::MutableAttributeAccessor dst_attributes)
|
||||
static void reorder_attributes_group_to_group(
|
||||
const bke::AttributeAccessor src_attributes,
|
||||
const bke::AttrDomain domain,
|
||||
const bke::AnonymousAttributePropagationInfo &propagation_info,
|
||||
const OffsetIndices<int> src_offsets,
|
||||
const OffsetIndices<int> dst_offsets,
|
||||
const Span<int> old_by_new_map,
|
||||
bke::MutableAttributeAccessor dst_attributes)
|
||||
{
|
||||
src_attributes.for_all(
|
||||
[&](const bke::AttributeIDRef &id, const bke::AttributeMetaData meta_data) {
|
||||
if (id.is_anonymous() && !propagation_info.propagate(id.anonymous_id())) {
|
||||
return true;
|
||||
}
|
||||
if (meta_data.domain != domain) {
|
||||
return true;
|
||||
}
|
||||
|
@ -83,13 +88,32 @@ static Array<int> invert_permutation(const Span<int> permutation)
|
|||
return data;
|
||||
}
|
||||
|
||||
static void reorder_mesh_verts_exec(const Mesh &src_mesh,
|
||||
const Span<int> old_by_new_map,
|
||||
Mesh &dst_mesh)
|
||||
static void copy_and_reorder_mesh_verts(
|
||||
const Mesh &src_mesh,
|
||||
const Span<int> old_by_new_map,
|
||||
const bke::AnonymousAttributePropagationInfo &propagation_info,
|
||||
Mesh &dst_mesh)
|
||||
{
|
||||
bke::copy_attributes(src_mesh.attributes(),
|
||||
bke::AttrDomain::Edge,
|
||||
propagation_info,
|
||||
{},
|
||||
dst_mesh.attributes_for_write());
|
||||
bke::copy_attributes(src_mesh.attributes(),
|
||||
bke::AttrDomain::Face,
|
||||
propagation_info,
|
||||
{},
|
||||
dst_mesh.attributes_for_write());
|
||||
array_utils::copy(src_mesh.face_offsets(), dst_mesh.face_offsets_for_write());
|
||||
bke::copy_attributes(src_mesh.attributes(),
|
||||
bke::AttrDomain::Corner,
|
||||
propagation_info,
|
||||
{},
|
||||
dst_mesh.attributes_for_write());
|
||||
|
||||
bke::gather_attributes(src_mesh.attributes(),
|
||||
bke::AttrDomain::Point,
|
||||
{},
|
||||
propagation_info,
|
||||
{},
|
||||
old_by_new_map,
|
||||
dst_mesh.attributes_for_write());
|
||||
|
@ -101,13 +125,32 @@ static void reorder_mesh_verts_exec(const Mesh &src_mesh,
|
|||
new_by_old_map.as_span(), dst_mesh.corner_verts(), dst_mesh.corner_verts_for_write());
|
||||
}
|
||||
|
||||
static void reorder_mesh_edges_exec(const Mesh &src_mesh,
|
||||
const Span<int> old_by_new_map,
|
||||
Mesh &dst_mesh)
|
||||
static void copy_and_reorder_mesh_edges(
|
||||
const Mesh &src_mesh,
|
||||
const Span<int> old_by_new_map,
|
||||
const bke::AnonymousAttributePropagationInfo &propagation_info,
|
||||
Mesh &dst_mesh)
|
||||
{
|
||||
bke::copy_attributes(src_mesh.attributes(),
|
||||
bke::AttrDomain::Point,
|
||||
propagation_info,
|
||||
{},
|
||||
dst_mesh.attributes_for_write());
|
||||
bke::copy_attributes(src_mesh.attributes(),
|
||||
bke::AttrDomain::Face,
|
||||
propagation_info,
|
||||
{},
|
||||
dst_mesh.attributes_for_write());
|
||||
array_utils::copy(src_mesh.face_offsets(), dst_mesh.face_offsets_for_write());
|
||||
bke::copy_attributes(src_mesh.attributes(),
|
||||
bke::AttrDomain::Corner,
|
||||
propagation_info,
|
||||
{},
|
||||
dst_mesh.attributes_for_write());
|
||||
|
||||
bke::gather_attributes(src_mesh.attributes(),
|
||||
bke::AttrDomain::Edge,
|
||||
{},
|
||||
propagation_info,
|
||||
{},
|
||||
old_by_new_map,
|
||||
dst_mesh.attributes_for_write());
|
||||
|
@ -116,13 +159,26 @@ static void reorder_mesh_edges_exec(const Mesh &src_mesh,
|
|||
new_by_old_map.as_span(), dst_mesh.corner_edges(), dst_mesh.corner_edges_for_write());
|
||||
}
|
||||
|
||||
static void reorder_mesh_faces_exec(const Mesh &src_mesh,
|
||||
const Span<int> old_by_new_map,
|
||||
Mesh &dst_mesh)
|
||||
static void copy_and_reorder_mesh_faces(
|
||||
const Mesh &src_mesh,
|
||||
const Span<int> old_by_new_map,
|
||||
const bke::AnonymousAttributePropagationInfo &propagation_info,
|
||||
Mesh &dst_mesh)
|
||||
{
|
||||
bke::copy_attributes(src_mesh.attributes(),
|
||||
bke::AttrDomain::Point,
|
||||
propagation_info,
|
||||
{},
|
||||
dst_mesh.attributes_for_write());
|
||||
bke::copy_attributes(src_mesh.attributes(),
|
||||
bke::AttrDomain::Edge,
|
||||
propagation_info,
|
||||
{},
|
||||
dst_mesh.attributes_for_write());
|
||||
|
||||
bke::gather_attributes(src_mesh.attributes(),
|
||||
bke::AttrDomain::Face,
|
||||
{},
|
||||
propagation_info,
|
||||
{},
|
||||
old_by_new_map,
|
||||
dst_mesh.attributes_for_write());
|
||||
|
@ -132,26 +188,29 @@ static void reorder_mesh_faces_exec(const Mesh &src_mesh,
|
|||
offset_indices::accumulate_counts_to_offsets(new_offsets);
|
||||
reorder_attributes_group_to_group(src_mesh.attributes(),
|
||||
bke::AttrDomain::Corner,
|
||||
propagation_info,
|
||||
old_offsets,
|
||||
new_offsets.as_span(),
|
||||
old_by_new_map,
|
||||
dst_mesh.attributes_for_write());
|
||||
}
|
||||
|
||||
static void reorder_mesh_exec(const Mesh &src_mesh,
|
||||
const Span<int> old_by_new_map,
|
||||
const bke::AttrDomain domain,
|
||||
Mesh &dst_mesh)
|
||||
static void copy_and_reorder_mesh(const Mesh &src_mesh,
|
||||
const Span<int> old_by_new_map,
|
||||
const bke::AttrDomain domain,
|
||||
const bke::AnonymousAttributePropagationInfo &propagation_info,
|
||||
Mesh &dst_mesh)
|
||||
{
|
||||
BKE_mesh_copy_parameters(&dst_mesh, &src_mesh);
|
||||
switch (domain) {
|
||||
case bke::AttrDomain::Point:
|
||||
reorder_mesh_verts_exec(src_mesh, old_by_new_map, dst_mesh);
|
||||
copy_and_reorder_mesh_verts(src_mesh, old_by_new_map, propagation_info, dst_mesh);
|
||||
break;
|
||||
case bke::AttrDomain::Edge:
|
||||
reorder_mesh_edges_exec(src_mesh, old_by_new_map, dst_mesh);
|
||||
copy_and_reorder_mesh_edges(src_mesh, old_by_new_map, propagation_info, dst_mesh);
|
||||
break;
|
||||
case bke::AttrDomain::Face:
|
||||
reorder_mesh_faces_exec(src_mesh, old_by_new_map, dst_mesh);
|
||||
copy_and_reorder_mesh_faces(src_mesh, old_by_new_map, propagation_info, dst_mesh);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -160,13 +219,14 @@ static void reorder_mesh_exec(const Mesh &src_mesh,
|
|||
dst_mesh.tag_topology_changed();
|
||||
}
|
||||
|
||||
static void reorder_points_exec(const PointCloud &src_pointcloud,
|
||||
const Span<int> old_by_new_map,
|
||||
PointCloud &dst_pointcloud)
|
||||
static void copy_and_reorder_points(const PointCloud &src_pointcloud,
|
||||
const Span<int> old_by_new_map,
|
||||
const bke::AnonymousAttributePropagationInfo &propagation_info,
|
||||
PointCloud &dst_pointcloud)
|
||||
{
|
||||
bke::gather_attributes(src_pointcloud.attributes(),
|
||||
bke::AttrDomain::Point,
|
||||
{},
|
||||
propagation_info,
|
||||
{},
|
||||
old_by_new_map,
|
||||
dst_pointcloud.attributes_for_write());
|
||||
|
@ -174,13 +234,14 @@ static void reorder_points_exec(const PointCloud &src_pointcloud,
|
|||
dst_pointcloud.tag_radii_changed();
|
||||
}
|
||||
|
||||
static void reorder_curves_exec(const bke::CurvesGeometry &src_curves,
|
||||
const Span<int> old_by_new_map,
|
||||
bke::CurvesGeometry &dst_curves)
|
||||
static void copy_and_reorder_curves(const bke::CurvesGeometry &src_curves,
|
||||
const Span<int> old_by_new_map,
|
||||
const bke::AnonymousAttributePropagationInfo &propagation_info,
|
||||
bke::CurvesGeometry &dst_curves)
|
||||
{
|
||||
bke::gather_attributes(src_curves.attributes(),
|
||||
bke::AttrDomain::Curve,
|
||||
{},
|
||||
propagation_info,
|
||||
{},
|
||||
old_by_new_map,
|
||||
dst_curves.attributes_for_write());
|
||||
|
@ -192,6 +253,7 @@ static void reorder_curves_exec(const bke::CurvesGeometry &src_curves,
|
|||
|
||||
reorder_attributes_group_to_group(src_curves.attributes(),
|
||||
bke::AttrDomain::Point,
|
||||
propagation_info,
|
||||
old_offsets,
|
||||
new_offsets.as_span(),
|
||||
old_by_new_map,
|
||||
|
@ -202,8 +264,8 @@ static void reorder_curves_exec(const bke::CurvesGeometry &src_curves,
|
|||
static void copy_and_reorder_instaces(
|
||||
const bke::Instances &src_instances,
|
||||
const Span<int> old_by_new_map,
|
||||
bke::Instances &dst_instances,
|
||||
const bke::AnonymousAttributePropagationInfo &propagation_info)
|
||||
const bke::AnonymousAttributePropagationInfo &propagation_info,
|
||||
bke::Instances &dst_instances)
|
||||
{
|
||||
dst_instances.resize(src_instances.instances_num());
|
||||
bke::gather_attributes(src_instances.attributes(),
|
||||
|
@ -231,56 +293,34 @@ static void copy_and_reorder_instaces(
|
|||
array_utils::gather(old_transforms, old_by_new_map, new_transforms);
|
||||
}
|
||||
|
||||
static void clean_unused_attributes(const bke::AnonymousAttributePropagationInfo &propagation_info,
|
||||
bke::MutableAttributeAccessor attributes)
|
||||
{
|
||||
Vector<std::string> unused_ids;
|
||||
attributes.for_all(
|
||||
[&](const bke::AttributeIDRef &id, const bke::AttributeMetaData /*meta_data*/) {
|
||||
if (!id.is_anonymous()) {
|
||||
return true;
|
||||
}
|
||||
if (propagation_info.propagate(id.anonymous_id())) {
|
||||
return true;
|
||||
}
|
||||
unused_ids.append(id.name());
|
||||
return true;
|
||||
});
|
||||
|
||||
for (const std::string &unused_id : unused_ids) {
|
||||
attributes.remove(unused_id);
|
||||
}
|
||||
}
|
||||
|
||||
Mesh *reorder_mesh(const Mesh &src_mesh,
|
||||
Span<int> old_by_new_map,
|
||||
bke::AttrDomain domain,
|
||||
const Span<int> old_by_new_map,
|
||||
const bke::AttrDomain domain,
|
||||
const bke::AnonymousAttributePropagationInfo &propagation_info)
|
||||
{
|
||||
Mesh *dst_mesh = BKE_mesh_copy_for_eval(&src_mesh);
|
||||
clean_unused_attributes(propagation_info, dst_mesh->attributes_for_write());
|
||||
reorder_mesh_exec(src_mesh, old_by_new_map, domain, *dst_mesh);
|
||||
Mesh *dst_mesh = BKE_mesh_new_nomain(
|
||||
src_mesh.verts_num, src_mesh.edges_num, src_mesh.faces_num, src_mesh.corners_num);
|
||||
copy_and_reorder_mesh(src_mesh, old_by_new_map, domain, propagation_info, *dst_mesh);
|
||||
return dst_mesh;
|
||||
}
|
||||
|
||||
PointCloud *reorder_points(const PointCloud &src_pointcloud,
|
||||
Span<int> old_by_new_map,
|
||||
const Span<int> old_by_new_map,
|
||||
const bke::AnonymousAttributePropagationInfo &propagation_info)
|
||||
{
|
||||
PointCloud *dst_pointcloud = BKE_pointcloud_copy_for_eval(&src_pointcloud);
|
||||
clean_unused_attributes(propagation_info, dst_pointcloud->attributes_for_write());
|
||||
reorder_points_exec(src_pointcloud, old_by_new_map, *dst_pointcloud);
|
||||
PointCloud *dst_pointcloud = BKE_pointcloud_new_nomain(src_pointcloud.totpoint);
|
||||
copy_and_reorder_points(src_pointcloud, old_by_new_map, propagation_info, *dst_pointcloud);
|
||||
return dst_pointcloud;
|
||||
}
|
||||
|
||||
bke::CurvesGeometry reorder_curves_geometry(
|
||||
const bke::CurvesGeometry &src_curves,
|
||||
Span<int> old_by_new_map,
|
||||
const Span<int> old_by_new_map,
|
||||
const bke::AnonymousAttributePropagationInfo &propagation_info)
|
||||
{
|
||||
bke::CurvesGeometry dst_curves = bke::CurvesGeometry(src_curves);
|
||||
clean_unused_attributes(propagation_info, dst_curves.attributes_for_write());
|
||||
reorder_curves_exec(src_curves, old_by_new_map, dst_curves);
|
||||
bke::CurvesGeometry dst_curves = bke::CurvesGeometry(src_curves.points_num(),
|
||||
src_curves.curves_num());
|
||||
copy_and_reorder_curves(src_curves, old_by_new_map, propagation_info, dst_curves);
|
||||
return dst_curves;
|
||||
}
|
||||
|
||||
|
@ -289,18 +329,19 @@ Curves *reorder_curves(const Curves &src_curves,
|
|||
const bke::AnonymousAttributePropagationInfo &propagation_info)
|
||||
{
|
||||
const bke::CurvesGeometry src_curve_geometry = src_curves.geometry.wrap();
|
||||
Curves *dst_curves = BKE_curves_copy_for_eval(&src_curves);
|
||||
Curves *dst_curves = bke::curves_new_nomain(src_curve_geometry.points_num(),
|
||||
src_curve_geometry.curves_num());
|
||||
dst_curves->geometry.wrap() = reorder_curves_geometry(
|
||||
src_curve_geometry, old_by_new_map, propagation_info);
|
||||
return dst_curves;
|
||||
}
|
||||
|
||||
bke::Instances *reorder_instaces(const bke::Instances &src_instances,
|
||||
Span<int> old_by_new_map,
|
||||
const Span<int> old_by_new_map,
|
||||
const bke::AnonymousAttributePropagationInfo &propagation_info)
|
||||
{
|
||||
bke::Instances *dst_instances = new bke::Instances();
|
||||
copy_and_reorder_instaces(src_instances, old_by_new_map, *dst_instances, propagation_info);
|
||||
copy_and_reorder_instaces(src_instances, old_by_new_map, propagation_info, *dst_instances);
|
||||
return dst_instances;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue