diff options
-rw-r--r-- | release/io/import_obj.py | 23 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_mesh_api.c | 37 |
2 files changed, 42 insertions, 18 deletions
diff --git a/release/io/import_obj.py b/release/io/import_obj.py index a4778ac7790..2a5d92969af 100644 --- a/release/io/import_obj.py +++ b/release/io/import_obj.py @@ -83,9 +83,11 @@ def unpack_list(list_of_tuples): 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 @@ def create_materials(filepath, material_libs, unique_materials, unique_material_ # 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 @@ def create_mesh(scn, new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_l 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 @@ def create_mesh(scn, new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_l 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 @@ def create_mesh(scn, new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_l 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 @@ def create_mesh(scn, new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_l # del me_edges - me.calc_normals() + me.update() # me.calcNormals() ob= bpy.data.add_object("MESH", "Mesh") diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c index 9a527948b0f..b50cc678f4f 100644 --- a/source/blender/makesrna/intern/rna_mesh_api.c +++ b/source/blender/makesrna/intern/rna_mesh_api.c @@ -258,6 +258,29 @@ static void rna_Mesh_calc_normals(Mesh *me) 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 @@ void RNA_api_mesh(StructRNA *srna) 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 |