@@ -46,6 +46,7 @@ def _fread3_many(fobj, n):
4646
4747
4848def _read_volume_info (fobj ):
49+ """Helper for reading the footer from a surface file."""
4950 volume_info = OrderedDict ()
5051 head = np .fromfile (fobj , '>i4' , 1 )
5152 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):
106107 """
107108 volume_info = OrderedDict ()
108109
110+ TRIANGLE_MAGIC = 16777214
111+ QUAD_MAGIC = 16777215
112+ NEW_QUAD_MAGIC = 16777213
109113 with open (filepath , "rb" ) as fobj :
110114 magic = _fread3 (fobj )
111- if magic in (16777215 , 16777213 ): # Quad file
115+ if magic in (QUAD_MAGIC , NEW_QUAD_MAGIC ): # Quad file
112116 nvert = _fread3 (fobj )
113117 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 )
116121 quads = _fread3_many (fobj , nquad * 4 )
117122 quads = quads .reshape (nquad , 4 )
118123 #
@@ -132,7 +137,7 @@ def read_geometry(filepath, read_metadata=False, read_stamp=False):
132137 faces [nface ] = quad [0 ], quad [2 ], quad [3 ]
133138 nface += 1
134139
135- elif magic == 16777214 : # Triangle file
140+ elif magic == TRIANGLE_MAGIC : # Triangle file
136141 create_stamp = fobj .readline ().rstrip (b'\n ' ).decode ('utf-8' )
137142 fobj .readline ()
138143 vnum = np .fromfile (fobj , ">i4" , 1 )[0 ]
0 commit comments