1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License
4 * as published by the Free Software Foundation; either version 2
5 * of the License, or (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software Foundation,
14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15 */
16
17 /** \file
18 * \ingroup RNA
19 */
20
21 #include "DNA_layer_types.h"
22 #include "DNA_scene_types.h"
23 #include "DNA_view3d_types.h"
24
25 #include "BLT_translation.h"
26
27 #include "ED_object.h"
28 #include "ED_render.h"
29
30 #include "RE_engine.h"
31
32 #include "WM_api.h"
33 #include "WM_types.h"
34
35 #include "RNA_define.h"
36
37 #include "rna_internal.h"
38
39 #ifdef RNA_RUNTIME
40
41 # ifdef WITH_PYTHON
42 # include "BPY_extern.h"
43 # endif
44
45 # include "DNA_collection_types.h"
46 # include "DNA_object_types.h"
47
48 # include "RNA_access.h"
49
50 # include "BKE_idprop.h"
51 # include "BKE_layer.h"
52 # include "BKE_mesh.h"
53 # include "BKE_node.h"
54 # include "BKE_scene.h"
55
56 # include "BLI_listbase.h"
57
58 # include "DEG_depsgraph_build.h"
59 # include "DEG_depsgraph_query.h"
60
61 /***********************************/
62
rna_ViewLayer_active_layer_collection_get(PointerRNA * ptr)63 static PointerRNA rna_ViewLayer_active_layer_collection_get(PointerRNA *ptr)
64 {
65 ViewLayer *view_layer = (ViewLayer *)ptr->data;
66 LayerCollection *lc = view_layer->active_collection;
67 return rna_pointer_inherit_refine(ptr, &RNA_LayerCollection, lc);
68 }
69
rna_ViewLayer_active_layer_collection_set(PointerRNA * ptr,PointerRNA value,struct ReportList * UNUSED (reports))70 static void rna_ViewLayer_active_layer_collection_set(PointerRNA *ptr,
71 PointerRNA value,
72 struct ReportList *UNUSED(reports))
73 {
74 ViewLayer *view_layer = (ViewLayer *)ptr->data;
75 LayerCollection *lc = (LayerCollection *)value.data;
76 const int index = BKE_layer_collection_findindex(view_layer, lc);
77 if (index != -1) {
78 BKE_layer_collection_activate(view_layer, lc);
79 }
80 }
81
rna_LayerObjects_active_object_get(PointerRNA * ptr)82 static PointerRNA rna_LayerObjects_active_object_get(PointerRNA *ptr)
83 {
84 ViewLayer *view_layer = (ViewLayer *)ptr->data;
85 return rna_pointer_inherit_refine(
86 ptr, &RNA_Object, view_layer->basact ? view_layer->basact->object : NULL);
87 }
88
rna_LayerObjects_active_object_set(PointerRNA * ptr,PointerRNA value,struct ReportList * reports)89 static void rna_LayerObjects_active_object_set(PointerRNA *ptr,
90 PointerRNA value,
91 struct ReportList *reports)
92 {
93 ViewLayer *view_layer = (ViewLayer *)ptr->data;
94 if (value.data) {
95 Object *ob = value.data;
96 Base *basact_test = BKE_view_layer_base_find(view_layer, ob);
97 if (basact_test != NULL) {
98 view_layer->basact = basact_test;
99 }
100 else {
101 BKE_reportf(reports,
102 RPT_ERROR,
103 "ViewLayer '%s' does not contain object '%s'",
104 view_layer->name,
105 ob->id.name + 2);
106 }
107 }
108 else {
109 view_layer->basact = NULL;
110 }
111 }
112
rna_ViewLayer_path(PointerRNA * ptr)113 static char *rna_ViewLayer_path(PointerRNA *ptr)
114 {
115 ViewLayer *srl = (ViewLayer *)ptr->data;
116 char name_esc[sizeof(srl->name) * 2];
117
118 BLI_strescape(name_esc, srl->name, sizeof(name_esc));
119 return BLI_sprintfN("view_layers[\"%s\"]", name_esc);
120 }
121
rna_ViewLayer_idprops(PointerRNA * ptr,bool create)122 static IDProperty *rna_ViewLayer_idprops(PointerRNA *ptr, bool create)
123 {
124 ViewLayer *view_layer = (ViewLayer *)ptr->data;
125
126 if (create && !view_layer->id_properties) {
127 IDPropertyTemplate val = {0};
128 view_layer->id_properties = IDP_New(IDP_GROUP, &val, "ViewLayer ID properties");
129 }
130
131 return view_layer->id_properties;
132 }
133
rna_LayerCollection_visible_get(LayerCollection * layer_collection,bContext * C)134 static bool rna_LayerCollection_visible_get(LayerCollection *layer_collection, bContext *C)
135 {
136 View3D *v3d = CTX_wm_view3d(C);
137
138 if ((v3d == NULL) || ((v3d->flag & V3D_LOCAL_COLLECTIONS) == 0)) {
139 return (layer_collection->runtime_flag & LAYER_COLLECTION_VISIBLE_VIEW_LAYER) != 0;
140 }
141
142 if (v3d->local_collections_uuid & layer_collection->local_collections_bits) {
143 return (layer_collection->runtime_flag & LAYER_COLLECTION_RESTRICT_VIEWPORT) == 0;
144 }
145
146 return false;
147 }
148
rna_ViewLayer_update_render_passes(ID * id)149 static void rna_ViewLayer_update_render_passes(ID *id)
150 {
151 Scene *scene = (Scene *)id;
152 if (scene->nodetree) {
153 ntreeCompositUpdateRLayers(scene->nodetree);
154 }
155 }
156
rna_ViewLayer_objects_get(CollectionPropertyIterator * iter)157 static PointerRNA rna_ViewLayer_objects_get(CollectionPropertyIterator *iter)
158 {
159 ListBaseIterator *internal = &iter->internal.listbase;
160
161 /* we are actually iterating a ObjectBase list */
162 Base *base = (Base *)internal->link;
163 return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, base->object);
164 }
165
rna_ViewLayer_objects_selected_skip(CollectionPropertyIterator * iter,void * UNUSED (data))166 static int rna_ViewLayer_objects_selected_skip(CollectionPropertyIterator *iter,
167 void *UNUSED(data))
168 {
169 ListBaseIterator *internal = &iter->internal.listbase;
170 Base *base = (Base *)internal->link;
171
172 if ((base->flag & BASE_SELECTED) != 0) {
173 return 0;
174 }
175
176 return 1;
177 };
178
rna_ViewLayer_depsgraph_get(PointerRNA * ptr)179 static PointerRNA rna_ViewLayer_depsgraph_get(PointerRNA *ptr)
180 {
181 ID *id = ptr->owner_id;
182 if (GS(id->name) == ID_SCE) {
183 Scene *scene = (Scene *)id;
184 ViewLayer *view_layer = (ViewLayer *)ptr->data;
185 Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer);
186 return rna_pointer_inherit_refine(ptr, &RNA_Depsgraph, depsgraph);
187 }
188 return PointerRNA_NULL;
189 }
190
rna_LayerObjects_selected_begin(CollectionPropertyIterator * iter,PointerRNA * ptr)191 static void rna_LayerObjects_selected_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
192 {
193 ViewLayer *view_layer = (ViewLayer *)ptr->data;
194 rna_iterator_listbase_begin(
195 iter, &view_layer->object_bases, rna_ViewLayer_objects_selected_skip);
196 }
197
rna_ViewLayer_update_tagged(ID * id_ptr,ViewLayer * view_layer,Main * bmain,ReportList * reports)198 static void rna_ViewLayer_update_tagged(ID *id_ptr,
199 ViewLayer *view_layer,
200 Main *bmain,
201 ReportList *reports)
202 {
203 Scene *scene = (Scene *)id_ptr;
204 Depsgraph *depsgraph = BKE_scene_ensure_depsgraph(bmain, scene, view_layer);
205
206 if (DEG_is_evaluating(depsgraph)) {
207 BKE_report(reports, RPT_ERROR, "Dependency graph update requested during evaluation");
208 return;
209 }
210
211 # ifdef WITH_PYTHON
212 /* Allow drivers to be evaluated */
213 BPy_BEGIN_ALLOW_THREADS;
214 # endif
215
216 /* NOTE: This is similar to CTX_data_depsgraph_pointer(). Ideally such access would be
217 * de-duplicated across all possible cases, but for now this is safest and easiest way to go.
218 *
219 * The reason for this is that it's possible to have Python operator which asks view layer to
220 * be updated. After re-do of such operator view layer's dependency graph will not be marked
221 * as active. */
222 DEG_make_active(depsgraph);
223 BKE_scene_graph_update_tagged(depsgraph, bmain);
224
225 # ifdef WITH_PYTHON
226 BPy_END_ALLOW_THREADS;
227 # endif
228 }
229
rna_ObjectBase_select_update(Main * UNUSED (bmain),Scene * UNUSED (scene),PointerRNA * ptr)230 static void rna_ObjectBase_select_update(Main *UNUSED(bmain),
231 Scene *UNUSED(scene),
232 PointerRNA *ptr)
233 {
234 Base *base = (Base *)ptr->data;
235 short mode = (base->flag & BASE_SELECTED) ? BA_SELECT : BA_DESELECT;
236 ED_object_base_select(base, mode);
237 }
238
rna_ObjectBase_hide_viewport_update(bContext * C,PointerRNA * UNUSED (ptr))239 static void rna_ObjectBase_hide_viewport_update(bContext *C, PointerRNA *UNUSED(ptr))
240 {
241 Scene *scene = CTX_data_scene(C);
242 ViewLayer *view_layer = CTX_data_view_layer(C);
243 BKE_layer_collection_sync(scene, view_layer);
244 DEG_id_tag_update(&scene->id, ID_RECALC_BASE_FLAGS);
245 WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
246 }
247
rna_LayerCollection_name_get(struct PointerRNA * ptr,char * value)248 static void rna_LayerCollection_name_get(struct PointerRNA *ptr, char *value)
249 {
250 ID *id = (ID *)((LayerCollection *)ptr->data)->collection;
251 BLI_strncpy(value, id->name + 2, sizeof(id->name) - 2);
252 }
253
rna_LayerCollection_name_length(PointerRNA * ptr)254 int rna_LayerCollection_name_length(PointerRNA *ptr)
255 {
256 ID *id = (ID *)((LayerCollection *)ptr->data)->collection;
257 return strlen(id->name + 2);
258 }
259
rna_LayerCollection_flag_set(PointerRNA * ptr,const bool value,const int flag)260 static void rna_LayerCollection_flag_set(PointerRNA *ptr, const bool value, const int flag)
261 {
262 LayerCollection *layer_collection = (LayerCollection *)ptr->data;
263 Collection *collection = layer_collection->collection;
264
265 if (collection->flag & COLLECTION_IS_MASTER) {
266 return;
267 }
268
269 if (value) {
270 layer_collection->flag |= flag;
271 }
272 else {
273 layer_collection->flag &= ~flag;
274 }
275 }
276
rna_LayerCollection_exclude_set(PointerRNA * ptr,bool value)277 static void rna_LayerCollection_exclude_set(PointerRNA *ptr, bool value)
278 {
279 rna_LayerCollection_flag_set(ptr, value, LAYER_COLLECTION_EXCLUDE);
280 }
281
rna_LayerCollection_holdout_set(PointerRNA * ptr,bool value)282 static void rna_LayerCollection_holdout_set(PointerRNA *ptr, bool value)
283 {
284 rna_LayerCollection_flag_set(ptr, value, LAYER_COLLECTION_HOLDOUT);
285 }
286
rna_LayerCollection_indirect_only_set(PointerRNA * ptr,bool value)287 static void rna_LayerCollection_indirect_only_set(PointerRNA *ptr, bool value)
288 {
289 rna_LayerCollection_flag_set(ptr, value, LAYER_COLLECTION_INDIRECT_ONLY);
290 }
291
rna_LayerCollection_hide_viewport_set(PointerRNA * ptr,bool value)292 static void rna_LayerCollection_hide_viewport_set(PointerRNA *ptr, bool value)
293 {
294 rna_LayerCollection_flag_set(ptr, value, LAYER_COLLECTION_HIDE);
295 }
296
rna_LayerCollection_exclude_update(Main * bmain,Scene * UNUSED (scene),PointerRNA * ptr)297 static void rna_LayerCollection_exclude_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
298 {
299 Scene *scene = (Scene *)ptr->owner_id;
300 LayerCollection *lc = (LayerCollection *)ptr->data;
301 ViewLayer *view_layer = BKE_view_layer_find_from_collection(scene, lc);
302
303 /* Set/Unset it recursively to match the behavior of excluding via the menu or shortcuts. */
304 const bool exclude = (lc->flag & LAYER_COLLECTION_EXCLUDE) != 0;
305 BKE_layer_collection_set_flag(lc, LAYER_COLLECTION_EXCLUDE, exclude);
306
307 BKE_layer_collection_sync(scene, view_layer);
308
309 DEG_id_tag_update(&scene->id, ID_RECALC_BASE_FLAGS);
310 DEG_relations_tag_update(bmain);
311 WM_main_add_notifier(NC_SCENE | ND_LAYER_CONTENT, NULL);
312 if (exclude) {
313 ED_object_base_active_refresh(bmain, scene, view_layer);
314 }
315 }
316
rna_LayerCollection_update(Main * UNUSED (bmain),Scene * UNUSED (scene),PointerRNA * ptr)317 static void rna_LayerCollection_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
318 {
319 Scene *scene = (Scene *)ptr->owner_id;
320 LayerCollection *lc = (LayerCollection *)ptr->data;
321 ViewLayer *view_layer = BKE_view_layer_find_from_collection(scene, lc);
322
323 BKE_layer_collection_sync(scene, view_layer);
324
325 DEG_id_tag_update(&scene->id, ID_RECALC_BASE_FLAGS);
326
327 WM_main_add_notifier(NC_SCENE | ND_LAYER_CONTENT, NULL);
328 }
329
rna_LayerCollection_has_objects(LayerCollection * lc)330 static bool rna_LayerCollection_has_objects(LayerCollection *lc)
331 {
332 return (lc->runtime_flag & LAYER_COLLECTION_HAS_OBJECTS) != 0;
333 }
334
rna_LayerCollection_has_selected_objects(LayerCollection * lc,ViewLayer * view_layer)335 static bool rna_LayerCollection_has_selected_objects(LayerCollection *lc, ViewLayer *view_layer)
336 {
337 return BKE_layer_collection_has_selected_objects(view_layer, lc);
338 }
339
340 #else
341
rna_def_layer_collection(BlenderRNA * brna)342 static void rna_def_layer_collection(BlenderRNA *brna)
343 {
344 StructRNA *srna;
345 FunctionRNA *func;
346 PropertyRNA *prop;
347
348 srna = RNA_def_struct(brna, "LayerCollection", NULL);
349 RNA_def_struct_ui_text(srna, "Layer Collection", "Layer collection");
350 RNA_def_struct_ui_icon(srna, ICON_OUTLINER_COLLECTION);
351
352 prop = RNA_def_property(srna, "collection", PROP_POINTER, PROP_NONE);
353 RNA_def_property_flag(prop, PROP_NEVER_NULL);
354 RNA_def_property_clear_flag(prop, PROP_EDITABLE | PROP_ANIMATABLE);
355 RNA_def_property_struct_type(prop, "Collection");
356 RNA_def_property_ui_text(prop, "Collection", "Collection this layer collection is wrapping");
357
358 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
359 RNA_def_property_string_sdna(prop, NULL, "collection->id.name");
360 RNA_def_property_clear_flag(prop, PROP_EDITABLE | PROP_ANIMATABLE);
361 RNA_def_property_ui_text(prop, "Name", "Name of this view layer (same as its collection one)");
362 RNA_def_property_string_funcs(
363 prop, "rna_LayerCollection_name_get", "rna_LayerCollection_name_length", NULL);
364 RNA_def_struct_name_property(srna, prop);
365
366 prop = RNA_def_property(srna, "children", PROP_COLLECTION, PROP_NONE);
367 RNA_def_property_collection_sdna(prop, NULL, "layer_collections", NULL);
368 RNA_def_property_struct_type(prop, "LayerCollection");
369 RNA_def_property_ui_text(prop, "Children", "Child layer collections");
370
371 /* Restriction flags. */
372 prop = RNA_def_property(srna, "exclude", PROP_BOOLEAN, PROP_NONE);
373 RNA_def_property_boolean_sdna(prop, NULL, "flag", LAYER_COLLECTION_EXCLUDE);
374 RNA_def_property_boolean_funcs(prop, NULL, "rna_LayerCollection_exclude_set");
375 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
376 RNA_def_property_ui_text(prop, "Exclude from View Layer", "Exclude from view layer");
377 RNA_def_property_ui_icon(prop, ICON_CHECKBOX_HLT, -1);
378 RNA_def_property_update(prop, NC_SCENE | ND_LAYER, "rna_LayerCollection_exclude_update");
379
380 prop = RNA_def_property(srna, "holdout", PROP_BOOLEAN, PROP_NONE);
381 RNA_def_property_boolean_sdna(prop, NULL, "flag", LAYER_COLLECTION_HOLDOUT);
382 RNA_def_property_boolean_funcs(prop, NULL, "rna_LayerCollection_holdout_set");
383 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
384 RNA_def_property_ui_icon(prop, ICON_HOLDOUT_OFF, 1);
385 RNA_def_property_ui_text(prop, "Holdout", "Mask out objects in collection from view layer");
386 RNA_def_property_update(prop, NC_SCENE | ND_LAYER, "rna_LayerCollection_update");
387
388 prop = RNA_def_property(srna, "indirect_only", PROP_BOOLEAN, PROP_NONE);
389 RNA_def_property_boolean_sdna(prop, NULL, "flag", LAYER_COLLECTION_INDIRECT_ONLY);
390 RNA_def_property_boolean_funcs(prop, NULL, "rna_LayerCollection_indirect_only_set");
391 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
392 RNA_def_property_ui_icon(prop, ICON_INDIRECT_ONLY_OFF, 1);
393 RNA_def_property_ui_text(
394 prop,
395 "Indirect Only",
396 "Objects in collection only contribute indirectly (through shadows and reflections) "
397 "in the view layer");
398 RNA_def_property_update(prop, NC_SCENE | ND_LAYER, "rna_LayerCollection_update");
399
400 prop = RNA_def_property(srna, "hide_viewport", PROP_BOOLEAN, PROP_NONE);
401 RNA_def_property_boolean_sdna(prop, NULL, "flag", LAYER_COLLECTION_HIDE);
402 RNA_def_property_boolean_funcs(prop, NULL, "rna_LayerCollection_hide_viewport_set");
403 RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
404 RNA_def_property_ui_icon(prop, ICON_HIDE_OFF, -1);
405 RNA_def_property_ui_text(prop, "Hide in Viewport", "Temporarily hide in viewport");
406 RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_LayerCollection_update");
407
408 func = RNA_def_function(srna, "visible_get", "rna_LayerCollection_visible_get");
409 RNA_def_function_ui_description(func,
410 "Whether this collection is visible, take into account the "
411 "collection parent and the viewport");
412 RNA_def_function_flag(func, FUNC_USE_CONTEXT);
413 RNA_def_function_return(func, RNA_def_boolean(func, "result", 0, "", ""));
414
415 /* Run-time flags. */
416 prop = RNA_def_property(srna, "is_visible", PROP_BOOLEAN, PROP_NONE);
417 RNA_def_property_boolean_sdna(prop, NULL, "runtime_flag", LAYER_COLLECTION_VISIBLE_VIEW_LAYER);
418 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
419 RNA_def_property_ui_text(prop,
420 "Visible",
421 "Whether this collection is visible for the view layer, take into "
422 "account the collection parent");
423
424 func = RNA_def_function(srna, "has_objects", "rna_LayerCollection_has_objects");
425 RNA_def_function_ui_description(func, "");
426 RNA_def_function_return(func, RNA_def_boolean(func, "result", 0, "", ""));
427
428 func = RNA_def_function(
429 srna, "has_selected_objects", "rna_LayerCollection_has_selected_objects");
430 RNA_def_function_ui_description(func, "");
431 prop = RNA_def_pointer(
432 func, "view_layer", "ViewLayer", "", "View layer the layer collection belongs to");
433 RNA_def_parameter_flags(prop, 0, PARM_REQUIRED);
434 RNA_def_function_return(func, RNA_def_boolean(func, "result", 0, "", ""));
435 }
436
rna_def_layer_objects(BlenderRNA * brna,PropertyRNA * cprop)437 static void rna_def_layer_objects(BlenderRNA *brna, PropertyRNA *cprop)
438 {
439 StructRNA *srna;
440 PropertyRNA *prop;
441
442 RNA_def_property_srna(cprop, "LayerObjects");
443 srna = RNA_def_struct(brna, "LayerObjects", NULL);
444 RNA_def_struct_sdna(srna, "ViewLayer");
445 RNA_def_struct_ui_text(srna, "Layer Objects", "Collections of objects");
446
447 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
448 RNA_def_property_struct_type(prop, "Object");
449 RNA_def_property_pointer_funcs(prop,
450 "rna_LayerObjects_active_object_get",
451 "rna_LayerObjects_active_object_set",
452 NULL,
453 NULL);
454 RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
455 RNA_def_property_ui_text(prop, "Active Object", "Active object for this layer");
456 /* Could call: `ED_object_base_activate(C, view_layer->basact);`
457 * but would be a bad level call and it seems the notifier is enough */
458 RNA_def_property_update(prop, NC_SCENE | ND_OB_ACTIVE, NULL);
459
460 prop = RNA_def_property(srna, "selected", PROP_COLLECTION, PROP_NONE);
461 RNA_def_property_collection_sdna(prop, NULL, "object_bases", NULL);
462 RNA_def_property_struct_type(prop, "Object");
463 RNA_def_property_collection_funcs(prop,
464 "rna_LayerObjects_selected_begin",
465 "rna_iterator_listbase_next",
466 "rna_iterator_listbase_end",
467 "rna_ViewLayer_objects_get",
468 NULL,
469 NULL,
470 NULL,
471 NULL);
472 RNA_def_property_ui_text(prop, "Selected Objects", "All the selected objects of this layer");
473 }
474
rna_def_object_base(BlenderRNA * brna)475 static void rna_def_object_base(BlenderRNA *brna)
476 {
477 StructRNA *srna;
478 PropertyRNA *prop;
479
480 srna = RNA_def_struct(brna, "ObjectBase", NULL);
481 RNA_def_struct_sdna(srna, "Base");
482 RNA_def_struct_ui_text(srna, "Object Base", "An object instance in a render layer");
483 RNA_def_struct_ui_icon(srna, ICON_OBJECT_DATA);
484
485 prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
486 RNA_def_property_pointer_sdna(prop, NULL, "object");
487 RNA_def_property_ui_text(prop, "Object", "Object this base links to");
488
489 prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
490 RNA_def_property_boolean_sdna(prop, NULL, "flag", BASE_SELECTED);
491 RNA_def_property_ui_text(prop, "Select", "Object base selection state");
492 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_ObjectBase_select_update");
493
494 prop = RNA_def_property(srna, "hide_viewport", PROP_BOOLEAN, PROP_NONE);
495 RNA_def_property_boolean_sdna(prop, NULL, "flag", BASE_HIDDEN);
496 RNA_def_property_flag(prop, PROP_LIB_EXCEPTION);
497 RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY);
498 RNA_def_property_ui_icon(prop, ICON_HIDE_OFF, -1);
499 RNA_def_property_ui_text(prop, "Hide in Viewport", "Temporarily hide in viewport");
500 RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
501 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_ObjectBase_hide_viewport_update");
502 }
503
RNA_def_view_layer(BlenderRNA * brna)504 void RNA_def_view_layer(BlenderRNA *brna)
505 {
506 FunctionRNA *func;
507 StructRNA *srna;
508 PropertyRNA *prop;
509
510 srna = RNA_def_struct(brna, "ViewLayer", NULL);
511 RNA_def_struct_ui_text(srna, "View Layer", "View layer");
512 RNA_def_struct_ui_icon(srna, ICON_RENDER_RESULT);
513 RNA_def_struct_path_func(srna, "rna_ViewLayer_path");
514 RNA_def_struct_idprops_func(srna, "rna_ViewLayer_idprops");
515
516 rna_def_view_layer_common(srna, true);
517
518 func = RNA_def_function(srna, "update_render_passes", "rna_ViewLayer_update_render_passes");
519 RNA_def_function_ui_description(func,
520 "Requery the enabled render passes from the render engine");
521 RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_NO_SELF);
522
523 prop = RNA_def_property(srna, "layer_collection", PROP_POINTER, PROP_NONE);
524 RNA_def_property_struct_type(prop, "LayerCollection");
525 RNA_def_property_pointer_sdna(prop, NULL, "layer_collections.first");
526 RNA_def_property_flag(prop, PROP_NEVER_NULL);
527 RNA_def_property_ui_text(
528 prop,
529 "Layer Collection",
530 "Root of collections hierarchy of this view layer,"
531 "its 'collection' pointer property is the same as the scene's master collection");
532
533 prop = RNA_def_property(srna, "active_layer_collection", PROP_POINTER, PROP_NONE);
534 RNA_def_property_struct_type(prop, "LayerCollection");
535 RNA_def_property_pointer_funcs(prop,
536 "rna_ViewLayer_active_layer_collection_get",
537 "rna_ViewLayer_active_layer_collection_set",
538 NULL,
539 NULL);
540 RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
541 RNA_def_property_ui_text(
542 prop, "Active Layer Collection", "Active layer collection in this view layer's hierarchy");
543 RNA_def_property_update(prop, NC_SCENE | ND_LAYER, NULL);
544
545 prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
546 RNA_def_property_collection_sdna(prop, NULL, "object_bases", NULL);
547 RNA_def_property_struct_type(prop, "Object");
548 RNA_def_property_collection_funcs(
549 prop, NULL, NULL, NULL, "rna_ViewLayer_objects_get", NULL, NULL, NULL, NULL);
550 RNA_def_property_ui_text(prop, "Objects", "All the objects in this layer");
551 rna_def_layer_objects(brna, prop);
552
553 /* layer options */
554 prop = RNA_def_property(srna, "use", PROP_BOOLEAN, PROP_NONE);
555 RNA_def_property_boolean_sdna(prop, NULL, "flag", VIEW_LAYER_RENDER);
556 RNA_def_property_ui_text(prop, "Enabled", "Enable or disable rendering of this View Layer");
557 RNA_def_property_update(prop, NC_SCENE | ND_LAYER, NULL);
558
559 prop = RNA_def_property(srna, "use_freestyle", PROP_BOOLEAN, PROP_NONE);
560 RNA_def_property_boolean_sdna(prop, NULL, "flag", VIEW_LAYER_FREESTYLE);
561 RNA_def_property_ui_text(prop, "Freestyle", "Render stylized strokes in this Layer");
562 RNA_def_property_update(prop, NC_SCENE | ND_LAYER, NULL);
563
564 /* Freestyle */
565 rna_def_freestyle_settings(brna);
566
567 prop = RNA_def_property(srna, "freestyle_settings", PROP_POINTER, PROP_NONE);
568 RNA_def_property_flag(prop, PROP_NEVER_NULL);
569 RNA_def_property_pointer_sdna(prop, NULL, "freestyle_config");
570 RNA_def_property_struct_type(prop, "FreestyleSettings");
571 RNA_def_property_ui_text(prop, "Freestyle Settings", "");
572
573 /* debug update routine */
574 func = RNA_def_function(srna, "update", "rna_ViewLayer_update_tagged");
575 RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN | FUNC_USE_REPORTS);
576 RNA_def_function_ui_description(
577 func, "Update data tagged to be updated from previous access to data or operators");
578
579 /* Dependency Graph */
580 prop = RNA_def_property(srna, "depsgraph", PROP_POINTER, PROP_NONE);
581 RNA_def_property_struct_type(prop, "Depsgraph");
582 RNA_def_property_override_flag(prop, PROPOVERRIDE_NO_COMPARISON);
583 RNA_def_property_ui_text(prop, "Dependency Graph", "Dependencies in the scene data");
584 RNA_def_property_pointer_funcs(prop, "rna_ViewLayer_depsgraph_get", NULL, NULL, NULL);
585
586 /* Nested Data */
587 /* *** Non-Animated *** */
588 RNA_define_animate_sdna(false);
589 rna_def_layer_collection(brna);
590 rna_def_object_base(brna);
591 RNA_define_animate_sdna(true);
592 /* *** Animated *** */
593 }
594
595 #endif
596