Fixed the texture preview to work with multi-output node-based textures.
authorRobin Allen <roblovski@gmail.com>
Tue, 18 Aug 2009 19:58:27 +0000 (19:58 +0000)
committerRobin Allen <roblovski@gmail.com>
Tue, 18 Aug 2009 19:58:27 +0000 (19:58 +0000)
release/ui/buttons_texture.py
source/blender/editors/include/ED_previewrender.h
source/blender/editors/include/UI_interface.h
source/blender/editors/interface/interface.c
source/blender/editors/interface/interface_intern.h
source/blender/editors/interface/interface_templates.c
source/blender/editors/interface/interface_widgets.c
source/blender/editors/preview/previewrender.c
source/blender/editors/space_node/space_node.c
source/blender/makesrna/intern/rna_texture.c
source/blender/makesrna/intern/rna_ui_api.c

index 18c836f9080fe7abd20dc4d6be45f02e40bde50e..29e43981fd2d5b663cc6bc7457abef954f37d117 100644 (file)
@@ -17,21 +17,22 @@ class TEXTURE_PT_preview(TextureButtonsPanel):
                layout = self.layout
                
                tex = context.texture
+               slot = context.texture_slot
                ma = context.material
                la = context.lamp
                wo = context.world
                br = context.brush
                
                if ma:
-                       layout.template_preview(tex, parent=ma)
+                       layout.template_preview(tex, parent=ma, slot=slot)
                elif la:
-                       layout.template_preview(tex, parent=la)
+                       layout.template_preview(tex, parent=la, slot=slot)
                elif wo:
-                       layout.template_preview(tex, parent=wo)
+                       layout.template_preview(tex, parent=wo, slot=slot)
                elif br:
-                       layout.template_preview(tex, parent=br)
+                       layout.template_preview(tex, parent=br, slot=slot)
                else:
-                       layout.template_preview(tex)
+                       layout.template_preview(tex, slot=slot)
                        
 class TEXTURE_PT_context_texture(TextureButtonsPanel):
        __show_header__ = False
index 41cbecb53531126b819add87238af1c5045bb18a..7e0d71db7e115845db14d8547c8bdd408ddc7ad3 100644 (file)
@@ -34,6 +34,7 @@ struct Image;
 struct Render;
 struct bContext;
 struct ID;
+struct MTex;
 
 #define PREVIEW_RENDERSIZE 140
 
@@ -70,9 +71,9 @@ pr_method:
 void ED_preview_init_dbase(void);
 void ED_preview_free_dbase(void);
 
-void ED_preview_shader_job(const struct bContext *C, void *owner, struct ID *id, struct ID *parent, int sizex, int sizey);
+void ED_preview_shader_job(const struct bContext *C, void *owner, struct ID *id, struct ID *parent, struct MTex *slot, int sizex, int sizey);
 void ED_preview_iconrender(struct Scene *scene, struct ID *id, unsigned int *rect, int sizex, int sizey);
 
-void ED_preview_draw(const struct bContext *C, void *idp, void *parentp, rcti *rect);
+void ED_preview_draw(const struct bContext *C, void *idp, void *parentp, void *slot, rcti *rect);
 
 #endif
index 8da2702b603b5d2d8a9b7004da933d6eef2f0fd4..46da4b507a710e61fb1610b1dcfcbb9beff9249a 100644 (file)
@@ -60,6 +60,7 @@ struct Image;
 struct ImageUser;
 struct uiWidgetColors;
 struct Tex;
+struct MTex;
 
 typedef struct uiBut uiBut;
 typedef struct uiBlock uiBlock;
@@ -490,7 +491,7 @@ void        uiButSetNFunc           (uiBut *but,            uiButHandleNFunc func, void *argN, void *arg2)
 
 void   uiButSetCompleteFunc(uiBut *but,                uiButCompleteFunc func, void *arg);
 
-void   uiBlockSetDrawExtraFunc(uiBlock *block, void (*func)(const struct bContext *C, void *, void *, struct rcti *rect), void *arg);
+void   uiBlockSetDrawExtraFunc(uiBlock *block, void (*func)(const struct bContext *C, void *, void *, void *, struct rcti *rect), void *arg1, void *arg2);
 
 /* Autocomplete
  *
@@ -630,7 +631,7 @@ void uiTemplateID(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr,
        char *newop, char *unlinkop);
 uiLayout *uiTemplateModifier(uiLayout *layout, struct PointerRNA *ptr);
 uiLayout *uiTemplateConstraint(uiLayout *layout, struct PointerRNA *ptr);
-void uiTemplatePreview(uiLayout *layout, struct ID *id, struct ID *parent);
+void uiTemplatePreview(uiLayout *layout, struct ID *id, struct ID *parent, struct MTex *slot);
 void uiTemplateColorRamp(uiLayout *layout, struct ColorBand *coba, int expand);
 void uiTemplateCurveMapping(uiLayout *layout, struct CurveMapping *cumap, int type, int compact);
 void uiTemplateTriColorSet(uiLayout *layout, struct PointerRNA *ptr, char *propname);
index 4f6c6db3b16a5a46ae0e8c6d73992b3d4d5ebe50..92a3a4cf8412bb5aed1a79f58c1f4fcc31cbdbad 100644 (file)
@@ -2931,10 +2931,11 @@ void uiButSetRenameFunc(uiBut *but, uiButHandleRenameFunc func, void *arg1)
        but->rename_arg1= arg1;
 }
 
-void uiBlockSetDrawExtraFunc(uiBlock *block, void (*func)(const bContext *C, void *idv, void *argv, rcti *rect), void *arg)
+void uiBlockSetDrawExtraFunc(uiBlock *block, void (*func)(const bContext *C, void *idv, void *arg1, void *arg2, rcti *rect), void *arg1, void *arg2)
 {
        block->drawextra= func;
-       block->drawextra_arg= arg;
+       block->drawextra_arg1= arg1;
+       block->drawextra_arg2= arg2;
 }
 
 void uiButSetFunc(uiBut *but, uiButHandleFunc func, void *arg1, void *arg2)
index fbf95a4cde87de08816a5bda91c6e5b10274af43..9ef5d65b69f45b17cfdac33f7b917b24f1760f64 100644 (file)
@@ -273,8 +273,9 @@ struct uiBlock {
        int (*block_event_func)(const struct bContext *C, struct uiBlock *, struct wmEvent *);
        
        /* extra draw function for custom blocks */
-       void (*drawextra)(const struct bContext *C, void *idv, void *argv, rcti *rect);
-       void *drawextra_arg;
+       void (*drawextra)(const struct bContext *C, void *idv, void *arg1, void *arg2, rcti *rect);
+       void *drawextra_arg1;
+       void *drawextra_arg2;
 
        int afterval, flag;
        
index 0ee21cbcf77b9ec91f75dd33b304001241d8a7d2..0557512cc2a1c8e1e6dbd3df51a13ff909ce7ecb 100644 (file)
@@ -1088,7 +1088,7 @@ static void do_preview_buttons(bContext *C, void *arg, int event)
        }
 }
 
-void uiTemplatePreview(uiLayout *layout, ID *id, ID *parent)
+void uiTemplatePreview(uiLayout *layout, ID *id, ID *parent, MTex *slot)
 {
        uiLayout *row, *col;
        uiBlock *block;
@@ -1129,7 +1129,7 @@ void uiTemplatePreview(uiLayout *layout, ID *id, ID *parent)
        
        /* add preview */
        uiDefBut(block, BUT_EXTRA, 0, "", 0, 0, UI_UNIT_X*6, UI_UNIT_Y*6, pid, 0.0, 0.0, 0, 0, "");
-       uiBlockSetDrawExtraFunc(block, ED_preview_draw, pparent);
+       uiBlockSetDrawExtraFunc(block, ED_preview_draw, pparent, slot);
        uiBlockSetHandleFunc(block, do_preview_buttons, NULL);
        
        /* add buttons */
index cea3038b901fd69caf0bd2a65c473bbdc5ae4a28..2e0f0897af4a8b77e85ea4b4c4fee200728e4e38 100644 (file)
@@ -2065,7 +2065,7 @@ static void widget_draw_extra_mask(const bContext *C, uiBut *but, uiWidgetType *
        
        if(but->block->drawextra) {
                /* note: drawextra can change rect +1 or -1, to match round errors of existing previews */
-               but->block->drawextra(C, but->poin, but->block->drawextra_arg, rect);
+               but->block->drawextra(C, but->poin, but->block->drawextra_arg1, but->block->drawextra_arg2, rect);
                
                /* make mask to draw over image */
                UI_GetThemeColor3ubv(TH_BACK, col);
index 159e644bb390aa060242688cfce098648e7289f7..8fcf65202ee4fc3b72508329bb6cc9656465971e 100644 (file)
@@ -113,6 +113,7 @@ typedef struct ShaderPreview {
        Scene *scene;
        ID *id;
        ID *parent;
+       MTex *slot;
        
        int sizex, sizey;
        int *pr_rect;
@@ -364,6 +365,10 @@ static Scene *preview_prepare_scene(Scene *scene, ID *id, int id_type, ShaderPre
                                        Material *mat= give_current_material(base->object, base->object->actcol);
                                        if(mat && mat->mtex[0]) {
                                                mat->mtex[0]->tex= tex;
+                                               
+                                               if(sp && sp->slot)
+                                                       mat->mtex[0]->which_output = sp->slot->which_output;
+                                               
                                                /* show alpha in this case */
                                                if(tex==NULL || (tex->flag & TEX_PRV_ALPHA)) {
                                                        mat->mtex[0]->mapto |= MAP_ALPHA;
@@ -457,13 +462,14 @@ static int ed_preview_draw_rect(ScrArea *sa, Scene *sce, ID *id, int split, int
        return 0;
 }
 
-void ED_preview_draw(const bContext *C, void *idp, void *parentp, rcti *rect)
+void ED_preview_draw(const bContext *C, void *idp, void *parentp, void *slotp, rcti *rect)
 {
        if(idp) {
                ScrArea *sa= CTX_wm_area(C);
                Scene *sce = CTX_data_scene(C);
                ID *id = (ID *)idp;
                ID *parent= (ID *)parentp;
+               MTex *slot= (MTex *)slotp;
                SpaceButs *sbuts= sa->spacedata.first;
                rcti newrect;
                int ok;
@@ -491,7 +497,7 @@ void ED_preview_draw(const bContext *C, void *idp, void *parentp, rcti *rect)
                }
                
                if(ok==0) {
-                       ED_preview_shader_job(C, sa, id, parent, newx, newy);
+                       ED_preview_shader_job(C, sa, id, parent, slot, newx, newy);
                }
        }       
 }
@@ -932,7 +938,7 @@ static void shader_preview_free(void *customdata)
        MEM_freeN(sp);
 }
 
-void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, int sizex, int sizey)
+void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, MTex *slot, int sizex, int sizey)
 {
        wmJob *steve;
        ShaderPreview *sp;
@@ -952,6 +958,7 @@ void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, i
        sp->pr_method= PR_DO_RENDER;
        sp->id = id;
        sp->parent= parent;
+       sp->slot= slot;
        
        /* setup job */
        WM_jobs_customdata(steve, sp, shader_preview_free);
index 5db9d7331b80885bee752b92f054d2706dde2587..07277fe878d4e62919ec8308429abecc13077b2f 100644 (file)
@@ -174,7 +174,7 @@ static void node_area_refresh(const struct bContext *C, struct ScrArea *sa)
                if(snode->treetype==NTREE_SHADER) {
                        Material *ma= (Material *)snode->id;
                        if(ma->use_nodes)
-                               ED_preview_shader_job(C, sa, snode->id, NULL, 100, 100);
+                               ED_preview_shader_job(C, sa, snode->id, NULL, NULL, 100, 100);
                }
                else if(snode->treetype==NTREE_COMPOSIT) {
                        Scene *scene= (Scene *)snode->id;
index 76cb99863067ac053aceb61375c1a2782eb99f4f..a5737536b7d721fba6d647543df967f44aacf148 100644 (file)
@@ -110,6 +110,30 @@ static void rna_TextureSlot_name_get(PointerRNA *ptr, char *str)
                strcpy(str, "");
 }
 
+static int rna_TextureSlot_output_node_get(PointerRNA *ptr)
+{
+       MTex *mtex= ptr->data;
+       Tex *tex= mtex->tex;
+       int cur= mtex->which_output;
+       
+       if(tex) {
+               bNodeTree *ntree= tex->nodetree;
+               bNode *node;
+               if(ntree) {
+                       for(node= ntree->nodes.first; node; node= node->next) {
+                               if(node->type == TEX_NODE_OUTPUT) {
+                                       if(cur == node->custom1)
+                                               return cur;
+                               }
+                       }
+               }
+       }
+       
+       mtex->which_output= 0;
+       return 0;
+}
+
+
 static EnumPropertyItem *rna_TextureSlot_output_node_itemf(bContext *C, PointerRNA *ptr, int *free)
 {
        MTex *mtex= ptr->data;
@@ -117,11 +141,9 @@ static EnumPropertyItem *rna_TextureSlot_output_node_itemf(bContext *C, PointerR
        EnumPropertyItem *item= NULL;
        int totitem= 0;
        
-       if(tex)
-       {
+       if(tex) {
                bNodeTree *ntree= tex->nodetree;
-               if(ntree)
-               {
+               if(ntree) {
                        EnumPropertyItem tmp= {0, "", 0, "", ""};
                        bNode *node;
                        
@@ -433,7 +455,7 @@ static void rna_def_mtex(BlenderRNA *brna)
        prop= RNA_def_property(srna, "output_node", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "which_output");
        RNA_def_property_enum_items(prop, output_node_items);
-       RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_TextureSlot_output_node_itemf");
+       RNA_def_property_enum_funcs(prop, "rna_TextureSlot_output_node_get", NULL, "rna_TextureSlot_output_node_itemf");
        RNA_def_property_ui_text(prop, "Output Node", "Which output node to use, for node-based textures.");
        RNA_def_property_update(prop, NC_TEXTURE, NULL);
 }
index f9287bddc101f7ec9c84c6c8686e52c178f44812..82694098e699f489ab72c5c7fefeb22b9712a941 100644 (file)
@@ -244,6 +244,7 @@ void RNA_api_ui_layout(StructRNA *srna)
        parm= RNA_def_pointer(func, "id", "ID", "", "ID datablock.");
        RNA_def_property_flag(parm, PROP_REQUIRED);
        parm= RNA_def_pointer(func, "parent", "ID", "", "ID datablock.");
+       parm= RNA_def_pointer(func, "slot", "TextureSlot", "", "Texture slot.");
 
        func= RNA_def_function(srna, "template_curve_mapping", "uiTemplateCurveMapping");
        parm= RNA_def_pointer(func, "curvemap", "CurveMapping", "", "Curve mapping pointer.");