Blender V5.3
object_light_linking_ops.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "object_intern.hh"
10
11#include "BKE_context.hh"
12#include "BKE_light_linking.h"
13#include "BKE_scene.hh"
14
15#include "ED_object.hh"
16#include "ED_screen.hh"
17
18#include "WM_api.hh"
19#include "WM_types.hh"
20
21#include "UI_resources.hh"
22
24
25#include "RNA_access.hh"
26#include "RNA_define.hh"
27#include "RNA_prototypes.hh"
28
29namespace blender::ed::object {
30
31/* -------------------------------------------------------------------- */
34
35template<LightLinkingType link_type>
37{
38 Main *bmain = CTX_data_main(C);
40
41 BKE_light_linking_collection_new(bmain, object, link_type);
42
43 return OPERATOR_FINISHED;
44}
45
47{
48 /* identifiers */
49 ot->name = "New Light Linking Collection";
50 ot->description = "Create new light linking collection used by the active emitter";
51 ot->idname = "OBJECT_OT_light_linking_receiver_collection_new";
52
53 /* API callbacks. */
56
57 /* flags */
59}
60
62{
63 /* identifiers */
64 ot->name = "New Light Linking Collection";
65 ot->description = "Create new light linking collection used by the active emitter";
66 ot->idname = "OBJECT_OT_light_linking_blocker_collection_new";
67
68 /* API callbacks. */
71
72 /* flags */
74}
75
77
78/* -------------------------------------------------------------------- */
81
82template<LightLinkingType link_type>
84{
85 const Main *bmain = CTX_data_main(C);
86 Scene *scene = CTX_data_scene(C);
87 ViewLayer *view_layer = CTX_data_view_layer(C);
88 Object *emitter = context_active_object(C);
89
90 BKE_light_linking_select_receivers_of_emitter(*bmain, scene, view_layer, emitter, link_type);
91
93
94 return OPERATOR_FINISHED;
95}
96
98{
99 /* identifiers */
100 ot->name = "Select Light Linking Receivers";
101 ot->description = "Select all objects which receive light from this emitter";
102 ot->idname = "OBJECT_OT_light_linking_receivers_select";
103
104 /* API callbacks. */
107
108 /* flags */
110}
111
113{
114 /* identifiers */
115 ot->name = "Select Light Linking Blockers";
116 ot->description = "Select all objects which block light from this emitter";
117 ot->idname = "OBJECT_OT_light_linking_blockers_select";
118
119 /* API callbacks. */
122
123 /* flags */
125}
126
128
129/* -------------------------------------------------------------------- */
132
133template<LightLinkingType link_type>
135{
136 Main *bmain = CTX_data_main(C);
137 Scene *scene = CTX_data_scene(C);
138 Object *emitter = context_active_object(C);
139
141 RNA_enum_get(op->ptr, "link_state"));
142
143 Collection *collection = BKE_light_linking_collection_get(emitter, link_type);
144 if (Scene *collection_scene = BKE_scene_find_from_collection(bmain, collection);
145 collection_scene != nullptr)
146 {
148 RPT_ERROR,
149 "Cannot link to light linking collection '%s' that is used by scene '%s'",
150 collection->id.name + 2,
151 collection_scene->id.name + 2);
152 return OPERATOR_CANCELLED;
153 }
154
155 CTX_DATA_BEGIN (C, Object *, receiver, selected_objects) {
156 if (receiver == emitter) {
157 continue;
158 }
159
160 BKE_light_linking_link_receiver_to_emitter(bmain, emitter, receiver, link_type, link_state);
161 }
163
164 /* It is possible that the receiver collection is also used by the view layer.
165 * For this case send a notifier so that the UI is updated for the changes in the collection
166 * content. */
168
169 return OPERATOR_FINISHED;
170}
171
173{
174 static const EnumPropertyItem link_state_items[] = {
176 "INCLUDE",
177 ICON_NONE,
178 "Include",
179 "Include selected receivers to receive light from the active emitter"},
181 "EXCLUDE",
182 ICON_NONE,
183 "Exclude",
184 "Exclude selected receivers from receiving light from the active emitter"},
185 {0, nullptr, 0, nullptr, nullptr},
186 };
187
188 /* identifiers */
189 ot->name = "Link Receiver Objects to Emitter";
190 ot->description = "Light link selected objects to the active emitter object";
191 ot->idname = "OBJECT_OT_light_linking_receivers_link";
192
193 /* API callbacks. */
196
197 /* flags */
199
200 ot->prop = RNA_def_enum(ot->srna,
201 "link_state",
202 link_state_items,
204 "Link State",
205 "State of the light linking");
206}
207
209{
210 static const EnumPropertyItem link_state_items[] = {
212 "INCLUDE",
213 ICON_NONE,
214 "Include",
215 "Include selected blockers to cast shadows from the active emitter"},
217 "EXCLUDE",
218 ICON_NONE,
219 "Exclude",
220 "Exclude selected blockers from casting shadows from the active emitter"},
221 {0, nullptr, 0, nullptr, nullptr},
222 };
223
224 /* identifiers */
225 ot->name = "Link Blockers to Emitter";
226 ot->description = "Light link selected blockers to the active emitter object";
227 ot->idname = "OBJECT_OT_light_linking_blockers_link";
228
229 /* API callbacks. */
232
233 /* flags */
235
236 ot->prop = RNA_def_enum(ot->srna,
237 "link_state",
238 link_state_items,
240 "Link State",
241 "State of the shadow linking");
242}
243
245
246/* -------------------------------------------------------------------- */
249
251{
252 Main *bmain = CTX_data_main(C);
253
254 ID *id = static_cast<ID *>(CTX_data_pointer_get_type(C, "id", RNA_ID).data);
255 Collection *collection = static_cast<Collection *>(
256 CTX_data_pointer_get_type(C, "collection", RNA_Collection).data);
257
258 if (!id || !collection) {
260 }
261
262 if (Scene *scene = BKE_scene_find_from_collection(bmain, collection); scene != nullptr) {
264 RPT_ERROR,
265 "Cannot unlink from light linking collection '%s' that is used by scene '%s'",
266 collection->id.name + 2,
267 scene->id.name + 2);
268 return OPERATOR_CANCELLED;
269 }
270
271 if (!BKE_light_linking_unlink_id_from_collection(bmain, collection, id, op->reports)) {
272 return OPERATOR_CANCELLED;
273 }
274
275 /* Copy notifiers from the Outliner's "Unlink" operation for objects and collections. */
279
280 return OPERATOR_FINISHED;
281}
282
284{
285 /* identifiers */
286 ot->name = "Remove From Light Linking Collection";
287 ot->description = "Remove this object or collection from the light linking collection";
288 ot->idname = "OBJECT_OT_light_linking_unlink_from_collection";
289
290 /* API callbacks. */
293
294 /* flags */
296}
297
299
300} // namespace blender::ed::object
#define CTX_DATA_BEGIN(C, Type, instance, member)
#define CTX_DATA_END
Object groups, one object can be in many groups at once.
#define C
Definition RandGen.cpp:29
#define NC_ID
Definition WM_types.hh:408
#define ND_OB_SELECT
Definition WM_types.hh:461
#define NC_SCENE
Definition WM_types.hh:391
#define ND_LAYER_CONTENT
Definition WM_types.hh:472
#define NA_EDITED
Definition WM_types.hh:634
#define ND_LAYER
Definition WM_types.hh:469
#define NC_SPACE
Definition WM_types.hh:405
#define ND_SPACE_OUTLINER
Definition WM_types.hh:570
void OBJECT_OT_light_linking_receiver_collection_new(wmOperatorType *ot)
static wmOperatorStatus light_linking_collection_new_exec(bContext *C, wmOperator *)
static wmOperatorStatus light_linking_link_exec(bContext *C, wmOperator *op)
static wmOperatorStatus light_linking_select_exec(bContext *C, wmOperator *)
void OBJECT_OT_light_linking_blocker_collection_new(wmOperatorType *ot)
static wmOperatorStatus light_linking_unlink_from_collection_exec(bContext *C, wmOperator *op)
void OBJECT_OT_light_linking_unlink_from_collection(wmOperatorType *ot)
Object * context_active_object(const bContext *C)
void OBJECT_OT_light_linking_receivers_link(wmOperatorType *ot)
void OBJECT_OT_light_linking_blockers_select(wmOperatorType *ot)
void OBJECT_OT_light_linking_receivers_select(wmOperatorType *ot)
void OBJECT_OT_light_linking_blockers_link(wmOperatorType *ot)
struct Collection * BKE_light_linking_collection_new(struct Main *bmain, struct Object *object, LightLinkingType link_type)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
ViewLayer * CTX_data_view_layer(const bContext *C)
@ COLLECTION_LIGHT_LINKING_STATE_INCLUDE
@ COLLECTION_LIGHT_LINKING_STATE_EXCLUDE
struct Collection * BKE_light_linking_collection_get(const struct Object *object, LightLinkingType link_type)
void BKE_light_linking_select_receivers_of_emitter(const Main &bmain, struct Scene *scene, struct ViewLayer *view_layer, struct Object *emitter, LightLinkingType link_type)
bool ED_operator_object_active(bContext *C)
bool ED_operator_object_active_editable(bContext *C)
Scene * BKE_scene_find_from_collection(const Main *bmain, const Collection *collection)
Definition scene.cc:2427
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
bool BKE_light_linking_unlink_id_from_collection(struct Main *bmain, struct Collection *collection, struct ID *id, struct ReportList *reports)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
Main * CTX_data_main(const bContext *C)
void BKE_light_linking_link_receiver_to_emitter(struct Main *bmain, struct Object *emitter, struct Object *receiver, LightLinkingType link_type, eCollectionLightLinkingState link_state)
Scene * CTX_data_scene(const bContext *C)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
char name[258]
Definition DNA_ID.h:433
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
struct ReportList * reports