Fix some issues with showing the current textures when using
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 9 Oct 2009 09:50:49 +0000 (09:50 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 9 Oct 2009 09:50:49 +0000 (09:50 +0000)
material nodes and texture nodes. Made it all use the same
give_current_*_texture functions now.

release/scripts/ui/buttons_texture.py
source/blender/blenkernel/BKE_texture.h
source/blender/blenkernel/intern/texture.c
source/blender/editors/space_buttons/buttons_context.c
source/blender/editors/space_node/node_edit.c

index c4866edcaaa2b1cb65e9773f6a6d54c45482b587..b76f35c3ec3c9f7242b4075d83da43b2df7d3763 100644 (file)
@@ -75,11 +75,13 @@ class TEXTURE_PT_context_texture(TextureButtonsPanel):
                        layout.itemR(tex, "use_nodes")
                        
                        split = layout.split(percentage=0.2)
-                       
+
                        if tex.use_nodes:
                                slot = context.texture_slot
-                               split.itemL(text="Output:")
-                               split.itemR(slot, "output_node", text="")
+
+                               if slot:
+                                       split.itemL(text="Output:")
+                                       split.itemR(slot, "output_node", text="")
 
                        else:
                                split.itemL(text="Type:")
index a9862ba586b18a4bb4bf10eedc09af6babd6ea46..407dc94adfa5531badd23ab4bad4c8355ead2d3f 100644 (file)
 #ifndef BKE_TEXTURE_H
 #define BKE_TEXTURE_H
 
-struct Scene;
-struct Tex;
-struct MTex;
-struct PluginTex;
-struct LampRen;
+struct Brush;
 struct ColorBand;
-struct HaloRen;
-struct TexMapping;
 struct EnvMap;
+struct HaloRen;
+struct Lamp;
+struct LampRen;
+struct Material;
+struct MTex;
+struct PluginTex;
 struct PointDensity;
+struct Tex;
+struct TexMapping;
 struct VoxelData;
+struct World;
 
 /*  in ColorBand struct */
 #define MAXCOLORBAND 32
@@ -65,8 +68,12 @@ struct MTex *add_mtex(void);
 struct Tex *copy_texture(struct Tex *tex);
 void make_local_texture(struct Tex *tex);
 void autotexname(struct Tex *tex);
-struct Tex *give_current_texture(struct Object *ob, int act);
-struct Tex *give_current_world_texture(struct Scene *scene);
+
+struct Tex *give_current_object_texture(struct Object *ob);
+struct Tex *give_current_material_texture(struct Material *ma);
+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 TexMapping *add_mapping(void);
 void init_mapping(struct TexMapping *texmap);
index 3b8ae9a6c7f56ab29e242a7dc025789985306bd6..f09abf93bb847445c2e78f685514027ab315e90f 100644 (file)
@@ -809,72 +809,90 @@ void autotexname(Tex *tex)
 
 /* ------------------------------------------------------------------------- */
 
-Tex *give_current_texture(Object *ob, int act)
+Tex *give_current_object_texture(Object *ob)
 {
-       Material ***matarar, *ma;
-       Lamp *la = 0;
-       MTex *mtex = 0;
-       Tex *tex = 0;
-       bNode *node;
+       Material *ma;
+       Tex *tex= NULL;
        
        if(ob==0) return 0;
        if(ob->totcol==0 && !(ob->type==OB_LAMP)) return 0;
        
        if(ob->type==OB_LAMP) {
-               la=(Lamp *)ob->data;
-               if(la) {
-                       mtex= la->mtex[(int)(la->texact)];
-                       if(mtex) tex= mtex->tex;
-               }
+               tex= give_current_lamp_texture(ob->data);
        } else {
-               if(act>ob->totcol) act= ob->totcol;
-               else if(act==0) act= 1;
-               
-               if(ob->matbits[act-1]) {        /* in object */
-                       ma= ob->mat[act-1];
-               }
-               else {                                                          /* in data */
-                       matarar= give_matarar(ob);
-                       
-                       if(matarar && *matarar) ma= (*matarar)[act-1];
-                       else ma= 0;
-               }
+               ma= give_current_material(ob, ob->actcol);
+               tex= give_current_material_texture(ma);
+       }
+       
+       return tex;
+}
 
-               if(ma && ma->use_nodes && ma->nodetree) {
-                       node= nodeGetActiveID(ma->nodetree, ID_TE);
+Tex *give_current_lamp_texture(Lamp *la)
+{
+       MTex *mtex= NULL;
+       Tex *tex= NULL;
 
-                       if(node) {
-                               tex= (Tex *)node->id;
-                               ma= NULL;
-                       }
-                       else {
-                               node= nodeGetActiveID(ma->nodetree, ID_MA);
-                               if(node)
-                                       ma= (Material*)node->id;
-                       }
+       if(la) {
+               mtex= la->mtex[(int)(la->texact)];
+               if(mtex) tex= mtex->tex;
+       }
+
+       return tex;
+}
+
+Tex *give_current_material_texture(Material *ma)
+{
+       MTex *mtex= NULL;
+       Tex *tex= NULL;
+       bNode *node;
+       
+       if(ma && ma->use_nodes && ma->nodetree) {
+               node= nodeGetActiveID(ma->nodetree, ID_TE);
+
+               if(node) {
+                       tex= (Tex *)node->id;
+                       ma= NULL;
                }
-               if(ma) {
-                       mtex= ma->mtex[(int)(ma->texact)];
-                       if(mtex) tex= mtex->tex;
+               else {
+                       node= nodeGetActiveID(ma->nodetree, ID_MA);
+                       if(node)
+                               ma= (Material*)node->id;
                }
        }
+       if(ma) {
+               mtex= ma->mtex[(int)(ma->texact)];
+               if(mtex) tex= mtex->tex;
+       }
        
        return tex;
 }
 
-Tex *give_current_world_texture(Scene *scene)
+Tex *give_current_world_texture(World *world)
 {
-       MTex *mtex = 0;
-       Tex *tex = 0;
+       MTex *mtex= NULL;
+       Tex *tex= NULL;
        
-       if(!(scene->world)) return 0;
+       if(!world) return 0;
        
-       mtex= scene->world->mtex[(int)(scene->world->texact)];
+       mtex= world->mtex[(int)(world->texact)];
        if(mtex) tex= mtex->tex;
        
        return tex;
 }
 
+Tex *give_current_brush_texture(Brush *br)
+{
+       MTex *mtex= NULL;
+       Tex *tex= NULL;
+
+       if(br) {
+               mtex= br->mtex[(int)(br->texact)];
+               if(mtex) tex= mtex->tex;
+       }
+
+       return tex;
+}
+
 /* ------------------------------------------------------------------------- */
 
 EnvMap *BKE_add_envmap(void)
index 9333ba9209cfb5e929dd3fc4630669712a40e72f..a5a7524e584fe8c80d39359abddfdf395f7d851c 100644 (file)
@@ -52,6 +52,7 @@
 #include "BKE_paint.h"
 #include "BKE_particle.h"
 #include "BKE_screen.h"
+#include "BKE_texture.h"
 #include "BKE_utildefines.h"
 #include "BKE_world.h"
 
@@ -342,7 +343,6 @@ static int buttons_context_path_texture(const bContext *C, ButsContextPath *path
        Lamp *la;
        Brush *br;
        World *wo;
-       MTex *mtex;
        Tex *tex;
        PointerRNA *ptr= &path->ptr[path->len-1];
 
@@ -355,8 +355,7 @@ static int buttons_context_path_texture(const bContext *C, ButsContextPath *path
                br= path->ptr[path->len-1].data;
 
                if(br) {
-                       mtex= br->mtex[(int)br->texact];
-                       tex= (mtex)? mtex->tex: NULL;
+                       tex= give_current_brush_texture(br);
 
                        RNA_id_pointer_create(&tex->id, &path->ptr[path->len]);
                        path->len++;
@@ -368,8 +367,7 @@ static int buttons_context_path_texture(const bContext *C, ButsContextPath *path
                wo= path->ptr[path->len-1].data;
 
                if(wo) {
-                       mtex= wo->mtex[(int)wo->texact];
-                       tex= (mtex)? mtex->tex: NULL;
+                       give_current_world_texture(wo);
 
                        RNA_id_pointer_create(&tex->id, &path->ptr[path->len]);
                        path->len++;
@@ -381,8 +379,7 @@ static int buttons_context_path_texture(const bContext *C, ButsContextPath *path
                ma= path->ptr[path->len-1].data;
 
                if(ma) {
-                       mtex= ma->mtex[(int)ma->texact];
-                       tex= (mtex)? mtex->tex: NULL;
+                       tex= give_current_material_texture(ma);
 
                        RNA_id_pointer_create(&tex->id, &path->ptr[path->len]);
                        path->len++;
@@ -394,8 +391,7 @@ static int buttons_context_path_texture(const bContext *C, ButsContextPath *path
                la= path->ptr[path->len-1].data;
 
                if(la) {
-                       mtex= la->mtex[(int)la->texact];
-                       tex= (mtex)? mtex->tex: NULL;
+                       tex= give_current_lamp_texture(la);
 
                        RNA_id_pointer_create(&tex->id, &path->ptr[path->len]);
                        path->len++;
index cee90b5a1482da5e7baac0dd11c73a3abf7fca22..13421adf6e63bc60df62f7ae48b2e37306e60f68 100644 (file)
@@ -645,7 +645,7 @@ void snode_set_context(SpaceNode *snode, Scene *scene)
 
                if(snode->texfrom==SNODE_TEX_OBJECT) {
                        if(ob) {
-                               tx= give_current_texture(ob, ob->actcol);
+                               tx= give_current_object_texture(ob);
 
                                if(ob->type == OB_LAMP)
                                        snode->from= (ID*)ob->data;
@@ -656,11 +656,10 @@ void snode_set_context(SpaceNode *snode, Scene *scene)
                        }
                }
                else if(snode->texfrom==SNODE_TEX_WORLD) {
-                       tx= give_current_world_texture(scene);
+                       tx= give_current_world_texture(scene->world);
                        snode->from= (ID *)scene->world;
                }
                else {
-                       MTex *mtex= NULL;
                        Brush *brush= NULL;
                        
                        if(ob && (ob->mode & OB_MODE_SCULPT))
@@ -668,13 +667,8 @@ void snode_set_context(SpaceNode *snode, Scene *scene)
                        else
                                brush= paint_brush(&scene->toolsettings->imapaint.paint);
 
-                       if(brush && brush->texact != -1)
-                               mtex= brush->mtex[brush->texact];
-
                        snode->from= (ID *)brush;
-
-                       if(mtex)
-                               tx= mtex->tex;
+                       tx= give_current_brush_texture(brush);
                }
                
                snode->id= &tx->id;