2.5: Materials and textures can now be assigned again
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 28 Jul 2009 18:54:02 +0000 (18:54 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Tue, 28 Jul 2009 18:54:02 +0000 (18:54 +0000)
even if not slot for them is available.

release/ui/buttons_material.py
release/ui/buttons_texture.py
source/blender/makesrna/intern/rna_brush.c
source/blender/makesrna/intern/rna_lamp.c
source/blender/makesrna/intern/rna_material.c
source/blender/makesrna/intern/rna_object.c
source/blender/makesrna/intern/rna_world.c

index 30f7f71..66eca1a 100644 (file)
@@ -52,10 +52,13 @@ class MATERIAL_PT_context_material(MaterialButtonsPanel):
 
                split = layout.split(percentage=0.65)
 
-               if ob and slot:
-                       split.template_ID(slot, "material", new="material.new")
+               if ob:
+                       split.template_ID(ob, "active_material", new="material.new")
                        row = split.row()
-                       row.itemR(slot, "link", expand=True)
+                       if slot:
+                               row.itemR(slot, "link", expand=True)
+                       else:
+                               row.itemL()
                elif mat:
                        split.template_ID(space, "pin_id")
                        split.itemS()
index df409d3..d638d13 100644 (file)
@@ -48,26 +48,26 @@ class TEXTURE_PT_context_texture(TextureButtonsPanel):
                wo = context.world
                br = context.brush
                space = context.space_data
-               slot = context.texture_slot
 
-               if ma or la or wo or br:
+               if ma:
+                       id = ma
+               elif la:
+                       id = la
+               elif wo:
+                       id = wo
+               elif br:
+                       id = br
+               else:
+                       id = None
+
+               if id:
                        row = layout.row()
-                       if ma:
-                               row.template_list(ma, "textures", ma, "active_texture_index", type="ICONS")
-                       elif la:
-                               row.template_list(la, "textures", la, "active_texture_index", type="ICONS")
-                       elif wo:
-                               row.template_list(wo, "textures", wo, "active_texture_index", type="ICONS")
-                       elif br:
-                               row.template_list(br, "textures", br, "active_texture_index", type="ICONS")
+                       row.template_list(id, "textures", id, "active_texture_index", type="ICONS")
 
                split = layout.split(percentage=0.65)
 
-               if ma or la or wo or br:
-                       if slot:
-                               split.template_ID(slot, "texture", new="texture.new")
-                       else:
-                               split.itemS()
+               if id:
+                       split.template_ID(id, "active_texture", new="texture.new")
                elif tex:
                        split.template_ID(space, "pin_id")
 
@@ -75,8 +75,6 @@ class TEXTURE_PT_context_texture(TextureButtonsPanel):
                   (context.sculpt_object or context.vertex_paint_object or \
                   context.weight_paint_object or context.texture_paint_object):
                        split.itemR(space, "brush_texture", text="Brush", toggle=True)
-               else:
-                       split.itemS()
                
                layout.itemS()
 
index e064fd7..2bb4333 100644 (file)
@@ -46,29 +46,32 @@ static void rna_Brush_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *p
 
 static PointerRNA rna_Brush_active_texture_get(PointerRNA *ptr)
 {
-       Brush *brush= (Brush*)ptr->data;
-       return rna_pointer_inherit_refine(ptr, &RNA_TextureSlot, brush->mtex[(int)brush->texact]);
+       Brush *br= (Brush*)ptr->data;
+       Tex *tex;
+
+       tex= (br->mtex[(int)br->texact])? br->mtex[(int)br->texact]->tex: NULL;
+       return rna_pointer_inherit_refine(ptr, &RNA_Texture, tex);
 }
 
-static void rna_Brush_active_texture_index_set(PointerRNA *ptr, int value)
+static void rna_Brush_active_texture_set(PointerRNA *ptr, PointerRNA value)
 {
-       Brush *brush= (Brush*)ptr->data;
-       int act= brush->texact;
-
-       if(value == act || value < 0 || value >= MAX_MTEX)
-               return;
-
-       /* auto create/free mtex on activate/deactive, so we can edit
-        * the texture pointer in the buttons UI. */
-       if(brush->mtex[act] && !brush->mtex[act]->tex) {
-               MEM_freeN(brush->mtex[act]);
-               brush->mtex[act]= NULL;
+       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;
        }
-
-       brush->texact= value;
-
-       if(!brush->mtex[value])
-               brush->mtex[value]= add_mtex();
 }
 
 static float rna_Brush_rotation_get(PointerRNA *ptr)
@@ -224,7 +227,8 @@ void rna_def_brush(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Curve", "Editable falloff curve.");
 
        /* texture */
-       rna_def_mtex_common(srna, "rna_Brush_mtex_begin", "rna_Brush_active_texture_get", "rna_Brush_active_texture_index_set", "TextureSlot");
+       rna_def_mtex_common(srna, "rna_Brush_mtex_begin", "rna_Brush_active_texture_get",
+               "rna_Brush_active_texture_set", "TextureSlot");
 
        /* clone tool */
        prop= RNA_def_property(srna, "clone_image", PROP_POINTER, PROP_NONE);
index b8150ee..299bd37 100644 (file)
@@ -64,30 +64,33 @@ static void rna_Lamp_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *pt
 static PointerRNA rna_Lamp_active_texture_get(PointerRNA *ptr)
 {
        Lamp *la= (Lamp*)ptr->data;
-       return rna_pointer_inherit_refine(ptr, &RNA_TextureSlot, la->mtex[(int)la->texact]);
+       Tex *tex;
+
+       tex= (la->mtex[(int)la->texact])? la->mtex[(int)la->texact]->tex: NULL;
+       return rna_pointer_inherit_refine(ptr, &RNA_Texture, tex);
 }
 
-static void rna_Lamp_active_texture_index_set(PointerRNA *ptr, int value)
+static void rna_Lamp_active_texture_set(PointerRNA *ptr, PointerRNA value)
 {
        Lamp *la= (Lamp*)ptr->data;
        int act= la->texact;
 
-       if(value == act || value < 0 || value >= MAX_MTEX)
-               return;
+       if(la->mtex[act] && la->mtex[act]->tex)
+               id_us_min(&la->mtex[act]->tex->id);
 
-       /* auto create/free mtex on activate/deactive, so we can edit
-        * the texture pointer in the buttons UI. */
-       if(la->mtex[act] && !la->mtex[act]->tex) {
+       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;
        }
-
-       la->texact= value;
-
-       if(!la->mtex[value]) {
-               la->mtex[value]= add_mtex();
-               la->mtex[value]->texco= TEXCO_GLOB;
-       }
 }
 
 static StructRNA* rna_Lamp_refine(struct PointerRNA *ptr)
@@ -349,7 +352,8 @@ static void rna_def_lamp(BlenderRNA *brna)
        RNA_def_property_update(prop, NC_LAMP|ND_LIGHTING, NULL);
 
        /* textures */
-       rna_def_mtex_common(srna, "rna_Lamp_mtex_begin", "rna_Lamp_active_texture_get", "rna_Lamp_active_texture_index_set", "LampTextureSlot");
+       rna_def_mtex_common(srna, "rna_Lamp_mtex_begin", "rna_Lamp_active_texture_get",
+               "rna_Lamp_active_texture_set", "LampTextureSlot");
 }
 
 static void rna_def_lamp_falloff(StructRNA *srna)
index f8cead5..d7c677d 100644 (file)
@@ -85,28 +85,31 @@ static void rna_Material_mtex_begin(CollectionPropertyIterator *iter, PointerRNA
 static PointerRNA rna_Material_active_texture_get(PointerRNA *ptr)
 {
        Material *ma= (Material*)ptr->data;
-       return rna_pointer_inherit_refine(ptr, &RNA_TextureSlot, ma->mtex[(int)ma->texact]);
+       Tex *tex;
+
+       tex= (ma->mtex[(int)ma->texact])? ma->mtex[(int)ma->texact]->tex: NULL;
+       return rna_pointer_inherit_refine(ptr, &RNA_Texture, tex);
 }
 
-static void rna_Material_active_texture_index_set(PointerRNA *ptr, int value)
+static void rna_Material_active_texture_set(PointerRNA *ptr, PointerRNA value)
 {
        Material *ma= (Material*)ptr->data;
        int act= ma->texact;
 
-       if(value == act || value < 0 || value >= MAX_MTEX)
-               return;
+       if(ma->mtex[act] && ma->mtex[act]->tex)
+               id_us_min(&ma->mtex[act]->tex->id);
 
-       /* auto create/free mtex on activate/deactive, so we can edit
-        * the texture pointer in the buttons UI. */
-       if(ma->mtex[act] && !ma->mtex[act]->tex) {
+       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;
        }
-
-       ma->texact= value;
-
-       if(!ma->mtex[value])
-               ma->mtex[value]= add_mtex();
 }
 
 static void rna_MaterialStrand_start_size_range(PointerRNA *ptr, float *min, float *max)
@@ -1276,7 +1279,8 @@ void RNA_def_material(BlenderRNA *brna)
 
        /* common */
        rna_def_animdata_common(srna);
-       rna_def_mtex_common(srna, "rna_Material_mtex_begin", "rna_Material_active_texture_get", "rna_Material_active_texture_index_set", "MaterialTextureSlot");
+       rna_def_mtex_common(srna, "rna_Material_mtex_begin", "rna_Material_active_texture_get",
+               "rna_Material_active_texture_set", "MaterialTextureSlot");
        
        rna_def_material_colors(srna);
        rna_def_material_diffuse(srna);
@@ -1302,14 +1306,13 @@ void rna_def_mtex_common(StructRNA *srna, const char *begin, const char *activeg
        RNA_def_property_ui_text(prop, "Textures", "Texture slots defining the mapping and influence of textures.");
 
        prop= RNA_def_property(srna, "active_texture", PROP_POINTER, PROP_NONE);
-       RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-       RNA_def_property_struct_type(prop, structname);
-       RNA_def_property_pointer_funcs(prop, activeget, NULL, NULL);
+       RNA_def_property_struct_type(prop, "Texture");
+       RNA_def_property_flag(prop, PROP_EDITABLE);
+       RNA_def_property_pointer_funcs(prop, activeget, activeset, NULL);
        RNA_def_property_ui_text(prop, "Active Texture", "Active texture slot being displayed.");
 
        prop= RNA_def_property(srna, "active_texture_index", PROP_INT, PROP_UNSIGNED);
        RNA_def_property_int_sdna(prop, NULL, "texact");
-       RNA_def_property_int_funcs(prop, NULL, activeset, NULL);
        RNA_def_property_range(prop, 0, MAX_MTEX-1);
        RNA_def_property_ui_text(prop, "Active Texture Index", "Index of active texture slot.");
 }
index 8c6f77a..53a73e0 100644 (file)
@@ -377,7 +377,17 @@ static void rna_Object_active_material_index_range(PointerRNA *ptr, int *min, in
 static PointerRNA rna_Object_active_material_get(PointerRNA *ptr)
 {
        Object *ob= (Object*)ptr->id.data;
-       return rna_pointer_inherit_refine(ptr, &RNA_MaterialSlot, ob->mat+ob->actcol);
+       Material *ma;
+
+       ma= (ob->totcol)? give_current_material(ob, ob->actcol): NULL;
+       return rna_pointer_inherit_refine(ptr, &RNA_Material, ma);
+}
+
+static void rna_Object_active_material_set(PointerRNA *ptr, PointerRNA value)
+{
+       Object *ob= (Object*)ptr->id.data;
+
+       assign_material(ob, value.data, ob->actcol);
 }
 
 static void rna_Object_active_particle_system_index_range(PointerRNA *ptr, int *min, int *max)
@@ -400,15 +410,6 @@ static void rna_Object_active_particle_system_index_set(struct PointerRNA *ptr,
        psys_set_current_num(ob, value);
 }
 
-#if 0
-static void rna_Object_active_material_set(PointerRNA *ptr, PointerRNA value)
-{
-       Object *ob= (Object*)ptr->id.data;
-
-       assign_material(ob, value.data, ob->actcol);
-}
-#endif
-
 static PointerRNA rna_MaterialSlot_material_get(PointerRNA *ptr)
 {
        Object *ob= (Object*)ptr->id.data;
@@ -1027,9 +1028,11 @@ static void rna_def_object(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Materials", "Material slots in the object.");
 
        prop= RNA_def_property(srna, "active_material", PROP_POINTER, PROP_NONE);
-       RNA_def_property_struct_type(prop, "MaterialSlot");
-       RNA_def_property_pointer_funcs(prop, "rna_Object_active_material_get", NULL, NULL);
+       RNA_def_property_struct_type(prop, "Material");
+       RNA_def_property_pointer_funcs(prop, "rna_Object_active_material_get", "rna_Object_active_material_set", NULL);
+       RNA_def_property_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Active Material", "Active material being displayed.");
+       RNA_def_property_update(prop, NC_OBJECT|ND_SHADING, "rna_Object_update");
 
        prop= RNA_def_property(srna, "active_material_index", PROP_INT, PROP_UNSIGNED);
        RNA_def_property_int_sdna(prop, NULL, "actcol");
index 8beaa85..f23b893 100644 (file)
@@ -66,31 +66,33 @@ static void rna_World_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *p
 static PointerRNA rna_World_active_texture_get(PointerRNA *ptr)
 {
        World *wo= (World*)ptr->data;
+       Tex *tex;
 
-       return rna_pointer_inherit_refine(ptr, &RNA_TextureSlot, wo->mtex[(int)wo->texact]);
+       tex= (wo->mtex[(int)wo->texact])? wo->mtex[(int)wo->texact]->tex: NULL;
+       return rna_pointer_inherit_refine(ptr, &RNA_Texture, tex);
 }
 
-static void rna_World_active_texture_index_set(PointerRNA *ptr, int value)
+static void rna_World_active_texture_set(PointerRNA *ptr, PointerRNA value)
 {
        World *wo= (World*)ptr->data;
        int act= wo->texact;
 
-       if(value == act || value < 0 || value >= MAX_MTEX)
-               return;
-
-       /* auto create/free mtex on activate/deactive, so we can edit
-        * the texture pointer in the buttons UI. */
-       if(wo->mtex[act] && !wo->mtex[act]->tex) {
+       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;
        }
-
-       wo->texact= value;
-
-       if(!wo->mtex[value]) {
-               wo->mtex[value]= add_mtex();
-               wo->mtex[value]->texco= TEXCO_VIEW;
-       }
 }
 
 #else
@@ -407,7 +409,8 @@ void RNA_def_world(BlenderRNA *brna)
        RNA_def_struct_ui_icon(srna, ICON_WORLD_DATA);
 
        rna_def_animdata_common(srna);
-       rna_def_mtex_common(srna, "rna_World_mtex_begin", "rna_World_active_texture_get", "rna_World_active_texture_index_set", "WorldTextureSlot");
+       rna_def_mtex_common(srna, "rna_World_mtex_begin", "rna_World_active_texture_get",
+               "rna_World_active_texture_set", "WorldTextureSlot");
 
        /* colors */
        prop= RNA_def_property(srna, "horizon_color", PROP_FLOAT, PROP_COLOR);