Partial revert of r46542.
authorLukas Toenne <lukas.toenne@googlemail.com>
Fri, 18 May 2012 09:26:55 +0000 (09:26 +0000)
committerLukas Toenne <lukas.toenne@googlemail.com>
Fri, 18 May 2012 09:26:55 +0000 (09:26 +0000)
Displaying image layers with flattened names (render_layer.render_pass) can lead to extremely long socket lists, especially with older files that were used with distinct render layers before. In general the flattening of names would be preferable, but it needs a sensible way of limiting the number of displayed outputs. For now the render layer dropdown selection is the best option to ensure usability.

source/blender/blenloader/intern/readfile.c
source/blender/compositor/nodes/COM_ImageNode.cpp
source/blender/editors/space_node/drawnode.c
source/blender/makesdna/DNA_node_types.h
source/blender/makesrna/intern/rna_nodetree.c
source/blender/nodes/composite/nodes/node_composite_image.c

index 20f53af..62e2cd8 100644 (file)
@@ -6855,13 +6855,10 @@ static void do_versions_nodetree_image_layer_2_64_5(bNodeTree *ntree)
        
        for (node = ntree->nodes.first; node; node = node->next) {
                if (node->type == CMP_NODE_IMAGE) {
-                       ImageUser *iuser = (ImageUser *)node->storage;
                        bNodeSocket *sock;
                        for (sock = node->outputs.first; sock; sock = sock->next) {
                                NodeImageLayer *output = MEM_callocN(sizeof(NodeImageLayer), "node image layer");
                                
-                               /* take layer index from image user (this is ignored from now on) */
-                               output->layer_index = iuser->layer;
                                /* take pass index both from current storage ptr (actually an int) */
                                output->pass_index = GET_INT_FROM_POINTER(sock->storage);
                                
index cc2f5f6..5300d2d 100644 (file)
@@ -71,23 +71,21 @@ void ImageNode::convertToOperations(ExecutionSystem *graph, CompositorContext *
        if (image && image->type==IMA_TYPE_MULTILAYER) {
                BKE_image_get_ibuf(image, imageuser);
                if (image->rr) {
-                       OutputSocket * socket;
-                       int index;
-                       for (index = 0 ; index < numberOfOutputs ; index ++) {
-                               socket = this->getOutputSocket(index);
-                               if (socket->isConnected() || index == 0) {
-                                       bNodeSocket *bnodeSocket = socket->getbNodeSocket();
-                                       NodeImageLayer *storage = (NodeImageLayer*)bnodeSocket->storage;
-                                       int passindex = storage->pass_index;
-                                       int layerindex = storage->layer_index;
-                                       RenderLayer *rl = (RenderLayer*)BLI_findlink(&image->rr->layers, layerindex);
-                                       if (rl) {
-                                       
+                       RenderLayer *rl = (RenderLayer*)BLI_findlink(&image->rr->layers, imageuser->layer);
+                       if (rl) {
+                               OutputSocket * socket;
+                               int index;
+                               for (index = 0 ; index < numberOfOutputs ; index ++) {
+                                       socket = this->getOutputSocket(index);
+                                       if (socket->isConnected() || index == 0) {
+                                               bNodeSocket *bnodeSocket = socket->getbNodeSocket();
+                                               NodeImageLayer *storage = (NodeImageLayer*)bnodeSocket->storage;
+                                               int passindex = storage->pass_index;
+                                               
                                                RenderPass *rpass = (RenderPass *)BLI_findlink(&rl->passes, passindex);
                                                if (rpass) {
                                                        NodeOperation * operation = NULL;
                                                        imageuser->pass = passindex;
-                                                       imageuser->layer = layerindex;
                                                        switch (rpass->channels) {
                                                        case 1:
                                                                operation = doMultilayerCheck(graph, rl, image, imageuser, framenumber, index, passindex, COM_DT_VALUE);
index d9fc793..ac12f2f 100644 (file)
@@ -1262,6 +1262,9 @@ static void node_composit_buts_image(uiLayout *layout, bContext *C, PointerRNA *
        }
 
        col= uiLayoutColumn(layout, 0);
+
+       if (RNA_enum_get(&imaptr, "type")== IMA_TYPE_MULTILAYER)
+               uiItemR(col, ptr, "layer", 0, NULL, ICON_NONE);
 }
 
 static void node_composit_buts_renderlayers(uiLayout *layout, bContext *C, PointerRNA *ptr)
index 077c401..4bbd1e2 100644 (file)
@@ -398,8 +398,8 @@ typedef struct NodeEllipseMask {
 
 /* layer info for image node outputs */
 typedef struct NodeImageLayer {
-       /* index in the Image->layers and Image->layers->passes lists */
-       int layer_index, pass_index;
+       /* index in the Image->layers->passes lists */
+       int pass_index;
        /* render pass flag, in case this is an original render pass */
        int pass_flag;
 } NodeImageLayer;
index 6c8293f..b341249 100644 (file)
@@ -492,6 +492,18 @@ static void rna_NodeSocketVector_range(PointerRNA *ptr, float *min, float *max,
        *softmax = val->max;
 }
 
+static void rna_Node_image_layer_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+       bNode *node = (bNode*)ptr->data;
+       Image *ima = (Image *)node->id;
+       ImageUser *iuser = node->storage;
+       
+       BKE_image_multilayer_index(ima->rr, iuser);
+       BKE_image_signal(ima, iuser, IMA_SIGNAL_SRC_CHANGE);
+       
+       rna_Node_update(bmain, scene, ptr);
+}
+
 static EnumPropertyItem *renderresult_layers_add_enum(RenderLayer *rl)
 {
        EnumPropertyItem *item = NULL;
@@ -511,6 +523,24 @@ static EnumPropertyItem *renderresult_layers_add_enum(RenderLayer *rl)
        return item;
 }
 
+static EnumPropertyItem *rna_Node_image_layer_itemf(bContext *UNUSED(C), PointerRNA *ptr,
+                                                    PropertyRNA *UNUSED(prop), int *free)
+{
+       bNode *node = (bNode*)ptr->data;
+       Image *ima = (Image *)node->id;
+       EnumPropertyItem *item = NULL;
+       RenderLayer *rl;
+       
+       if (!ima || !(ima->rr)) return NULL;
+       
+       rl = ima->rr->layers.first;
+       item = renderresult_layers_add_enum(rl);
+       
+       *free = 1;
+       
+       return item;
+}
+
 static EnumPropertyItem *rna_Node_scene_layer_itemf(bContext *UNUSED(C), PointerRNA *ptr,
                                                     PropertyRNA *UNUSED(prop), int *free)
 {
@@ -897,6 +927,10 @@ static void rna_NodeOutputFileSlotLayer_name_set(PointerRNA *ptr, const char *va
 
 #else
 
+static EnumPropertyItem prop_image_layer_items[] = {
+{ 0, "PLACEHOLDER",          0, "Placeholder",          ""},
+{0, NULL, 0, NULL, NULL}};
+
 static EnumPropertyItem prop_scene_layer_items[] = {
 { 0, "PLACEHOLDER",          0, "Placeholder",          ""},
 {0, NULL, 0, NULL, NULL}};
@@ -1816,6 +1850,13 @@ static void def_cmp_image(StructRNA *srna)
                /* copied from the rna_image.c */
        RNA_def_property_ui_text(prop, "Auto-Refresh", "Always refresh image on frame changes");
        RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_update");
+
+       prop = RNA_def_property(srna, "layer", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "layer");
+       RNA_def_property_enum_items(prop, prop_image_layer_items);
+       RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Node_image_layer_itemf");
+       RNA_def_property_ui_text(prop, "Layer", "");
+       RNA_def_property_update(prop, NC_NODE|NA_EDITED, "rna_Node_image_layer_update");
 }
 
 static void def_cmp_render_layers(StructRNA *srna)
index ad1264a..70d6873 100644 (file)
@@ -145,37 +145,26 @@ static void cmp_node_image_add_render_pass_outputs(bNodeTree *ntree, bNode *node
                cmp_node_image_add_render_pass_output(ntree, node, SCE_PASS_TRANSM_COLOR, RRES_OUT_TRANSM_COLOR);
 }
 
-static void cmp_node_image_add_multilayer_outputs(bNodeTree *ntree, bNode *node, ListBase *layers)
+static void cmp_node_image_add_multilayer_outputs(bNodeTree *ntree, bNode *node, RenderLayer *rl)
 {
        bNodeSocket *sock;
        NodeImageLayer *sockdata;
-       RenderLayer *rl;
        RenderPass *rpass;
-       int layer_index, pass_index;
-       char name[30];  /* EXR_TOT_MAXNAME-2 ('.' and channel char are appended) */
-       int type;
-       
-       for (rl=layers->first, layer_index=0; rl; rl=rl->next, ++layer_index) {
-               for (rpass=rl->passes.first, pass_index=0; rpass; rpass=rpass->next, ++pass_index) {
-                       /* reconstruct layer name from <render layer>.<render pass> strings */
-                       if (rl->name[0] != '\0')
-                               BLI_snprintf(name, sizeof(name), "%s.%s", rl->name, rpass->name);
-                       else
-                               BLI_strncpy(name, rpass->name, sizeof(name));
-                       
-                       if (rpass->channels == 1)
-                               type = SOCK_FLOAT;
-                       else
-                               type = SOCK_RGBA;
-                       
-                       sock = nodeAddSocket(ntree, node, SOCK_OUT, name, type);
-                       /* extra socket info */
-                       sockdata = MEM_callocN(sizeof(NodeImageLayer), "node image layer");
-                       sock->storage = sockdata;
-                       
-                       sockdata->layer_index = layer_index;
-                       sockdata->pass_index = pass_index;
-               }
+       int index;
+       for (rpass=rl->passes.first, index=0; rpass; rpass=rpass->next, ++index) {
+               int type;
+               if (rpass->channels == 1)
+                       type = SOCK_FLOAT;
+               else
+                       type = SOCK_RGBA;
+               
+               sock = nodeAddSocket(ntree, node, SOCK_OUT, rpass->name, type);
+               /* extra socket info */
+               sockdata = MEM_callocN(sizeof(NodeImageLayer), "node image layer");
+               sock->storage = sockdata;
+               
+               sockdata->pass_index = index;
+               sockdata->pass_flag = rpass->passtype;
        }
 }
 
@@ -189,16 +178,16 @@ static void cmp_node_image_create_outputs(bNodeTree *ntree, bNode *node)
                BKE_image_get_ibuf(ima, iuser);
                
                if (ima->rr) {
-                       if (ima->type == IMA_TYPE_MULTILAYER) {
-                               cmp_node_image_add_multilayer_outputs(ntree, node, &ima->rr->layers);
-                       }
-                       else {
-                               RenderLayer *rl= BLI_findlink(&ima->rr->layers, iuser->layer);
-                               if (rl)
+                       RenderLayer *rl= BLI_findlink(&ima->rr->layers, iuser->layer);
+                       
+                       if (rl) {
+                               if (ima->type!=IMA_TYPE_MULTILAYER)
                                        cmp_node_image_add_render_pass_outputs(ntree, node, rl->passflag);
                                else
-                                       cmp_node_image_add_render_pass_outputs(ntree, node, RRES_OUT_IMAGE|RRES_OUT_ALPHA);
+                                       cmp_node_image_add_multilayer_outputs(ntree, node, rl);
                        }
+                       else
+                               cmp_node_image_add_render_pass_outputs(ntree, node, RRES_OUT_IMAGE|RRES_OUT_ALPHA);
                }
                else
                        cmp_node_image_add_render_pass_outputs(ntree, node, RRES_OUT_IMAGE|RRES_OUT_ALPHA|RRES_OUT_Z);
@@ -415,28 +404,23 @@ static CompBuf *node_composit_get_zimage(bNode *node, RenderData *rd)
 }
 
 /* check if layer is available, returns pass buffer */
-static CompBuf *compbuf_multilayer_get(RenderData *rd, Image *ima, ImageUser *iuser, int layer_index, int pass_index)
+static CompBuf *compbuf_multilayer_get(RenderData *rd, RenderLayer *rl, Image *ima, ImageUser *iuser, int passindex)
 {
-       RenderLayer *rl = BLI_findlink(&ima->rr->layers, layer_index);
-       if (rl) {
-               RenderPass *rpass = BLI_findlink(&rl->passes, pass_index);
-               if (rpass) {
-                       CompBuf *cbuf;
-                       
-                       iuser->layer = layer_index;
-                       iuser->pass = pass_index;
-                       BKE_image_multilayer_index(ima->rr, iuser);
-                       cbuf = node_composit_get_image(rd, ima, iuser);
-                       
-                       return cbuf;
-               }
+       RenderPass *rpass = BLI_findlink(&rl->passes, passindex);
+       if (rpass) {
+               CompBuf *cbuf;
+               
+               iuser->pass = passindex;
+               BKE_image_multilayer_index(ima->rr, iuser);
+               cbuf = node_composit_get_image(rd, ima, iuser);
+               
+               return cbuf;
        }
        return NULL;
 }
 
 static void node_composit_exec_image(void *data, bNode *node, bNodeStack **UNUSED(in), bNodeStack **out)
 {
-       
        /* image assigned to output */
        /* stack order input sockets: col, alpha */
        if (node->id) {
@@ -447,11 +431,14 @@ static void node_composit_exec_image(void *data, bNode *node, bNodeStack **UNUSE
                /* first set the right frame number in iuser */
                BKE_image_user_frame_calc(iuser, rd->cfra, 0);
                
-               if (ima->type==IMA_TYPE_MULTILAYER) {
-                       /* force a load, we assume iuser index will be set OK anyway */
+               /* force a load, we assume iuser index will be set OK anyway */
+               if (ima->type==IMA_TYPE_MULTILAYER)
                        BKE_image_get_ibuf(ima, iuser);
                
-                       if (ima->rr) {
+               if (ima->type==IMA_TYPE_MULTILAYER && ima->rr) {
+                       RenderLayer *rl= BLI_findlink(&ima->rr->layers, iuser->layer);
+                       
+                       if (rl) {
                                bNodeSocket *sock;
                                NodeImageLayer *sockdata;
                                int out_index;
@@ -460,7 +447,7 @@ static void node_composit_exec_image(void *data, bNode *node, bNodeStack **UNUSE
                                for (sock=node->outputs.first, out_index=0; sock; sock=sock->next, ++out_index) {
                                        sockdata = sock->storage;
                                        if (out[out_index]->hasoutput) {
-                                               CompBuf *stackbuf = out[out_index]->data = compbuf_multilayer_get(rd, ima, iuser, sockdata->layer_index, sockdata->pass_index);
+                                               CompBuf *stackbuf = out[out_index]->data = compbuf_multilayer_get(rd, rl, ima, iuser, sockdata->pass_index);
                                                if (stackbuf) {
                                                        /* preview policy: take first 'Combined' pass if available,
                                                         * otherwise just use the first layer.
@@ -469,7 +456,7 @@ static void node_composit_exec_image(void *data, bNode *node, bNodeStack **UNUSE
                                                                firstbuf = stackbuf;
                                                        }
                                                        if (!combinedbuf &&
-                                                                       (strcmp(sock->name, "Combined") == 0 || strcmp(sock->name, "Image") == 0))
+                                                           (strcmp(sock->name, "Combined") == 0 || strcmp(sock->name, "Image") == 0))
                                                        {
                                                                combinedbuf = stackbuf;
                                                        }