-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathImodMesh.py
executable file
·39 lines (34 loc) · 1.16 KB
/
ImodMesh.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
37
38
import struct
class ImodMesh(object):
def __init__(self,
fid = None,
debug = 0,
nVertices = 0,
nIndices = 0,
flag = 0,
type = 0,
pad = 0,
vertices = [],
indices = [],
**kwargs):
self.__dict__.update(kwargs)
self.__dict__.update(locals())
if self.fid:
self.read_file()
def read_file(self):
fid = self.fid
self.nVertices = struct.unpack('>l', fid.read(4))[0]
self.nIndices = struct.unpack('>l', fid.read(4))[0]
self.flag = struct.unpack('>l', fid.read(4))[0]
self.type = struct.unpack('>h', fid.read(2))[0]
self.pad = struct.unpack('>h', fid.read(2))[0]
self.vertices = struct.unpack('>{0}f'.format(3 * self.nVertices),
fid.read(12 * self.nVertices))
self.indices = struct.unpack('>{0}l'.format(self.nIndices),
fid.read(4 * self.nIndices))
return self
def dump(self):
from collections import OrderedDict as od
for key, value in od(sorted(self.__dict__.items())).iteritems():
print key, value
print "\n"