forked from BruntonUWBio/OpenMind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
obj2srf
executable file
·46 lines (39 loc) · 1.17 KB
/
obj2srf
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
44
45
46
#!/usr/bin/gawk -f
BEGIN { if (ARGV[1] == "") {
print "Convert simple OBJ to Surface ASCII format."
print "Only vertices and faces are converted, without"
print "normals, materials or groups."
print ""
print "Usage:"
print "obj2srf input.obj > output.srf"
print ""
print "The output goes to stdout. Use > to redirect to"
print "a file, as shown above"
print ""
print "_____________________________________"
print "Anderson M. Winkler"
print "Yale University / Institute of Living"
print "Jan/2011 (first version)"
print "Apr/2015 (this version)"
print "http://brainder.org"
exit }
# Initialise counters
v = 0;
f = 0 }
# Build arrays for the vertices and faces.
# All the rest will be ignored.
/^v/ { vtx[v,1] = $2 ; vtx[v,2] = $3 ; vtx[v,3] = $4 ; v++ }
/^f/ { fac[f,1] = $2-1 ; fac[f,2] = $3-1 ; fac[f,3] = $4-1 ; f++ }
# Start to create the Surface file
END {
# Number of vertices and faces
nV = v-1 ;
nF = f-1 ;
# Output file header
if (ARGV[1] != "") {
print "#!ascii"
print nV+1 , nF+1 }
# Convert vertex coordinates and indices
for ( v = 0 ; v <= nV ; v++ ) { print vtx[v,1], vtx[v,2], vtx[v,3], 0 }
for ( f = 0 ; f <= nF ; f++ ) { print fac[f,1], fac[f,2], fac[f,3], 0 }
}