我想通过Python API在Blender(2.50)中创建一个简单的网眼,但是API文档中的示例尚不正常。

我尝试了以下内容,但是 来自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.5倍API的文档。我知道,尽管最高警告了,但最常用的部分现在相当稳定。我还没有尝试过。

编辑:

我认为相关的一点是 本节 - 看来您创建了顶点面的列表,然后将其传递给此。这似乎与我可以找到的最新示例发生了变化。尝试在您的脚本文件夹中查看 - 您可能会看到一个示例。

编辑2:我已经更新了链接,以指向当前的实时文档。那里的笔记表明,现在可能有更好的方法可以做到这一点,但是自从我做了任何搅拌器脚本以来已经很长时间了,所以无济于事。

其他提示

多亏了尼尔,我从文档中找到了以下部分:

Blender 2.50的脚本 - 添加网格脚本

我将尝试以下脚本并报告我的结果:

添加固体对象网格

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top