@@ -50,17 +50,21 @@ def __init__(self):
5050 self .vertexBuffers = []
5151 self .submeshes = []
5252
53+ self .vertexCount = 0
54+ self .vertexBufferCount = 0
55+ self .submeshCount = 0
56+
5357 def read2 (self , stream ):
5458 # Read vertex buffers
55- vertexCount , bufferCount = unpackStream ("<2I" , stream )
56- for _ in range (bufferCount ):
59+ self . vertexCount , self . vertexBufferCount = unpackStream ("<2I" , stream )
60+ for _ in range (self . vertexBufferCount ):
5761 vertexBuffer = A3DVertexBuffer ()
58- vertexBuffer .read2 (vertexCount , stream )
62+ vertexBuffer .read2 (self . vertexCount , stream )
5963 self .vertexBuffers .append (vertexBuffer )
6064
6165 # Read submeshes
62- submeshCount , = unpackStream ("<I" , stream )
63- for _ in range (submeshCount ):
66+ self . submeshCount , = unpackStream ("<I" , stream )
67+ for _ in range (self . submeshCount ):
6468 submesh = A3DSubmesh ()
6569 submesh .read2 (stream )
6670 self .submeshes .append (submesh )
@@ -76,15 +80,15 @@ def read3(self, stream):
7680 stream .read (4 ) # XXX: Unknown float value
7781
7882 # Read vertex buffers
79- vertexCount , bufferCount = unpackStream ("<2I" , stream )
80- for _ in range (bufferCount ):
83+ self . vertexCount , self . vertexBufferCount = unpackStream ("<2I" , stream )
84+ for _ in range (self . vertexBufferCount ):
8185 vertexBuffer = A3DVertexBuffer ()
82- vertexBuffer .read2 (vertexCount , stream )
86+ vertexBuffer .read2 (self . vertexCount , stream )
8387 self .vertexBuffers .append (vertexBuffer )
8488
8589 # Read submeshes
86- submeshCount , = unpackStream ("<I" , stream )
87- for _ in range (submeshCount ):
90+ self . submeshCount , = unpackStream ("<I" , stream )
91+ for _ in range (self . submeshCount ):
8892 submesh = A3DSubmesh ()
8993 submesh .read3 (stream )
9094 self .submeshes .append (submesh )
@@ -125,34 +129,29 @@ def read2(self, vertexCount, stream):
125129class A3DSubmesh :
126130 def __init__ (self ):
127131 self .indices = []
128- self .faces = []
129132 self .smoothingGroups = []
130133 self .materialID = None
131134
135+ self .indexCount = 0
136+
132137 def read2 (self , stream ):
133- faceCount , = unpackStream ("<I" , stream )
134- for _ in range (faceCount ):
135- face = unpackStream ("<3H" , stream )
136- self .faces .append (face )
137- for _ in range (faceCount ):
138- smoothingGroup , = unpackStream ("<I" , stream )
139- self .smoothingGroups .append (smoothingGroup )
138+ self .indexCount , = unpackStream ("<I" , stream )* 3
139+ self .indices = list (unpackStream (f"<{ self .indexCount } H" , stream ))
140+ self .smoothingGroups = list (unpackStream (f"<{ self .indexCount // 3 } I" , stream ))
140141 self .materialID , = unpackStream ("<H" , stream )
141142
142- print (f"[A3DSubmesh indices: { len (self .indices )} faces: { len ( self . faces ) } smoothing groups: { len (self .smoothingGroups )} materialID: { self .materialID } ]" )
143+ print (f"[A3DSubmesh indices: { len (self .indices )} smoothing groups: { len (self .smoothingGroups )} materialID: { self .materialID } ]" )
143144
144145 def read3 (self , stream ):
145146 # Read indices
146- indexCount , = unpackStream ("<I" , stream )
147- for _ in range (indexCount ):
148- index , = unpackStream ("<H" , stream )
149- self .indices .append (index )
147+ self .indexCount , = unpackStream ("<I" , stream )
148+ self .indices = list (unpackStream (f"<{ self .indexCount } H" , stream ))
150149
151150 # Padding
152- padding = calculatePadding (indexCount * 2 ) # Each index is 2 bytes
151+ padding = calculatePadding (self . indexCount * 2 ) # Each index is 2 bytes
153152 stream .read (padding )
154153
155- print (f"[A3DSubmesh indices: { len (self .indices )} faces: { len ( self . faces ) } smoothing groups: { len (self .smoothingGroups )} materialID: { self .materialID } ]" )
154+ print (f"[A3DSubmesh indices: { len (self .indices )} smoothing groups: { len (self .smoothingGroups )} materialID: { self .materialID } ]" )
156155
157156class A3DTransform :
158157 def __init__ (self ):
@@ -183,17 +182,19 @@ def __init__(self):
183182 self .transformID = None
184183 self .materialIDs = []
185184
185+ self .materialCount = 0
186+
186187 def read2 (self , stream ):
187188 self .name = readNullTerminatedString (stream )
188189 self .meshID , self .transformID = unpackStream ("<2I" , stream )
189190
190191 print (f"[A3DObject name: { self .name } meshID: { self .meshID } transformID: { self .transformID } materialIDs: { len (self .materialIDs )} ]" )
191192
192193 def read3 (self , stream ):
193- self .meshID , self .transformID , materialCount = unpackStream ("<3I" , stream )
194+ self .meshID , self .transformID , self . materialCount = unpackStream ("<3I" , stream )
194195
195196 # Read material IDs
196- for _ in range (materialCount ):
197+ for _ in range (self . materialCount ):
197198 materialID , = unpackStream ("<I" , stream )
198199 self .materialIDs .append (materialID )
199200
0 commit comments