【问题标题】:How to create a simple mesh in Blender 2.50 via the Python API如何通过 Python API 在 Blender 2.50 中创建一个简单的网格
【发布时间】:2011-04-09 02:22:00
【问题描述】:

我想通过 Python API 在 Blender (2.50) 中创建一个简单的网格,但 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

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

有没有办法做到这一点?

【问题讨论】:

    标签: python blender blender-2.50


    【解决方案1】:

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

    编辑:

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

    编辑 2:我已更新链接以指向当前的实时文档。那里的注释表明现在可能有更好的方法来做到这一点,但我已经很长时间没有做过任何搅拌机脚本了,所以无能为力。

    【讨论】:

    • 感谢您提供此链接,即使我已经知道这一点。您能否将我指向本文档中的特定页面?我还没有找到一个可行的例子。
    • 我无法使用文档编写工作示例。你能帮我解决这个问题吗?
    • 抱歉,我没有对新的 API 做任何事情,我只是在查看文档并按照我在其他地方阅读的内容进行操作。您可能会在 Python 和插件论坛的 blenderartists.org 上获得更多帮助。
    • “此部分”的链接目前已失效。
    【解决方案2】:

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

    Scripts for Blender 2.50 - Add Mesh Scripts

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

    Add Solid Object Mesh

    【讨论】:

      猜你喜欢
      • 2020-12-26
      • 1970-01-01
      • 1970-01-01
      • 2015-05-13
      • 2011-02-27
      • 2012-08-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多