Open BIT-TYJ opened 7 months ago
Thank you for your help!
---Original--- From: @.> Date: Mon, Apr 1, 2024 20:16 PM To: @.>; Cc: "yujie @.**@.>; Subject: Re: [JiehongLin/SAM-6D] .obj format (Issue #36)
Just convert obj to ply. Hope this code help you. def obj_to_ply(obj_file, ply_file): vertices = [] faces = [] with open(obj_file, 'r') as file: for line in file: if line.startswith('v '): vertex = list(map(float, line.strip().split()[1:])) vertices.append(vertex) elif line.startswith('f '): face = line.strip().split()[1:] face_indices = [ int(vertex.split('/')[0]) - 1 for vertex in face] faces.append(face_indices) vertices = np.array(vertices) faces = np.array(faces) with open(ply_file, 'w') as file: # Write PLY header file.write("ply\n") file.write("format ascii 1.0\n") file.write("element vertex {}\n".format(len(vertices))) file.write("property float x\n") file.write("property float y\n") file.write("property float z\n") file.write("element face {}\n".format(len(faces))) file.write("property list uchar int vertex_index\n") file.write("end_header\n") # Write vertex data for vertex in vertices: vertex *= 1000 # m to mm file.write("{} {} {}\n".format( vertex[0], vertex[1], vertex[2])) # Write face data for face in faces: file.write("{} ".format(len(face))) for index in face: file.write("{} ".format(index)) file.write("\n") print("PLY 文件已生成:", ply_file)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: @.***>
yes it works for .obj file as well
Hello, thanks for the great work! Can the format of 'mesh' be .obj?