Blender
V4.5
source
blender
editors
pointcloud
intern
pointcloud/intern/join.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2025 Blender Authors
2
*
3
* SPDX-License-Identifier: GPL-2.0-or-later */
4
5
#include "
BLI_map.hh
"
6
7
#include "
DNA_scene_types.h
"
8
9
#include "
BKE_context.hh
"
10
#include "
BKE_instances.hh
"
11
#include "
BKE_pointcloud.hh
"
12
#include "
BKE_report.hh
"
13
14
#include "
DEG_depsgraph.hh
"
15
#include "
DEG_depsgraph_build.hh
"
16
17
#include "
WM_api.hh
"
18
#include "
WM_types.hh
"
19
20
#include "
ED_object.hh
"
21
#include "
ED_pointcloud.hh
"
22
23
#include "
GEO_realize_instances.hh
"
24
25
namespace
blender::ed::pointcloud
{
26
27
wmOperatorStatus
join_objects_exec
(
bContext
*C,
wmOperator
*op)
28
{
29
Main
*bmain =
CTX_data_main
(C);
30
Scene
*
scene
=
CTX_data_scene
(C);
31
Object
*active_object =
CTX_data_active_object
(C);
32
BLI_assert
(active_object);
33
BLI_assert
(active_object->
type
==
OB_POINTCLOUD
);
34
PointCloud
&active_pointcloud = *
static_cast<
PointCloud
*
>
(active_object->
data
);
35
const
float4x4
&world_to_active = active_object->world_to_object();
36
37
Vector<Object *>
objects{active_object};
38
bool
active_object_selected =
false
;
39
CTX_DATA_BEGIN
(C,
Object
*,
object
, selected_editable_objects) {
40
if
(
object
== active_object) {
41
active_object_selected =
true
;
42
continue
;
43
}
44
if
(object->type !=
OB_POINTCLOUD
) {
45
continue
;
46
}
47
objects.append(
object
);
48
}
49
CTX_DATA_END
;
50
51
if
(!active_object_selected) {
52
BKE_report
(op->
reports
,
RPT_WARNING
,
"Active object is not a selected point cloud object"
);
53
return
OPERATOR_CANCELLED
;
54
}
55
56
bke::Instances
instances;
57
instances.
resize
(objects.size());
58
MutableSpan<float4x4>
transforms = instances.
transforms_for_write
();
59
MutableSpan<int>
references = instances.
reference_handles_for_write
();
60
Map<const PointCloud *, int>
reference_by_orig_points;
61
for
(
const
int
i : objects.index_range()) {
62
transforms[i] = world_to_active * objects[i]->object_to_world();
63
const
PointCloud
*orig_points =
static_cast<
const
PointCloud
*
>
(objects[i]->data);
64
references[i] = reference_by_orig_points.
lookup_or_add_cb
(orig_points, [&]() {
65
auto
geometry =
bke::GeometrySet::from_pointcloud
(
BKE_pointcloud_copy_for_eval
(orig_points));
66
return
instances.
add_new_reference
(std::move(geometry));
67
});
68
}
69
70
bke::GeometrySet
realized_geometry =
geometry::realize_instances
(
71
bke::GeometrySet::from_instances
(&instances,
bke::GeometryOwnershipType::ReadOnly
),
72
geometry::RealizeInstancesOptions
());
73
74
if
(!realized_geometry.
has_pointcloud
()) {
75
BKE_report
(op->
reports
,
RPT_WARNING
,
"No point cloud data to join"
);
76
return
OPERATOR_CANCELLED
;
77
}
78
79
PointCloud
*realized_points =
80
realized_geometry.
get_component_for_write
<
bke::PointCloudComponent
>().release();
81
BKE_pointcloud_nomain_to_pointcloud
(realized_points, &active_pointcloud);
82
83
for
(
Object
*
object
: objects.as_span().drop_front(1)) {
84
object::base_free_and_unlink
(bmain,
scene
,
object
);
85
}
86
87
DEG_relations_tag_update
(bmain);
88
DEG_id_tag_update
(&active_object->
id
,
ID_RECALC_TRANSFORM
|
ID_RECALC_GEOMETRY
);
89
DEG_id_tag_update
(&
scene
->
id
,
ID_RECALC_SELECT
);
90
WM_event_add_notifier
(C,
NC_SCENE
|
ND_OB_ACTIVE
,
scene
);
91
WM_event_add_notifier
(C,
NC_SCENE
|
ND_LAYER_CONTENT
,
scene
);
92
93
return
OPERATOR_FINISHED
;
94
}
95
96
}
// namespace blender::ed::pointcloud
BKE_context.hh
CTX_DATA_BEGIN
#define CTX_DATA_BEGIN(C, Type, instance, member)
Definition
BKE_context.hh:342
CTX_data_active_object
Object * CTX_data_active_object(const bContext *C)
Definition
blenkernel/intern/context.cc:1433
CTX_data_scene
Scene * CTX_data_scene(const bContext *C)
Definition
blenkernel/intern/context.cc:1151
CTX_data_main
Main * CTX_data_main(const bContext *C)
Definition
blenkernel/intern/context.cc:1135
CTX_DATA_END
#define CTX_DATA_END
Definition
BKE_context.hh:349
BKE_instances.hh
BKE_pointcloud.hh
General operations for point clouds.
BKE_pointcloud_copy_for_eval
PointCloud * BKE_pointcloud_copy_for_eval(const PointCloud *pointcloud_src)
Definition
pointcloud.cc:385
BKE_pointcloud_nomain_to_pointcloud
void BKE_pointcloud_nomain_to_pointcloud(PointCloud *pointcloud_src, PointCloud *pointcloud_dst)
Definition
pointcloud.cc:293
BKE_report.hh
BKE_report
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition
report.cc:126
BLI_assert
#define BLI_assert(a)
Definition
BLI_assert.h:46
BLI_map.hh
DEG_depsgraph.hh
DEG_id_tag_update
void DEG_id_tag_update(ID *id, unsigned int flags)
Definition
depsgraph_tag.cc:827
DEG_depsgraph_build.hh
DEG_relations_tag_update
void DEG_relations_tag_update(Main *bmain)
Definition
depsgraph_build.cc:331
ID_RECALC_TRANSFORM
@ ID_RECALC_TRANSFORM
Definition
DNA_ID.h:962
ID_RECALC_SELECT
@ ID_RECALC_SELECT
Definition
DNA_ID.h:1009
ID_RECALC_GEOMETRY
@ ID_RECALC_GEOMETRY
Definition
DNA_ID.h:982
OB_POINTCLOUD
@ OB_POINTCLOUD
Definition
DNA_object_types.h:468
DNA_scene_types.h
wmOperatorStatus
wmOperatorStatus
Definition
DNA_windowmanager_enums.h:16
OPERATOR_CANCELLED
@ OPERATOR_CANCELLED
Definition
DNA_windowmanager_enums.h:18
OPERATOR_FINISHED
@ OPERATOR_FINISHED
Definition
DNA_windowmanager_enums.h:19
RPT_WARNING
@ RPT_WARNING
Definition
DNA_windowmanager_types.h:77
ED_object.hh
ED_pointcloud.hh
GEO_realize_instances.hh
WM_api.hh
WM_types.hh
ND_OB_ACTIVE
#define ND_OB_ACTIVE
Definition
WM_types.hh:437
NC_SCENE
#define NC_SCENE
Definition
WM_types.hh:375
ND_LAYER_CONTENT
#define ND_LAYER_CONTENT
Definition
WM_types.hh:450
blender::Map
Definition
BLI_map.hh:129
blender::Map::lookup_or_add_cb
Value & lookup_or_add_cb(const Key &key, const CreateValueF &create_value)
Definition
BLI_map.hh:620
blender::MutableSpan
Definition
BLI_span.hh:443
blender::Vector
Definition
BLI_vector.hh:76
blender::bke::Instances
Definition
BKE_instances.hh:113
blender::bke::Instances::reference_handles_for_write
MutableSpan< int > reference_handles_for_write()
Definition
instances.cc:222
blender::bke::Instances::add_new_reference
int add_new_reference(const InstanceReference &reference)
Definition
instances.cc:279
blender::bke::Instances::resize
void resize(int capacity)
Definition
instances.cc:197
blender::bke::Instances::transforms_for_write
MutableSpan< float4x4 > transforms_for_write()
Definition
instances.cc:240
blender::bke::PointCloudComponent
Definition
BKE_geometry_set.hh:542
scene
Scene scene
Definition
deg_eval_copy_on_write.cc:98
blender::bke::GeometryOwnershipType::ReadOnly
@ ReadOnly
blender::ed::object::base_free_and_unlink
void base_free_and_unlink(Main *bmain, Scene *scene, Object *ob)
Definition
object_add.cc:2181
blender::ed::pointcloud
Definition
ED_pointcloud.hh:38
blender::ed::pointcloud::join_objects_exec
wmOperatorStatus join_objects_exec(bContext *C, wmOperator *op)
Definition
pointcloud/intern/join.cc:27
blender::geometry::realize_instances
bke::GeometrySet realize_instances(bke::GeometrySet geometry_set, const RealizeInstancesOptions &options)
Definition
realize_instances.cc:2488
Main
Definition
BKE_main.hh:141
Object
Definition
DNA_object_types.h:192
Object::type
short type
Definition
DNA_object_types.h:205
Object::id
ID id
Definition
DNA_object_types.h:199
Object::data
void * data
Definition
DNA_object_types.h:224
PointCloud
Definition
DNA_pointcloud_types.h:40
Scene
Definition
DNA_scene_types.h:2106
Scene::id
ID id
Definition
DNA_scene_types.h:2112
bContext
Definition
blenkernel/intern/context.cc:58
blender::MatBase< float, 4, 4 >
blender::bke::GeometrySet
Definition
BKE_geometry_set.hh:145
blender::bke::GeometrySet::get_component_for_write
GeometryComponent & get_component_for_write(GeometryComponent::Type component_type)
Definition
geometry_set.cc:113
blender::bke::GeometrySet::from_instances
static GeometrySet from_instances(Instances *instances, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Definition
geometry_set.cc:468
blender::bke::GeometrySet::has_pointcloud
bool has_pointcloud() const
Definition
geometry_set.cc:391
blender::bke::GeometrySet::from_pointcloud
static GeometrySet from_pointcloud(PointCloud *pointcloud, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Definition
geometry_set.cc:454
blender::geometry::RealizeInstancesOptions
Definition
GEO_realize_instances.hh:14
wmOperator
Definition
DNA_windowmanager_types.h:636
wmOperator::reports
struct ReportList * reports
Definition
DNA_windowmanager_types.h:656
WM_event_add_notifier
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
Definition
wm_event_system.cc:395
Generated on Fri Apr 3 2026 06:33:18 for Blender by
doxygen
1.11.0