2010-09-07 73 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