如何从顶点列表创建一个bmesh

4
在Blender中,我可以使用像这样的顶点列表创建一个网格“me”:
me = bpy.data.meshes.new("name") 
me.from_pydata(vertices,[],[])

但是对于bmesh,这个功能并不存在。我的想法是:
bme=bmesh.new()
bme.from_pydata(vertices,[],[])

我该如何实现这一点?

1个回答

5
稍微修改一下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行可能可以完成工作。但是是否有与“mesh.from_pydata”函数相当的bmesh等效函数?我不想在常规网格上绕路,也要避免循环顶点。 - katosh
我不相信在bmesh中有from_pydata函数。最终,你的代码循环遍历顶点添加它们和内置函数为你完成这个任务之间并没有太大的区别。 - sambler
1
实际上,内部代码通常比纯Python代码运行更快,更高效,特别是在处理大型数据集时。请参见此帖子和引用的文章 - SO_fix_the_vote_sorting_bug

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接