-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmeshutils.py
More file actions
44 lines (34 loc) · 1.23 KB
/
meshutils.py
File metadata and controls
44 lines (34 loc) · 1.23 KB
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
37
38
39
40
41
42
43
def writeply(X,color,tri,filename):
"""
Save out a triangulated mesh to a ply file
Parameters
----------
pts3 : 2D numpy.array (dtype=float)
vertex coordinates shape (3,Nvert)
color : 2D numpy.array (dtype=float)
vertex colors shape (3,Nvert)
should be float in range (0..1)
tri : 2D numpy.array (dtype=float)
triangular faces shape (Ntri,3)
filename : string
filename to save to
"""
f = open(filename,"w");
f.write('ply\n');
f.write('format ascii 1.0\n');
f.write('element vertex %i\n' % X.shape[1]);
f.write('property float x\n');
f.write('property float y\n');
f.write('property float z\n');
f.write('property uchar red\n');
f.write('property uchar green\n');
f.write('property uchar blue\n');
f.write('element face %d\n' % tri.shape[0]);
f.write('property list uchar int vertex_indices\n');
f.write('end_header\n');
C = (255*color).astype('uint8')
for i in range(X.shape[1]):
f.write('%f %f %f %i %i %i\n' % (X[0,i],X[1,i],X[2,i],C[0,i],C[1,i],C[2,i]));
for t in range(tri.shape[0]):
f.write('3 %d %d %d\n' % (tri[t,1],tri[t,0],tri[t,2]))
f.close();