Blender Python脚本删除网格



我有一个脚本,我试图在blender中运行,它将通过一个目录中的所有文件,然后每次打开一个文件,并将该文件的顶点和面数打印到文件中。我遇到的一个问题是在我移动到下一个网格之前从场景中删除一个网格。这是目前为止的内容

import bpy

# print all objects
for obj in bpy.data.objects:
    print(obj.name)

# print all scene names in a list
print(bpy.data.scenes.keys())

# remove mesh Cube
if "Cube" in bpy.data.meshes:
    mesh = bpy.data.meshes["Cube"]
    print("removing mesh", mesh)
    bpy.data.meshes.remove(mesh)

# write images into a file next to the blend
import os
import bmesh
file = open("C:\Users\Jon\Documents\Dataset\ReadMe.txt", 'a')
file.write("Name t Vertices t Faces t QuadOrTriangle t n")
#os.chdir("C:\Users\Jon\Documents\Dataset\SingleObjects\")
path = "C:\Users\Jon\Documents\Dataset\SingleObjects\"
for data in os.listdir(path):
    bpy.ops.import_mesh.ply(filepath="C:\Users\Jon\Documents\Dataset\SingleObjects\" + data)
    me = bpy.context.object.data
    bm = bmesh.new()   # create an empty BMesh
    bm.from_mesh(me)   # fill it in from a Mesh
    #filepath = bpy.data.filepath
    for t in bpy.data.meshes:
         directory = bpy.path.abspath(t.name)
    FaceCounter = 0
    VertCounter = 0
    #QuadOrTri = 0
    for f in bm.faces:
        QuadOrTri = 0
        for v in f.verts:
            QuadOrTri = QuadOrTri + 1
    for f in bm.faces:
        FaceCounter = FaceCounter +1
    for v in bm.verts:
        VertCounter = VertCounter + 1
    file.write("%s.ply t %d t %d t %d n" % (directory, VertCounter, FaceCounter, QuadOrTri))
    for item in bpy.data.meshes:
        bpy.data.meshes.remove(item)
    file.close()

这必须使用ply文件完成。如果有人能给我一些提示或建议,那就太好了!谢谢!

bpy.ops.object.delete()将删除选中的对象,包括它的网格数据。

你不需要网格来做你想做的事情,网格只需要编辑网格数据。你可以从object.data

中的顶点列表的长度中获得顶点计数
VertCount = len(bpy.context.active_object.data.vertices)
EdgeCount = len(bpy.context.active_object.data.edges)
FaceCount = len(bpy.context.active_object.data.polygons)

相关内容

  • 没有找到相关文章

最新更新