diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-10-12 17:12:45 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-10-12 17:12:45 +0400 |
commit | f1a0df22df7b929601db58db5ecb77ed82bf8361 (patch) | |
tree | 106260cd3e3753debf685a0434078a3a3f1cf238 /source/blender/blenkernel | |
parent | e36003e8e73e42e7b559d4cec19b9004d14fefa6 (diff) |
Bugfix: texture nodes header was still showing wrong texture
when using node materials.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_texture.h | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/texture.c | 105 |
2 files changed, 110 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_texture.h b/source/blender/blenkernel/BKE_texture.h index 407dc94adfa..c7a6e20cc8b 100644 --- a/source/blender/blenkernel/BKE_texture.h +++ b/source/blender/blenkernel/BKE_texture.h @@ -75,6 +75,11 @@ 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); +void set_current_brush_texture(struct Brush *br, struct Tex *tex); +void set_current_world_texture(struct World *wo, struct Tex *tex); +void set_current_material_texture(struct Material *ma, struct Tex *tex); +void set_current_lamp_texture(struct Lamp *la, struct Tex *tex); + struct TexMapping *add_mapping(void); void init_mapping(struct TexMapping *texmap); diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index f09abf93bb8..d1c26b5a1b4 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -840,6 +840,28 @@ Tex *give_current_lamp_texture(Lamp *la) return tex; } +void set_current_lamp_texture(Lamp *la, Tex *newtex) +{ + int act= la->texact; + + if(la->mtex[act] && la->mtex[act]->tex) + id_us_min(&la->mtex[act]->tex->id); + + if(newtex) { + if(!la->mtex[act]) { + la->mtex[act]= add_mtex(); + la->mtex[act]->texco= TEXCO_GLOB; + } + + la->mtex[act]->tex= newtex; + id_us_plus(&newtex->id); + } + else if(la->mtex[act]) { + MEM_freeN(la->mtex[act]); + la->mtex[act]= NULL; + } +} + Tex *give_current_material_texture(Material *ma) { MTex *mtex= NULL; @@ -867,6 +889,47 @@ Tex *give_current_material_texture(Material *ma) return tex; } +void set_current_material_texture(Material *ma, Tex *newtex) +{ + Tex *tex= NULL; + bNode *node; + + if(ma && ma->use_nodes && ma->nodetree) { + node= nodeGetActiveID(ma->nodetree, ID_TE); + + if(node) { + tex= (Tex *)node->id; + id_us_min(&tex->id); + node->id= &newtex->id; + id_us_plus(&newtex->id); + ma= NULL; + } + else { + node= nodeGetActiveID(ma->nodetree, ID_MA); + if(node) + ma= (Material*)node->id; + } + } + if(ma) { + int act= (int)ma->texact; + + tex= (ma->mtex[act])? ma->mtex[act]->tex: NULL; + id_us_min(&tex->id); + + if(newtex) { + if(!ma->mtex[act]) + ma->mtex[act]= add_mtex(); + + ma->mtex[act]->tex= newtex; + id_us_plus(&newtex->id); + } + else if(ma->mtex[act]) { + MEM_freeN(ma->mtex[act]); + ma->mtex[act]= NULL; + } + } +} + Tex *give_current_world_texture(World *world) { MTex *mtex= NULL; @@ -880,6 +943,28 @@ Tex *give_current_world_texture(World *world) return tex; } +void set_current_world_texture(World *wo, Tex *newtex) +{ + int act= wo->texact; + + if(wo->mtex[act] && wo->mtex[act]->tex) + id_us_min(&wo->mtex[act]->tex->id); + + if(newtex) { + if(!wo->mtex[act]) { + wo->mtex[act]= add_mtex(); + wo->mtex[act]->texco= TEXCO_VIEW; + } + + wo->mtex[act]->tex= newtex; + id_us_plus(&newtex->id); + } + else if(wo->mtex[act]) { + MEM_freeN(wo->mtex[act]); + wo->mtex[act]= NULL; + } +} + Tex *give_current_brush_texture(Brush *br) { MTex *mtex= NULL; @@ -893,6 +978,26 @@ Tex *give_current_brush_texture(Brush *br) return tex; } +void set_current_brush_texture(Brush *br, Tex *newtex) +{ + int act= br->texact; + + if(br->mtex[act] && br->mtex[act]->tex) + id_us_min(&br->mtex[act]->tex->id); + + if(newtex) { + if(!br->mtex[act]) + br->mtex[act]= add_mtex(); + + br->mtex[act]->tex= newtex; + id_us_plus(&newtex->id); + } + else if(br->mtex[act]) { + MEM_freeN(br->mtex[act]); + br->mtex[act]= NULL; + } +} + /* ------------------------------------------------------------------------- */ EnvMap *BKE_add_envmap(void) |