我想通过Python API在Blender(2.50)中创建一个简单的mesh,但是API文档中的示例还不能工作。
我试过下面的,但是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
这不起作用,因为网格对象没有任何faces
或verts
成员。
有什么选择吗?
试试2.5xapi的this文档。我知道,尽管上面有很多警告,但现在最常用的部分还是相当稳定的。我还没试过呢。
编辑:
我认为相关的位是this section-看起来您创建了一个顶点面列表等,并将其传递给这个。这似乎与我能找到的最近的例子有所不同。尝试在脚本文件夹中查找-可能有一个可以查看的示例。
编辑2:我已经更新了指向当前实时文档的链接。这里的注释表明,现在可能有更好的方法来实现这一点,但是我已经很久没有做过任何搅拌机脚本了,所以无法提供更多帮助。
感谢尼尔,我从文档中找到了以下部分:
Scripts for Blender 2.50 - Add Mesh Scripts
我将尝试以下脚本并报告我的结果:
Add Solid Object Mesh
相关问题 更多 >
编程相关推荐