Example #1
0
	def save(self, filepath):
		names_writer = BinaryStream()
		data_writer = BinaryStream()
		# shader name is at 0
		names_writer.write_zstring(self.shader_name)
		# attribs are written first
		for attrib in self.attributes:
			attrib.offset = names_writer.tell()
			names_writer.write_zstring(attrib.name)
			attrib.first_value_offset = data_writer.tell()
			fmt = dtypes[attrib.dtype]
			b = struct.pack("<" + fmt, *attrib.value)
			data_writer.write(b)
		for texture in self.textures:
			if texture.textured:
				for i in range(len(texture.indices)):
					# uint - hashes
					texture.indices[i] = max(0, texture.value[i])
				tex_ind = texture.indices[0]
				self.texture_names[tex_ind] = texture.name
			texture.offset = names_writer.tell()
			names_writer.write_zstring(texture.type)

		# write the output stream
		with self.writer(filepath) as stream:
			self.write(stream)
			stream.write(b"\x00" * self.zeros_size)
			stream.write(data_writer.getvalue())
			stream.write(names_writer.getvalue())
Example #2
0
 def save(self, filepath):
     names_writer = BinaryStream()
     data_writer = BinaryStream()
     # shader name is at 0
     names_writer.write_zstring(self.shader_name)
     names_writer.write(b"\x00")
     # attribs are written first
     for attrib in self.attributes:
         attrib.offset = names_writer.tell()
         names_writer.write_zstring(attrib.name)
         attrib.value_offset = data_writer.tell()
         b = struct.pack(f"<{dtypes[attrib.dtype]}", *attrib.value)
         data_writer.write(b)
     self.texture_files.clear()
     for texture in self.textures:
         # if the texture has a file, store its index
         if texture.textured:
             texture.indices[0] = len(self.texture_files)
             self.texture_files.append(texture.file)
         texture.offset = names_writer.tell()
         names_writer.write_zstring(texture.name)
     # update counts
     data_bytes = data_writer.getvalue()
     self.data_lib_size = len(data_bytes)
     self.dependency_count = len(self.texture_files)
     self.fgm_info.texture_count = len(self.textures)
     self.fgm_info.attribute_count = len(self.attributes)
     # write the output stream
     with self.writer(filepath) as stream:
         self.write(stream)
         stream.write(data_bytes)
         stream.write(names_writer.getvalue())