Bugfix: texture nodes header was still showing wrong texture

when using node materials.
This commit is contained in:
Brecht Van Lommel
2009-10-12 13:12:45 +00:00
parent e36003e8e7
commit f1a0df22df
6 changed files with 118 additions and 68 deletions

View File

@@ -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);

View File

@@ -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)

View File

@@ -65,29 +65,15 @@ static PointerRNA rna_Brush_active_texture_get(PointerRNA *ptr)
Brush *br= (Brush*)ptr->data;
Tex *tex;
tex= (br->mtex[(int)br->texact])? br->mtex[(int)br->texact]->tex: NULL;
tex= give_current_brush_texture(br);
return rna_pointer_inherit_refine(ptr, &RNA_Texture, tex);
}
static void rna_Brush_active_texture_set(PointerRNA *ptr, PointerRNA value)
{
Brush *br= (Brush*)ptr->data;
int act= br->texact;
if(br->mtex[act] && br->mtex[act]->tex)
id_us_min(&br->mtex[act]->tex->id);
if(value.data) {
if(!br->mtex[act])
br->mtex[act]= add_mtex();
br->mtex[act]->tex= value.data;
id_us_plus(&br->mtex[act]->tex->id);
}
else if(br->mtex[act]) {
MEM_freeN(br->mtex[act]);
br->mtex[act]= NULL;
}
set_current_brush_texture(br, value.data);
}
static void rna_Brush_update(bContext *C, PointerRNA *ptr)

View File

@@ -69,31 +69,15 @@ static PointerRNA rna_Lamp_active_texture_get(PointerRNA *ptr)
Lamp *la= (Lamp*)ptr->data;
Tex *tex;
tex= (la->mtex[(int)la->texact])? la->mtex[(int)la->texact]->tex: NULL;
tex= give_current_lamp_texture(la);
return rna_pointer_inherit_refine(ptr, &RNA_Texture, tex);
}
static void rna_Lamp_active_texture_set(PointerRNA *ptr, PointerRNA value)
{
Lamp *la= (Lamp*)ptr->data;
int act= la->texact;
if(la->mtex[act] && la->mtex[act]->tex)
id_us_min(&la->mtex[act]->tex->id);
if(value.data) {
if(!la->mtex[act]) {
la->mtex[act]= add_mtex();
la->mtex[act]->texco= TEXCO_GLOB;
}
la->mtex[act]->tex= value.data;
id_us_plus(&la->mtex[act]->tex->id);
}
else if(la->mtex[act]) {
MEM_freeN(la->mtex[act]);
la->mtex[act]= NULL;
}
set_current_lamp_texture(la, value.data);
}
static StructRNA* rna_Lamp_refine(struct PointerRNA *ptr)

View File

@@ -130,29 +130,15 @@ static PointerRNA rna_Material_active_texture_get(PointerRNA *ptr)
Material *ma= (Material*)ptr->data;
Tex *tex;
tex= (ma->mtex[(int)ma->texact])? ma->mtex[(int)ma->texact]->tex: NULL;
tex= give_current_material_texture(ma);
return rna_pointer_inherit_refine(ptr, &RNA_Texture, tex);
}
static void rna_Material_active_texture_set(PointerRNA *ptr, PointerRNA value)
{
Material *ma= (Material*)ptr->data;
int act= ma->texact;
if(ma->mtex[act] && ma->mtex[act]->tex)
id_us_min(&ma->mtex[act]->tex->id);
if(value.data) {
if(!ma->mtex[act])
ma->mtex[act]= add_mtex();
ma->mtex[act]->tex= value.data;
id_us_plus(&ma->mtex[act]->tex->id);
}
else if(ma->mtex[act]) {
MEM_freeN(ma->mtex[act]);
ma->mtex[act]= NULL;
}
set_current_material_texture(ma, value.data);
}
static PointerRNA rna_Material_active_node_material_get(PointerRNA *ptr)

View File

@@ -71,31 +71,15 @@ static PointerRNA rna_World_active_texture_get(PointerRNA *ptr)
World *wo= (World*)ptr->data;
Tex *tex;
tex= (wo->mtex[(int)wo->texact])? wo->mtex[(int)wo->texact]->tex: NULL;
tex= give_current_world_texture(wo);
return rna_pointer_inherit_refine(ptr, &RNA_Texture, tex);
}
static void rna_World_active_texture_set(PointerRNA *ptr, PointerRNA value)
{
World *wo= (World*)ptr->data;
int act= wo->texact;
if(wo->mtex[act] && wo->mtex[act]->tex)
id_us_min(&wo->mtex[act]->tex->id);
if(value.data) {
if(!wo->mtex[act]) {
wo->mtex[act]= add_mtex();
wo->mtex[act]->texco= TEXCO_VIEW;
}
wo->mtex[act]->tex= value.data;
id_us_plus(&wo->mtex[act]->tex->id);
}
else if(wo->mtex[act]) {
MEM_freeN(wo->mtex[act]);
wo->mtex[act]= NULL;
}
set_current_world_texture(wo, value.data);
}
static void rna_World_update(bContext *C, PointerRNA *ptr)