Blender V4.3
rna_collection.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <cstdlib>
10
11#include "BKE_file_handler.hh"
12
14
15#include "DNA_lineart_types.h"
16
17#include "BLI_utildefines.h"
18
19#include "RNA_define.hh"
20#include "RNA_enum_types.hh"
21
22#include "rna_internal.hh"
23
24#include "WM_types.hh"
25
27 {COLLECTION_COLOR_NONE, "NONE", ICON_X, "None", "Assign no color tag to the collection"},
28 {COLLECTION_COLOR_01, "COLOR_01", ICON_COLLECTION_COLOR_01, "Color 01", ""},
29 {COLLECTION_COLOR_02, "COLOR_02", ICON_COLLECTION_COLOR_02, "Color 02", ""},
30 {COLLECTION_COLOR_03, "COLOR_03", ICON_COLLECTION_COLOR_03, "Color 03", ""},
31 {COLLECTION_COLOR_04, "COLOR_04", ICON_COLLECTION_COLOR_04, "Color 04", ""},
32 {COLLECTION_COLOR_05, "COLOR_05", ICON_COLLECTION_COLOR_05, "Color 05", ""},
33 {COLLECTION_COLOR_06, "COLOR_06", ICON_COLLECTION_COLOR_06, "Color 06", ""},
34 {COLLECTION_COLOR_07, "COLOR_07", ICON_COLLECTION_COLOR_07, "Color 07", ""},
35 {COLLECTION_COLOR_08, "COLOR_08", ICON_COLLECTION_COLOR_08, "Color 08", ""},
36 {0, nullptr, 0, nullptr, nullptr},
37};
38/* Minus 1 for NONE & 1 for the nullptr sentinel. */
40 "Collection color total is an invalid size");
41
42#ifdef RNA_RUNTIME
43
44# include <fmt/format.h>
45
46# include "DNA_object_types.h"
47# include "DNA_scene_types.h"
48
49# include "DEG_depsgraph.hh"
50# include "DEG_depsgraph_build.hh"
51# include "DEG_depsgraph_query.hh"
52
53# include "BKE_collection.hh"
54# include "BKE_global.hh"
55# include "BKE_layer.hh"
56
57# include "BLT_translation.hh"
58
59# include "WM_api.hh"
60
61# include "RNA_access.hh"
62
63static void rna_Collection_all_objects_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
64{
65 Collection *collection = (Collection *)ptr->data;
66 ListBase collection_objects = BKE_collection_object_cache_get(collection);
67 rna_iterator_listbase_begin(iter, &collection_objects, nullptr);
68}
69
70static PointerRNA rna_Collection_all_objects_get(CollectionPropertyIterator *iter)
71{
72 ListBaseIterator *internal = &iter->internal.listbase;
73
74 /* we are actually iterating a ObjectBase list, so override get */
75 Base *base = (Base *)internal->link;
76 return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, base->object);
77}
78
79static void rna_Collection_objects_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
80{
81 Collection *collection = (Collection *)ptr->data;
82 rna_iterator_listbase_begin(iter, &collection->gobject, nullptr);
83}
84
85static PointerRNA rna_Collection_objects_get(CollectionPropertyIterator *iter)
86{
87 ListBaseIterator *internal = &iter->internal.listbase;
88
89 /* we are actually iterating a ObjectBase list, so override get */
90 CollectionObject *cob = (CollectionObject *)internal->link;
91 return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, cob->ob);
92}
93
94static bool rna_collection_objects_edit_check(Collection *collection,
95 ReportList *reports,
96 Object *object)
97{
98 if (!DEG_is_original_id(&collection->id)) {
100 reports, RPT_ERROR, "Collection '%s' is not an original ID", collection->id.name + 2);
101 return false;
102 }
103 if (!DEG_is_original_id(&object->id)) {
104 BKE_reportf(reports, RPT_ERROR, "Collection '%s' is not an original ID", object->id.name + 2);
105 return false;
106 }
107 /* Currently this should not be allowed (might be supported in the future though...). */
108 if (ID_IS_OVERRIDE_LIBRARY(&collection->id)) {
109 BKE_reportf(reports,
110 RPT_ERROR,
111 "Could not (un)link the object '%s' because the collection '%s' is overridden",
112 object->id.name + 2,
113 collection->id.name + 2);
114 return false;
115 }
116 if (!ID_IS_EDITABLE(&collection->id)) {
117 BKE_reportf(reports,
118 RPT_ERROR,
119 "Could not (un)link the object '%s' because the collection '%s' is linked",
120 object->id.name + 2,
121 collection->id.name + 2);
122 return false;
123 }
124 return true;
125}
126
127static void rna_Collection_objects_link(Collection *collection,
128 Main *bmain,
129 ReportList *reports,
130 Object *object)
131{
132 if (!rna_collection_objects_edit_check(collection, reports, object)) {
133 return;
134 }
135 if (!BKE_collection_object_add(bmain, collection, object)) {
136 BKE_reportf(reports,
137 RPT_ERROR,
138 "Object '%s' already in collection '%s'",
139 object->id.name + 2,
140 collection->id.name + 2);
141 return;
142 }
143
146 WM_main_add_notifier(NC_OBJECT | ND_DRAW, &object->id);
147}
148
149static void rna_Collection_objects_unlink(Collection *collection,
150 Main *bmain,
151 ReportList *reports,
152 Object *object)
153{
154 if (!rna_collection_objects_edit_check(collection, reports, object)) {
155 return;
156 }
157 if (!BKE_collection_object_remove(bmain, collection, object, false)) {
158 BKE_reportf(reports,
159 RPT_ERROR,
160 "Object '%s' not in collection '%s'",
161 object->id.name + 2,
162 collection->id.name + 2);
163 return;
164 }
165
168 WM_main_add_notifier(NC_OBJECT | ND_DRAW, &object->id);
169}
170
171static bool rna_Collection_objects_override_apply(Main *bmain,
173{
174 PointerRNA *ptr_dst = &rnaapply_ctx.ptr_dst;
175 PropertyRNA *prop_dst = rnaapply_ctx.prop_dst;
176 PointerRNA *ptr_item_dst = &rnaapply_ctx.ptr_item_dst;
177 PointerRNA *ptr_item_src = &rnaapply_ctx.ptr_item_src;
179
181 "Unsupported RNA override operation on collections' objects");
182 UNUSED_VARS_NDEBUG(opop);
183
184 Collection *coll_dst = (Collection *)ptr_dst->owner_id;
185
186 if (ptr_item_dst->type == nullptr || ptr_item_src->type == nullptr) {
187 // BLI_assert_msg(0, "invalid source or destination object.");
188 return false;
189 }
190
191 Object *ob_dst = static_cast<Object *>(ptr_item_dst->data);
192 Object *ob_src = static_cast<Object *>(ptr_item_src->data);
193
194 if (ob_src == ob_dst) {
195 return true;
196 }
197
198 if (!BKE_collection_object_replace(bmain, coll_dst, ob_dst, ob_src)) {
199 BLI_assert_msg(0, "Could not find destination object in destination collection!");
200 return false;
201 }
202
203 RNA_property_update_main(bmain, nullptr, ptr_dst, prop_dst);
204 return true;
205}
206
207static void rna_Collection_children_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
208{
209 Collection *collection = (Collection *)ptr->data;
210 rna_iterator_listbase_begin(iter, &collection->children, nullptr);
211}
212
213static PointerRNA rna_Collection_children_get(CollectionPropertyIterator *iter)
214{
215 ListBaseIterator *internal = &iter->internal.listbase;
216
217 /* we are actually iterating a CollectionChild list, so override get */
218 CollectionChild *child = (CollectionChild *)internal->link;
219 return rna_pointer_inherit_refine(&iter->parent, &RNA_Collection, child->collection);
220}
221
222static bool rna_collection_children_edit_check(Collection *collection,
223 ReportList *reports,
224 Collection *child)
225{
226 if (!DEG_is_original_id(&collection->id)) {
228 reports, RPT_ERROR, "Collection '%s' is not an original ID", collection->id.name + 2);
229 return false;
230 }
231 if (!DEG_is_original_id(&child->id)) {
232 BKE_reportf(reports, RPT_ERROR, "Collection '%s' is not an original ID", child->id.name + 2);
233 return false;
234 }
235 /* Currently this should not be allowed (might be supported in the future though...). */
236 if (ID_IS_OVERRIDE_LIBRARY(&collection->id)) {
237 BKE_reportf(reports,
238 RPT_ERROR,
239 "Could not (un)link the collection '%s' because the collection '%s' is overridden",
240 child->id.name + 2,
241 collection->id.name + 2);
242 return false;
243 }
244 if (!ID_IS_EDITABLE(&collection->id)) {
245 BKE_reportf(reports,
246 RPT_ERROR,
247 "Could not (un)link the collection '%s' because the collection '%s' is linked",
248 child->id.name + 2,
249 collection->id.name + 2);
250 return false;
251 }
252 return true;
253}
254
255static void rna_Collection_children_link(Collection *collection,
256 Main *bmain,
257 ReportList *reports,
258 Collection *child)
259{
260 if (!rna_collection_children_edit_check(collection, reports, child)) {
261 return;
262 }
263 if (!BKE_collection_child_add(bmain, collection, child)) {
264 BKE_reportf(reports,
265 RPT_ERROR,
266 "Collection '%s' already in collection '%s'",
267 child->id.name + 2,
268 collection->id.name + 2);
269 return;
270 }
271
275}
276
277static void rna_Collection_children_unlink(Collection *collection,
278 Main *bmain,
279 ReportList *reports,
280 Collection *child)
281{
282 if (!rna_collection_children_edit_check(collection, reports, child)) {
283 return;
284 }
285 if (!BKE_collection_child_remove(bmain, collection, child)) {
286 BKE_reportf(reports,
287 RPT_ERROR,
288 "Collection '%s' not in collection '%s'",
289 child->id.name + 2,
290 collection->id.name + 2);
291 return;
292 }
293
297}
298
299static bool rna_Collection_children_override_apply(Main *bmain,
301{
302 PointerRNA *ptr_dst = &rnaapply_ctx.ptr_dst;
303 PropertyRNA *prop_dst = rnaapply_ctx.prop_dst;
304 PointerRNA *ptr_item_dst = &rnaapply_ctx.ptr_item_dst;
305 PointerRNA *ptr_item_src = &rnaapply_ctx.ptr_item_src;
307
309 "Unsupported RNA override operation on collections' children");
310 UNUSED_VARS_NDEBUG(opop);
311
312 Collection *coll_dst = (Collection *)ptr_dst->owner_id;
313
314 if (ptr_item_dst->type == nullptr || ptr_item_src->type == nullptr) {
315 /* This can happen when reference and overrides differ, just ignore then. */
316 return false;
317 }
318
319 Collection *subcoll_dst = static_cast<Collection *>(ptr_item_dst->data);
320 Collection *subcoll_src = static_cast<Collection *>(ptr_item_src->data);
321
322 CollectionChild *collchild_dst = static_cast<CollectionChild *>(
323 BLI_findptr(&coll_dst->children, subcoll_dst, offsetof(CollectionChild, collection)));
324
325 if (collchild_dst == nullptr) {
326 BLI_assert_msg(0, "Could not find destination sub-collection in destination collection!");
327 return false;
328 }
329
330 /* XXX TODO: We most certainly rather want to have a 'swap object pointer in collection'
331 * util in BKE_collection. This is only temp quick dirty test! */
332 id_us_min(&collchild_dst->collection->id);
333 collchild_dst->collection = subcoll_src;
334 id_us_plus(&collchild_dst->collection->id);
335
336 BKE_collection_object_cache_free(bmain, coll_dst, 0);
338
339 RNA_property_update_main(bmain, nullptr, ptr_dst, prop_dst);
340 return true;
341}
342
343static void rna_Collection_flag_set(PointerRNA *ptr, const bool value, const int flag)
344{
345 Collection *collection = (Collection *)ptr->data;
346
347 if (collection->flag & COLLECTION_IS_MASTER) {
348 return;
349 }
350
351 if (value) {
352 collection->flag |= flag;
353 }
354 else {
355 collection->flag &= ~flag;
356 }
357}
358
359static void rna_Collection_hide_select_set(PointerRNA *ptr, bool value)
360{
361 rna_Collection_flag_set(ptr, value, COLLECTION_HIDE_SELECT);
362}
363
364static void rna_Collection_hide_viewport_set(PointerRNA *ptr, bool value)
365{
366 rna_Collection_flag_set(ptr, value, COLLECTION_HIDE_VIEWPORT);
367}
368
369static void rna_Collection_hide_render_set(PointerRNA *ptr, bool value)
370{
371 rna_Collection_flag_set(ptr, value, COLLECTION_HIDE_RENDER);
372}
373
374static void rna_Collection_flag_update(Main *bmain, Scene *scene, PointerRNA *ptr)
375{
376 Collection *collection = (Collection *)ptr->data;
377 BKE_collection_object_cache_free(bmain, collection, 0);
379
383}
384
385static int rna_Collection_color_tag_get(PointerRNA *ptr)
386{
387 Collection *collection = (Collection *)ptr->data;
388
389 return collection->color_tag;
390}
391
392static void rna_Collection_color_tag_set(PointerRNA *ptr, int value)
393{
394 Collection *collection = (Collection *)ptr->data;
395
396 if (collection->flag & COLLECTION_IS_MASTER) {
397 return;
398 }
399
400 collection->color_tag = value;
401}
402
403static void rna_Collection_color_tag_update(Main * /*bmain*/, Scene *scene, PointerRNA * /*ptr*/)
404{
406}
407
408static void rna_Collection_instance_offset_update(Main * /*bmain*/,
409 Scene * /*scene*/,
411{
412 Collection *collection = (Collection *)ptr->data;
413 DEG_id_tag_update(&collection->id, ID_RECALC_GEOMETRY);
414}
415
416static std::optional<std::string> rna_CollectionLightLinking_path(const PointerRNA *ptr)
417{
418 Collection *collection = (Collection *)ptr->owner_id;
419 CollectionLightLinking *collection_light_linking = (CollectionLightLinking *)ptr->data;
420
421 int counter;
422
423 counter = 0;
424 LISTBASE_FOREACH (CollectionObject *, collection_object, &collection->gobject) {
425 if (&collection_object->light_linking == collection_light_linking) {
426 return fmt::format("collection_objects[{}].light_linking", counter);
427 }
428 ++counter;
429 }
430
431 counter = 0;
432 LISTBASE_FOREACH (CollectionChild *, collection_child, &collection->children) {
433 if (&collection_child->light_linking == collection_light_linking) {
434 return fmt::format("collection_children[{}].light_linking", counter);
435 }
436 ++counter;
437 }
438
439 return "..";
440}
441
442static void rna_CollectionLightLinking_update(Main *bmain, Scene * /*scene*/, PointerRNA *ptr)
443{
444 /* The light linking collection comes from the collection. It does not have shading component,
445 * but is collected to objects via hierarchy component. Tagging its hierarchy for update will
446 * lead the objects which use the collection to update its shading. */
448
449 /* Tag relations for update so that an updated state of light sets is calculated. */
451}
452
453static void rna_CollectionExport_name_set(PointerRNA *ptr, const char *value)
454{
455 CollectionExport *data = reinterpret_cast<CollectionExport *>(ptr->data);
456 BKE_collection_exporter_name_set(nullptr, data, value);
457}
458
459static PointerRNA rna_CollectionExport_export_properties_get(PointerRNA *ptr)
460{
461 const CollectionExport *data = reinterpret_cast<CollectionExport *>(ptr->data);
462
463 /* If the File Handler or Operator is missing, we allow the data to be accessible
464 * as generic ID properties. */
466 if (!fh) {
467 return RNA_pointer_create(ptr->owner_id, &RNA_IDPropertyWrapPtr, data->export_properties);
468 }
469
471 if (!ot) {
472 return RNA_pointer_create(ptr->owner_id, &RNA_IDPropertyWrapPtr, data->export_properties);
473 }
474
475 return RNA_pointer_create(ptr->owner_id, ot->srna, data->export_properties);
476}
477
478#else
479
480/* collection.objects */
482{
483 StructRNA *srna;
484 FunctionRNA *func;
485 PropertyRNA *parm;
486
487 RNA_def_property_srna(cprop, "CollectionObjects");
488 srna = RNA_def_struct(brna, "CollectionObjects", nullptr);
489 RNA_def_struct_sdna(srna, "Collection");
490 RNA_def_struct_ui_text(srna, "Collection Objects", "Collection of collection objects");
491
492 /* add object */
493 func = RNA_def_function(srna, "link", "rna_Collection_objects_link");
495 RNA_def_function_ui_description(func, "Add this object to a collection");
496 parm = RNA_def_pointer(func, "object", "Object", "", "Object to add");
498
499 /* remove object */
500 func = RNA_def_function(srna, "unlink", "rna_Collection_objects_unlink");
501 RNA_def_function_ui_description(func, "Remove this object from a collection");
503 parm = RNA_def_pointer(func, "object", "Object", "", "Object to remove");
505}
506
507/* collection.children */
509{
510 StructRNA *srna;
511 FunctionRNA *func;
512 PropertyRNA *parm;
513
514 RNA_def_property_srna(cprop, "CollectionChildren");
515 srna = RNA_def_struct(brna, "CollectionChildren", nullptr);
516 RNA_def_struct_sdna(srna, "Collection");
517 RNA_def_struct_ui_text(srna, "Collection Children", "Collection of child collections");
518
519 /* add child */
520 func = RNA_def_function(srna, "link", "rna_Collection_children_link");
522 RNA_def_function_ui_description(func, "Add this collection as child of this collection");
523 parm = RNA_def_pointer(func, "child", "Collection", "", "Collection to add");
525
526 /* remove child */
527 func = RNA_def_function(srna, "unlink", "rna_Collection_children_unlink");
528 RNA_def_function_ui_description(func, "Remove this child collection from a collection");
530 parm = RNA_def_pointer(func, "child", "Collection", "", "Collection to remove");
532}
533
535{
536 StructRNA *srna;
537 PropertyRNA *prop;
538
539 /* TODO(sergey): Use proper icons. */
540 static const EnumPropertyItem light_linking_state_items[] = {
541 {COLLECTION_LIGHT_LINKING_STATE_INCLUDE, "INCLUDE", ICON_OUTLINER_OB_LIGHT, "Include", ""},
542 {COLLECTION_LIGHT_LINKING_STATE_EXCLUDE, "EXCLUDE", ICON_LIGHT, "Exclude", ""},
543 {0, nullptr, 0, nullptr, nullptr},
544 };
545
546 srna = RNA_def_struct(brna, "CollectionLightLinking", nullptr);
547 RNA_def_struct_sdna(srna, "CollectionLightLinking");
549 srna,
550 "Collection Light Linking",
551 "Light linking settings of objects and children collections of a collection");
552 RNA_def_struct_path_func(srna, "rna_CollectionLightLinking_path");
553
554 /* Light state. */
555 prop = RNA_def_property(srna, "link_state", PROP_ENUM, PROP_NONE);
556 RNA_def_property_enum_items(prop, light_linking_state_items);
558 prop, "Link State", "Light or shadow receiving state of the object or collection");
560 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_CollectionLightLinking_update");
561}
562
564{
565 StructRNA *srna;
566 PropertyRNA *prop;
567
568 srna = RNA_def_struct(brna, "CollectionObject", nullptr);
569 RNA_def_struct_sdna(srna, "CollectionObject");
571 srna, "Collection Object", "Object of a collection with its collection related settings");
572
573 /* Light Linking. */
574 prop = RNA_def_property(srna, "light_linking", PROP_POINTER, PROP_NONE);
576 RNA_def_property_struct_type(prop, "CollectionLightLinking");
577 RNA_def_property_ui_text(prop, "Light Linking", "Light linking settings of the collection");
578}
579
581{
582 StructRNA *srna;
583 PropertyRNA *prop;
584
585 srna = RNA_def_struct(brna, "CollectionChild", nullptr);
586 RNA_def_struct_sdna(srna, "CollectionChild");
588 srna, "Collection Child", "Child collection with its collection related settings");
589
590 /* Light Linking. */
591 prop = RNA_def_property(srna, "light_linking", PROP_POINTER, PROP_NONE);
593 RNA_def_property_struct_type(prop, "CollectionLightLinking");
595 prop, "Light Linking", "Light linking settings of the collection object");
596}
597
599{
600 StructRNA *srna;
601 PropertyRNA *prop;
602
603 srna = RNA_def_struct(brna, "CollectionExport", nullptr);
604 RNA_def_struct_sdna(srna, "CollectionExport");
605 RNA_def_struct_ui_text(srna, "Collection Export Data", "Exporter configured for the collection");
606
607 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
608 RNA_def_struct_ui_text(srna, "Name", "");
610 RNA_def_property_string_funcs(prop, nullptr, nullptr, "rna_CollectionExport_name_set");
611
612 prop = RNA_def_property(srna, "is_open", PROP_BOOLEAN, PROP_NONE);
614 RNA_def_property_ui_text(prop, "Is Open", "Whether the panel is expanded or closed");
617
618 prop = RNA_def_property(srna, "export_properties", PROP_POINTER, PROP_NONE);
619 RNA_def_property_struct_type(prop, "PropertyGroup");
621 prop, "Export Properties", "Properties associated with the configured exporter");
623 prop, "rna_CollectionExport_export_properties_get", nullptr, nullptr, nullptr);
624}
625
627{
628 StructRNA *srna;
629 PropertyRNA *prop;
630
631 srna = RNA_def_struct(brna, "Collection", "ID");
632 RNA_def_struct_ui_text(srna, "Collection", "Collection of Object data-blocks");
633 RNA_def_struct_ui_icon(srna, ICON_OUTLINER_COLLECTION);
634 /* This is done on save/load in `readfile.cc`,
635 * removed if no objects are in the collection and not in a scene. */
637
639
640 prop = RNA_def_property(srna, "instance_offset", PROP_FLOAT, PROP_TRANSLATION);
642 prop, "Instance Offset", "Offset from the origin to use when instancing");
643 RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, RNA_TRANSLATION_PREC_DEFAULT);
644 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Collection_instance_offset_update");
645
646 prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
647 RNA_def_property_struct_type(prop, "Object");
648 RNA_def_property_override_funcs(prop, nullptr, nullptr, "rna_Collection_objects_override_apply");
649 RNA_def_property_ui_text(prop, "Objects", "Objects that are directly in this collection");
651 "rna_Collection_objects_begin",
652 "rna_iterator_listbase_next",
653 "rna_iterator_listbase_end",
654 "rna_Collection_objects_get",
655 nullptr,
656 nullptr,
657 nullptr,
658 nullptr);
659 rna_def_collection_objects(brna, prop);
660
661 prop = RNA_def_property(srna, "all_objects", PROP_COLLECTION, PROP_NONE);
662 RNA_def_property_struct_type(prop, "Object");
664 prop, "All Objects", "Objects that are in this collection and its child collections");
668 "rna_Collection_all_objects_begin",
669 "rna_iterator_listbase_next",
670 "rna_iterator_listbase_end",
671 "rna_Collection_all_objects_get",
672 nullptr,
673 nullptr,
674 nullptr,
675 nullptr);
676
677 prop = RNA_def_property(srna, "children", PROP_COLLECTION, PROP_NONE);
678 RNA_def_property_struct_type(prop, "Collection");
680 prop, nullptr, nullptr, "rna_Collection_children_override_apply");
682 prop, "Children", "Collections that are immediate children of this collection");
684 "rna_Collection_children_begin",
685 "rna_iterator_listbase_next",
686 "rna_iterator_listbase_end",
687 "rna_Collection_children_get",
688 nullptr,
689 nullptr,
690 nullptr,
691 nullptr);
692 rna_def_collection_children(brna, prop);
693
694 /* Collection objects. */
695 prop = RNA_def_property(srna, "collection_objects", PROP_COLLECTION, PROP_NONE);
696 RNA_def_property_struct_type(prop, "CollectionObject");
697 RNA_def_property_collection_sdna(prop, nullptr, "gobject", nullptr);
699 prop,
700 "Collection Objects",
701 "Objects of the collection with their parent-collection-specific settings");
702 /* TODO(sergey): Functions to link and unlink objects. */
703
704 /* Children collections. */
705 prop = RNA_def_property(srna, "collection_children", PROP_COLLECTION, PROP_NONE);
706 RNA_def_property_struct_type(prop, "CollectionChild");
707 RNA_def_property_collection_sdna(prop, nullptr, "children", nullptr);
709 "Collection Children",
710 "Children collections with their parent-collection-specific settings");
711
712 /* Export Handlers. */
713 prop = RNA_def_property(srna, "exporters", PROP_COLLECTION, PROP_NONE);
714 RNA_def_property_struct_type(prop, "CollectionExport");
715 RNA_def_property_collection_sdna(prop, nullptr, "exporters", nullptr);
717 prop, "Collection Export Handlers", "Export Handlers configured for the collection");
718
719 prop = RNA_def_property(srna, "active_exporter_index", PROP_INT, PROP_UNSIGNED);
722 prop, "Active Collection Exporter Index", "Active index in the exporters list");
723
724 /* TODO(sergey): Functions to link and unlink collections. */
725
726 /* Flags */
727 prop = RNA_def_property(srna, "hide_select", PROP_BOOLEAN, PROP_NONE);
729 RNA_def_property_boolean_funcs(prop, nullptr, "rna_Collection_hide_select_set");
731 RNA_def_property_ui_icon(prop, ICON_RESTRICT_SELECT_OFF, -1);
732 RNA_def_property_ui_text(prop, "Disable Selection", "Disable selection in viewport");
733 RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_Collection_flag_update");
734
735 prop = RNA_def_property(srna, "hide_viewport", PROP_BOOLEAN, PROP_NONE);
737 RNA_def_property_boolean_funcs(prop, nullptr, "rna_Collection_hide_viewport_set");
739 RNA_def_property_ui_icon(prop, ICON_RESTRICT_VIEW_OFF, -1);
740 RNA_def_property_ui_text(prop, "Disable in Viewports", "Globally disable in viewports");
741 RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_Collection_flag_update");
742
743 prop = RNA_def_property(srna, "hide_render", PROP_BOOLEAN, PROP_NONE);
745 RNA_def_property_boolean_funcs(prop, nullptr, "rna_Collection_hide_render_set");
747 RNA_def_property_ui_icon(prop, ICON_RESTRICT_RENDER_OFF, -1);
748 RNA_def_property_ui_text(prop, "Disable in Renders", "Globally disable in renders");
749 RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_Collection_flag_update");
750
751 static const EnumPropertyItem rna_collection_lineart_usage[] = {
753 "INCLUDE",
754 0,
755 "Include",
756 "Generate feature lines for this collection"},
758 "OCCLUSION_ONLY",
759 0,
760 "Occlusion Only",
761 "Only use the collection to produce occlusion"},
762 {COLLECTION_LRT_EXCLUDE, "EXCLUDE", 0, "Exclude", "Don't use this collection in Line Art"},
764 "INTERSECTION_ONLY",
765 0,
766 "Intersection Only",
767 "Only generate intersection lines for this collection"},
769 "NO_INTERSECTION",
770 0,
771 "No Intersection",
772 "Include this collection but do not generate intersection lines"},
774 "FORCE_INTERSECTION",
775 0,
776 "Force Intersection",
777 "Generate intersection lines even with objects that disabled intersection"},
778 {0, nullptr, 0, nullptr, nullptr}};
779
780 prop = RNA_def_property(srna, "lineart_usage", PROP_ENUM, PROP_NONE);
781 RNA_def_property_enum_items(prop, rna_collection_lineart_usage);
782 RNA_def_property_ui_text(prop, "Usage", "How to use this collection in Line Art calculation");
783 RNA_def_property_update(prop, NC_SCENE, nullptr);
784
785 prop = RNA_def_property(srna, "lineart_use_intersection_mask", PROP_BOOLEAN, PROP_NONE);
786 RNA_def_property_boolean_sdna(prop, nullptr, "lineart_flags", 1);
788 prop, "Use Intersection Masks", "Use custom intersection mask for faces in this collection");
789 RNA_def_property_update(prop, NC_SCENE, nullptr);
790
791 prop = RNA_def_property(srna, "lineart_intersection_mask", PROP_BOOLEAN, PROP_NONE);
792 RNA_def_property_boolean_sdna(prop, nullptr, "lineart_intersection_mask", 1);
793 RNA_def_property_array(prop, 8);
795 prop, "Masks", "Intersection generated by this collection will have this mask value");
796 RNA_def_property_update(prop, NC_SCENE, nullptr);
797
798 prop = RNA_def_property(srna, "lineart_intersection_priority", PROP_INT, PROP_NONE);
800 "Intersection Priority",
801 "The intersection line will be included into the object with the "
802 "higher intersection priority value");
803 RNA_def_property_update(prop, NC_SCENE, nullptr);
804
805 prop = RNA_def_property(srna, "use_lineart_intersection_priority", PROP_BOOLEAN, PROP_NONE);
808 prop, nullptr, "lineart_flags", COLLECTION_LRT_USE_INTERSECTION_PRIORITY);
810 prop, "Use Intersection Priority", "Assign intersection priority value for this collection");
811 RNA_def_property_update(prop, NC_SCENE, nullptr);
812
813 prop = RNA_def_property(srna, "color_tag", PROP_ENUM, PROP_NONE);
814 RNA_def_property_enum_sdna(prop, nullptr, "color_tag");
816 prop, "rna_Collection_color_tag_get", "rna_Collection_color_tag_set", nullptr);
818 RNA_def_property_ui_text(prop, "Collection Color", "Color tag for a collection");
819 RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_Collection_color_tag_update");
820
822
827}
828
829#endif
bool BKE_collection_object_remove(Main *bmain, Collection *collection, Object *ob, bool free_us)
void BKE_collection_object_cache_free(const Main *bmain, Collection *collection, const int id_create_flag)
bool BKE_collection_child_remove(Main *bmain, Collection *parent, Collection *child)
bool BKE_collection_object_replace(Main *bmain, Collection *collection, Object *ob_old, Object *ob_new)
bool BKE_collection_child_add(Main *bmain, Collection *parent, Collection *child)
void BKE_collection_exporter_name_set(const ListBase *exporters, CollectionExport *data, const char *newname)
ListBase BKE_collection_object_cache_get(Collection *collection)
bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
void BKE_main_collection_sync(const Main *bmain)
void id_us_plus(ID *id)
Definition lib_id.cc:351
void id_us_min(ID *id)
Definition lib_id.cc:359
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
#define BLI_STATIC_ASSERT(a, msg)
Definition BLI_assert.h:87
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:57
#define LISTBASE_FOREACH(type, var, list)
void * BLI_findptr(const struct ListBase *listbase, const void *ptr, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define ARRAY_SIZE(arr)
#define UNUSED_VARS_NDEBUG(...)
void DEG_id_tag_update(ID *id, unsigned int flags)
void DEG_relations_tag_update(Main *bmain)
bool DEG_is_original_id(const ID *id)
@ ID_RECALC_HIERARCHY
Definition DNA_ID.h:1125
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1085
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1041
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:658
@ LIBOVERRIDE_OP_REPLACE
Definition DNA_ID.h:229
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:683
Object groups, one object can be in many groups at once.
@ COLLECTION_HIDE_RENDER
@ COLLECTION_HIDE_SELECT
@ COLLECTION_IS_MASTER
@ COLLECTION_HIDE_VIEWPORT
@ COLLECTION_LIGHT_LINKING_STATE_EXCLUDE
@ COLLECTION_LIGHT_LINKING_STATE_INCLUDE
@ COLLECTION_LRT_EXCLUDE
@ COLLECTION_LRT_INCLUDE
@ COLLECTION_LRT_INTERSECTION_ONLY
@ COLLECTION_LRT_FORCE_INTERSECTION
@ COLLECTION_LRT_OCCLUSION_ONLY
@ COLLECTION_LRT_NO_INTERSECTION
@ COLLECTION_LRT_USE_INTERSECTION_PRIORITY
@ IO_HANDLER_PANEL_OPEN
@ COLLECTION_COLOR_NONE
@ COLLECTION_COLOR_02
@ COLLECTION_COLOR_05
@ COLLECTION_COLOR_07
@ COLLECTION_COLOR_06
@ COLLECTION_COLOR_TOT
@ COLLECTION_COLOR_04
@ COLLECTION_COLOR_01
@ COLLECTION_COLOR_08
@ COLLECTION_COLOR_03
Object is a sort of wrapper for general info.
@ PARM_REQUIRED
Definition RNA_types.hh:397
@ FUNC_USE_REPORTS
Definition RNA_types.hh:680
@ FUNC_USE_MAIN
Definition RNA_types.hh:678
@ STRUCT_ID_REFCOUNT
Definition RNA_types.hh:720
@ PROP_FLOAT
Definition RNA_types.hh:67
@ PROP_BOOLEAN
Definition RNA_types.hh:65
@ PROP_ENUM
Definition RNA_types.hh:69
@ PROP_INT
Definition RNA_types.hh:66
@ PROP_STRING
Definition RNA_types.hh:68
@ PROP_POINTER
Definition RNA_types.hh:70
@ PROP_COLLECTION
Definition RNA_types.hh:71
#define RNA_TRANSLATION_PREC_DEFAULT
Definition RNA_types.hh:127
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition RNA_types.hh:355
@ PROPOVERRIDE_NO_COMPARISON
Definition RNA_types.hh:363
PropertyFlag
Definition RNA_types.hh:201
@ PROP_ANIMATABLE
Definition RNA_types.hh:220
@ PROP_NEVER_NULL
Definition RNA_types.hh:266
@ PROP_NO_DEG_UPDATE
Definition RNA_types.hh:328
@ PROP_NONE
Definition RNA_types.hh:136
@ PROP_TRANSLATION
Definition RNA_types.hh:164
@ PROP_UNSIGNED
Definition RNA_types.hh:152
#define ND_DRAW
Definition WM_types.hh:428
#define ND_OB_SELECT
Definition WM_types.hh:409
#define ND_SPACE_PROPERTIES
Definition WM_types.hh:495
#define NC_SCENE
Definition WM_types.hh:345
#define ND_LAYER_CONTENT
Definition WM_types.hh:420
#define NC_OBJECT
Definition WM_types.hh:346
#define NC_SPACE
Definition WM_types.hh:359
#define offsetof(t, d)
FileHandlerType * file_handler_find(StringRef idname)
void rna_iterator_listbase_begin(CollectionPropertyIterator *iter, ListBase *lb, IteratorSkipFunc skip)
void RNA_property_update_main(Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
PointerRNA rna_pointer_inherit_refine(const PointerRNA *ptr, StructRNA *type, void *data)
PointerRNA RNA_pointer_create(ID *id, StructRNA *type, void *data)
static void rna_def_collection_child(BlenderRNA *brna)
static void rna_def_collection_objects(BlenderRNA *brna, PropertyRNA *cprop)
static void rna_def_collection_object(BlenderRNA *brna)
static void rna_def_collection_exporter_data(BlenderRNA *brna)
static void rna_def_collection_children(BlenderRNA *brna, PropertyRNA *cprop)
void RNA_def_collections(BlenderRNA *brna)
static void rna_def_collection_light_linking(BlenderRNA *brna)
const EnumPropertyItem rna_enum_collection_color_items[]
void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop)
void RNA_define_lib_overridable(const bool make_overridable)
void RNA_def_struct_path_func(StructRNA *srna, const char *path)
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t bit)
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
void RNA_def_property_collection_funcs(PropertyRNA *prop, const char *begin, const char *next, const char *end, const char *get, const char *length, const char *lookupint, const char *lookupstring, const char *assignint)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
void RNA_def_property_boolean_default(PropertyRNA *prop, bool value)
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
void RNA_def_struct_clear_flag(StructRNA *srna, int flag)
void RNA_def_property_array(PropertyRNA *prop, int length)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
void RNA_def_function_flag(FunctionRNA *func, int flag)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
void RNA_def_property_override_funcs(PropertyRNA *prop, const char *diff, const char *store, const char *apply)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_override_clear_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
void RNA_def_property_override_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
struct Collection * collection
ListBaseIterator listbase
Definition RNA_types.hh:455
union CollectionPropertyIterator::@1329 internal
char name[66]
Definition DNA_ID.h:425
ID * owner_id
Definition RNA_types.hh:40
void * data
Definition RNA_types.hh:42
IDOverrideLibraryPropertyOperation * liboverride_operation
char export_operator[OP_MAX_TYPENAME]
StructRNA * srna
Definition WM_types.hh:1080
void WM_main_add_notifier(uint type, void *reference)
PointerRNA * ptr
Definition wm_files.cc:4126
wmOperatorType * ot
Definition wm_files.cc:4125
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
uint8_t flag
Definition wm_window.cc:138