Esempio n. 1
0
 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
Esempio n. 2
0
 def read_mdx(self, stream: BinaryStream, version):
     start = stream.index
     size = stream.read_uint32()
     super().read_mdx(stream, version)
     self.path = stream.read(260)
     self.attachment_id = stream.read_int32()
     self.read_animations(stream, size - (stream.index - start))
Esempio n. 3
0
 def write_mdx(self, stream: BinaryStream, version):
     stream.write_uint32(self.get_byte_length())
     stream.write_float32(self.alpha)
     stream.write_uint32(self.flags)
     stream.write_float32_array(self.color)
     stream.write_int32(self.geoset_id)
     self.write_animations(stream)
Esempio n. 4
0
 def read_mdx(self, stream: BinaryStream, version):
     size = stream.read_uint32()
     self.name = stream.read(80)
     self.object_id = stream.read_int32()
     self.parent_id = stream.read_int32()
     self.flags = stream.read_uint32()
     self.read_animations(stream, size - 96)
Esempio n. 5
0
 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)
Esempio n. 6
0
 def read_mdx(self, stream: BinaryStream, version):
     size = stream.read_uint32()
     self.alpha = stream.read_float32()
     self.flags = stream.read_uint32()
     self.color = stream.read_float32_array(3)
     self.geoset_id = stream.read_int32()
     self.read_animations(stream, size - 28)
Esempio n. 7
0
 def read_mdx(self, stream: BinaryStream, version):
     super().read_mdx(stream, version)
     self.type = stream.read_uint32()
     self.vertices[0] = stream.read_float32_array(3)
     if self.type != 2:
         self.vertices[1] = stream.read_float32_array(3)
     if self.type == 2 or self.type == 3:
         self.bounds_radius = stream.read_float32()
Esempio n. 8
0
 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)
Esempio n. 9
0
 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)
Esempio n. 10
0
 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)
Esempio n. 11
0
 def write_mdx(self, stream: BinaryStream, version):
     super().write_mdx(stream, version)
     stream.write_uint32(self.type)
     stream.write_float32_array(self.vertices[0])
     if self.type != 2:
         stream.write_float32_array(self.vertices[1])
     if self.type == 2 or self.type == 3:
         stream.write_float32(self.bounds_radius)
Esempio n. 12
0
 def read_animations(self, stream: BinaryStream, size: int):
     end = stream.index + size
     while stream.index < end:
         name = stream.read(4)
         animation = animation_map[name][1]()
         animation.read_mdx(stream, name)
         self.animations.append(animation)
Esempio n. 13
0
 def read_mdx(self, stream: BinaryStream, name: str):
     frames = self.frames
     values = self.values
     in_tans = self.in_tans
     out_tans = self.out_tans
     tracks_count = stream.read_uint32()
     interpolation_type = stream.read_uint32()
     self.name = name
     self.interpolation_type = interpolation_type
     self.global_sequence_id = stream.read_int32()
     for i in range(tracks_count):
         frames.append(stream.read_int32())
         values.append(self.read_mdx_value(stream))
         if interpolation_type > 1:
             in_tans.append(self.read_mdx_value(stream))
             out_tans.append(self.read_mdx_value(stream))
Esempio n. 14
0
 def load(self):
     if isinstance(self.buffer, str):
         self.stream = TokenStream(buffer=self.buffer)
         self.load_mdl(self.stream)
     elif isinstance(self.buffer, (bytearray, bytes)):
         self.stream = BinaryStream(self.buffer)
         self.load_mdx()
 def read_mdx(self, stream: BinaryStream, version):
     start = stream.index
     size = stream.read_uint32()
     super().read_mdx(stream, version)
     self.life_span = stream.read_float32()
     self.emission_rate = stream.read_float32()
     self.speed = stream.read_float32()
     self.color = stream.read_float32_array(3)
     self.alpha = stream.read_float32()
     self.replaceable_id = stream.read_uint32()
     self.path = stream.read(260)
     self.animation_visibility_guide = stream.read(260)
     self.read_animations(stream, size - (stream.index - start))
Esempio n. 16
0
 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])
Esempio n. 17
0
 def read_mdx(self, stream: BinaryStream, version: int):
     stream.read_uint32()
     self.priority_plane = stream.read_int32()
     self.flags = stream.read_uint32()
     if version > 800:
         self.shader = stream.read(80)
     stream.skip(4)  # LAYS
     for i in range(stream.read_uint32()):
         layer = Layer()
         layer.read_mdx(stream, version)
         self.layers.append(layer)
Esempio n. 18
0
 def read_mdx(self, stream: BinaryStream, version):
     start = stream.index
     size = stream.read_uint32()
     super().read_mdx(stream, version)
     self.emission_rate = stream.read_float32()
     self.gravity = stream.read_float32()
     self.longitude = stream.read_float32()
     self.latitude = stream.read_float32()
     self.path = stream.read(260)
     self.life_span = stream.read_float32()
     self.speed = stream.read_float32()
     self.read_animations(stream, size - (stream.index - start))
Esempio n. 19
0
 def read_mdx(self, stream: BinaryStream, version):
     size = stream.read_uint32()
     self.name = stream.read(80)
     self.position = stream.read_float32_array(3)
     self.field_of_view = stream.read_float32()
     self.far_clipping_plane = stream.read_float32()
     self.near_clipping_plane = stream.read_float32()
     self.target_position = stream.read_float32_array(3)
     self.read_animations(stream, size - 120)
Esempio n. 20
0
 def read_mdx(self, stream: BinaryStream, version):
     start = stream.index
     size = stream.read_uint32()
     super().read_mdx(stream, version)
     self.type = stream.read_uint32()
     self.attenuation = stream.read_float32_array(2)
     self.color = stream.read_float32_array(3)
     self.intensity = stream.read_float32()
     self.ambient_color = stream.read_float32_array(3)
     self.ambient_intensity = stream.read_float32()
     self.read_animations(stream, size - (stream.index - start))
Esempio n. 21
0
 def read_mdx(self, stream: BinaryStream):
     self.name = stream.read(80)
     self.interval = stream.read_uint32_array(2)
     self.move_speed = stream.read_float32()
     self.flags = stream.read_uint32()
     self.rarity = stream.read_float32()
     self.sync_point = stream.read_uint32()
     self.extent.read_mdx(stream)
Esempio n. 22
0
 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)
Esempio n. 23
0
 def read_mdx(self, stream: BinaryStream, version):
     super().read_mdx(stream, version)
     stream.skip(4)  # KEVT TAG
     count = stream.read_uint32()
     self.global_sequence_id = stream.read_int32()
     self.tracks = stream.read_uint32_array(count)
Esempio n. 24
0
 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))
Esempio n. 25
0
 def read_mdx(self, stream: BinaryStream):
     self.type = stream.read(80)
     self.path = stream.read(260)
Esempio n. 26
0
 def write_mdx(self, stream: BinaryStream):
     stream.write(self.tag)
     stream.write_uint32(len(self.chunk))
     stream.write_uint8_array(self.chunk)
Esempio n. 27
0
 def __init__(self, stream: BinaryStream, size: int, tag: str):
     self.tag = tag
     self.chunk = stream.read_uint8_array(size)
Esempio n. 28
0
 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)
Esempio n. 29
0
 def write_mdx(self, stream: BinaryStream, version):
     stream.write_uint32(self.get_byte_length())
     super().write_mdx(stream, version)
     stream.write_uint32(self.name)
     stream.write_float32_array(self.attenuation)
     stream.write_float32_array(self.color)
     stream.write_float32(self.intensity)
     stream.write_float32_array(self.ambient_color)
     stream.write_float32(self.ambient_intensity)
     self.write_non_generic_animation_chunks(stream)
Esempio n. 30
0
 def write_mdx(self, stream: BinaryStream, version):
     super().write_mdx(stream, version)
     stream.write_int32(self.geoset_id)
     stream.write_int32(self.geoset_animation_id)