def save_static_object_chunk(self, stream: BinaryStream, name, objects, size): if len(objects): stream.write(name) stream.write_uint32(len(objects) * size) for obj in objects: obj.write_mdx(stream)
def save_mdx(self): buffer = bytearray(self.get_byte_length()) stream = BinaryStream(buffer) stream.write('MDLX') self.save_version_chunk(stream) self.save_model_chunk(stream) self.save_static_object_chunk(stream, 'SEQS', self.sequences, 132) self.save_global_sequence_chunk(stream) self.save_dynamic_object_chunk(stream, 'MTLS', self.materials) self.save_static_object_chunk(stream, 'TEXS', self.textures, 268) self.save_dynamic_object_chunk(stream, 'TXAN', self.texture_animations) self.save_dynamic_object_chunk(stream, 'GEOS', self.geosets) self.save_dynamic_object_chunk(stream, 'GEOA', self.geoset_animations) self.save_dynamic_object_chunk(stream, 'BONE', self.bones) self.save_dynamic_object_chunk(stream, 'LITE', self.lights) self.save_dynamic_object_chunk(stream, 'HELP', self.helpers) self.save_dynamic_object_chunk(stream, 'ATCH', self.attachments) self.save_pivot_point_chunk(stream) self.save_dynamic_object_chunk(stream, 'PREM', self.particle_emitters) self.save_dynamic_object_chunk(stream, 'PRE2', self.particle_emitters2) if self.version > 800: self.save_dynamic_object_chunk(stream, 'CORN', self.particle_emitters_popcorn) self.save_dynamic_object_chunk(stream, 'RIBB', self.ribbon_emitters) self.save_dynamic_object_chunk(stream, 'CAMS', self.cameras) self.save_dynamic_object_chunk(stream, 'EVTS', self.event_objects) self.save_dynamic_object_chunk(stream, 'CLID', self.collision_shapes) if self.version > 800: self.save_static_object_chunk(stream, 'FAFX', self.face_effects, 340) self.save_bind_pose_chunk(stream) for chunk in self.unknown_chunks: chunk.write_mdx(stream) return stream.buffer_array
def save_bind_pose_chunk(self, stream: BinaryStream): if len(self.bind_pose): stream.write('BPOS') stream.write_uint32(4 + len(self.bind_pose) * 48) stream.write_uint32(len(self.bind_pose)) for matrix in self.bind_pose: stream.write_float32_array(matrix)
def write_mdx(self, stream: BinaryStream, version): stream.write_uint32(self.get_byte_length()) super().write_mdx(stream, version) stream.write(self.path) stream.skip(260 - len(self.path)) stream.write_int32(self.attachment_id) self.write_non_generic_animation_chunks(stream)
def write_mdx(self, stream: BinaryStream, version): stream.write_uint32(self.get_generic_byte_length()) stream.write(self.name) stream.skip(80 - len(self.name)) stream.write_int32(self.object_id) stream.write_int32(self.parent_id) stream.write_uint32(self.flags) for animation in self.each_animation(True): animation.write_mdx(stream)
def write_mdx(self, stream: BinaryStream): stream.write(self.name) stream.skip(80 - len(self.name)) stream.write_uint32_array(self.interval) stream.write_float32(self.move_speed) stream.write_uint32(self.flags) stream.write_float32(self.rarity) stream.write_uint32(self.sync_point) self.extent.write_mdx(stream)
def write_mdx(self, stream: BinaryStream, version): stream.write_uint32(self.get_byte_length(version=version)) stream.write(self.name) stream.skip(80 - len(self.name)) stream.write_float32_array(self.position) stream.write_float32(self.field_of_view) stream.write_float32(self.far_clipping_plane) stream.write_float32(self.near_clipping_plane) stream.write_float32_array(self.target_position) self.write_animations(stream)
def write_mdx(self, stream: BinaryStream, version: int): stream.write_uint32(self.get_byte_length(version)) stream.write_int32(self.priority_plane) stream.write_uint32(self.flags) if version > 800: stream.write(self.shader) stream.skip(80 - len(self.shader)) stream.write('LAYS') stream.write_uint32(len(self.layers)) for layer in self.layers: layer.write_mdx(stream, version)
def write_mdx(self, stream: BinaryStream, version): stream.write_int32(self.get_byte_length()) super().write_mdx(stream, version) stream.write_float32(self.emission_rate) stream.write_float32(self.gravity) stream.write_float32(self.longitude) stream.write_float32(self.latitude) stream.write(self.path) stream.skip(260 - len(self.path)) stream.write_float32(self.life_span) stream.write_float32(self.speed) self.write_non_generic_animation_chunks(stream)
def write_mdx(self, stream: BinaryStream, version): stream.write_uint32(self.get_byte_length()) super().write_mdx(stream, version) stream.write_float32(self.life_span) stream.write_float32(self.emission_rate) stream.write_float32(self.speed) stream.write_float32_array(self.color) stream.write_float32(self.alpha) stream.write_uint32(self.replaceable_id) stream.write(self.path) stream.skip(260 - len(self.path)) stream.write(self.animation_visibility_guide) stream.skip(260 - len(self.animation_visibility_guide)) self.write_non_generic_animation_chunks(stream)
def write_mdx(self, stream: BinaryStream): interpolation_type = self.interpolation_type frames = self.frames values = self.values in_tans = self.in_tans out_tans = self.out_tans tracks_count = len(frames) stream.write(self.name) stream.write_uint32(tracks_count) stream.write_uint32(interpolation_type) stream.write_int32(self.global_sequence_id) for i in range(tracks_count): stream.write_int32(frames[i]) self.write_mdx_value(stream, values[i]) if interpolation_type > 1: self.write_mdx_value(stream, in_tans[i]) self.write_mdx_value(stream, out_tans[i])
def save_model_chunk(self, stream: BinaryStream): stream.write('MODL') stream.write_uint32(372) stream.write(self.name) stream.skip(80 - len(self.name)) stream.write(self.animation_file) stream.skip(260 - len(self.animation_file)) self.extent.write_mdx(stream) stream.write_uint32(self.blend_time)
def write_mdx(self, stream: BinaryStream, version): super().write_mdx(stream, version) stream.write('KEVT') stream.write_uint32(len(self.tracks)) stream.write_int32(self.global_sequence_id) stream.write_uint32_array(self.tracks)
def write_mdx(self, stream: BinaryStream): stream.write(self.type) stream.skip(80 - len(self.type)) stream.write(self.path) stream.skip(260 - len(self.path))
def write_mdx(self, stream: BinaryStream): stream.write(self.tag) stream.write_uint32(len(self.chunk)) stream.write_uint8_array(self.chunk)
def write_mdx(self, stream: BinaryStream, version: int): stream.write_uint32(self.get_byte_length(version)) stream.write('VRTX') stream.write_uint32(len(self.vertices) // 3) stream.write_float32_array(self.vertices) stream.write('NRMS') stream.write_uint32(len(self.normals) // 3) stream.write_float32_array(self.normals) stream.write('PTYP') stream.write_uint32(len(self.face_type_groups)) stream.write_uint32_array(self.face_type_groups) stream.write('PCNT') stream.write_uint32(len(self.face_groups)) stream.write_uint32_array(self.face_groups) stream.write('PVTX') stream.write_uint32(len(self.faces)) stream.write_uint16_array(self.faces) stream.write('GNDX') stream.write_uint32(len(self.vertex_groups)) stream.write_uint8_array(self.vertex_groups) stream.write('MTGC') stream.write_uint32(len(self.matrix_groups)) stream.write_uint32_array(self.matrix_groups) stream.write('MATS') stream.write_uint32(len(self.matrix_indices)) stream.write_uint32_array(self.matrix_indices) stream.write_uint32(self.material_id) stream.write_uint32(self.selection_group) stream.write_uint32(self.selection_flags) if version > 800: stream.write_int32(self.lod) stream.write(self.lod_name) stream.skip(80 - len(self.lod_name)) self.extent.write_mdx(stream) stream.write_uint32(len(self.sequence_extents)) for sequence_extent in self.sequence_extents: sequence_extent.write_mdx(stream) if version > 800: if len(self.tangents): stream.write('TANG') stream.write_uint32(len(self.tangents) // 4) stream.write_float32_array(self.tangents) if len(self.skin): stream.write('SKIN') stream.write_uint32(len(self.skin)) stream.write_uint8_array(self.skin) stream.write('UVAS') stream.write_uint32(len(self.uv_sets)) for uv_set in self.uv_sets: stream.write('UVBS') stream.write_uint32(len(uv_set) // 2) stream.write_float32_array(uv_set)
def save_version_chunk(self, stream: BinaryStream): stream.write('VERS') stream.write_uint32(4) stream.write_uint32(self.version)
def write_mdx(self, stream: BinaryStream): stream.write_uint32(self.replaceable_id) stream.write(self.path) stream.skip(260 - len(self.path)) stream.write_uint32(self.flags)
def save_global_sequence_chunk(self, stream: BinaryStream): if len(self.global_sequences): stream.write('GLBS') stream.write_uint32(len(self.global_sequences) * 4) for global_sequence in self.global_sequences: stream.write_uint32(global_sequence)
def save_dynamic_object_chunk(self, stream: BinaryStream, name, objects): if len(objects): stream.write(name) stream.write_uint32(self.get_objects_byte_length(objects)) for obj in objects: obj.write_mdx(stream, self.version)
def save_pivot_point_chunk(self, stream: BinaryStream): if len(self.pivot_points): stream.write('PIVT') stream.write_uint32(len(self.pivot_points) * 12) for pivot_point in self.pivot_points: stream.write_float32_array(pivot_point)