Bugfix 18671 revisted

Node editor didn't support editing non-material texture node trees.
Campbell pointed me to fact it's been used already, like for brush
painting. However, this only worked via linking the texture to a
material... hackish stuff.

Now the Node Editor supports all other Textures too, with three extra
icon buttons to define which.

- Active Object: for textures linked to Materials or Lamps
- World: textures from Scene world.
- Brush: textures from active Brush 

The latter can only be set and used when in Paint or Sculpt mode:

- Paint mode: in Image window, Paint Tool panel, set active brush
- Sculpt mode: in EditButtons, Texture panel, select empty slot, add texture.

Note that refreshes of previews in Node Editor is not always happening on
switching contextes. Just click a socket to refresh view.
This commit is contained in:
Ton Roosendaal 2009-05-03 13:22:26 +00:00
parent c35299363f
commit 56b8ce2ec1
4 changed files with 63 additions and 10 deletions

@ -356,7 +356,8 @@ typedef struct SpaceNode {
float xof, yof; /* offset for drawing the backdrop */
struct bNodeTree *nodetree, *edittree;
int treetype, pad; /* treetype: as same nodetree->type */
int treetype; /* treetype: as same nodetree->type */
short texfrom, pad; /* texfrom object, world or brush */
struct bGPdata *gpd; /* grease-pencil data */
} SpaceNode;
@ -366,6 +367,11 @@ typedef struct SpaceNode {
#define SNODE_BACKDRAW 2
#define SNODE_DISPGP 4
/* snode->texfrom */
#define SNODE_TEX_OBJECT 0
#define SNODE_TEX_WORLD 1
#define SNODE_TEX_BRUSH 2
typedef struct SpaceImaSel {
SpaceLink *next, *prev;
int spacetype;

@ -1705,8 +1705,7 @@ static void texture_panel_texture(MTex *actmtex, Material *ma, World *wrld, Lamp
uiDefButS(block, MENU, B_TEXTYPE, textypes, 160, 125, 140, 25, &tex->type, 0,0,0,0, "Select texture type");
}
if(ma)
uiDefButC(block, TOG, B_TEX_USENODES, "Nodes", 160, 100, 140, 25, &tex->use_nodes, 0.0f, 0.0f, 0, 0, "");
uiDefButC(block, TOG, B_TEX_USENODES, "Nodes", 160, 100, 140, 25, &tex->use_nodes, 0.0f, 0.0f, 0, 0, "");
}
else {

@ -35,6 +35,7 @@
#include "MEM_guardedalloc.h"
#include "DNA_action_types.h"
#include "DNA_brush_types.h"
#include "DNA_color_types.h"
#include "DNA_image_types.h"
#include "DNA_ipo_types.h"
@ -583,14 +584,42 @@ void snode_set_context(SpaceNode *snode)
snode->nodetree= G.scene->nodetree;
}
else if(snode->treetype==NTREE_TEXTURE) {
if(ob) {
Tex *tx= give_current_texture(ob, ob->actcol);
if(tx) {
snode->from= (ID*)ob; /* please check this; i have no idea what 'from' is. */
snode->id= &tx->id;
snode->nodetree= tx->nodetree;
Tex *tx= NULL;
if(snode->texfrom==SNODE_TEX_OBJECT) {
if(ob) {
tx= give_current_texture(ob, ob->actcol);
snode->from= (ID *)ob;
}
}
else if(snode->texfrom==SNODE_TEX_WORLD) {
tx= give_current_world_texture();
snode->from= (ID *)G.scene->world;
}
else {
MTex *mtex= NULL;
if(G.f & G_SCULPTMODE) {
SculptData *sd= &G.scene->sculptdata;
if(sd->texact != -1)
mtex= sd->mtex[sd->texact];
}
else {
Brush *br= G.scene->toolsettings->imapaint.brush;
if(br)
mtex= br->mtex[br->texact];
}
if(mtex) {
snode->from= (ID *)G.scene;
tx= mtex->tex;
}
}
if(tx) {
snode->id= &tx->id;
snode->nodetree= tx->nodetree;
}
}
/* find editable group */

@ -756,8 +756,26 @@ void node_buttons(ScrArea *sa)
uiDefIconButI(block, ROW, B_REDR, ICON_TEXTURE_DEHLT, xco,2,XIC,YIC-2,
&(snode->treetype), 2, 2, 0, 0, "Texture Nodes");
xco+= 2*XIC;
uiBlockEndAlign(block);
if(snode->treetype==NTREE_TEXTURE) {
uiBlockBeginAlign(block);
uiDefIconButS(block, ROW, B_REDR, ICON_OBJECT, xco,2,XIC,YIC-2,
&(snode->texfrom), 3, SNODE_TEX_OBJECT, 0, 0, "Texture Nodes from Object");
xco+= XIC;
uiDefIconButS(block, ROW, B_REDR, ICON_WORLD_DEHLT, xco,2,XIC,YIC-2,
&(snode->texfrom), 3, SNODE_TEX_WORLD, 0, 0, "Texture Nodes from World");
xco+= XIC;
uiDefIconButS(block, ROW, B_REDR, ICON_TPAINT_DEHLT, xco,2,XIC,YIC-2,
&(snode->texfrom), 3, SNODE_TEX_BRUSH, 0, 0, "Texture Nodes from Active Brush or Sculpt Data");
xco+= 2*XIC;
uiBlockEndAlign(block);
}
/* find and set the context */
snode_set_context(snode);
@ -785,8 +803,9 @@ void node_buttons(ScrArea *sa)
else if(snode->treetype==NTREE_TEXTURE) {
if(snode->from) {
/* can't use unlink etc here, code requires buttons context */
xco= std_libbuttons(block, xco, 0, 0, NULL, B_TEXBROWSE, ID_TE, 1, snode->id, snode->from, &(snode->menunr),
B_TEXALONE, B_TEXLOCAL, B_TEXDELETE, B_AUTOTEXNAME, B_KEEPDATA);
0, 0, 0, B_AUTOTEXNAME, B_KEEPDATA);
if(snode->id) {
Tex *tx= (Tex *)snode->id;