bmesh and mesh needs help simple mesh build

I been trying to get the new mesh format to work but no luck. I try to understand the import obj file and not sure how the faces work. As well for the uv texture. I am getting no where at this point. >.<


me = bpy.data.meshes.new("test")
ob = bpy.data.objects.new("TestObject",me)

bpy.data.scenes[0].objects.link(ob)
verts = [(0,0,0),(2,0,0),(2,0,2)]
faces = [(1,2,3)]

me.vertices.add(len(verts))
me.tessfaces.add(len(faces))
me.vertices.foreach_set("co", unpack_list(verts))
me.tessfaces.foreach_set("vertices_raw", (faces))#not working


This fail to work. Any one?

In my Blender 2.62 ‘unpack_list’ does not exist ?

Maybe you look in ‘templates’ for operator_mesh_add.py to learn how it is possible too

That help but needed to get the uv texture working with it. Just not how it setup right.

Manage to see how the code work a bit. Trying to get the uv texture working with this type format.

It base on importer .obj format.


        me = bpy.data.meshes.new("test")
        obmade = bpy.data.objects.new("TestObject",me)
        print("Create Simple Mesh")
        bpy.data.scenes[0].objects.link(obmade)
        for i in bpy.context.scene.objects: i.select = False #deselect all objects
        obmade.select = True
        bpy.context.scene.objects.active = obmade

        verts = [(0,0,0),(2,0,0),(2,0,2)]
        edges = [(0,1),(1,2),(2,0)]
        faces = []
        faces.extend([(0,1,2,0)])
        #me.vertices.add(len(verts))
        #print(dir(me))
        me.vertices.add(len(verts))
        me.tessfaces.add(len(faces))
        for face in me.tessfaces:
            print(dir(face))
        
        me.vertices.foreach_set("co", unpack_list(verts))
        me.tessfaces.foreach_set("vertices_raw", unpack_list(faces))
        me.edges.add(len(edges))
        me.edges.foreach_set("vertices", unpack_list(edges))
        
        #print(len(me.tessfaces))
        me.tessface_uv_textures.new("uvtexture")
        #for uv in me.tessface_uv_textures:
            #print(len(uv.data))
            #print(dir(uv.data[0]))
            #print(dir(uv.data[0].uv1))