[Bf-blender-cvs] [3c65f2f] render-layers: More RNA: objects, objects_filter (for SceneCollection), .new, remove
Dalai Felinto
noreply at git.blender.org
Fri Dec 2 17:56:13 CET 2016
Commit: 3c65f2f542a75f8c00a0d423d606096eb155a586
Author: Dalai Felinto
Date: Fri Dec 2 17:50:53 2016 +0100
Branches: render-layers
https://developer.blender.org/rB3c65f2f542a75f8c00a0d423d606096eb155a586
More RNA: objects, objects_filter (for SceneCollection), .new, remove
===================================================================
M source/blender/blenkernel/BKE_collection.h
M source/blender/blenkernel/intern/collection.c
M source/blender/makesrna/intern/rna_scene.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h
index e286efe..41e1b69 100644
--- a/source/blender/blenkernel/BKE_collection.h
+++ b/source/blender/blenkernel/BKE_collection.h
@@ -39,6 +39,7 @@ struct SceneCollection *BKE_collection_add(struct Scene *scene, struct SceneColl
bool BKE_collection_remove(struct Scene *scene, struct SceneCollection *sc);
struct SceneCollection *BKE_collection_master(struct Scene *scene);
void BKE_collection_object_add(struct Scene *scene, struct SceneCollection *sc, struct Object *object);
+void BKE_collection_object_remove(struct Scene *scene, struct SceneCollection *sc, struct Object *object);
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 41603f2..f145a4f 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -135,4 +135,22 @@ void BKE_collection_object_add(struct Scene *UNUSED(scene), struct SceneCollecti
BLI_addtail(&sc->objects, BLI_genericNodeN(ob));
id_us_plus((ID *)ob);
TODO_LAYER_SYNC;
+ /* add the equivalent object base to all layers that have this collection */
+}
+
+/*
+ * Remove object from collection
+ */
+void BKE_collection_object_remove(struct Scene *UNUSED(scene), struct SceneCollection *sc, struct Object *ob)
+{
+
+ LinkData *link = BLI_findptr(&sc->objects, ob, offsetof(LinkData, data));
+ BLI_remlink(&sc->objects, link);
+ MEM_freeN(link);
+
+ id_us_min((ID *)ob);
+ TODO_LAYER_SYNC;
+
+ /* remove the equivalent object base to all layers that have this collection
+ * also remove all reference to ob in the filter_objects */
}
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 0766e80..a945239 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -2148,6 +2148,14 @@ static void rna_SceneCollection_filter_set(PointerRNA *ptr, const char *value)
(void)scene;
}
+static PointerRNA rna_SceneCollection_objects_get(CollectionPropertyIterator *iter)
+{
+ ListBaseIterator *internal = &iter->internal.listbase;
+
+ /* we are actually iterating a LinkData list, so override get */
+ return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((LinkData *)internal->link)->data);
+}
+
static SceneCollection *rna_SceneCollection_new(ID *id, SceneCollection *sc_parent, const char *name)
{
Scene *scene = (Scene *)id;
@@ -2184,6 +2192,43 @@ static void rna_SceneCollection_remove(
WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
}
+void rna_SceneCollection_object_link(
+ ID *id, SceneCollection *sc, Main *bmain, ReportList *reports, Object *ob)
+{
+ Scene *scene = (Scene *)id;
+
+ if (BLI_findptr(&sc->objects, ob, offsetof(LinkData, data))) {
+ BKE_reportf(reports, RPT_ERROR, "Object '%s' is already in collection '%s'", ob->id.name + 2, sc->name);
+ return;
+ }
+
+ BKE_collection_object_add(scene, sc, ob);
+
+ /* TODO(sergey): Only update relations for the current scene. */
+ DAG_relations_tag_update(bmain);
+ DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+
+ WM_main_add_notifier(NC_SCENE | ND_LAYER | ND_OB_ACTIVE, scene);
+}
+
+static void rna_SceneCollection_object_unlink(
+ ID *id, SceneCollection *sc, Main *bmain, ReportList *reports, Object *ob)
+{
+ Scene *scene = (Scene *)id;
+
+ if (!BLI_findptr(&sc->objects, ob, offsetof(LinkData, data))) {
+ BKE_reportf(reports, RPT_ERROR, "Object '%s' is not in collection '%s'", ob->id.name + 2, sc->name);
+ return;
+ }
+
+ BKE_collection_object_remove(scene, sc, ob);
+
+ /* needed otherwise the depgraph will contain freed objects which can crash, see [#20958] */
+ DAG_relations_tag_update(bmain);
+
+ WM_main_add_notifier(NC_SCENE | ND_LAYER | ND_OB_ACTIVE, scene);
+}
+
static void rna_SceneLayer_name_set(PointerRNA *ptr, const char *value)
{
Scene *scene = (Scene *)ptr->id.data;
@@ -5049,6 +5094,30 @@ static void rna_def_scene_collections(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
}
+static void rna_def_collection_objects(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ RNA_def_property_srna(cprop, "CollectionObjects");
+ srna = RNA_def_struct(brna, "CollectionObjects", NULL);
+ RNA_def_struct_sdna(srna, "SceneCollection");
+ RNA_def_struct_ui_text(srna, "Collection Objects", "Objects of a collection");
+
+ func = RNA_def_function(srna, "link", "rna_SceneCollection_object_link");
+ RNA_def_function_ui_description(func, "Link an object to collection");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN | FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "object", "Object", "", "Object to add to collection");
+ RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
+
+ func = RNA_def_function(srna, "unlink", "rna_SceneCollection_object_unlink");
+ RNA_def_function_ui_description(func, "Unlink object from collection");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN | FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "object", "Object", "", "Object to remove from collection");
+ RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
+}
+
static void rna_def_scene_collection(BlenderRNA *brna)
{
StructRNA *srna;
@@ -5074,9 +5143,18 @@ static void rna_def_scene_collection(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "SceneCollections", "");
rna_def_scene_collections(brna, prop);
-#if 0
- /* objects_filter, objects */
-#endif
+ prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "objects", NULL);
+ RNA_def_property_struct_type(prop, "Object");
+ RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, "rna_SceneCollection_objects_get", NULL, NULL, NULL, NULL);
+ RNA_def_property_ui_text(prop, "Objects", "All the objects directly added to this collection (not including sub-collection objects)");
+ rna_def_collection_objects(brna, prop);
+
+ prop = RNA_def_property(srna, "filters_objects", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "filter_objects", NULL);
+ RNA_def_property_struct_type(prop, "Object");
+ RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, "rna_SceneCollection_objects_get", NULL, NULL, NULL, NULL);
+ RNA_def_property_ui_text(prop, "Filter Objects", "All the objects dynamically added to this collection via the filter");
}
static void rna_def_scene_layer(BlenderRNA *brna)
More information about the Bf-blender-cvs
mailing list