make_ply.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 #write a ply file for a list of vertices and faces
00004 def write_ply(vertices, faces, outfile):
00005     vertex_count = len(vertices)
00006     face_count = len(faces)
00007     outfile.write("ply\nformat ascii 1.0\nelement vertex %d\nproperty float x\nproperty float y\nproperty float z\nelement face %d\nproperty list uchar int vertex_index\nend_header\n"%(vertex_count, face_count))
00008     for vertex in vertices:
00009         outfile.write("%0.5f %0.5f %0.5f\n"%(vertex[0], vertex[1], vertex[2]))
00010     for face in faces:
00011         outfile.write("%d "%len(face))
00012         for index in face:
00013             outfile.write("%d "%index)
00014         outfile.write("\n")
00015 
00016 #generate vertices and faces for a box
00017 def add_box(corner, x_len, y_len, z_len, vertices, faces):
00018     box_vertices = [[corner[0], corner[1], corner[2]],
00019                 [corner[0]+x_len, corner[1], corner[2]],
00020                 [corner[0]+x_len, corner[1]+y_len, corner[2]],
00021                 [corner[0], corner[1]+y_len, corner[2]],
00022                 [corner[0], corner[1], corner[2]+z_len],
00023                 [corner[0]+x_len, corner[1], corner[2]+z_len],
00024                 [corner[0]+x_len, corner[1]+y_len, corner[2]+z_len],
00025                 [corner[0], corner[1]+y_len, corner[2]+z_len]]
00026     box_faces = [[0,2,1],[0,1,2],
00027              [0,3,2],[0,2,3],
00028              [0,1,4],[0,4,1],
00029              [1,5,4],[1,4,5],
00030              [1,2,6],[1,6,2],
00031              [1,6,5],[1,5,6],
00032              [0,4,7],[0,7,4],
00033              [0,7,3],[0,3,7],
00034              [3,2,7],[3,7,2],
00035              [2,6,7],[2,7,6],
00036              [4,5,6],[4,6,5],
00037              [4,6,7],[4,7,6]]
00038     for i in range(len(box_faces)):
00039         for j in range(3):
00040             box_faces[i][j] += len(vertices)
00041     vertices.extend(box_vertices)
00042     faces.extend(box_faces)
00043 


manipulation_worlds
Author(s): Matei Ciocarlie
autogenerated on Mon Oct 6 2014 12:59:08