Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/pointcloud.cc')
-rw-r--r--source/blender/blenkernel/intern/pointcloud.cc81
1 files changed, 41 insertions, 40 deletions
diff --git a/source/blender/blenkernel/intern/pointcloud.cc b/source/blender/blenkernel/intern/pointcloud.cc
index 261b053e4f9..119daccce20 100644
--- a/source/blender/blenkernel/intern/pointcloud.cc
+++ b/source/blender/blenkernel/intern/pointcloud.cc
@@ -64,13 +64,13 @@ static void pointcloud_init_data(ID *id)
CustomData_reset(&pointcloud->pdata);
CustomData_add_layer_named(&pointcloud->pdata,
CD_PROP_FLOAT3,
- CD_CALLOC,
+ CD_SET_DEFAULT,
nullptr,
pointcloud->totpoint,
POINTCLOUD_ATTR_POSITION);
}
-static void pointcloud_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, const int flag)
+static void pointcloud_copy_data(Main * /*bmain*/, ID *id_dst, const ID *id_src, const int flag)
{
PointCloud *pointcloud_dst = (PointCloud *)id_dst;
const PointCloud *pointcloud_src = (const PointCloud *)id_src;
@@ -175,7 +175,7 @@ IDTypeInfo IDType_ID_PT = {
/* foreach_id */ pointcloud_foreach_id,
/* foreach_cache */ nullptr,
/* foreach_path */ nullptr,
- /* owner_get */ nullptr,
+ /* owner_pointer_get */ nullptr,
/* blend_write */ pointcloud_blend_write,
/* blend_read_data */ pointcloud_blend_read_data,
@@ -189,13 +189,13 @@ IDTypeInfo IDType_ID_PT = {
static void pointcloud_random(PointCloud *pointcloud)
{
+ BLI_assert(pointcloud->totpoint == 0);
pointcloud->totpoint = 400;
- CustomData_realloc(&pointcloud->pdata, pointcloud->totpoint);
+ CustomData_realloc(&pointcloud->pdata, 0, pointcloud->totpoint);
RNG *rng = BLI_rng_new(0);
- blender::bke::MutableAttributeAccessor attributes =
- blender::bke::pointcloud_attributes_for_write(*pointcloud);
+ blender::bke::MutableAttributeAccessor attributes = pointcloud->attributes_for_write();
blender::bke::SpanAttributeWriter positions =
attributes.lookup_or_add_for_write_only_span<float3>(POINTCLOUD_ATTR_POSITION,
ATTR_DOMAIN_POINT);
@@ -228,13 +228,6 @@ void *BKE_pointcloud_add_default(Main *bmain, const char *name)
PointCloud *pointcloud = static_cast<PointCloud *>(BKE_libblock_alloc(bmain, ID_PT, name, 0));
pointcloud_init_data(&pointcloud->id);
-
- CustomData_add_layer_named(&pointcloud->pdata,
- CD_PROP_FLOAT,
- CD_CALLOC,
- nullptr,
- pointcloud->totpoint,
- POINTCLOUD_ATTR_RADIUS);
pointcloud_random(pointcloud);
return pointcloud;
@@ -247,25 +240,47 @@ PointCloud *BKE_pointcloud_new_nomain(const int totpoint)
pointcloud_init_data(&pointcloud->id);
+ CustomData_realloc(&pointcloud->pdata, 0, totpoint);
pointcloud->totpoint = totpoint;
- CustomData_add_layer_named(&pointcloud->pdata,
- CD_PROP_FLOAT,
- CD_CALLOC,
- nullptr,
- pointcloud->totpoint,
- POINTCLOUD_ATTR_RADIUS);
+ return pointcloud;
+}
- pointcloud->totpoint = totpoint;
- CustomData_realloc(&pointcloud->pdata, pointcloud->totpoint);
+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);
- return pointcloud;
+ 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)
{
- blender::bke::AttributeAccessor attributes = blender::bke::pointcloud_attributes(pointcloud);
+ blender::bke::AttributeAccessor attributes = pointcloud.attributes();
blender::VArraySpan<float3> positions = attributes.lookup_or_default<float3>(
POINTCLOUD_ATTR_POSITION, ATTR_DOMAIN_POINT, float3(0));
blender::VArray<float> radii = attributes.lookup_or_default<float>(
@@ -318,29 +333,13 @@ BoundBox *BKE_pointcloud_boundbox_get(Object *ob)
return ob->runtime.bb;
}
-bool BKE_pointcloud_customdata_required(const PointCloud *UNUSED(pointcloud), const char *name)
+bool BKE_pointcloud_attribute_required(const PointCloud * /*pointcloud*/, const char *name)
{
return STREQ(name, POINTCLOUD_ATTR_POSITION);
}
/* Dependency Graph */
-PointCloud *BKE_pointcloud_new_for_eval(const PointCloud *pointcloud_src, int totpoint)
-{
- PointCloud *pointcloud_dst = static_cast<PointCloud *>(BKE_id_new_nomain(ID_PT, nullptr));
- CustomData_free(&pointcloud_dst->pdata, pointcloud_dst->totpoint);
-
- STRNCPY(pointcloud_dst->id.name, pointcloud_src->id.name);
- pointcloud_dst->mat = static_cast<Material **>(MEM_dupallocN(pointcloud_src->mat));
- pointcloud_dst->totcol = pointcloud_src->totcol;
-
- pointcloud_dst->totpoint = totpoint;
- CustomData_copy(
- &pointcloud_src->pdata, &pointcloud_dst->pdata, CD_MASK_ALL, CD_CALLOC, totpoint);
-
- return pointcloud_dst;
-}
-
PointCloud *BKE_pointcloud_copy_for_eval(struct PointCloud *pointcloud_src, bool reference)
{
int flags = LIB_ID_COPY_LOCALIZE;
@@ -364,6 +363,8 @@ static void pointcloud_evaluate_modifiers(struct Depsgraph *depsgraph,
ModifierApplyFlag apply_flag = use_render ? MOD_APPLY_RENDER : MOD_APPLY_USECACHE;
const ModifierEvalContext mectx = {depsgraph, object, apply_flag};
+ BKE_modifiers_clear_errors(object);
+
/* Get effective list of modifiers to execute. Some effects like shape keys
* are added as virtual modifiers before the user created modifiers. */
VirtualModifierData virtualModifierData;