Example #1
0
 def read_mdl(self, stream: TokenStream):
     self.name = stream.read()
     for token in stream.read_block():
         if token == 'Position':
             self.position = stream.read_vector(3)
         elif token == 'Translation':
             self.read_animation(stream, 'KCTR')
         elif token == 'Rotation':
             self.read_animation(stream, 'KCRL')
         elif token == 'FieldOfView':
             self.field_of_view = stream.read_float()
         elif token == 'FarClip':
             self.far_clipping_plane = stream.read_float()
         elif token == 'NearClip':
             self.near_clipping_plane = stream.read_float()
         elif token == 'Target':
             for token in stream.read_block():
                 if token == 'Position':
                     self.target_position = stream.read_vector(3)
                 elif token == 'Translation':
                     self.read_animation(stream, 'KTTR')
                 else:
                     raise TokenStreamError('Camera', token, want_name=self.name, want_target=1)
         else:
             raise TokenStreamError('Camera', token, want_name=self.name)
Example #2
0
 def read_mdl(self, stream: TokenStream, version=None):
     self.type = stream.read()
     for token in stream.read_block():
         if token == 'Path':
             self.path = stream.read()
         else:
             raise TokenStreamError('FaceEffect', token)
Example #3
0
 def read_generic_block(self, stream: TokenStream):
     self.name = stream.read()
     for token in self.read_animated_block(stream):
         if token == 'ObjectId':
             self.object_id = stream.read_int()
         elif token == 'Parent':
             self.parent_id = stream.read_int()
         elif token == 'BillboardedLockZ':
             self.flags |= 0x40
         elif token == 'BillboardedLockY':
             self.flags |= 0x20
         elif token == 'BillboardedLockX':
             self.flags |= 0x10
         elif token == 'Billboarded':
             self.flags |= 0x8
         elif token == 'CameraAnchored':
             self.flags |= 0x80
         elif token == 'DontInherit':
             for token in stream.read_block():
                 if token == 'Rotation':
                     self.flags |= 0x2
                 elif token == 'Translation':
                     self.flags |= 0x1
                 elif token == 'Scaling':
                     self.flags |= 0x4
         elif token == 'Translation':
             self.read_animation(stream, 'KGTR')
         elif token == 'Rotation':
             self.read_animation(stream, 'KGRT')
         elif token == 'Scaling':
             self.read_animation(stream, 'KGSC')
         else:
             yield token
Example #4
0
 def load_global_sequence_block(self, stream: TokenStream):
     stream.read()
     for token in stream.read_block():
         if token == 'Duration':
             self.global_sequences.append(stream.read_int())
         else:
             raise TokenStreamError('GlobalSequences', token)
 def read_mdl(self, stream: TokenStream):
     for token in stream.read_block():
         if token == 'Translation':
             self.read_animation(stream, 'KTAT')
         elif token == 'Rotation':
             self.read_animation(stream, 'KTAR')
         elif token == 'Scaling':
             self.read_animation(stream, 'KTAS')
         else:
             raise TokenStreamError('TextureAnimation', token)
Example #6
0
 def load_bind_pose_block(self, stream: TokenStream):
     for token in stream.read_block():
         if token == 'Matrices':
             matrices = stream.read_int()
             stream.read()
             for i in range(matrices):
                 self.bind_pose.append(stream.read_vector(12))
             stream.read()
         else:
             raise TokenStreamError('BindPose', token)
Example #7
0
 def load_numbered_object_block(self, out, class_name, name,
                                stream: TokenStream):
     stream.read()
     for token in stream.read_block():
         if token == name:
             obj = class_name()
             obj.read_mdl(stream)
             out.append(obj)
         else:
             raise TokenStreamError(name, token)
Example #8
0
 def read_mdl(self, stream: TokenStream):
     for token in stream.read_block():
         if token == 'Image':
             self.path = stream.read()
         elif token == 'ReplaceableId':
             self.replaceable_id = stream.read_int()
         elif token == 'WrapWidth':
             self.flags |= 0x1
         elif token == 'WrapHeight':
             self.flags |= 0x2
         else:
             raise TokenStreamError('Texture', token)
Example #9
0
 def load_model_block(self, stream: TokenStream):
     self.name = stream.read()
     for token in stream.read_block():
         if token.startswith('Num'):
             stream.read()
         elif token == 'BlendTime':
             self.blend_time = stream.read_int()
         elif token == 'MinimumExtent':
             self.extent.min = stream.read_vector(3)
         elif token == 'MaximumExtent':
             self.extent.max = stream.read_vector(3)
         elif token == 'BoundsRadius':
             self.extent.bounds_radius = stream.read_float()
         elif token == 'AnimationFile':
             self.animation_file = stream.read()
         else:
             raise TokenStreamError('Model', token)
Example #10
0
 def read_mdl(self, stream: TokenStream):
     self.name = stream.read()
     for token in stream.read_block():
         if token == 'Interval':
             self.interval = stream.read_vector(2)
         elif token == 'NonLooping':
             self.flags = 1
         elif token == 'MoveSpeed':
             self.move_speed = stream.read_float()
         elif token == 'Rarity':
             self.rarity = stream.read_float()
         elif token == 'MinimumExtent':
             self.extent.min = stream.read_vector(3)
         elif token == 'MaximumExtent':
             self.extent.max = stream.read_vector(3)
         elif token == 'BoundsRadius':
             self.extent.bounds_radius = stream.read_float()
         else:
             raise TokenStreamError('Sequence', token)
Example #11
0
 def read_mdl(self, stream: TokenStream, version=None):
     for token in stream.read_block():
         if token == 'ConstantColor':
             self.flags |= 0x1
         elif token == 'TwoSided':
             self.flags |= 0x2
         elif token == 'SortPrimsNearZ':
             self.flags |= 0x8
         elif token == 'SortPrimsFarZ':
             self.flags |= 0x10
         elif token == 'FullResolution':
             self.flags |= 0x20
         elif token == 'PriorityPlane':
             self.priority_plane = stream.read_int()
         elif token == 'Shader':
             self.shader = stream.read()
         elif token == 'Layer':
             layer = Layer()
             layer.read_mdl(stream)
             self.layers.append(layer)
         else:
             raise TokenStreamError('Material', token)
Example #12
0
 def read_mdl(self, stream: TokenStream):
     for token in stream.read_block():
         if token == 'Vertices':
             self.vertices = stream.read_vectors_block(stream.read_int(), 3)
         elif token == 'Normals':
             self.normals = stream.read_vectors_block(stream.read_int(), 3)
         elif token == 'TVertices':
             self.uv_sets.append(
                 stream.read_vectors_block(stream.read_int(), 2))
         elif token == 'VertexGroup':
             vertex_groups = []
             for vertex_group in stream.read_block():
                 vertex_groups.append(int(vertex_group))
             self.vertex_groups = vertex_groups
         elif token == 'Tangents':
             self.tangents = stream.read_vectors_block(stream.read_int(), 4)
         elif token == 'SkinWeights':
             self.skin = stream.read_vector(stream.read_int() * 8)
         elif token == 'Faces':
             self.face_type_groups = []
             vectors = stream.read_int()
             count = stream.read_int()
             stream.read()
             stream.read()
             self.faces = stream.read_single_vector_block(count)
             self.face_groups = [count]
             stream.read()
         elif token == 'Groups':
             indices = []
             groups = []
             stream.read_int()
             stream.read_int()
             for _ in stream.read_block():
                 size = 0
                 for index in stream.read_block():
                     indices.append(int(index))
                     size += 1
                 groups.append(size)
             self.matrix_indices = indices
             self.matrix_groups = groups
         elif token == 'MinimumExtent':
             self.extent.min = stream.read_vector(3)
         elif token == 'MaximumExtent':
             self.extent.max = stream.read_vector(3)
         elif token == 'BoundsRadius':
             self.extent.bounds_radius = stream.read_float()
         elif token == 'Anim':
             extent = Extent()
             for token in stream.read_block():
                 if token == 'MinimumExtent':
                     extent.min = stream.read_vector(3)
                 elif token == 'MaximumExtent':
                     extent.max = stream.read_vector(3)
                 elif token == 'BoundsRadius':
                     extent.bounds_radius = stream.read_float()
             self.sequence_extents.append(extent)
         elif token == 'MaterialID':
             self.material_id = stream.read_int()
         elif token == 'SelectionGroup':
             self.selection_group = stream.read_int()
         elif token == 'Unselectable':
             self.selection_flags = 4
         elif token == 'LevelOfDetail':
             self.lod = stream.read_int()
         elif token == 'Name':
             self.lod_name = stream.read()
         else:
             raise TokenStreamError('Geoset', token)
Example #13
0
 def read_animated_block(self, stream: TokenStream):
     for token in stream.read_block():
         if token == 'static':
             yield f'static {stream.read()}'
         else:
             yield token
Example #14
0
 def load_version_block(self, stream: TokenStream):
     for token in stream.read_block():
         if token == 'FormatVersion':
             self.version = stream.read_int()
         else:
             raise TokenStreamError('Version', token)