use set as a suffix (matches operators)
authorCampbell Barton <ideasman42@gmail.com>
Fri, 3 Sep 2010 07:25:37 +0000 (07:25 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 3 Sep 2010 07:25:37 +0000 (07:25 +0000)
 - set_frame() --> frame_set()
 - set_context_pointer() --> context_pointer_set()

material adding works for curves and metaballs, new function to remove materials.

materials.link() didnt well fit how this is used elsewhere
 - order matters
 - it can be linked more than once.
 - remove(material), isnt that useful since you need to manage indicies.

... use list style functions instead. materials.append(mat) / materials.pop(index)

24 files changed:
release/scripts/op/io_anim_bvh/import_bvh.py
release/scripts/op/io_scene_3ds/import_3ds.py
release/scripts/op/io_scene_fbx/export_fbx.py
release/scripts/op/io_scene_obj/import_obj.py
release/scripts/op/io_shape_mdd/export_mdd.py
release/scripts/op/nla.py
release/scripts/ui/properties_object.py
release/scripts/ui/properties_physics_cloth.py
release/scripts/ui/properties_physics_common.py
release/scripts/ui/properties_physics_field.py
release/scripts/ui/properties_physics_fluid.py
release/scripts/ui/properties_physics_smoke.py
release/scripts/ui/properties_physics_softbody.py
release/scripts/ui/space_userpref_keymap.py
source/blender/blenkernel/BKE_material.h
source/blender/blenkernel/intern/material.c
source/blender/editors/mesh/mesh_data.c
source/blender/makesdna/intern/makesdna.c
source/blender/makesrna/intern/rna_ID.c
source/blender/makesrna/intern/rna_curve.c
source/blender/makesrna/intern/rna_mesh.c
source/blender/makesrna/intern/rna_meta.c
source/blender/makesrna/intern/rna_scene_api.c
source/blender/makesrna/intern/rna_ui_api.c

index befd6cd..5f9de6c 100644 (file)
@@ -351,7 +351,7 @@ def bvh_node_dict2armature(context, bvh_nodes, ROT_MODE='XYZ', IMPORT_START_FRAM
     for ob in scn.objects:
         ob.select = False
 
-    scn.set_frame(IMPORT_START_FRAME)
+    scn.frame_set(IMPORT_START_FRAME)
 
     arm_data = bpy.data.armatures.new("MyBVH")
     arm_ob = bpy.data.objects.new("MyBVH", arm_data)
index 5ea705f..1f34d37 100644 (file)
@@ -240,7 +240,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
                     bmat = MATDICT[matName][1]
                     img = TEXTURE_DICT.get(bmat.name)
 
-                bmesh.materials.link(bmat) # can be None
+                bmesh.materials.append(bmat) # can be None
 
                 if uv_faces  and img:
                     for fidx in faces:
index ec13dec..51a5f86 100644 (file)
@@ -1965,7 +1965,7 @@ def save(operator, context, filepath="", \
                     ob_base.update(scene)
 
             # This causes the makeDisplayList command to effect the mesh
-            scene.set_frame(scene.frame_current)
+            scene.frame_set(scene.frame_current)
 #                      Blender.Set('curframe', Blender.Get('curframe'))
 
 
@@ -2138,7 +2138,7 @@ def save(operator, context, filepath="", \
                 if ob_base.type == 'ARMATURE':
                     ob_base.update(scene)
             # This causes the makeDisplayList command to effect the mesh
-            scene.set_frame(scene.frame_current)
+            scene.frame_set(scene.frame_current)
 #                      Blender.Set('curframe', Blender.Get('curframe'))
 
     del tmp_ob_type, tmp_objects
@@ -2758,7 +2758,7 @@ Takes:  {''')
             '''
             i = act_start
             while i <= act_end:
-                scene.set_frame(i)
+                scene.frame_set(i)
 #                              Blender.Set('curframe', i)
                 for ob_generic in ob_anim_lists:
                     for my_ob in ob_generic:
@@ -2898,8 +2898,7 @@ Takes:  {''')
 
         file.write('\n}')
 
-        scene.set_frame(frame_orig)
-#              Blender.Set('curframe', frame_orig)
+        scene.frame_set(frame_orig)
 
     else:
         # no animation
index b21db8a..73b5484 100644 (file)
@@ -593,7 +593,7 @@ def create_mesh(new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_loc, v
 
     # make sure the list isnt too big
     for material in materials:
-        me.materials.link(material)
+        me.materials.append(material)
 
     me.vertices.add(len(verts_loc))
     me.faces.add(len(faces))
index 1f0a5d9..3c57ae5 100644 (file)
@@ -69,7 +69,7 @@ def save(operator, context, filepath="", frame_start=1, frame_end=300, fps=25):
         bpy.ops.object.mode_set(mode='OBJECT')
 
     orig_frame = scene.frame_current
-    scene.set_frame(frame_start)
+    scene.frame_set(frame_start)
     me = obj.create_mesh(scene, True, 'PREVIEW')
 
     #Flip y and z
@@ -108,7 +108,7 @@ def save(operator, context, filepath="", frame_start=1, frame_end=300, fps=25):
         me_tmp.getFromObject(obj.name)
         """
 
-        scene.set_frame(frame)
+        scene.frame_set(frame)
         me = obj.create_mesh(scene, True, 'PREVIEW')
         check_vertcount(me, numverts)
         me.transform(mat_flip * obj.matrix_world)
@@ -126,6 +126,6 @@ def save(operator, context, filepath="", frame_start=1, frame_end=300, fps=25):
     Blender.Window.WaitCursor(0)
     Blender.Set('curframe', orig_frame)
     """
-    scene.set_frame(orig_frame)
+    scene.frame_set(orig_frame)
     
     return {'FINISHED'}
index cc48d39..27fd83c 100644 (file)
@@ -87,7 +87,7 @@ def bake(frame_start, frame_end, step=1, only_selected=False):
 
     # could spped this up by applying steps here too...
     for f in frame_range:
-        scene.set_frame(f)
+        scene.frame_set(f)
 
         info = pose_info()
         info_ls.append(info)
index 35037b1..66189f6 100644 (file)
@@ -142,7 +142,7 @@ class OBJECT_PT_groups(ObjectButtonsPanel, bpy.types.Panel):
             if ob.name in group.objects:
                 col = layout.column(align=True)
 
-                col.set_context_pointer("group", group)
+                col.context_pointer_set("group", group)
 
                 row = col.box().row()
                 row.prop(group, "name", text="")
index 4fd7fc9..2e50bab 100644 (file)
@@ -63,7 +63,7 @@ class PHYSICS_PT_cloth(PhysicButtonsPanel, bpy.types.Panel):
 
         if md:
             # remove modifier + settings
-            split.set_context_pointer("modifier", md)
+            split.context_pointer_set("modifier", md)
             split.operator("object.modifier_remove", text="Remove")
 
             row = split.row(align=True)
index c469263..68b9338 100644 (file)
@@ -26,7 +26,7 @@ import bpy
 def point_cache_ui(self, context, cache, enabled, cachetype):
     layout = self.layout
 
-    layout.set_context_pointer("point_cache", cache)
+    layout.context_pointer_set("point_cache", cache)
 
     row = layout.row()
     row.template_list(cache, "point_caches", cache.point_caches, "active_index", rows=2)
index 07d748e..a72103f 100644 (file)
@@ -175,7 +175,7 @@ class PHYSICS_PT_collision(PhysicButtonsPanel, bpy.types.Panel):
 
         if md:
             # remove modifier + settings
-            split.set_context_pointer("modifier", md)
+            split.context_pointer_set("modifier", md)
             split.operator("object.modifier_remove", text="Remove")
             col = split.column()
 
index 18c0204..dcdb2de 100644 (file)
@@ -44,7 +44,7 @@ class PHYSICS_PT_fluid(PhysicButtonsPanel, bpy.types.Panel):
 
         if md:
             # remove modifier + settings
-            split.set_context_pointer("modifier", md)
+            split.context_pointer_set("modifier", md)
             split.operator("object.modifier_remove", text="Remove")
 
             row = split.row(align=True)
index cf91705..1db6785 100644 (file)
@@ -49,7 +49,7 @@ class PHYSICS_PT_smoke(PhysicButtonsPanel, bpy.types.Panel):
 
         if md:
             # remove modifier + settings
-            split.set_context_pointer("modifier", md)
+            split.context_pointer_set("modifier", md)
             split.operator("object.modifier_remove", text="Remove")
 
             row = split.row(align=True)
index b9c4c87..08abf04 100644 (file)
@@ -55,7 +55,7 @@ class PHYSICS_PT_softbody(PhysicButtonsPanel, bpy.types.Panel):
 
         if md:
             # remove modifier + settings
-            split.set_context_pointer("modifier", md)
+            split.context_pointer_set("modifier", md)
             split.operator("object.modifier_remove", text="Remove")
 
             row = split.row(align=True)
index 3d76c01..d77acab 100644 (file)
@@ -161,7 +161,7 @@ class InputKeyMapPanel(bpy.types.Panel):
     def draw_km(self, display_keymaps, kc, km, children, layout, level):
         km = km.active()
 
-        layout.set_context_pointer("keymap", km)
+        layout.context_pointer_set("keymap", km)
 
         col = self.indented_layout(layout, level)
 
@@ -315,12 +315,12 @@ class InputKeyMapPanel(bpy.types.Panel):
                 kmm = kc.keymaps.find_modal(kmi.idname)
                 if kmm:
                     self.draw_km(display_keymaps, kc, kmm, None, layout, level + 1)
-                    layout.set_context_pointer("keymap", km)
+                    layout.context_pointer_set("keymap", km)
 
     def draw_filtered(self, display_keymaps, filter_text, layout):
         for km, kc in display_keymaps:
             km = km.active()
-            layout.set_context_pointer("keymap", km)
+            layout.context_pointer_set("keymap", km)
 
             filtered_items = [kmi for kmi in km.items if filter_text in kmi.name.lower()]
 
@@ -364,7 +364,7 @@ class InputKeyMapPanel(bpy.types.Panel):
 
         row = subcol.row()
         row.prop_search(wm.keyconfigs, "active", wm, "keyconfigs", text="Key Config:")
-        layout.set_context_pointer("keyconfig", wm.keyconfigs.active)
+        layout.context_pointer_set("keyconfig", wm.keyconfigs.active)
         row.operator("wm.keyconfig_remove", text="", icon='X')
 
         row.prop(context.space_data, "filter_text", icon="VIEWZOOM")
index a220153..40d9839 100644 (file)
@@ -57,6 +57,9 @@ void automatname(struct Material *);
 
 struct Material ***give_matarar(struct Object *ob);
 short *give_totcolp(struct Object *ob);
+struct Material ***give_matarar_id(struct ID *id); /* same but for ID's */
+short *give_totcolp_id(struct ID *id);
+
 struct Material *give_current_material(struct Object *ob, int act);
 struct ID *material_from(struct Object *ob, int act);
 void assign_material(struct Object *ob, struct Material *ma, int act);
@@ -67,6 +70,10 @@ int find_material_index(struct Object *ob, struct Material *ma);
 int object_add_material_slot(struct Object *ob);
 int object_remove_material_slot(struct Object *ob);
 
+/* rna api */
+void material_append_id(struct ID *id, struct Material *ma);
+struct Material *material_pop_id(struct ID *id, int index);
+
 /* rendering */
 
 void init_render_material(struct Material *, int, float *);
index e6cf0be..beffd54 100644 (file)
@@ -434,6 +434,90 @@ short *give_totcolp(Object *ob)
        return NULL;
 }
 
+/* same as above but for ID's */
+Material ***give_matarar_id(ID *id)
+{
+       switch(GS(id->name)) {
+       case ID_ME:
+               return &(((Mesh *)id)->mat);
+               break;
+       case ID_CU:
+               return &(((Curve *)id)->mat);
+               break;
+       case ID_MB:
+               return &(((Curve *)id)->mat);
+               break;
+       }
+       return NULL;
+}
+
+short *give_totcolp_id(ID *id)
+{
+       switch(GS(id->name)) {
+       case ID_ME:
+               return &(((Mesh *)id)->totcol);
+               break;
+       case ID_CU:
+               return &(((Curve *)id)->totcol);
+               break;
+       case ID_MB:
+               return &(((Curve *)id)->totcol);
+               break;
+       }
+       return NULL;
+}
+
+void material_append_id(ID *id, Material *ma)
+{
+       Material ***matar;
+       if((matar= give_matarar_id(id))) {
+               short *totcol= give_totcolp_id(id);
+               Material **mat= MEM_callocN(sizeof(void *) * (*totcol) + 1, "newmatar");
+               if(*totcol) memcpy(mat, *matar, sizeof(void *) * (*totcol));
+               if(*matar) MEM_freeN(*matar);
+
+               *matar= mat;
+               (*matar)[(*totcol)++]= ma;
+
+               id_us_plus((ID *)ma);
+               test_object_materials(id);
+       }
+}
+
+Material *material_pop_id(ID *id, int index)
+{
+       Material *ret= NULL;
+       Material ***matar;
+       if((matar= give_matarar_id(id))) {
+               short *totcol= give_totcolp_id(id);
+               if(index >= 0 && index < (*totcol)) {
+                       ret= (*matar)[index];
+                       if(*totcol <= 1) {
+                               *totcol= 0;
+                               MEM_freeN(*matar);
+                               *matar= NULL;
+                       }
+                       else {
+                               Material **mat;
+
+                               if(index + 1 != (*totcol))
+                                       memmove((*matar), (*matar) + 1, (*totcol) - (index + 1));
+
+                               (*totcol)--;
+                               
+                               mat= MEM_callocN(sizeof(void *) * (*totcol), "newmatar");
+                               memcpy(mat, *matar, sizeof(void *) * (*totcol));
+                               MEM_freeN(*matar);
+
+                               *matar= mat;
+                               test_object_materials(id);
+                       }
+               }
+       }
+       
+       return ret;
+}
+
 Material *give_current_material(Object *ob, int act)
 {
        Material ***matarar, *ma;
index 35cb9f0..d1c6ff4 100644 (file)
@@ -772,24 +772,3 @@ void ED_mesh_calc_normals(Mesh *me)
 {
        mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
 }
-
-/* always adds the material even if its linked alredy
- * for pradictable material indicies */
-void ED_mesh_material_link(Mesh *me, Material *ma)
-{
-       int totcol = me->totcol + 1;
-       Material **mat;
-
-       mat= MEM_callocN(sizeof(void*)*totcol, "newmatar");
-
-       if(me->totcol) memcpy(mat, me->mat, sizeof(void*) * me->totcol);
-       if(me->mat) MEM_freeN(me->mat);
-
-       me->mat = mat;
-       me->mat[me->totcol++] = ma;
-       if(ma)
-               ma->id.us++;
-
-       test_object_materials((ID*)me);
-}
-
index 4133aff..7a2d659 100644 (file)
@@ -972,6 +972,8 @@ int make_structDNA(char *baseDirectory, FILE *file)
                dna_write(file, str, 4);
                len= nr_names;
                dna_write(file, &len, 4);
+               printf("LEEEN %d\n", len);
+               
                
                /* calculate size of datablock with strings */
                cp= names[nr_names-1];
index a8b7fb1..b9ef92c 100644 (file)
@@ -71,6 +71,7 @@ EnumPropertyItem id_type_items[] = {
 #include "BKE_idprop.h"
 #include "BKE_library.h"
 #include "BKE_animsys.h"
+#include "BKE_material.h"
 
 /* name functions that ignore the first two ID characters */
 void rna_ID_name_get(PointerRNA *ptr, char *value)
@@ -331,6 +332,31 @@ static void rna_def_ID_properties(BlenderRNA *brna)
        RNA_def_struct_name_property(srna, prop);
 }
 
+
+static void rna_def_ID_materials(BlenderRNA *brna)
+{
+       StructRNA *srna;
+       FunctionRNA *func;
+       PropertyRNA *parm;
+       
+       /* for mesh/mball/curve materials */
+       srna= RNA_def_struct(brna, "IDMaterials", NULL);
+       RNA_def_struct_sdna(srna, "ID");
+       RNA_def_struct_ui_text(srna, "ID Materials", "Collection of materials");
+
+       func= RNA_def_function(srna, "append", "material_append_id");
+       RNA_def_function_ui_description(func, "Add a new material to Mesh.");
+       parm= RNA_def_pointer(func, "material", "Material", "", "Material to add.");
+       RNA_def_property_flag(parm, PROP_REQUIRED);
+       
+       func= RNA_def_function(srna, "pop", "material_pop_id");
+       RNA_def_function_ui_description(func, "Add a new material to Mesh.");
+       parm= RNA_def_int(func, "index", 0, 0, INT_MAX, "", "Frame number to set.", 0, INT_MAX);
+       RNA_def_property_flag(parm, PROP_REQUIRED);
+       parm= RNA_def_pointer(func, "material", "Material", "", "Material to add.");
+       RNA_def_function_return(func, parm);
+}
+
 static void rna_def_ID(BlenderRNA *brna)
 {
        StructRNA *srna;
@@ -422,6 +448,7 @@ void RNA_def_ID(BlenderRNA *brna)
 
        rna_def_ID(brna);
        rna_def_ID_properties(brna);
+       rna_def_ID_materials(brna);
        rna_def_library(brna);
 }
 
index fb6da57..e282124 100644 (file)
@@ -1261,6 +1261,7 @@ static void rna_def_curve(BlenderRNA *brna)
        RNA_def_property_collection_sdna(prop, NULL, "mat", "totcol");
        RNA_def_property_struct_type(prop, "Material");
        RNA_def_property_ui_text(prop, "Materials", "");
+       RNA_def_property_srna(prop, "IDMaterials"); /* see rna_ID.c */  
 }
 
 static void rna_def_curve_nurb(BlenderRNA *brna)
index 741b5cb..db5a206 100644 (file)
@@ -1781,29 +1781,6 @@ static void rna_def_uv_textures(BlenderRNA *brna, PropertyRNA *cprop)
        RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
 }
 
-/* mesh.materials */
-static void rna_def_mesh_materials(BlenderRNA *brna, PropertyRNA *cprop)
-{
-       StructRNA *srna;
-       // PropertyRNA *prop;
-
-       FunctionRNA *func;
-       PropertyRNA *parm;
-
-       RNA_def_property_srna(cprop, "MeshMaterials");
-       srna= RNA_def_struct(brna, "MeshMaterials", NULL);
-       RNA_def_struct_sdna(srna, "Mesh");
-       RNA_def_struct_ui_text(srna, "Mesh Materials", "Collection of materials");
-       
-       func= RNA_def_function(srna, "link", "ED_mesh_material_link");
-       RNA_def_function_ui_description(func, "Add a new material to Mesh.");
-       parm= RNA_def_pointer(func, "material", "Material", "", "Material to add.");
-       RNA_def_property_flag(parm, PROP_REQUIRED);
-       
-       /* TODO, unlink? */
-}
-
-
 static void rna_def_mesh(BlenderRNA *brna)
 {
        StructRNA *srna;
@@ -1951,7 +1928,7 @@ static void rna_def_mesh(BlenderRNA *brna)
        RNA_def_property_collection_sdna(prop, NULL, "mat", "totcol");
        RNA_def_property_struct_type(prop, "Material");
        RNA_def_property_ui_text(prop, "Materials", "");
-       rna_def_mesh_materials(brna, prop);
+       RNA_def_property_srna(prop, "IDMaterials"); /* see rna_ID.c */
 
        /* Mesh Draw Options for Edit Mode*/
        
index 9bb25ac..18dfd05 100644 (file)
@@ -325,6 +325,7 @@ static void rna_def_metaball(BlenderRNA *brna)
        RNA_def_property_collection_sdna(prop, NULL, "mat", "totcol");
        RNA_def_property_struct_type(prop, "Material");
        RNA_def_property_ui_text(prop, "Materials", "");
+       RNA_def_property_srna(prop, "IDMaterials"); /* see rna_ID.c */  
        
        /* anim */
        rna_def_animdata_common(srna);
index 04fbae8..f6a6453 100644 (file)
@@ -47,7 +47,7 @@
 
 
 
-static void rna_Scene_set_frame(Scene *scene, int frame, float subframe)
+static void rna_Scene_frame_set(Scene *scene, int frame, float subframe)
 {
        scene->r.cfra= frame;
        scene->r.subframe= subframe;
@@ -78,7 +78,7 @@ void RNA_api_scene(StructRNA *srna)
        FunctionRNA *func;
        PropertyRNA *parm;
 
-       func= RNA_def_function(srna, "set_frame", "rna_Scene_set_frame");
+       func= RNA_def_function(srna, "frame_set", "rna_Scene_frame_set");
        RNA_def_function_ui_description(func, "Set scene frame updating all objects immediately.");
        parm= RNA_def_int(func, "frame", 0, MINAFRAME, MAXFRAME, "", "Frame number to set.", MINAFRAME, MAXFRAME);
        RNA_def_property_flag(parm, PROP_REQUIRED);
index 4f5c809..1d86faa 100644 (file)
@@ -259,7 +259,7 @@ void RNA_api_ui_layout(StructRNA *srna)
        RNA_def_function_ui_description(func, "Item. Inserts empty space into the layout between items.");
 
        /* context */
-       func= RNA_def_function(srna, "set_context_pointer", "uiLayoutSetContextPointer");
+       func= RNA_def_function(srna, "context_pointer_set", "uiLayoutSetContextPointer");
        parm= RNA_def_string(func, "name", "", 0, "Name", "Name of entry in the context.");
        RNA_def_property_flag(parm, PROP_REQUIRED);
        parm= RNA_def_pointer(func, "data", "AnyType", "", "Pointer to put in context.");