2010-09-07 57 views
6

我想通过Python API在Blender(2.50)中创建一个简单的网格,但API文档中的示例尚未运行。如何通过Python API在Blender 2.50中创建简单网格

我尝试以下,但它from API 2.49

from Blender import * 
    import bpy 

    editmode = Window.EditMode() # are we in edit mode? If so ... 
    if editmode: Window.EditMode(0) # leave edit mode before getting the mesh 

    # define vertices and faces for a pyramid 
    coords=[ [-1,-1,-1], [1,-1,-1], [1,1,-1], [-1,1,-1], [0,0,1] ] 
    faces= [ [3,2,1,0], [0,1,4], [1,2,4], [2,3,4], [3,0,4] ] 

    me = bpy.data.meshes.new('myMesh')   # create a new mesh 

    me.verts.extend(coords)   # add vertices to mesh 
    me.faces.extend(faces)   # add faces to the mesh (also adds edges) 

    me.vertexColors = 1    # enable vertex colors 
    me.faces[1].col[0].r = 255  # make each vertex a different color 
    me.faces[1].col[1].g = 255 
    me.faces[1].col[2].b = 255 

    scn = bpy.data.scenes.active  # link object to current scene 
    ob = scn.objects.new(me, 'myObj') 

    if editmode: Window.EditMode(1) # optional, just being nice 

这不起作用,因为网格对象不具有任何facesverts成员。

有没有什么办法可以做到这一点?

回答

3

尝试this 2.5x API文档。我明白,尽管顶部有很大的警告,但现在使用最多的部分相当稳定。我还没有尝试过。

编辑:

我认为相关的位this section - 看来你创建面等,并把它传递给这个顶点的列表。这似乎从我能找到的最新例子中改变了。尝试查看脚本文件夹 - 可能有一个示例可供您查看。

编辑2:我已经更新了链接以指向当前的直播文档。那里的注释表明,现在可能有更好的方法来做这件事,但是由于我已经完成了任何搅拌机脚本,所以无法提供更多帮助。

+0

感谢你为这个链接,即使我已经知道这一点。您能否指出我在本文档中的特定页面?我还没有找到一个工作示例。 – guerda 2010-09-07 09:36:12

+0

好吧,你的编辑似乎解决了这个问题,我会尝试。 – guerda 2010-09-07 11:10:33

+0

我无法用文档编写一个工作示例。你能帮我解决吗? – guerda 2010-09-08 08:51:12

相关问题