[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22226] branches/soc-2009-kazanbas: - added Mesh.add_material function
Arystanbek Dyussenov
arystan.d at gmail.com
Wed Aug 5 14:01:42 CEST 2009
Revision: 22226
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22226
Author: kazanbas
Date: 2009-08-05 14:01:42 +0200 (Wed, 05 Aug 2009)
Log Message:
-----------
- added Mesh.add_material function
- tweaked OBJ importer. It reads primitive files (cube, cone, etc.)
Modified Paths:
--------------
branches/soc-2009-kazanbas/release/io/import_obj.py
branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_mesh_api.c
Modified: branches/soc-2009-kazanbas/release/io/import_obj.py
===================================================================
--- branches/soc-2009-kazanbas/release/io/import_obj.py 2009-08-05 11:06:12 UTC (rev 22225)
+++ branches/soc-2009-kazanbas/release/io/import_obj.py 2009-08-05 12:01:42 UTC (rev 22226)
@@ -83,9 +83,11 @@
def unpack_face_list(list_of_tuples):
l = []
for t in list_of_tuples:
- if len(t) == 3:
- t += [0]
- l.extend(t)
+ face = [i for i in t]
+ if len(face) > 4:
+ raise RuntimeError("More than 4 vertices per face.")
+ if len(face) == 3: face.append(0)
+ l.extend(face)
return l
@@ -163,7 +165,7 @@
# Absolute path - c:\.. etc would work here
image= obj_image_load(imagepath, DIR, IMAGE_SEARCH)
- has_data = image.has_data
+ has_data = image.has_data if image else False
if image:
texture.image = image
@@ -503,8 +505,11 @@
me= bpy.data.add_mesh(dataname)
# me= bpy.data.meshes.new(dataname)
-
- me.materials= materials[0:16] # make sure the list isnt too big.
+
+ # make sure the list isnt too big
+ for material in materials[0:16]:
+ me.add_material(material)
+# me.materials= materials[0:16] # make sure the list isnt too big.
#me.verts.extend([(0,0,0)]) # dummy vert
me.add_geometry(len(verts_loc), 0, len(faces))
@@ -569,7 +574,7 @@
if verts_tex:
- blender_tface= me.uv_layers[0].data[i]
+ blender_tface= me.uv_textures[0].data[i]
if context_material:
image, has_data= unique_material_images[context_material]
@@ -621,7 +626,7 @@
if CREATE_EDGES:
- me.add_geometry(0, len(edges))
+ me.add_geometry(0, len(edges), 0)
# edges should be a list of (a, b) tuples
me.edges.foreach_set("verts", unpack_list(edges))
@@ -629,7 +634,7 @@
# del me_edges
- me.calc_normals()
+ me.update()
# me.calcNormals()
ob= bpy.data.add_object("MESH", "Mesh")
Modified: branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_mesh_api.c
===================================================================
--- branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_mesh_api.c 2009-08-05 11:06:12 UTC (rev 22225)
+++ branches/soc-2009-kazanbas/source/blender/makesrna/intern/rna_mesh_api.c 2009-08-05 12:01:42 UTC (rev 22226)
@@ -258,6 +258,29 @@
mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
}
+static void rna_Mesh_add_material(Mesh *me, Material *ma)
+{
+ int i;
+ int totcol = me->totcol + 1;
+ Material **mat;
+
+ /* don't add if mesh already has it */
+ for (i = 0; i < me->totcol; i++)
+ if (me->mat[i] == ma)
+ return;
+
+ 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;
+ ma->id.us++;
+
+ test_object_materials((ID*)me);
+}
+
#else
void RNA_api_mesh(StructRNA *srna)
@@ -289,17 +312,13 @@
func= RNA_def_function(srna, "calc_normals", "rna_Mesh_calc_normals");
RNA_def_function_ui_description(func, "Calculate vertex normals.");
- /*
- func= RNA_def_function(srna, "add_geom", "rna_Mesh_add_geom");
- RNA_def_function_ui_description(func, "Add geometry data to mesh.");
- prop= RNA_def_collection(func, "verts", "?", "", "Vertices.");
- RNA_def_property_flag(prop, PROP_REQUIRED);
- prop= RNA_def_collection(func, "faces", "?", "", "Faces.");
- RNA_def_property_flag(prop, PROP_REQUIRED);
- */
-
func= RNA_def_function(srna, "update", "rna_Mesh_update");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+
+ func= RNA_def_function(srna, "add_material", "rna_Mesh_add_material");
+ 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);
}
#endif
More information about the Bf-blender-cvs
mailing list