[Bf-blender-cvs] [89d2073] render-layers: layer.active_collection
Dalai Felinto
noreply at git.blender.org
Sat Dec 3 02:44:23 CET 2016
Commit: 89d20732a1fc279e9fcd531491ca5cc578bdf7e0
Author: Dalai Felinto
Date: Sat Dec 3 01:39:09 2016 +0100
Branches: render-layers
https://developer.blender.org/rB89d20732a1fc279e9fcd531491ca5cc578bdf7e0
layer.active_collection
This one is straight from the "layers" branch. I nailed it quite nicely there, so it was simply a matter of bringing it over :)
===================================================================
M source/blender/blenkernel/BKE_layer.h
M source/blender/blenkernel/intern/collection.c
M source/blender/blenkernel/intern/layer.c
M source/blender/makesrna/intern/rna_scene.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h
index d67304e..d3bb2b5 100644
--- a/source/blender/blenkernel/BKE_layer.h
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -49,6 +49,12 @@ void BKE_scene_layer_engine_set(struct SceneLayer *sl, const char *engine);
void BKE_layer_collection_free(struct SceneLayer *sl, struct LayerCollection *lc);
+struct LayerCollection *BKE_layer_collection_active(struct SceneLayer *sl);
+
+int BKE_layer_collection_count(struct SceneLayer *sl);
+
+int BKE_layer_collection_findindex(struct SceneLayer *sl, struct LayerCollection *lc);
+
struct LayerCollection *BKE_collection_link(struct SceneLayer *sl, struct SceneCollection *sc);
void BKE_collection_unlink(struct SceneLayer *sl, struct LayerCollection *lc);
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 1acb9e3..1a78084 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -144,6 +144,7 @@ bool BKE_collection_remove(Scene *scene, SceneCollection *sc)
/* check all layers that use this collection and clear them */
for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) {
layer_collection_remove(sl, &sl->collections, sc);
+ sl->active_collection = 0;
}
MEM_freeN(sc);
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index 5022f4e..924a6b2 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -157,6 +157,81 @@ void BKE_layer_collection_free(SceneLayer *sl, LayerCollection *lc)
}
}
+/* Recursively get the collection for a given index */
+static LayerCollection *collection_from_index(ListBase *lb, const int number, int *i)
+{
+ for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
+ if (*i == number) {
+ return lc;
+ }
+
+ (*i)++;
+
+ LayerCollection *lc_nested = collection_from_index(&lc->collections, number, i);
+ if (lc_nested) {
+ return lc_nested;
+ }
+ }
+ return NULL;
+}
+
+/*
+ * Get the active collection
+*/
+LayerCollection *BKE_layer_collection_active(SceneLayer *sl)
+{
+ int i = 0;
+ return collection_from_index(&sl->collections, sl->active_collection, &i);
+}
+
+/*
+ * Recursively get the count of collections
+*/
+static int collection_count(ListBase *lb)
+{
+ int i = 0;
+ for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
+ i += collection_count(&lc->collections) + 1;
+ }
+ return i;
+}
+
+/*
+ * Get the total number of collections
+ * (including all the nested collections)
+ */
+int BKE_layer_collection_count(SceneLayer *sl)
+{
+ return collection_count(&sl->collections);
+}
+
+/* Recursively get the index for a given collection */
+static int index_from_collection(ListBase *lb, LayerCollection *lc, int *i)
+{
+ for (LayerCollection *lcol = lb->first; lcol; lcol = lcol->next) {
+ if (lcol == lc) {
+ return *i;
+ }
+
+ (*i)++;
+
+ int i_nested = index_from_collection(&lcol->collections, lc, i);
+ if (i_nested != -1) {
+ return i_nested;
+ }
+ }
+ return -1;
+}
+
+/*
+ * Return -1 if not found
+ */
+int BKE_layer_collection_findindex(SceneLayer *sl, LayerCollection *lc)
+{
+ int i = 0;
+ return index_from_collection(&sl->collections, lc, &i);
+}
+
/*
* Link a collection to a renderlayer
* The collection needs to be created separately
@@ -177,6 +252,7 @@ void BKE_collection_unlink(SceneLayer *sl, LayerCollection *lc)
BLI_remlink(&sl->collections, lc);
MEM_freeN(lc);
+ sl->active_collection = 0;
}
static void object_base_populate(SceneLayer *sl, LayerCollection *lc, ListBase *objects)
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 3124924..da0cf40 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -2253,6 +2253,42 @@ static PointerRNA rna_LayerCollection_objects_get(CollectionPropertyIterator *it
return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, base->object);
}
+static int rna_LayerCollections_active_collection_index_get(PointerRNA *ptr)
+{
+ SceneLayer *sl = (SceneLayer *)ptr->data;
+ return sl->active_collection;
+}
+
+static void rna_LayerCollections_active_collection_index_set(PointerRNA *ptr, int value)
+{
+ SceneLayer *sl = (SceneLayer *)ptr->data;
+ int num_collections = BKE_layer_collection_count(sl);
+ sl->active_collection = min_ff(value, num_collections - 1);
+}
+
+static void rna_LayerCollections_active_collection_index_range(
+ PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
+{
+ SceneLayer *sl = (SceneLayer *)ptr->data;
+ *min = 0;
+ *max = max_ii(0, BKE_layer_collection_count(sl) - 1);
+}
+
+static PointerRNA rna_LayerCollections_active_collection_get(PointerRNA *ptr)
+{
+ SceneLayer *sl = (SceneLayer *)ptr->data;
+ LayerCollection *lc = BKE_layer_collection_active(sl);
+ return rna_pointer_inherit_refine(ptr, &RNA_LayerCollection, lc);
+}
+
+static void rna_LayerCollections_active_collection_set(PointerRNA *ptr, PointerRNA value)
+{
+ SceneLayer *sl = (SceneLayer *)ptr->data;
+ LayerCollection *lc = (LayerCollection *)value.data;
+ const int index = BKE_layer_collection_findindex(sl, lc);
+ if (index != -1) sl->active_collection = index;
+}
+
static void rna_SceneLayer_name_set(PointerRNA *ptr, const char *value)
{
Scene *scene = (Scene *)ptr->id.data;
@@ -5213,7 +5249,7 @@ static void rna_def_layer_collection(BlenderRNA *brna)
prop = RNA_def_property(srna, "collections", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "collections", NULL);
RNA_def_property_struct_type(prop, "LayerCollection");
- RNA_def_property_ui_text(prop, "LayerCollections", "");
+ RNA_def_property_ui_text(prop, "Layer Collections", "");
prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "object_bases", NULL);
@@ -5239,12 +5275,36 @@ static void rna_def_layer_collection(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Folded", "Folded collection");
RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, NULL);
-#if 0
- /* objects */
-#endif
/* TODO_LAYER_OVERRIDE */
}
+static void rna_def_layer_collections(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ RNA_def_property_srna(cprop, "LayerCollections");
+ srna = RNA_def_struct(brna, "LayerCollections", NULL);
+ RNA_def_struct_sdna(srna, "SceneLayer");
+ RNA_def_struct_ui_text(srna, "Layer Collections", "Collections of render layer");
+
+ prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_int_sdna(prop, NULL, "active_collection");
+ RNA_def_property_int_funcs(prop, "rna_LayerCollections_active_collection_index_get",
+ "rna_LayerCollections_active_collection_index_set",
+ "rna_LayerCollections_active_collection_index_range");
+ RNA_def_property_ui_text(prop, "Active Collection Index", "Active index in layer collection array");
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER, NULL);
+
+ prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "LayerCollection");
+ RNA_def_property_pointer_funcs(prop, "rna_LayerCollections_active_collection_get",
+ "rna_LayerCollections_active_collection_set", NULL, NULL);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
+ RNA_def_property_ui_text(prop, "Active Layer Collection", "Active Layer Collection");
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER, NULL);
+}
+
static void rna_def_scene_layer(BlenderRNA *brna)
{
StructRNA *srna;
@@ -5264,6 +5324,7 @@ static void rna_def_scene_layer(BlenderRNA *brna)
RNA_def_property_collection_sdna(prop, NULL, "collections", NULL);
RNA_def_property_struct_type(prop, "LayerCollection");
RNA_def_property_ui_text(prop, "Layer Collections", "");
+ rna_def_layer_collections(brna, prop);
prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "object_bases", NULL);
@@ -5272,7 +5333,7 @@ static void rna_def_scene_layer(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Objects", "All the objects in this layer");
#if 0
- /* engine, active_object, active collection, ... */
+ /* engine, active_object, ... */
#endif
}
More information about the Bf-blender-cvs
mailing list