如何通过 Python API 在 Blender 2.50 中创建简单的网格

发布于 2024-09-18 17:37:32 字数 1245 浏览 9 评论 0原文

我想通过 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

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

有什么选择可以做到这一点吗?

I would like to create a simple mesh in Blender (2.50) via the Python API but the examples from the API documentation don't work yet.

I tried the following but it's 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

This does not work because the mesh object doesn't have any faces or verts members.

Are there any options to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

从﹋此江山别 2024-09-25 17:37:32

尝试 2.5x API 文档。据我所知,尽管顶部有很大的警告,但最常用的部分现在相当稳定。我还没试过。

编辑:

我认为相关位是 本节 - 看来您创建了一个顶点面等列表并将其传递给此部分。这似乎与我能找到的最新示例有所不同。尝试查看您的脚本文件夹 - 那里可能有一个示例可供您查看。

编辑 2:我已更新链接以指向当前的实时文档。那里的注释表明现在可能有更好的方法来做到这一点,但自从我完成任何搅拌器脚本以来已经很长时间了,所以无法提供更多帮助。

Try this documentation for the 2.5x API. I understand that despite the big warnings at the top, the most used sections are fairly stable now. I've not tried it yet.

EDIT:

I think the relevant bit is this section - it seems you create a list of vertices faces etc. and pass it to this. This seems to have changed from the most recent examples I can find. Try looking in your scripts folder - there might be an example there that you can look at.

EDIT 2: I have updated the link to point to the current live docs. The notes there suggest that there are probably better ways of doing this now but it is a long time since I have done any blender scripting so can't help more.

ㄟ。诗瑗 2024-09-25 17:37:32

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

脚本对于 Blender 2.50 - 添加网格脚本

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

添加实体网格

Thanks to neil, I found the following section from the documentation:

Scripts for Blender 2.50 - Add Mesh Scripts

I will try the following script and report my results:

Add Solid Object Mesh

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文