def read(self, reader: ByteIO, stripgroup: SourceVtxStripGroup): global max_bones_per_vertex self.bone_weight_index = [reader.read_uint8() for _ in range(max_bones_per_vertex)] self.bone_count = reader.read_uint8() self.original_mesh_vertex_index = reader.read_uint16() self.bone_id = [reader.read_uint8() for _ in range(max_bones_per_vertex)] stripgroup.vtx_vertexes.append(self)
def read_header00(self, reader: ByteIO): self.id = ''.join(list([chr(reader.read_uint8()) for _ in range(4)])) self.version = reader.read_uint32() print('Found MDL version', self.version) # self.checksum = reader.read_uint32() self.name = reader.read_ascii_string(64) self.file_size = reader.read_uint32()
def read(self, reader: ByteIO): entry = reader.tell() self.vertex_count = reader.read_uint32() self.vertex_offset = reader.read_uint32() self.index_count = reader.read_uint32() self.index_offset = reader.read_uint32() self.strip_count = reader.read_uint32() self.strip_offset = reader.read_uint32() self.flags = StripGroupFlags(reader.read_uint8()) global extra_8 if extra_8: self.topology_indices_count = reader.read_uint32() self.topology_offset = reader.read_uint32() with reader.save_current_pos(): reader.seek(entry + self.index_offset) for _ in range(self.index_count): self.vtx_indexes.append(reader.read_uint16()) reader.seek(entry + self.vertex_offset) for _ in range(self.vertex_count): SourceVtxVertex().read(reader, self) reader.seek(entry + self.strip_offset) for _ in range(self.strip_count): SourceVtxStrip().read(reader, self) if extra_8: reader.seek(entry + self.topology_offset) # for _ in range(self.topology_indices_count): self.topology = (reader.read_bytes(self.topology_indices_count * 2)) return self
def read(self, reader: ByteIO): entry = reader.tell() self.strip_group_count = reader.read_uint32() self.strip_group_offset = reader.read_uint32() self.flags = reader.read_uint8() with reader.save_current_pos(): if self.strip_group_offset > 0: reader.seek(entry + self.strip_group_offset) for _ in range(self.strip_group_count): self.vtx_strip_groups.append(SourceVtxStripGroup().read(reader)) return self
def read(self,reader:ByteIO): entry = reader.tell() self.cycle = reader.read_float() self.eventIndex = reader.read_uint32() self.eventType = reader.read_uint32() self.options = [reader.read_uint8() for _ in range(64)] self.nameOffset = reader.read_uint32() if self.nameOffset: self.theName = reader.read_from_offset(self.nameOffset+entry,reader.read_ascii_string) else: self.theName = str(self.eventIndex) return self
def read(self, reader: ByteIO, stripgroup: SourceVtxStripGroup): entry = reader.tell() self.index_count = reader.read_uint32() self.index_mesh_index = reader.read_uint32() self.vertex_count = reader.read_uint32() self.vertex_mesh_index = reader.read_uint32() self.bone_count = reader.read_uint16() self.flags = StripHeaderFlags(reader.read_uint8()) self.bone_state_change_count = reader.read_uint32() self.bone_state_change_offset = reader.read_uint32() global extra_8 if extra_8: self.topology_indices_count = reader.read_int32() self.topology_offset = reader.read_int32() # print('Strip end',reader.tell()) stripgroup.vtx_strips.append(self)
def read(self, reader: ByteIO): self.theBytes.clear() self.theBytes = [reader.read_uint8() for _ in range(8)] print(self.theBytes)
def read(self, frame_count, anim_section, mdl: SourceMdlFileData, reader: ByteIO): anim_entry = reader.tell() self.boneIndex = reader.read_uint8() print('BoneIndex:',self.boneIndex) try: self.bone_name = mdl.bones[self.boneIndex].name except: self.bone_name = "ERROR" print('BoneName:',self.bone_name) if self.boneIndex == 255: reader.skip(3) return self, 0 if self.boneIndex >= mdl.bone_count: print('Bone index out of range {} - {}'.format(self.boneIndex, mdl.bone_count)) return self, 0 self.flags = reader.read_uint8() self.sflags = self.STUDIO_ANIM.get_flags(self.flags) self.nextSourceMdlAnimationOffset = reader.read_int16() pdata = reader.tell() print('Seq flag',self.flags,self.sflags) if (self.flags & self.STUDIO_ANIM.RAWROT2) > 0: with reader.save_current_pos(): reader.seek(pdata) self.theRot64bits.read(reader) print('Rot 64',self.theRot64bits) if (self.flags & self.STUDIO_ANIM.RAWROT) > 0: with reader.save_current_pos(): reader.seek(pdata) self.theRot48bits.read(reader) print('Rot 48', self.theRot48bits) if (self.flags & self.STUDIO_ANIM.RAWPOS) > 0: with reader.save_current_pos(): reader.seek(pdata+(((self.flags & self.STUDIO_ANIM.RAWROT) != 0)*6) + ((self.flags & self.STUDIO_ANIM.RAWROT2) != 0)*8) self.thePos.read(reader) print('Pos', self.thePos) if (self.flags & self.STUDIO_ANIM.ANIMROT) > 0: with reader.save_current_pos(): rotV_entry = reader.tell() reader.seek(pdata) self.theRotV.read(reader) self.theRotV.read_values(rotV_entry, frame_count, reader) print('Rot V', self.theRotV) if (self.flags & self.STUDIO_ANIM.ANIMPOS) > 0: with reader.save_current_pos(): reader.seek(((self.flags & self.STUDIO_ANIM.ANIMPOS)!=0) + pdata) posV_entry = reader.tell() self.thePosV.read(reader) self.thePosV.read_values(posV_entry, frame_count, reader) print('Pos V', self.thePosV) print('\n') pprint(self.__dict__) print('\n') if self.nextSourceMdlAnimationOffset == 0: print('DONE WITH ANIMATIONS') reader.seek(pdata) return self, -1 else: nextAnimationInputFileStreamPosition = anim_entry + self.nextSourceMdlAnimationOffset if nextAnimationInputFileStreamPosition < reader.tell(): print('PROBLEM! Should not be going backwards in file.') # raise BufferError('PROBLEM! Should not be going backwards in file.') reader.seek(nextAnimationInputFileStreamPosition) anim_section.append(self) return self, 1
def read(self, reader: ByteIO): self.weight = [reader.read_float() for _ in range(3)] self.bone = [reader.read_uint8() for _ in range(3)] self.boneCount = reader.read_uint8() return self
def read_from_buffer(self, reader: ByteIO): if self.format == DXGI_FORMAT.R32G32B32_FLOAT: return [ reader.read_float() for _ in range(self.format.name.count('32')) ] elif self.format == DXGI_FORMAT.R32G32B32_UINT: return [ reader.read_uint32() for _ in range(self.format.name.count('32')) ] elif self.format == DXGI_FORMAT.R32G32B32_SINT: return [ reader.read_int32() for _ in range(self.format.name.count('32')) ] elif self.format == DXGI_FORMAT.R32G32B32A32_FLOAT: return [ reader.read_float() for _ in range(self.format.name.count('32')) ] elif self.format == DXGI_FORMAT.R32G32B32A32_UINT: return [ reader.read_uint32() for _ in range(self.format.name.count('32')) ] elif self.format == DXGI_FORMAT.R32G32B32A32_SINT: return [ reader.read_int32() for _ in range(self.format.name.count('32')) ] elif self.format == DXGI_FORMAT.R16G16_FLOAT: return [ short_to_float(reader.read_int16()) for _ in range(self.format.name.count('16')) ] elif self.format == DXGI_FORMAT.R32G32_FLOAT: return [ short_to_float(reader.read_float()) for _ in range(self.format.name.count('32')) ] elif self.format == DXGI_FORMAT.R16G16_SINT: return [ reader.read_int16() for _ in range(self.format.name.count('16')) ] elif self.format == DXGI_FORMAT.R16G16_UINT: return [ reader.read_uint16() for _ in range(self.format.name.count('16')) ] elif self.format == DXGI_FORMAT.R8G8B8A8_SNORM: return [ reader.read_int8() for _ in range(self.format.name.count('8')) ] elif self.format == DXGI_FORMAT.R8G8B8A8_UNORM: return [ reader.read_uint8() for _ in range(self.format.name.count('8')) ] elif self.format == DXGI_FORMAT.R8G8B8A8_UINT: return [ reader.read_uint8() for _ in range(self.format.name.count('8')) ] else: raise NotImplementedError('Unknown buffer format {}'.format( self.format.name))