fix for material slot removal (r38879)
authorCampbell Barton <ideasman42@gmail.com>
Sun, 31 Jul 2011 12:43:41 +0000 (12:43 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 31 Jul 2011 12:43:41 +0000 (12:43 +0000)
- The object ID was being passed to the data_delete_material_index_id() from object_remove_material_slot(), rather then the object data. (so the material slot fix wouldnt run in that case).
- add support for fixing text object materials too.

source/blender/blenkernel/BKE_curve.h
source/blender/blenkernel/intern/curve.c
source/blender/blenkernel/intern/material.c
source/blender/makesrna/intern/rna_ID.c

index 0491116d199c33c1e3c38483ec1f805e0234eb06..557ce417b1424fa86860476c579c60d59a7350c2 100644 (file)
@@ -115,5 +115,6 @@ int minmax_curve(struct Curve *cu, float min[3], float max[3]);
 int curve_center_median(struct Curve *cu, float cent[3]);
 int curve_center_bounds(struct Curve *cu, float cent[3]);
 void curve_translate(struct Curve *cu, float offset[3], int do_keys);
+void curve_delete_material_index(struct Curve *cu, int index);
 #endif
 
index 202a3f28d9ab6750e2871c06628d6a122aee5402..66ab11938f39b72b528fb81d5e9afe2d4231b0ae 100644 (file)
@@ -3259,3 +3259,28 @@ void curve_translate(Curve *cu, float offset[3], int do_keys)
                }
        }
 }
+
+void curve_delete_material_index(Curve *cu, int index)
+{
+       const int curvetype= curve_type(cu);
+
+       if(curvetype == OB_FONT) {
+               struct CharInfo *info= cu->strinfo;
+               int i;
+               for(i= cu->len-1; i >= 0; i--, info++) {
+                       if (info->mat_nr && info->mat_nr>=index) {
+                               info->mat_nr--;
+                       }
+               }
+       }
+       else {
+               Nurb *nu;
+
+               for (nu= cu->nurb.first; nu; nu= nu->next) {
+                       if(nu->mat_nr && nu->mat_nr>=index) {
+                               nu->mat_nr--;
+                               if (curvetype == OB_CURVE) nu->charidx--;
+                       }
+               }
+       }
+}
index 1f2544c9706a33daba85394209c966a635722ac1..9c455e84109dacbdc9cbf5026fa3267b00a3fca8 100644 (file)
@@ -517,31 +517,15 @@ short *give_totcolp_id(ID *id)
 
 void data_delete_material_index_id(ID *id, int index)
 {
-       Mesh *me;
-       Curve *cu;
-       Nurb *nu;
-       int curvetype;
-
        switch(GS(id->name)) {
        case ID_ME:
-               me=(Mesh *)id;
-               mesh_delete_material_index(me, index);
+               mesh_delete_material_index((Mesh *)id, index);
                break;
        case ID_CU:
-               cu= (Curve *)id;
-               nu= cu->nurb.first;
-
-               curvetype=curve_type(cu);
-               if (!ELEM(curvetype, OB_CURVE, OB_SURF))
-                       return;
-               
-               while (nu) {
-                       if(nu->mat_nr && nu->mat_nr>=index) {
-                               nu->mat_nr--;
-                               if (curvetype == OB_CURVE) nu->charidx--;
-                       }
-                       nu= nu->next;
-               }
+               curve_delete_material_index((Curve *)id, index);
+               break;
+       case ID_MB:
+               /* meta-elems dont have materials atm */
                break;
        }
 }
@@ -1124,8 +1108,8 @@ int object_remove_material_slot(Object *ob)
        }
 
        /* check indices from mesh */
-       if (ELEM3(ob->type, OB_MESH, OB_CURVE, OB_SURF)) {
-               data_delete_material_index_id(&ob->id, actcol-1);
+       if (ELEM4(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT)) {
+               data_delete_material_index_id((ID *)ob->data, actcol-1);
                freedisplist(&ob->disp);
        }
 
index 6d7fc0ee57bf7d081a3c5e9e70c0dce5804d8c67..8d57403ec353c6964ed98a611630bbe094a26171 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "DNA_ID.h"
 #include "DNA_vfont_types.h"
+#include "DNA_material_types.h"
 #include "DNA_object_types.h"
 
 #include "WM_types.h"
@@ -416,9 +417,9 @@ static void rna_def_ID_materials(BlenderRNA *brna)
        
        func= RNA_def_function(srna, "pop", "material_pop_id");
        RNA_def_function_ui_description(func, "Remove a material from the data block.");
-       parm= RNA_def_int(func, "index", 0, 0, INT_MAX, "", "Index of material to remove.", 0, INT_MAX);
+       parm= RNA_def_int(func, "index", 0, 0, MAXMAT, "", "Index of material to remove.", 0, MAXMAT);
        RNA_def_property_flag(parm, PROP_REQUIRED);
-       RNA_def_boolean(func, "remove_material_slot", 1, "", "Remove the material slot and assign 1st material to old faces.");
+       RNA_def_boolean(func, "update_data", 0, "", "Update data by re-adjusting the material slots assigned.");
        parm= RNA_def_pointer(func, "material", "Material", "", "Material to remove.");
        RNA_def_function_return(func, parm);
 }