use set as a suffix (matches operators)

- 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)
This commit is contained in:
Campbell Barton 2010-09-03 07:25:37 +00:00
parent 870469ec0e
commit d0c54d3d0e
24 changed files with 148 additions and 71 deletions

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

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

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

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

@ -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'}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -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*/

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

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

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