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)
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 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)
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)
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)
def read_mdl(self, stream: TokenStream): for token in super().read_generic_block(stream): if token == 'GeosetId': token = stream.read() if token == 'Multiple': self.geoset_id = -1 else: self.geoset_id = int(token) elif token == 'GeosetAnimId': token = stream.read() if token == 'None': self.geoset_animation_id = -1 else: self.geoset_animation_id = int(token) else: raise TokenStreamError('Bone', token, want_name=self.name)
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
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)
def read_mdl(self, stream: TokenStream): for token in super().read_generic_block(stream): if token == 'Box': self.type = 0 elif token == 'Plane': self.type = 1 elif token == 'Sphere': self.type = 2 elif token == 'Cylinder': self.type = 3 elif token == 'Vertices': count = stream.read_int() stream.read() self.vertices[0] = stream.read_vector(3) if count == 2: self.vertices[1] = stream.read_vector(3) stream.read() elif token == 'BoundsRadius': self.bounds_radius = stream.read_float() else: raise TokenStreamError('CollisionShape', token)
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)
def read_mdl(self, stream: TokenStream): for token in super().read_generic_block(stream): if token == 'AttachmentID': self.attachment_id = stream.read_int() elif token == 'Path': self.path = stream.read() elif token == 'Visibility': self.read_animation(stream, 'KATV') else: raise TokenStreamError('Attachment', token, want_name=self.name)
def read_mdl(self, stream: TokenStream): for token in super().read_generic_block(stream): if token == 'SortPrimsFarZ': self.flags = 0x10000 elif token == 'Unshaded': self.flags = 0x8000 elif token == 'Unfogged': self.flags = 0x40000 elif token == 'static LifeSpan': self.life_span = stream.read_float() elif token == 'LifeSpan': self.read_animation(stream, 'KPPL') elif token == 'static EmissionRate': self.emission_rate = stream.read_float() elif token == 'EmissionRate': self.read_animation(stream, 'KPPE') elif token == 'static Speed': self.speed = stream.read_float() elif token == 'Speed': self.read_animation(stream, 'KPPS') elif token == 'static Color': self.color = stream.read_vector(3) elif token == 'Color': self.read_animation(stream, 'KPPC') elif token == 'static Alpha': self.alpha = stream.read_float() elif token == 'Alpha': self.read_animation(stream, 'KPPA') elif token == 'Visibility': self.read_animation(stream, 'KPPV') elif token == 'ReplaceableId': self.replaceable_id = stream.read_int() elif token == 'Path': self.path = stream.read() elif token == 'AnimVisibilityGuide': self.animation_visibility_guide = stream.read() else: raise TokenStreamError('ParticleEmitterPopcorn', token)
def read_mdl(self, stream: TokenStream): for token in super().read_animated_block(stream): if token == 'FilterMode': self.filter_mode = filter_mode_to_mdx(stream.read()) elif token == 'Unshaded': self.flags |= 0x1 elif token == 'SphereEnvMap': self.flags |= 0x2 elif token == 'TwoSided': self.flags |= 0x10 elif token == 'Unfogged': self.flags |= 0x20 elif token == 'NoDepthTest': self.flags |= 0x40 elif token == 'NoDepthSet': self.flags |= 0x80 elif token == 'Unlit': self.flags |= 0x100 elif token == 'static TextureID': self.texture_id = stream.read_int() elif token == 'TextureID': self.read_animation(stream, 'KMTF') elif token == 'TVertexAnimId': self.texture_animation_id = stream.read_int() elif token == 'CoordId': self.coord_id = stream.read_int() elif token == 'static Alpha': self.alpha = stream.read_float() elif token == 'Alpha': self.read_animation(stream, 'KMTA') elif token == 'static EmissiveGain': self.emissive_gain = stream.read_float() elif token == 'EmissiveGain': self.read_animation(stream, 'KMTE') elif token == 'static FresnelColor': self.fresnel_color = stream.read_vector(3) elif token == 'FresnelColor': self.read_animation(stream, 'KFC3') elif token == 'static FresnelOpacity': self.fresnel_opacity = stream.read_float() elif token == 'FresnelOpacity': self.read_animation(stream, 'KFCA') elif token == 'static FresnelTeamColor': self.fresnel_team_color = stream.read_float() elif token == 'FresnelTeamColor': self.read_animation(stream, 'KFTC') else: raise TokenStreamError('Layer', token)
def read_mdl(self, stream: TokenStream): for token in super().read_generic_block(stream): if token == 'EventTrack': count = stream.read_int() stream.read() if stream.peek() == 'GlobalSeqId': stream.read() self.global_sequence_id = stream.read_int() for i in range(count): self.tracks.append(stream.read_int()) stream.read() else: raise TokenStreamError('EventObject', token)
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)
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)
def read_mdl(self, stream: TokenStream, version=None): for token in super().read_generic_block(stream): if token == 'EmitterUsesMDL': self.flags = 0x8000 elif token == 'EmitterUsesTGA': self.flags = 0x10000 elif token == 'static EmissionRate': self.emission_rate = stream.read_float() elif token == 'EmissionRate': self.read_animation(stream, 'KPEE') elif token == 'static Gravity': self.gravity = stream.read_float() elif token == 'Gravity': self.read_animation(stream, 'KPEG') elif token == 'static Longitude': self.longitude = stream.read_float() elif token == 'Longitude': self.read_animation(stream, 'KPLN') elif token == 'static Latitude': self.latitude = stream.read_float() elif token == 'Latitude': self.read_animation(stream, 'KPLT') elif token == 'Visibility': self.read_animation(stream, 'KPEV') elif token == 'Particle': for token in self.read_animated_block(stream): if token == 'static LifeSpan': self.life_span = stream.read_float() elif token == 'LifeSpan': self.read_animation(stream, 'KPEL') elif token == 'static InitVelocity': self.speed = stream.read_float() elif token == 'InitVelocity': self.read_animation(stream, 'KPES') elif token == 'Path': self.path = stream.read() else: raise TokenStreamError('ParticleEmitter', token)
def load_pivot_point_block(self, stream: TokenStream): count = stream.read_int() stream.read() for i in range(count): self.pivot_points.append(stream.read_vector(3)) stream.read()
def read_mdl(self, stream: TokenStream, name): frames = self.frames values = self.values in_tans = self.in_tans out_tans = self.out_tans self.name = name tracks_count = stream.read_int() stream.read() interpolation_type = 0 token = stream.read() if token == 'DontInterp': interpolation_type = 0 elif token == 'Linear': interpolation_type = 1 elif token == 'Hermite': interpolation_type = 2 elif token == 'Bezier': interpolation_type = 3 self.interpolation_type = interpolation_type if stream.peek() == 'GlobalSeqId': stream.read() self.global_sequence_id = stream.read_int() for i in range(tracks_count): frames.append(stream.read_int()) values.append(self.read_mdl_value(stream)) if interpolation_type > 1: stream.read() in_tans.append(self.read_mdl_value(stream)) stream.read() out_tans.append(self.read_mdl_value(stream)) stream.read()
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)
def read_mdl(self, stream: TokenStream): for token in super().read_generic_block(stream): if token == 'SortPrimsFarZ': self.flags = self.flags or 0x10000 elif token == 'Unshaded': self.flags = self.flags or 0x8000 elif token == 'LineEmitter': self.flags = self.flags or 0x20000 elif token == 'Unfogged': self.flags = self.flags or 0x40000 elif token == 'ModelSpace': self.flags = self.flags or 0x80000 elif token == 'XYQuad': self.flags = self.flags or 0x100000 elif token == 'static Speed': self.speed = stream.read_float() elif token == 'Speed': self.read_animation(stream, 'KP2S') elif token == 'static Variation': self.variation = stream.read_float() elif token == 'Variation': self.read_animation(stream, 'KP2R') elif token == 'static Latitude': self.latitude = stream.read_float() elif token == 'Latitude': self.read_animation(stream, 'KP2L') elif token == 'static Gravity': self.gravity = stream.read_float() elif token == 'Gravity': self.read_animation(stream, 'KP2G') elif token == 'Visibility': self.read_animation(stream, 'KP2V') elif token == 'Squirt': self.squirt = 1 elif token == 'LifeSpan': self.life_span = stream.read_float() elif token == 'static EmissionRate': self.emission_rate = stream.read_float() elif token == 'EmissionRate': self.read_animation(stream, 'KP2E') elif token == 'static Width': self.width = stream.read_float() elif token == 'Width': self.read_animation(stream, 'KP2N') elif token == 'static Length': self.length = stream.read_float() elif token == 'Length': self.read_animation(stream, 'KP2W') elif token == 'Blend': self.filter_mode = 0 elif token == 'Additive': self.filter_mode = 1 elif token == 'Modulate': self.filter_mode = 2 elif token == 'Modulate2x': self.filter_mode = 3 elif token == 'AlphaKey': self.filter_mode = 4 elif token == 'Rows': self.rows = stream.read_int() elif token == 'Columns': self.columns = stream.read_int() elif token == 'Head': self.head_or_tail = 0 elif token == 'Tail': self.head_or_tail = 1 elif token == 'Both': self.head_or_tail = 2 elif token == 'TailLength': self.tail_length = stream.read_float() elif token == 'Time': self.time_middle = stream.read_float() elif token == 'SegmentColor': stream.read() for i in range(3): stream.read() self.segment_colors[i] = stream.read_color() stream.read() elif token == 'Alpha': self.segment_alphas = stream.read_vector(3) elif token == 'ParticleScaling': self.segment_scaling = stream.read_vector(3) elif token == 'LifeSpanUVAnim': self.head_intervals[0] = stream.read_vector(3) elif token == 'DecayUVAnim': self.head_intervals[1] = stream.read_vector(3) elif token == 'TailUVAnim': self.tail_intervals[0] = stream.read_vector(3) elif token == 'TailDecayUVAnim': self.tail_intervals[1] = stream.read_vector(3) elif token == 'TextureID': self.texture_id = stream.read_int() elif token == 'ReplaceableId': self.replaceable_id = stream.read_int() elif token == 'PriorityPlane': self.priority_plane = stream.read_int() else: raise TokenStreamError('ParticleEmitter2', token)