-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathply_from_array.py
38 lines (28 loc) · 911 Bytes
/
ply_from_array.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import numpy as np
__all__ = ["points_normals_from" ,"ply_from_array"]
def points_normals_from(filename):
array = np.genfromtxt(filename)
return array[:,0:3], array[:,3:6]
def ply_from_array(points, faces, output_file):
num_points = len(points)
num_triangles = len(faces)
header = '''ply
format ascii 1.0
element vertex {0}
property float x
property float y
property float z
element face {1}
property list uchar int vertex_indices
end_header\n'''.format(num_points, num_triangles)
with open(output_file,'wb') as f:
f.writelines(header)
for item in points:
f.write("{0:0.6f} {1:0.6f} {2:0.6f}\n".format(item[0],item[1], item[2]))
for item in faces:
number = len(item)
row = "{0}".format(number)
for elem in item:
row += " {0} ".format(elem)
row += "\n"
f.write(row)