Blender V5.0
curves/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 "DNA_scene_types.h"
6
7#include "BKE_context.hh"
8#include "BKE_instances.hh"
9#include "BKE_report.hh"
10
11#include "DEG_depsgraph.hh"
13
14#include "WM_api.hh"
15#include "WM_types.hh"
16
17#include "ED_curves.hh"
18#include "ED_object.hh"
19
21
22namespace blender::ed::curves {
23
25{
26 Main *bmain = CTX_data_main(C);
27 Scene *scene = CTX_data_scene(C);
28 Object *active_object = CTX_data_active_object(C);
29 BLI_assert(active_object);
30 BLI_assert(active_object->type == OB_CURVES);
31 Curves &active_curves = *static_cast<Curves *>(active_object->data);
32 const float4x4 &world_to_active = active_object->world_to_object();
33
34 Vector<Object *> objects{active_object};
35 bool active_object_selected = false;
36 CTX_DATA_BEGIN (C, Object *, object, selected_editable_objects) {
37 if (object == active_object) {
38 active_object_selected = true;
39 continue;
40 }
41 if (object->type != OB_CURVES) {
42 continue;
43 }
44 objects.append(object);
45 }
47
48 if (!active_object_selected) {
49 BKE_report(op->reports, RPT_WARNING, "Active object is not a selected curves object");
50 return OPERATOR_CANCELLED;
51 }
52
53 bke::Instances instances;
54 instances.resize(objects.size());
55 MutableSpan<float4x4> transforms = instances.transforms_for_write();
56 MutableSpan<int> references = instances.reference_handles_for_write();
57 Map<const Curves *, int> reference_by_orig_curves;
58 for (const int i : objects.index_range()) {
59 transforms[i] = world_to_active * objects[i]->object_to_world();
60 const Curves *orig_curves = static_cast<const Curves *>(objects[i]->data);
61 references[i] = reference_by_orig_curves.lookup_or_add_cb(orig_curves, [&]() {
63 return instances.add_new_reference(std::move(geometry));
64 });
65 }
66
71 .geometry;
72
73 if (!realized_geometry.has_curves()) {
74 BKE_report(op->reports, RPT_WARNING, "No curves data to join");
75 return OPERATOR_CANCELLED;
76 }
77
78 Curves *realized_curves = realized_geometry.get_curves_for_write();
79 active_curves.geometry.wrap() = std::move(realized_curves->geometry.wrap());
80
81 for (Object *object : objects.as_span().drop_front(1)) {
82 object::base_free_and_unlink(bmain, scene, object);
83 }
84
90
91 return OPERATOR_FINISHED;
92}
93
94} // namespace blender::ed::curves
#define CTX_DATA_BEGIN(C, Type, instance, member)
Object * CTX_data_active_object(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
#define CTX_DATA_END
struct Curves * BKE_curves_copy_for_eval(const struct Curves *curves_src)
@ RPT_WARNING
Definition BKE_report.hh:38
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:153
#define BLI_assert(a)
Definition BLI_assert.h:46
void DEG_id_tag_update(ID *id, unsigned int flags)
void DEG_relations_tag_update(Main *bmain)
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:1054
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
@ OB_CURVES
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
#define C
Definition RandGen.cpp:29
#define ND_OB_ACTIVE
Definition WM_types.hh:440
#define NC_SCENE
Definition WM_types.hh:378
#define ND_LAYER_CONTENT
Definition WM_types.hh:453
Value & lookup_or_add_cb(const Key &key, const CreateValueF &create_value)
Definition BLI_map.hh:620
int64_t size() const
void append(const T &value)
IndexRange index_range() const
Span< T > as_span() const
MutableSpan< int > reference_handles_for_write()
Definition instances.cc:222
int add_new_reference(const InstanceReference &reference)
Definition instances.cc:269
void resize(int capacity)
Definition instances.cc:191
MutableSpan< float4x4 > transforms_for_write()
Definition instances.cc:235
wmOperatorStatus join_objects_exec(bContext *C, wmOperator *op)
void base_free_and_unlink(Main *bmain, Scene *scene, Object *ob)
RealizeInstancesResult realize_instances(bke::GeometrySet geometry_set, const RealizeInstancesOptions &options)
MatBase< float, 4, 4 > float4x4
CurvesGeometry geometry
static GeometrySet from_instances(Instances *instances, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
static GeometrySet from_curves(Curves *curves, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
struct ReportList * reports
i
Definition text_draw.cc:230
void WM_event_add_notifier(const bContext *C, uint type, void *reference)