Fixed the texture preview to work with multi-output node-based textures.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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.");
|
||||
|
||||
Reference in New Issue
Block a user