Commit: 0abcddf470d7254a80d11ddc9527f2c0937d6020
Author: Dalai Felinto
Date:   Wed Dec 21 12:27:50 2016 +0100
Branches: render-layers
https://developer.blender.org/rB0abcddf470d7254a80d11ddc9527f2c0937d6020

Syncing: update layercollection tree when a new scenecollection is added

===================================================================

M       source/blender/blenkernel/BKE_layer.h
M       source/blender/blenkernel/intern/collection.c
M       source/blender/blenkernel/intern/layer.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_layer.h 
b/source/blender/blenkernel/BKE_layer.h
index 090ab34..b450b38 100644
--- a/source/blender/blenkernel/BKE_layer.h
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -72,6 +72,12 @@ struct LayerCollection *BKE_collection_link(struct 
SceneLayer *sl, struct SceneC
 
 void BKE_collection_unlink(struct SceneLayer *sl, struct LayerCollection *lc);
 
+/* syncing */
+
+void BKE_layer_sync_new_scene_collection(struct Scene *scene, const struct 
SceneCollection *sc_parent, struct SceneCollection *sc);
+
+/* override */
+
 void BKE_collection_override_datablock_add(struct LayerCollection *lc, const 
char *data_path, struct ID *id);
 
 /* iterators */
diff --git a/source/blender/blenkernel/intern/collection.c 
b/source/blender/blenkernel/intern/collection.c
index e32fa4e..25763dd 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -55,7 +55,7 @@ SceneCollection *BKE_collection_add(Scene *scene, 
SceneCollection *sc_parent, co
 
        BLI_addtail(&sc_parent->scene_collections, sc);
 
-       TODO_LAYER_SYNC;
+       BKE_layer_sync_new_scene_collection(scene, sc_parent, sc);
        return sc;
 }
 
diff --git a/source/blender/blenkernel/intern/layer.c 
b/source/blender/blenkernel/intern/layer.c
index 6c58482..73e834b 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -343,6 +343,41 @@ LayerCollection *layer_collection_add(SceneLayer *sl, 
ListBase *lb, SceneCollect
        return lc;
 }
 
+
+/* ---------------------------------------------------------------------- */
+/* Syncing */
+
+static LayerCollection 
*find_layer_collection_by_scene_collection(LayerCollection *lc, const 
SceneCollection *sc)
+{
+       if (lc->scene_collection == sc) {
+               return lc;
+       }
+
+       for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = 
nlc->next) {
+               LayerCollection *found = 
find_layer_collection_by_scene_collection(nlc, sc);
+               if (found) {
+                       return found;
+               }
+       }
+       return NULL;
+}
+
+/**
+ * Add a new LayerCollection for all the SceneLayers that have sc_parent
+ */
+void BKE_layer_sync_new_scene_collection(Scene *scene, const SceneCollection 
*sc_parent, SceneCollection *sc)
+{
+       for (SceneLayer *sl = scene->render_layers.first; sl; sl = sl->next) {
+               for (LayerCollection *lc = sl->layer_collections.first; lc; lc 
= lc->next) {
+                       LayerCollection *lc_parent = 
find_layer_collection_by_scene_collection(lc, sc_parent);
+                       if (lc_parent) {
+                               layer_collection_add(sl, 
&lc_parent->layer_collections, sc);
+                       }
+               }
+       }
+}
+
+/* ---------------------------------------------------------------------- */
 /* Override */
 
 /**

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to