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 | |
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')
-rw-r--r-- | source/blender/blenkernel/BKE_pointcloud.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/pointcloud.cc | 31 |
2 files changed, 34 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_pointcloud.h b/source/blender/blenkernel/BKE_pointcloud.h index 62a1824d844..5fd601e4332 100644 --- a/source/blender/blenkernel/BKE_pointcloud.h +++ b/source/blender/blenkernel/BKE_pointcloud.h @@ -25,6 +25,9 @@ extern const char *POINTCLOUD_ATTR_RADIUS; void *BKE_pointcloud_add(struct Main *bmain, const char *name); void *BKE_pointcloud_add_default(struct Main *bmain, const char *name); struct PointCloud *BKE_pointcloud_new_nomain(int totpoint); +void BKE_pointcloud_nomain_to_pointcloud(struct PointCloud *pointcloud_src, + struct PointCloud *pointcloud_dst, + bool take_ownership); struct BoundBox *BKE_pointcloud_boundbox_get(struct Object *ob); bool BKE_pointcloud_minmax(const struct PointCloud *pointcloud, float r_min[3], float r_max[3]); 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) { |