【问题标题】:How to create a bmesh from a list of vertices如何从顶点列表创建 bmesh
【发布时间】:2014-01-17 18:06:42
【问题描述】:

在搅拌机中,我可以从这样的顶点列表中创建一个网格“我”:

me = bpy.data.meshes.new("name") 
me.from_pydata(vertices,[],[])

但是对于 bmesh,这个功能不存在。我想做的是

bme=bmesh.new()
bme.from_pydata(vertices,[],[])

我怎样才能做到这一点?

【问题讨论】:

    标签: python blender


    【解决方案1】:

    bmesh 模板的略微修改版本将为您提供

    import bpy
    import bmesh
    
    myvertexlist = [[2,2,2],[4,4,4],[6,6,6],[8,8,8]]
    
    # Get the active mesh
    me = bpy.context.object.data
    
    # Get a BMesh representation
    bm = bmesh.new()   # create an empty BMesh
    bm.from_mesh(me)   # fill it in from a Mesh
    
    # Modify the BMesh, can do anything here...
    for newvert in myvertexlist:
        bm.verts.new(newvert)
    
    # also add bm.edges and bm.faces
    
    # Finish up, write the bmesh back to the mesh
    bm.to_mesh(me)
    bm.free()  # free and prevent further access
    

    【讨论】:

    • 谢谢。修改 bmesh 行可能可以完成这项工作。但是对于 bmesh 来说,难道没有等效于“mesh.from_pydata”的函数吗?我不想在常规网格上绕道,也避免在顶点上循环。
    • 我不相信bmesh中有from_pydata。最后,您的代码循环遍历顶点以添加它们或为您执行此操作的内置函数之间没有太大区别。
    • 内部代码通常比纯 Python 代码运行得更快、更高效,这实际上存在巨大差异,尤其是在大型数据集上。见帖子here 和引用article
    猜你喜欢
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    • 2017-05-07
    • 1970-01-01
    • 2013-06-05
    • 2020-05-19
    • 2013-06-14
    • 2020-03-02
    相关资源
    最近更新 更多