Blender V4.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
9#include "object_intern.hh"
10
11#include "BKE_context.hh"
12#include "BKE_light_linking.h"
13
14#include "ED_object.hh"
15#include "ED_screen.hh"
16
17#include "WM_api.hh"
18#include "WM_types.hh"
19
20#include "UI_resources.hh"
21
23
24#include "RNA_access.hh"
25#include "RNA_define.hh"
26#include "RNA_prototypes.hh"
27
28namespace blender::ed::object {
29
30/* -------------------------------------------------------------------- */
34template<LightLinkingType link_type>
36{
37 Main *bmain = CTX_data_main(C);
38 Object *object = context_active_object(C);
39
40 BKE_light_linking_collection_new(bmain, object, link_type);
41
42 return OPERATOR_FINISHED;
43}
44
46{
47 /* identifiers */
48 ot->name = "New Light Linking Collection";
49 ot->description = "Create new light linking collection used by the active emitter";
50 ot->idname = "OBJECT_OT_light_linking_receiver_collection_new";
51
52 /* api callbacks */
55
56 /* flags */
58}
59
61{
62 /* identifiers */
63 ot->name = "New Light Linking Collection";
64 ot->description = "Create new light linking collection used by the active emitter";
65 ot->idname = "OBJECT_OT_light_linking_blocker_collection_new";
66
67 /* api callbacks */
70
71 /* flags */
73}
74
77/* -------------------------------------------------------------------- */
81template<LightLinkingType link_type>
83{
84 Scene *scene = CTX_data_scene(C);
85 ViewLayer *view_layer = CTX_data_view_layer(C);
86 Object *emitter = context_active_object(C);
87
88 BKE_light_linking_select_receivers_of_emitter(scene, view_layer, emitter, link_type);
89
91
92 return OPERATOR_FINISHED;
93}
94
96{
97 /* identifiers */
98 ot->name = "Select Light Linking Receivers";
99 ot->description = "Select all objects which receive light from this emitter";
100 ot->idname = "OBJECT_OT_light_linking_receivers_select";
101
102 /* api callbacks */
105
106 /* flags */
108}
109
111{
112 /* identifiers */
113 ot->name = "Select Light Linking Blockers";
114 ot->description = "Select all objects which block light from this emitter";
115 ot->idname = "OBJECT_OT_light_linking_blockers_select";
116
117 /* api callbacks */
120
121 /* flags */
123}
124
127/* -------------------------------------------------------------------- */
131template<LightLinkingType link_type>
133{
134 Main *bmain = CTX_data_main(C);
135 Scene *scene = CTX_data_scene(C);
136 Object *emitter = context_active_object(C);
137
139 RNA_enum_get(op->ptr, "link_state"));
140
141 CTX_DATA_BEGIN (C, Object *, receiver, selected_objects) {
142 if (receiver == emitter) {
143 continue;
144 }
145
146 BKE_light_linking_link_receiver_to_emitter(bmain, emitter, receiver, link_type, link_state);
147 }
149
150 /* It is possible that the receiver collection is also used by the view layer.
151 * For this case send a notifier so that the UI is updated for the changes in the collection
152 * content. */
154
155 return OPERATOR_FINISHED;
156}
157
159{
160 static const EnumPropertyItem link_state_items[] = {
162 "INCLUDE",
163 ICON_NONE,
164 "Include",
165 "Include selected receivers to receive light from the active emitter"},
167 "EXCLUDE",
168 ICON_NONE,
169 "Exclude",
170 "Exclude selected receivers from receiving light from the active emitter"},
171 {0, nullptr, 0, nullptr, nullptr},
172 };
173
174 /* identifiers */
175 ot->name = "Link Receivers to Emitter";
176 ot->description = "Light link selected receivers to the active emitter object";
177 ot->idname = "OBJECT_OT_light_linking_receivers_link";
178
179 /* api callbacks */
182
183 /* flags */
185
187 "link_state",
188 link_state_items,
190 "Link State",
191 "State of the light linking");
192}
193
195{
196 static const EnumPropertyItem link_state_items[] = {
198 "INCLUDE",
199 ICON_NONE,
200 "Include",
201 "Include selected blockers to cast shadows from the active emitter"},
203 "EXCLUDE",
204 ICON_NONE,
205 "Exclude",
206 "Exclude selected blockers from casting shadows from the active emitter"},
207 {0, nullptr, 0, nullptr, nullptr},
208 };
209
210 /* identifiers */
211 ot->name = "Link Blockers to Emitter";
212 ot->description = "Light link selected blockers to the active emitter object";
213 ot->idname = "OBJECT_OT_light_linking_blockers_link";
214
215 /* api callbacks */
218
219 /* flags */
221
223 "link_state",
224 link_state_items,
226 "Link State",
227 "State of the shadow linking");
228}
229
232/* -------------------------------------------------------------------- */
237{
238 Main *bmain = CTX_data_main(C);
239
240 ID *id = static_cast<ID *>(CTX_data_pointer_get_type(C, "id", &RNA_ID).data);
241 Collection *collection = static_cast<Collection *>(
242 CTX_data_pointer_get_type(C, "collection", &RNA_Collection).data);
243
244 if (!id || !collection) {
246 }
247
248 if (!BKE_light_linking_unlink_id_from_collection(bmain, collection, id, op->reports)) {
249 return OPERATOR_CANCELLED;
250 }
251
252 /* Copy notifiers from the Outliner's "Unlink" operation for objects and collections. */
256
257 return OPERATOR_FINISHED;
258}
259
261{
262 /* identifiers */
263 ot->name = "Remove From Light Linking Collection";
264 ot->description = "Remove this object or collection from the light linking collection";
265 ot->idname = "OBJECT_OT_light_linking_unlink_from_collection";
266
267 /* api callbacks */
270
271 /* flags */
273}
274
277} // namespace blender::ed::object
#define CTX_DATA_BEGIN(C, Type, instance, member)
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
#define CTX_DATA_END
ViewLayer * CTX_data_view_layer(const bContext *C)
void BKE_light_linking_select_receivers_of_emitter(struct Scene *scene, struct ViewLayer *view_layer, struct Object *emitter, LightLinkingType link_type)
bool BKE_light_linking_unlink_id_from_collection(struct Main *bmain, struct Collection *collection, struct ID *id, struct ReportList *reports)
struct Collection * BKE_light_linking_collection_new(struct Main *bmain, struct Object *object, LightLinkingType link_type)
void BKE_light_linking_link_receiver_to_emitter(struct Main *bmain, struct Object *emitter, struct Object *receiver, LightLinkingType link_type, eCollectionLightLinkingState link_state)
Object groups, one object can be in many groups at once.
eCollectionLightLinkingState
@ COLLECTION_LIGHT_LINKING_STATE_EXCLUDE
@ COLLECTION_LIGHT_LINKING_STATE_INCLUDE
@ OPERATOR_PASS_THROUGH
bool ED_operator_object_active(bContext *C)
bool ED_operator_object_active_editable(bContext *C)
@ OPTYPE_UNDO
Definition WM_types.hh:162
@ OPTYPE_REGISTER
Definition WM_types.hh:160
#define NC_ID
Definition WM_types.hh:362
#define ND_OB_SELECT
Definition WM_types.hh:409
#define NC_SCENE
Definition WM_types.hh:345
#define ND_LAYER_CONTENT
Definition WM_types.hh:420
#define NA_EDITED
Definition WM_types.hh:550
#define ND_LAYER
Definition WM_types.hh:417
#define NC_SPACE
Definition WM_types.hh:359
#define ND_SPACE_OUTLINER
Definition WM_types.hh:493
void OBJECT_OT_light_linking_receiver_collection_new(wmOperatorType *ot)
static int light_linking_collection_new_exec(bContext *C, wmOperator *)
static int light_linking_link_exec(bContext *C, wmOperator *op)
static int light_linking_unlink_from_collection_exec(bContext *C, wmOperator *op)
static int light_linking_select_exec(bContext *C, wmOperator *)
void OBJECT_OT_light_linking_blocker_collection_new(wmOperatorType *ot)
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)
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)
Definition DNA_ID.h:413
void * data
Definition RNA_types.hh:42
const char * name
Definition WM_types.hh:990
bool(* poll)(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1042
const char * idname
Definition WM_types.hh:992
int(* exec)(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1006
const char * description
Definition WM_types.hh:996
PropertyRNA * prop
Definition WM_types.hh:1092
StructRNA * srna
Definition WM_types.hh:1080
struct ReportList * reports
struct PointerRNA * ptr
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition wm_files.cc:4125