Blender V4.5
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
8
9#include <cstdlib>
10
11#include "BKE_file_handler.hh"
12
14
15#include "BLI_path_utils.hh"
16#include "BLI_utildefines.h"
17
18#include "RNA_define.hh"
19#include "RNA_enum_types.hh"
20
21#include "rna_internal.hh"
22
23#include "WM_types.hh"
24
26 {COLLECTION_COLOR_NONE, "NONE", ICON_X, "None", "Assign no color tag to the collection"},
27 {COLLECTION_COLOR_01, "COLOR_01", ICON_COLLECTION_COLOR_01, "Color 01", ""},
28 {COLLECTION_COLOR_02, "COLOR_02", ICON_COLLECTION_COLOR_02, "Color 02", ""},
29 {COLLECTION_COLOR_03, "COLOR_03", ICON_COLLECTION_COLOR_03, "Color 03", ""},
30 {COLLECTION_COLOR_04, "COLOR_04", ICON_COLLECTION_COLOR_04, "Color 04", ""},
31 {COLLECTION_COLOR_05, "COLOR_05", ICON_COLLECTION_COLOR_05, "Color 05", ""},
32 {COLLECTION_COLOR_06, "COLOR_06", ICON_COLLECTION_COLOR_06, "Color 06", ""},
33 {COLLECTION_COLOR_07, "COLOR_07", ICON_COLLECTION_COLOR_07, "Color 07", ""},
34 {COLLECTION_COLOR_08, "COLOR_08", ICON_COLLECTION_COLOR_08, "Color 08", ""},
35 {0, nullptr, 0, nullptr, nullptr},
36};
37/* Minus 1 for NONE & 1 for the nullptr sentinel. */
39 "Collection color total is an invalid size");
40
41#ifdef RNA_RUNTIME
42
43# include <fmt/format.h>
44
45# include "DNA_object_types.h"
46# include "DNA_scene_types.h"
47
48# include "DEG_depsgraph.hh"
49# include "DEG_depsgraph_build.hh"
50# include "DEG_depsgraph_query.hh"
51
52# include "BKE_collection.hh"
53# include "BKE_global.hh"
54# include "BKE_idprop.hh"
55# include "BKE_layer.hh"
56# include "BKE_lib_id.hh"
57# include "BKE_library.hh"
58# include "BKE_report.hh"
59
60# include "BLT_translation.hh"
61
62# include "WM_api.hh"
63
64# include "RNA_access.hh"
65
66static void rna_Collection_all_objects_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
67{
68 Collection *collection = (Collection *)ptr->data;
69 ListBase collection_objects = BKE_collection_object_cache_get(collection);
70 rna_iterator_listbase_begin(iter, ptr, &collection_objects, nullptr);
71}
72
73static PointerRNA rna_Collection_all_objects_get(CollectionPropertyIterator *iter)
74{
75 ListBaseIterator *internal = &iter->internal.listbase;
76
77 /* we are actually iterating a ObjectBase list, so override get */
78 Base *base = (Base *)internal->link;
79 return RNA_id_pointer_create(&base->object->id);
80}
81
82static void rna_Collection_objects_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
83{
84 Collection *collection = (Collection *)ptr->data;
85 rna_iterator_listbase_begin(iter, ptr, &collection->gobject, nullptr);
86}
87
88static PointerRNA rna_Collection_objects_get(CollectionPropertyIterator *iter)
89{
90 ListBaseIterator *internal = &iter->internal.listbase;
91
92 /* we are actually iterating a ObjectBase list, so override get */
93 CollectionObject *cob = (CollectionObject *)internal->link;
94 return RNA_id_pointer_create(&cob->ob->id);
95}
96
97static bool rna_collection_objects_edit_check(Collection *collection,
99 Object *object)
100{
101 if (!DEG_is_original(collection)) {
103 reports, RPT_ERROR, "Collection '%s' is not an original ID", collection->id.name + 2);
104 return false;
105 }
106 if (!DEG_is_original(object)) {
107 BKE_reportf(reports, RPT_ERROR, "Collection '%s' is not an original ID", object->id.name + 2);
108 return false;
109 }
110 /* Currently this should not be allowed (might be supported in the future though...). */
111 if (ID_IS_OVERRIDE_LIBRARY(&collection->id)) {
113 RPT_ERROR,
114 "Could not (un)link the object '%s' because the collection '%s' is overridden",
115 object->id.name + 2,
116 collection->id.name + 2);
117 return false;
118 }
119 if (!ID_IS_EDITABLE(&collection->id)) {
121 RPT_ERROR,
122 "Could not (un)link the object '%s' because the collection '%s' is linked",
123 object->id.name + 2,
124 collection->id.name + 2);
125 return false;
126 }
127 return true;
128}
129
130static void rna_Collection_objects_link(Collection *collection,
131 Main *bmain,
133 Object *object)
134{
135 if (!rna_collection_objects_edit_check(collection, reports, object)) {
136 return;
137 }
138 if (!BKE_collection_object_add(bmain, collection, object)) {
140 RPT_ERROR,
141 "Object '%s' already in collection '%s'",
142 object->id.name + 2,
143 collection->id.name + 2);
144 return;
145 }
146
150}
151
152static void rna_Collection_objects_unlink(Collection *collection,
153 Main *bmain,
155 Object *object)
156{
157 if (!rna_collection_objects_edit_check(collection, reports, object)) {
158 return;
159 }
160 if (!BKE_collection_object_remove(bmain, collection, object, false)) {
162 RPT_ERROR,
163 "Object '%s' not in collection '%s'",
164 object->id.name + 2,
165 collection->id.name + 2);
166 return;
167 }
168
172}
173
174static bool rna_Collection_objects_override_apply(Main *bmain,
176{
177 PointerRNA *ptr_dst = &rnaapply_ctx.ptr_dst;
178 PropertyRNA *prop_dst = rnaapply_ctx.prop_dst;
179 PointerRNA *ptr_item_dst = &rnaapply_ctx.ptr_item_dst;
180 PointerRNA *ptr_item_src = &rnaapply_ctx.ptr_item_src;
182
184 "Unsupported RNA override operation on collections' objects");
185 UNUSED_VARS_NDEBUG(opop);
186
187 Collection *coll_dst = (Collection *)ptr_dst->owner_id;
188
189 if (ptr_item_dst->type == nullptr || ptr_item_src->type == nullptr) {
190 // BLI_assert_msg(0, "invalid source or destination object.");
191 return false;
192 }
193
194 Object *ob_dst = static_cast<Object *>(ptr_item_dst->data);
195 Object *ob_src = static_cast<Object *>(ptr_item_src->data);
196
197 if (ob_src == ob_dst) {
198 return true;
199 }
200
201 if (!BKE_collection_object_replace(bmain, coll_dst, ob_dst, ob_src)) {
202 BLI_assert_msg(0, "Could not find destination object in destination collection!");
203 return false;
204 }
205
206 RNA_property_update_main(bmain, nullptr, ptr_dst, prop_dst);
207 return true;
208}
209
210static void rna_Collection_children_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
211{
212 Collection *collection = (Collection *)ptr->data;
213 rna_iterator_listbase_begin(iter, ptr, &collection->children, nullptr);
214}
215
216static PointerRNA rna_Collection_children_get(CollectionPropertyIterator *iter)
217{
218 ListBaseIterator *internal = &iter->internal.listbase;
219
220 /* we are actually iterating a CollectionChild list, so override get */
221 CollectionChild *child = (CollectionChild *)internal->link;
222 return RNA_id_pointer_create(&child->collection->id);
223}
224
225static bool rna_collection_children_edit_check(Collection *collection,
227 Collection *child)
228{
229 if (!DEG_is_original(collection)) {
231 reports, RPT_ERROR, "Collection '%s' is not an original ID", collection->id.name + 2);
232 return false;
233 }
234 if (!DEG_is_original(child)) {
235 BKE_reportf(reports, RPT_ERROR, "Collection '%s' is not an original ID", child->id.name + 2);
236 return false;
237 }
238 /* Currently this should not be allowed (might be supported in the future though...). */
239 if (ID_IS_OVERRIDE_LIBRARY(&collection->id)) {
241 RPT_ERROR,
242 "Could not (un)link the collection '%s' because the collection '%s' is overridden",
243 child->id.name + 2,
244 collection->id.name + 2);
245 return false;
246 }
247 if (!ID_IS_EDITABLE(&collection->id)) {
249 RPT_ERROR,
250 "Could not (un)link the collection '%s' because the collection '%s' is linked",
251 child->id.name + 2,
252 collection->id.name + 2);
253 return false;
254 }
255 return true;
256}
257
258static void rna_Collection_children_link(Collection *collection,
259 Main *bmain,
261 Collection *child)
262{
263 if (!rna_collection_children_edit_check(collection, reports, child)) {
264 return;
265 }
266 if (!BKE_collection_child_add(bmain, collection, child)) {
268 RPT_ERROR,
269 "Collection '%s' already in collection '%s'",
270 child->id.name + 2,
271 collection->id.name + 2);
272 return;
273 }
274
278}
279
280static void rna_Collection_children_unlink(Collection *collection,
281 Main *bmain,
283 Collection *child)
284{
285 if (!rna_collection_children_edit_check(collection, reports, child)) {
286 return;
287 }
288 if (!BKE_collection_child_remove(bmain, collection, child)) {
290 RPT_ERROR,
291 "Collection '%s' not in collection '%s'",
292 child->id.name + 2,
293 collection->id.name + 2);
294 return;
295 }
296
300}
301
302static bool rna_Collection_children_override_apply(Main *bmain,
304{
305 PointerRNA *ptr_dst = &rnaapply_ctx.ptr_dst;
306 PropertyRNA *prop_dst = rnaapply_ctx.prop_dst;
307 PointerRNA *ptr_item_dst = &rnaapply_ctx.ptr_item_dst;
308 PointerRNA *ptr_item_src = &rnaapply_ctx.ptr_item_src;
310
312 "Unsupported RNA override operation on collections' children");
313 UNUSED_VARS_NDEBUG(opop);
314
315 Collection *coll_dst = (Collection *)ptr_dst->owner_id;
316
317 if (ptr_item_dst->type == nullptr || ptr_item_src->type == nullptr) {
318 /* This can happen when reference and overrides differ, just ignore then. */
319 return false;
320 }
321
322 Collection *subcoll_dst = static_cast<Collection *>(ptr_item_dst->data);
323 Collection *subcoll_src = static_cast<Collection *>(ptr_item_src->data);
324
325 CollectionChild *collchild_dst = static_cast<CollectionChild *>(
326 BLI_findptr(&coll_dst->children, subcoll_dst, offsetof(CollectionChild, collection)));
327
328 if (collchild_dst == nullptr) {
329 BLI_assert_msg(0, "Could not find destination sub-collection in destination collection!");
330 return false;
331 }
332
333 /* XXX TODO: We most certainly rather want to have a 'swap object pointer in collection'
334 * util in BKE_collection. This is only temp quick dirty test! */
335 id_us_min(&collchild_dst->collection->id);
336 collchild_dst->collection = subcoll_src;
337 id_us_plus(&collchild_dst->collection->id);
338
339 BKE_collection_object_cache_free(bmain, coll_dst, 0);
341
342 RNA_property_update_main(bmain, nullptr, ptr_dst, prop_dst);
343 return true;
344}
345
346static void rna_Collection_flag_set(PointerRNA *ptr, const bool value, const int flag)
347{
348 Collection *collection = (Collection *)ptr->data;
349
350 if (collection->flag & COLLECTION_IS_MASTER) {
351 return;
352 }
353
354 if (value) {
355 collection->flag |= flag;
356 }
357 else {
358 collection->flag &= ~flag;
359 }
360}
361
362static void rna_Collection_hide_select_set(PointerRNA *ptr, bool value)
363{
364 rna_Collection_flag_set(ptr, value, COLLECTION_HIDE_SELECT);
365}
366
367static void rna_Collection_hide_viewport_set(PointerRNA *ptr, bool value)
368{
369 rna_Collection_flag_set(ptr, value, COLLECTION_HIDE_VIEWPORT);
370}
371
372static void rna_Collection_hide_render_set(PointerRNA *ptr, bool value)
373{
374 rna_Collection_flag_set(ptr, value, COLLECTION_HIDE_RENDER);
375}
376
377static void rna_Collection_flag_update(Main *bmain, Scene *scene, PointerRNA *ptr)
378{
379 Collection *collection = (Collection *)ptr->data;
380 BKE_collection_object_cache_free(bmain, collection, 0);
382
386}
387
388static int rna_Collection_color_tag_get(PointerRNA *ptr)
389{
390 Collection *collection = (Collection *)ptr->data;
391
392 return collection->color_tag;
393}
394
395static void rna_Collection_color_tag_set(PointerRNA *ptr, int value)
396{
397 Collection *collection = (Collection *)ptr->data;
398
399 if (collection->flag & COLLECTION_IS_MASTER) {
400 return;
401 }
402
403 collection->color_tag = value;
404}
405
406static void rna_Collection_color_tag_update(Main * /*bmain*/, Scene *scene, PointerRNA * /*ptr*/)
407{
409}
410
411static void rna_Collection_instance_offset_update(Main * /*bmain*/,
412 Scene * /*scene*/,
414{
415 Collection *collection = (Collection *)ptr->data;
417}
418
419static std::optional<std::string> rna_CollectionLightLinking_path(const PointerRNA *ptr)
420{
421 Collection *collection = (Collection *)ptr->owner_id;
422 CollectionLightLinking *collection_light_linking = (CollectionLightLinking *)ptr->data;
423
424 int counter;
425
426 counter = 0;
427 LISTBASE_FOREACH (CollectionObject *, collection_object, &collection->gobject) {
428 if (&collection_object->light_linking == collection_light_linking) {
429 return fmt::format("collection_objects[{}].light_linking", counter);
430 }
431 ++counter;
432 }
433
434 counter = 0;
435 LISTBASE_FOREACH (CollectionChild *, collection_child, &collection->children) {
436 if (&collection_child->light_linking == collection_light_linking) {
437 return fmt::format("collection_children[{}].light_linking", counter);
438 }
439 ++counter;
440 }
441
442 return "..";
443}
444
445static void rna_CollectionLightLinking_update(Main *bmain, Scene * /*scene*/, PointerRNA *ptr)
446{
447 /* The light linking collection comes from the collection. It does not have shading component,
448 * but is collected to objects via hierarchy component. Tagging its hierarchy for update will
449 * lead the objects which use the collection to update its shading. */
451
452 /* Tag relations for update so that an updated state of light sets is calculated. */
454}
455
456static void rna_CollectionExport_name_set(PointerRNA *ptr, const char *value)
457{
458 CollectionExport *data = reinterpret_cast<CollectionExport *>(ptr->data);
459 BKE_collection_exporter_name_set(nullptr, data, value);
460}
461
462static PointerRNA rna_CollectionExport_export_properties_get(PointerRNA *ptr)
463{
464 const CollectionExport *data = reinterpret_cast<CollectionExport *>(ptr->data);
465
466 /* If the File Handler or Operator is missing, we allow the data to be accessible
467 * as generic ID properties. */
469 if (!fh) {
471 ptr->owner_id, &RNA_IDPropertyWrapPtr, data->export_properties);
472 }
473
475 if (!ot) {
477 ptr->owner_id, &RNA_IDPropertyWrapPtr, data->export_properties);
478 }
479
480 return RNA_pointer_create_discrete(ptr->owner_id, ot->srna, data->export_properties);
481}
482
483static const char *rna_CollectionExport_filepath_value_from_idprop(CollectionExport *data)
484{
485 if (IDProperty *group = data->export_properties) {
486 IDProperty *filepath_prop = IDP_GetPropertyFromGroup(group, "filepath");
487 if (filepath_prop && filepath_prop->type == IDP_STRING) {
488 return IDP_String(filepath_prop);
489 }
490 }
491 return nullptr;
492}
493
494static void rna_CollectionExport_filepath_get(PointerRNA *ptr, char *value)
495{
496 CollectionExport *data = reinterpret_cast<CollectionExport *>(ptr->data);
497 const char *value_src = rna_CollectionExport_filepath_value_from_idprop(data);
498 strcpy(value, value_src ? value_src : "");
499}
500static int rna_CollectionExport_filepath_length(PointerRNA *ptr)
501{
502 CollectionExport *data = reinterpret_cast<CollectionExport *>(ptr->data);
503 const char *value_src = rna_CollectionExport_filepath_value_from_idprop(data);
504 return value_src ? strlen(value_src) : 0;
505}
506static void rna_CollectionExport_filepath_set(PointerRNA *ptr, const char *value)
507{
508 CollectionExport *data = reinterpret_cast<CollectionExport *>(ptr->data);
509 if (!data->export_properties) {
510 IDPropertyTemplate val{};
511 data->export_properties = IDP_New(IDP_GROUP, &val, "export_properties");
512 }
513 IDProperty *group = data->export_properties;
514 /* By convention all exporters are expected to have a `filepath` property.
515 * See #WM_operator_properties_filesel. */
516 const char *prop_id = "filepath";
517 const size_t value_maxsize = FILE_MAX;
518 IDProperty *prop = IDP_GetPropertyFromGroup(group, prop_id);
519 if (prop && prop->type != IDP_STRING) {
520 IDP_FreeFromGroup(group, prop);
521 prop = nullptr;
522 }
523 if (prop == nullptr) {
524 prop = IDP_NewStringMaxSize(value, value_maxsize, prop_id);
525 IDP_AddToGroup(group, prop);
526 }
527 else {
528 IDP_AssignStringMaxSize(prop, value, value_maxsize);
529 }
530}
531
532#else
533
534/* collection.objects */
536{
537 StructRNA *srna;
538 FunctionRNA *func;
539 PropertyRNA *parm;
540
541 RNA_def_property_srna(cprop, "CollectionObjects");
542 srna = RNA_def_struct(brna, "CollectionObjects", nullptr);
543 RNA_def_struct_sdna(srna, "Collection");
544 RNA_def_struct_ui_text(srna, "Collection Objects", "Collection of collection objects");
545
546 /* add object */
547 func = RNA_def_function(srna, "link", "rna_Collection_objects_link");
549 RNA_def_function_ui_description(func, "Add this object to a collection");
550 parm = RNA_def_pointer(func, "object", "Object", "", "Object to add");
552
553 /* remove object */
554 func = RNA_def_function(srna, "unlink", "rna_Collection_objects_unlink");
555 RNA_def_function_ui_description(func, "Remove this object from a collection");
557 parm = RNA_def_pointer(func, "object", "Object", "", "Object to remove");
559}
560
561/* collection.children */
563{
564 StructRNA *srna;
565 FunctionRNA *func;
566 PropertyRNA *parm;
567
568 RNA_def_property_srna(cprop, "CollectionChildren");
569 srna = RNA_def_struct(brna, "CollectionChildren", nullptr);
570 RNA_def_struct_sdna(srna, "Collection");
571 RNA_def_struct_ui_text(srna, "Collection Children", "Collection of child collections");
572
573 /* add child */
574 func = RNA_def_function(srna, "link", "rna_Collection_children_link");
576 RNA_def_function_ui_description(func, "Add this collection as child of this collection");
577 parm = RNA_def_pointer(func, "child", "Collection", "", "Collection to add");
579
580 /* remove child */
581 func = RNA_def_function(srna, "unlink", "rna_Collection_children_unlink");
582 RNA_def_function_ui_description(func, "Remove this child collection from a collection");
584 parm = RNA_def_pointer(func, "child", "Collection", "", "Collection to remove");
586}
587
589{
590 StructRNA *srna;
591 PropertyRNA *prop;
592
593 /* TODO(sergey): Use proper icons. */
594 static const EnumPropertyItem light_linking_state_items[] = {
595 {COLLECTION_LIGHT_LINKING_STATE_INCLUDE, "INCLUDE", ICON_OUTLINER_OB_LIGHT, "Include", ""},
596 {COLLECTION_LIGHT_LINKING_STATE_EXCLUDE, "EXCLUDE", ICON_LIGHT, "Exclude", ""},
597 {0, nullptr, 0, nullptr, nullptr},
598 };
599
600 srna = RNA_def_struct(brna, "CollectionLightLinking", nullptr);
601 RNA_def_struct_sdna(srna, "CollectionLightLinking");
603 srna,
604 "Collection Light Linking",
605 "Light linking settings of objects and children collections of a collection");
606 RNA_def_struct_path_func(srna, "rna_CollectionLightLinking_path");
607
608 /* Light state. */
609 prop = RNA_def_property(srna, "link_state", PROP_ENUM, PROP_NONE);
610 RNA_def_property_enum_items(prop, light_linking_state_items);
612 prop, "Link State", "Light or shadow receiving state of the object or collection");
614 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_CollectionLightLinking_update");
615}
616
618{
619 StructRNA *srna;
620 PropertyRNA *prop;
621
622 srna = RNA_def_struct(brna, "CollectionObject", nullptr);
623 RNA_def_struct_sdna(srna, "CollectionObject");
625 srna, "Collection Object", "Object of a collection with its collection related settings");
626
627 /* Light Linking. */
628 prop = RNA_def_property(srna, "light_linking", PROP_POINTER, PROP_NONE);
630 RNA_def_property_struct_type(prop, "CollectionLightLinking");
631 RNA_def_property_ui_text(prop, "Light Linking", "Light linking settings of the collection");
632}
633
635{
636 StructRNA *srna;
637 PropertyRNA *prop;
638
639 srna = RNA_def_struct(brna, "CollectionChild", nullptr);
640 RNA_def_struct_sdna(srna, "CollectionChild");
642 srna, "Collection Child", "Child collection with its collection related settings");
643
644 /* Light Linking. */
645 prop = RNA_def_property(srna, "light_linking", PROP_POINTER, PROP_NONE);
647 RNA_def_property_struct_type(prop, "CollectionLightLinking");
649 prop, "Light Linking", "Light linking settings of the collection object");
650}
651
653{
654 StructRNA *srna;
655 PropertyRNA *prop;
656
657 srna = RNA_def_struct(brna, "CollectionExport", nullptr);
658 RNA_def_struct_sdna(srna, "CollectionExport");
659 RNA_def_struct_ui_text(srna, "Collection Export Data", "Exporter configured for the collection");
660
661 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
662 RNA_def_struct_ui_text(srna, "Name", "");
664 RNA_def_property_string_funcs(prop, nullptr, nullptr, "rna_CollectionExport_name_set");
665
666 prop = RNA_def_property(srna, "is_open", PROP_BOOLEAN, PROP_NONE);
668 RNA_def_property_ui_text(prop, "Is Open", "Whether the panel is expanded or closed");
671
672 prop = RNA_def_property(srna, "export_properties", PROP_POINTER, PROP_NONE);
673 RNA_def_property_struct_type(prop, "PropertyGroup");
675 prop, "Export Properties", "Properties associated with the configured exporter");
677 prop, "rna_CollectionExport_export_properties_get", nullptr, nullptr, nullptr);
678
679 /* Wrap the operator property because exposing the operator property directly
680 * causes problems, as the operator property typically wont support
681 * #PROP_PATH_SUPPORTS_BLEND_RELATIVE, when the collection property does since
682 * it's expanded before passing it to the operator, see #137856 & #137507. */
683 prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
686 "rna_CollectionExport_filepath_get",
687 "rna_CollectionExport_filepath_length",
688 "rna_CollectionExport_filepath_set");
690 RNA_def_property_ui_text(prop, "File Path", "The file path used for exporting");
693}
694
696{
697 StructRNA *srna;
698 PropertyRNA *prop;
699
700 srna = RNA_def_struct(brna, "Collection", "ID");
701 RNA_def_struct_ui_text(srna, "Collection", "Collection of Object data-blocks");
702 RNA_def_struct_ui_icon(srna, ICON_OUTLINER_COLLECTION);
703 /* This is done on save/load in `readfile.cc`,
704 * removed if no objects are in the collection and not in a scene. */
706
708
709 prop = RNA_def_property(srna, "instance_offset", PROP_FLOAT, PROP_TRANSLATION);
711 prop, "Instance Offset", "Offset from the origin to use when instancing");
712 RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, RNA_TRANSLATION_PREC_DEFAULT);
713 RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Collection_instance_offset_update");
714
715 prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
716 RNA_def_property_struct_type(prop, "Object");
717 RNA_def_property_override_funcs(prop, nullptr, nullptr, "rna_Collection_objects_override_apply");
718 RNA_def_property_ui_text(prop, "Objects", "Objects that are directly in this collection");
720 "rna_Collection_objects_begin",
721 "rna_iterator_listbase_next",
722 "rna_iterator_listbase_end",
723 "rna_Collection_objects_get",
724 nullptr,
725 nullptr,
726 nullptr,
727 nullptr);
728 rna_def_collection_objects(brna, prop);
729
730 prop = RNA_def_property(srna, "all_objects", PROP_COLLECTION, PROP_NONE);
731 RNA_def_property_struct_type(prop, "Object");
733 prop, "All Objects", "Objects that are in this collection and its child collections");
737 "rna_Collection_all_objects_begin",
738 "rna_iterator_listbase_next",
739 "rna_iterator_listbase_end",
740 "rna_Collection_all_objects_get",
741 nullptr,
742 nullptr,
743 nullptr,
744 nullptr);
745
746 prop = RNA_def_property(srna, "children", PROP_COLLECTION, PROP_NONE);
747 RNA_def_property_struct_type(prop, "Collection");
749 prop, nullptr, nullptr, "rna_Collection_children_override_apply");
751 prop, "Children", "Collections that are immediate children of this collection");
753 "rna_Collection_children_begin",
754 "rna_iterator_listbase_next",
755 "rna_iterator_listbase_end",
756 "rna_Collection_children_get",
757 nullptr,
758 nullptr,
759 nullptr,
760 nullptr);
761 rna_def_collection_children(brna, prop);
762
763 /* Collection objects. */
764 prop = RNA_def_property(srna, "collection_objects", PROP_COLLECTION, PROP_NONE);
765 RNA_def_property_struct_type(prop, "CollectionObject");
766 RNA_def_property_collection_sdna(prop, nullptr, "gobject", nullptr);
768 prop,
769 "Collection Objects",
770 "Objects of the collection with their parent-collection-specific settings");
771 /* TODO(sergey): Functions to link and unlink objects. */
772
773 /* Children collections. */
774 prop = RNA_def_property(srna, "collection_children", PROP_COLLECTION, PROP_NONE);
775 RNA_def_property_struct_type(prop, "CollectionChild");
776 RNA_def_property_collection_sdna(prop, nullptr, "children", nullptr);
778 "Collection Children",
779 "Children collections with their parent-collection-specific settings");
780
781 /* Export Handlers. */
782 prop = RNA_def_property(srna, "exporters", PROP_COLLECTION, PROP_NONE);
783 RNA_def_property_struct_type(prop, "CollectionExport");
784 RNA_def_property_collection_sdna(prop, nullptr, "exporters", nullptr);
786 prop, "Collection Export Handlers", "Export Handlers configured for the collection");
787
788 prop = RNA_def_property(srna, "active_exporter_index", PROP_INT, PROP_UNSIGNED);
791 prop, "Active Collection Exporter Index", "Active index in the exporters list");
792
793 /* TODO(sergey): Functions to link and unlink collections. */
794
795 /* Flags */
796 prop = RNA_def_property(srna, "hide_select", PROP_BOOLEAN, PROP_NONE);
798 RNA_def_property_boolean_funcs(prop, nullptr, "rna_Collection_hide_select_set");
800 RNA_def_property_ui_icon(prop, ICON_RESTRICT_SELECT_OFF, -1);
801 RNA_def_property_ui_text(prop, "Disable Selection", "Disable selection in viewport");
802 RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_Collection_flag_update");
803
804 prop = RNA_def_property(srna, "hide_viewport", PROP_BOOLEAN, PROP_NONE);
806 RNA_def_property_boolean_funcs(prop, nullptr, "rna_Collection_hide_viewport_set");
808 RNA_def_property_ui_icon(prop, ICON_RESTRICT_VIEW_OFF, -1);
809 RNA_def_property_ui_text(prop, "Disable in Viewports", "Globally disable in viewports");
810 RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_Collection_flag_update");
811
812 prop = RNA_def_property(srna, "hide_render", PROP_BOOLEAN, PROP_NONE);
814 RNA_def_property_boolean_funcs(prop, nullptr, "rna_Collection_hide_render_set");
816 RNA_def_property_ui_icon(prop, ICON_RESTRICT_RENDER_OFF, -1);
817 RNA_def_property_ui_text(prop, "Disable in Renders", "Globally disable in renders");
818 RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_Collection_flag_update");
819
820 static const EnumPropertyItem rna_collection_lineart_usage[] = {
822 "INCLUDE",
823 0,
824 "Include",
825 "Generate feature lines for this collection"},
827 "OCCLUSION_ONLY",
828 0,
829 "Occlusion Only",
830 "Only use the collection to produce occlusion"},
831 {COLLECTION_LRT_EXCLUDE, "EXCLUDE", 0, "Exclude", "Don't use this collection in Line Art"},
833 "INTERSECTION_ONLY",
834 0,
835 "Intersection Only",
836 "Only generate intersection lines for this collection"},
838 "NO_INTERSECTION",
839 0,
840 "No Intersection",
841 "Include this collection but do not generate intersection lines"},
843 "FORCE_INTERSECTION",
844 0,
845 "Force Intersection",
846 "Generate intersection lines even with objects that disabled intersection"},
847 {0, nullptr, 0, nullptr, nullptr}};
848
849 prop = RNA_def_property(srna, "lineart_usage", PROP_ENUM, PROP_NONE);
850 RNA_def_property_enum_items(prop, rna_collection_lineart_usage);
851 RNA_def_property_ui_text(prop, "Usage", "How to use this collection in Line Art calculation");
852 RNA_def_property_update(prop, NC_SCENE, nullptr);
853
854 prop = RNA_def_property(srna, "lineart_use_intersection_mask", PROP_BOOLEAN, PROP_NONE);
855 RNA_def_property_boolean_sdna(prop, nullptr, "lineart_flags", 1);
857 prop, "Use Intersection Masks", "Use custom intersection mask for faces in this collection");
858 RNA_def_property_update(prop, NC_SCENE, nullptr);
859
860 prop = RNA_def_property(srna, "lineart_intersection_mask", PROP_BOOLEAN, PROP_NONE);
862 prop, nullptr, "lineart_intersection_mask", 1 << 0, 8);
864 prop, "Masks", "Intersection generated by this collection will have this mask value");
865 RNA_def_property_update(prop, NC_SCENE, nullptr);
866
867 prop = RNA_def_property(srna, "lineart_intersection_priority", PROP_INT, PROP_NONE);
869 "Intersection Priority",
870 "The intersection line will be included into the object with the "
871 "higher intersection priority value");
872 RNA_def_property_update(prop, NC_SCENE, nullptr);
873
874 prop = RNA_def_property(srna, "use_lineart_intersection_priority", PROP_BOOLEAN, PROP_NONE);
877 prop, nullptr, "lineart_flags", COLLECTION_LRT_USE_INTERSECTION_PRIORITY);
879 prop, "Use Intersection Priority", "Assign intersection priority value for this collection");
880 RNA_def_property_update(prop, NC_SCENE, nullptr);
881
882 prop = RNA_def_property(srna, "color_tag", PROP_ENUM, PROP_NONE);
883 RNA_def_property_enum_sdna(prop, nullptr, "color_tag");
885 prop, "rna_Collection_color_tag_get", "rna_Collection_color_tag_set", nullptr);
887 RNA_def_property_ui_text(prop, "Collection Color", "Color tag for a collection");
888 RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_Collection_color_tag_update");
889
891
896}
897
898#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)
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, blender::StringRef name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:766
void IDP_FreeFromGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:760
void IDP_AssignStringMaxSize(IDProperty *prop, const char *st, size_t st_maxncpy) ATTR_NONNULL()
Definition idprop.cc:413
IDProperty * IDP_New(char type, const IDPropertyTemplate *val, blender::StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:1001
#define IDP_String(prop)
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:725
IDProperty * IDP_NewStringMaxSize(const char *st, size_t st_maxncpy, blender::StringRef name, eIDPropertyFlag flags={}) ATTR_WARN_UNUSED_RESULT
Definition idprop.cc:355
void BKE_main_collection_sync(const Main *bmain)
void id_us_plus(ID *id)
Definition lib_id.cc:353
void id_us_min(ID *id)
Definition lib_id.cc:361
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
#define BLI_STATIC_ASSERT(a, msg)
Definition BLI_assert.h:83
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:53
#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 FILE_MAX
#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(const T *id)
@ ID_RECALC_HIERARCHY
Definition DNA_ID.h:1066
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1026
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:982
@ LIBOVERRIDE_OP_REPLACE
Definition DNA_ID.h:220
@ IDP_STRING
@ IDP_GROUP
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:511
@ FUNC_USE_REPORTS
Definition RNA_types.hh:805
@ FUNC_USE_MAIN
Definition RNA_types.hh:803
@ STRUCT_ID_REFCOUNT
Definition RNA_types.hh:845
@ PROP_FLOAT
Definition RNA_types.hh:152
@ PROP_BOOLEAN
Definition RNA_types.hh:150
@ PROP_ENUM
Definition RNA_types.hh:154
@ PROP_INT
Definition RNA_types.hh:151
@ PROP_STRING
Definition RNA_types.hh:153
@ PROP_POINTER
Definition RNA_types.hh:155
@ PROP_COLLECTION
Definition RNA_types.hh:156
#define RNA_TRANSLATION_PREC_DEFAULT
Definition RNA_types.hh:212
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition RNA_types.hh:469
@ PROPOVERRIDE_NO_COMPARISON
Definition RNA_types.hh:477
PropertyFlag
Definition RNA_types.hh:286
@ PROP_ANIMATABLE
Definition RNA_types.hh:305
@ PROP_PATH_SUPPORTS_BLEND_RELATIVE
Definition RNA_types.hh:430
@ PROP_NEVER_NULL
Definition RNA_types.hh:351
@ PROP_NO_DEG_UPDATE
Definition RNA_types.hh:413
@ PROP_NONE
Definition RNA_types.hh:221
@ PROP_TRANSLATION
Definition RNA_types.hh:249
@ PROP_UNSIGNED
Definition RNA_types.hh:237
@ PROP_FILEPATH
Definition RNA_types.hh:224
#define ND_DRAW
Definition WM_types.hh:458
#define ND_OB_SELECT
Definition WM_types.hh:439
#define ND_SPACE_PROPERTIES
Definition WM_types.hh:526
#define NC_SCENE
Definition WM_types.hh:375
#define ND_LAYER_CONTENT
Definition WM_types.hh:450
ReportList * reports
Definition WM_types.hh:1025
#define NC_OBJECT
Definition WM_types.hh:376
#define NC_SPACE
Definition WM_types.hh:389
BMesh const char void * data
#define offsetof(t, d)
#define ID_IS_EDITABLE(_id)
#define ID_IS_OVERRIDE_LIBRARY(_id)
FileHandlerType * file_handler_find(StringRef idname)
void rna_iterator_listbase_begin(CollectionPropertyIterator *iter, PointerRNA *ptr, ListBase *lb, IteratorSkipFunc skip)
void RNA_property_update_main(Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
PointerRNA RNA_id_pointer_create(ID *id)
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_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
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_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_bitset_array_sdna(PropertyRNA *prop, const char *structname, const char *propname, const int64_t booleanbit, const int length)
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)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
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:572
union CollectionPropertyIterator::@277172262001176145116102322066145204253046376362 internal
char type
Definition DNA_ID.h:146
char name[66]
Definition DNA_ID.h:415
ID * owner_id
Definition RNA_types.hh:51
IDOverrideLibraryPropertyOperation * liboverride_operation
char export_operator[OP_MAX_TYPENAME]
void WM_main_add_notifier(uint type, void *reference)
PointerRNA * ptr
Definition wm_files.cc:4226
wmOperatorType * ot
Definition wm_files.cc:4225
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
uint8_t flag
Definition wm_window.cc:139