@@ -46,6 +46,7 @@ def _fread3_many(fobj, n):
46
46
47
47
48
48
def _read_volume_info (fobj ):
49
+ """Helper for reading the footer from a surface file."""
49
50
volume_info = OrderedDict ()
50
51
head = np .fromfile (fobj , '>i4' , 1 )
51
52
if not np .array_equal (head , [20 ]): # Read two bytes more
@@ -106,13 +107,17 @@ def read_geometry(filepath, read_metadata=False, read_stamp=False):
106
107
"""
107
108
volume_info = OrderedDict ()
108
109
110
+ TRIANGLE_MAGIC = 16777214
111
+ QUAD_MAGIC = 16777215
112
+ NEW_QUAD_MAGIC = 16777213
109
113
with open (filepath , "rb" ) as fobj :
110
114
magic = _fread3 (fobj )
111
- if magic in (16777215 , 16777213 ): # Quad file
115
+ if magic in (QUAD_MAGIC , NEW_QUAD_MAGIC ): # Quad file
112
116
nvert = _fread3 (fobj )
113
117
nquad = _fread3 (fobj )
114
- coords = np .fromfile (fobj , ">i2" , nvert * 3 ).astype (np .float )
115
- coords = coords .reshape (- 1 , 3 ) / 100.0
118
+ (fmt , div ) = (">i2" , 100. ) if magic == QUAD_MAGIC else (">f4" , 1. )
119
+ coords = np .fromfile (fobj , fmt , nvert * 3 ).astype (np .float ) / div
120
+ coords = coords .reshape (- 1 , 3 )
116
121
quads = _fread3_many (fobj , nquad * 4 )
117
122
quads = quads .reshape (nquad , 4 )
118
123
#
@@ -132,7 +137,7 @@ def read_geometry(filepath, read_metadata=False, read_stamp=False):
132
137
faces [nface ] = quad [0 ], quad [2 ], quad [3 ]
133
138
nface += 1
134
139
135
- elif magic == 16777214 : # Triangle file
140
+ elif magic == TRIANGLE_MAGIC : # Triangle file
136
141
create_stamp = fobj .readline ().rstrip (b'\n ' ).decode ('utf-8' )
137
142
fobj .readline ()
138
143
vnum = np .fromfile (fobj , ">i4" , 1 )[0 ]
0 commit comments