Fix #20549: selecting a texture node in a material node tree would
keep that texture locked as the current visible texture in the texture buttons.
This commit is contained in:
@@ -87,14 +87,13 @@ class TEXTURE_PT_context_texture(TextureButtonsPanel):
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
slot = context.texture_slot
|
||||
node = context.texture_node
|
||||
space = context.space_data
|
||||
tex = context.texture
|
||||
wide_ui = context.region.width > narrowui
|
||||
idblock = context_tex_datablock(context)
|
||||
tex_collection = space.pin_id == None and type(idblock) != bpy.types.Brush
|
||||
|
||||
|
||||
tex_collection = space.pin_id == None and type(idblock) != bpy.types.Brush and not node
|
||||
|
||||
if tex_collection:
|
||||
row = layout.row()
|
||||
@@ -113,6 +112,8 @@ class TEXTURE_PT_context_texture(TextureButtonsPanel):
|
||||
|
||||
if tex_collection:
|
||||
col.template_ID(idblock, "active_texture", new="texture.new")
|
||||
elif node:
|
||||
col.template_ID(node, "texture", new="texture.new")
|
||||
elif idblock:
|
||||
col.template_ID(idblock, "texture", new="texture.new")
|
||||
|
||||
@@ -129,7 +130,6 @@ class TEXTURE_PT_context_texture(TextureButtonsPanel):
|
||||
split = layout.split(percentage=0.2)
|
||||
|
||||
if tex.use_nodes:
|
||||
slot = context.texture_slot
|
||||
|
||||
if slot:
|
||||
split.label(text="Output:")
|
||||
|
@@ -31,6 +31,7 @@
|
||||
#ifndef BKE_TEXTURE_H
|
||||
#define BKE_TEXTURE_H
|
||||
|
||||
struct bNode;
|
||||
struct Brush;
|
||||
struct ColorBand;
|
||||
struct EnvMap;
|
||||
@@ -75,6 +76,8 @@ struct Tex *give_current_lamp_texture(struct Lamp *la);
|
||||
struct Tex *give_current_world_texture(struct World *world);
|
||||
struct Tex *give_current_brush_texture(struct Brush *br);
|
||||
|
||||
struct bNode *give_current_material_texture_node(struct Material *ma);
|
||||
|
||||
int give_active_mtex(struct ID *id, struct MTex ***mtex_ar, short *act);
|
||||
void set_active_mtex(struct ID *id, short act);
|
||||
|
||||
|
@@ -858,6 +858,16 @@ void set_current_lamp_texture(Lamp *la, Tex *newtex)
|
||||
}
|
||||
}
|
||||
|
||||
bNode *give_current_material_texture_node(Material *ma)
|
||||
{
|
||||
bNode *node;
|
||||
|
||||
if(ma && ma->use_nodes && ma->nodetree)
|
||||
return nodeGetActiveID(ma->nodetree, ID_TE);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Tex *give_current_material_texture(Material *ma)
|
||||
{
|
||||
MTex *mtex= NULL;
|
||||
@@ -865,6 +875,9 @@ Tex *give_current_material_texture(Material *ma)
|
||||
bNode *node;
|
||||
|
||||
if(ma && ma->use_nodes && ma->nodetree) {
|
||||
/* first check texture, then material, this works together
|
||||
with a hack that clears the active ID flag for textures on
|
||||
making a material node active */
|
||||
node= nodeGetActiveID(ma->nodetree, ID_TE);
|
||||
|
||||
if(node) {
|
||||
@@ -877,6 +890,7 @@ Tex *give_current_material_texture(Material *ma)
|
||||
ma= (Material*)node->id;
|
||||
}
|
||||
}
|
||||
|
||||
if(ma) {
|
||||
mtex= ma->mtex[(int)(ma->texact)];
|
||||
if(mtex) tex= mtex->tex;
|
||||
|
@@ -35,6 +35,7 @@
|
||||
#include "DNA_lamp_types.h"
|
||||
#include "DNA_material_types.h"
|
||||
#include "DNA_modifier_types.h"
|
||||
#include "DNA_node_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_screen_types.h"
|
||||
@@ -399,7 +400,6 @@ static int buttons_context_path_texture(const bContext *C, ButsContextPath *path
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/* TODO: material nodes */
|
||||
|
||||
/* no path to a texture possible */
|
||||
return 0;
|
||||
@@ -648,13 +648,29 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
|
||||
|
||||
return 1;
|
||||
}
|
||||
else if(CTX_data_equals(member, "texture_node")) {
|
||||
PointerRNA *ptr;
|
||||
|
||||
if((ptr=get_pointer_type(path, &RNA_Material))) {
|
||||
Material *ma= ptr->data;
|
||||
|
||||
if(ma) {
|
||||
bNode *node= give_current_material_texture_node(ma);
|
||||
CTX_data_pointer_set(result, &ma->id, &RNA_Node, node);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
else if(CTX_data_equals(member, "texture_slot")) {
|
||||
PointerRNA *ptr;
|
||||
|
||||
if((ptr=get_pointer_type(path, &RNA_Material))) {
|
||||
Material *ma= ptr->data; /* should this be made a different option? */
|
||||
Material *ma_node= give_node_material(ma);
|
||||
ma= ma_node?ma_node:ma;
|
||||
Material *ma= ptr->data;
|
||||
|
||||
/* if we have a node material, get slot from material in material node */
|
||||
if(ma && ma->use_nodes && ma->nodetree)
|
||||
ma= give_node_material(ma);
|
||||
|
||||
if(ma)
|
||||
CTX_data_pointer_set(result, &ma->id, &RNA_MaterialTextureSlot, ma->mtex[(int)ma->texact]);
|
||||
|
@@ -433,12 +433,12 @@ void node_set_active(SpaceNode *snode, bNode *node)
|
||||
if(node->type!=NODE_GROUP) {
|
||||
/* tree specific activate calls */
|
||||
if(snode->treetype==NTREE_SHADER) {
|
||||
// XXX
|
||||
#if 0
|
||||
|
||||
/* when we select a material, active texture is cleared, for buttons */
|
||||
if(node->id && GS(node->id->name)==ID_MA)
|
||||
nodeClearActiveID(snode->edittree, ID_TE);
|
||||
|
||||
// XXX
|
||||
#if 0
|
||||
if(node->id)
|
||||
; // XXX BIF_preview_changed(-1); /* temp hack to force texture preview to update */
|
||||
|
||||
|
@@ -122,7 +122,7 @@ static int node_select_exec(bContext *C, wmOperator *op)
|
||||
|
||||
/* WATCH THIS, there are a few other ways to change the active material */
|
||||
if(node) {
|
||||
if (node->id && GS(node->id->name)== ID_MA) {
|
||||
if (node->id && ELEM(GS(node->id->name), ID_MA, ID_TE)) {
|
||||
WM_event_add_notifier(C, NC_MATERIAL|ND_SHADING_DRAW, node->id);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user