diff options
author | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2022-09-15 16:21:25 +0300 |
---|---|---|
committer | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2022-09-15 16:21:25 +0300 |
commit | c41249d43638666abef3d5a46e71de7a8e162298 (patch) | |
tree | 5d83d1e23b1fac079b89eaa3d78f542c7f5808bc /source/blender/blenkernel/intern/pointcloud.cc | |
parent | a869fcd686f4728b187ed64864afbaa8784a94af (diff) |
PointCloud: add BKE_pointcloud_nomain_to_pointcloud
This adds a utility function to copy the data from a PointCloud
outside of the main database to one that is in the database. This
is similar to `BKE_mesh_nomain_to_mesh`.
Ref D11592
Diffstat (limited to 'source/blender/blenkernel/intern/pointcloud.cc')
-rw-r--r-- | source/blender/blenkernel/intern/pointcloud.cc | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/pointcloud.cc b/source/blender/blenkernel/intern/pointcloud.cc index b45e164b594..a17ca1447f6 100644 --- a/source/blender/blenkernel/intern/pointcloud.cc +++ b/source/blender/blenkernel/intern/pointcloud.cc @@ -252,6 +252,37 @@ PointCloud *BKE_pointcloud_new_nomain(const int totpoint) return pointcloud; } +void BKE_pointcloud_nomain_to_pointcloud(PointCloud *pointcloud_src, + PointCloud *pointcloud_dst, + bool take_ownership) +{ + BLI_assert(pointcloud_src->id.tag & LIB_TAG_NO_MAIN); + + eCDAllocType alloctype = CD_DUPLICATE; + + if (take_ownership) { + bool has_any_referenced_layers = CustomData_has_referenced(&pointcloud_src->pdata); + + if (!has_any_referenced_layers) { + alloctype = CD_ASSIGN; + } + } + + CustomData_free(&pointcloud_dst->pdata, pointcloud_dst->totpoint); + + const int totpoint = pointcloud_dst->totpoint = pointcloud_src->totpoint; + CustomData_copy( + &pointcloud_src->pdata, &pointcloud_dst->pdata, CD_MASK_ALL, alloctype, totpoint); + + if (take_ownership) { + if (alloctype == CD_ASSIGN) { + /* Free the CustomData but keep the layers. */ + CustomData_free_typemask(&pointcloud_src->pdata, pointcloud_src->totpoint, 0); + } + BKE_id_free(nullptr, pointcloud_src); + } +} + static std::optional<blender::bounds::MinMaxResult<float3>> point_cloud_bounds( const PointCloud &pointcloud) { |