public ReflectionMaterial(SectionHeader header, Stream stream) : base(header, stream) { var reader = new BinaryReader(stream); Scale = new Vector2(reader); Translation = new Vector2(reader); Intensity = reader.ReadSingle(); }
private Section(Stream stream, SectionData parent) { Header = SectionHeader.Read(stream, parent); var end = stream.Position + Header.Size; Data = SectionData.Read <TData>(Header, new FrameStream(stream, stream.Position, Header.Size)); stream.Seek(end, SeekOrigin.Begin); }
public Atomic(SectionHeader header, Stream stream) : base(header, stream) { var data = ReadSection <Data>(); // Struct var reader = new BinaryReader(new MemoryStream(data.Value)); FrameIndex = reader.ReadUInt32(); GeometryIndex = reader.ReadUInt32(); Flags = (AtomicFlag)reader.ReadUInt32(); Unused = reader.ReadUInt32(); }
public Texture(SectionHeader header, Stream stream) : base(header, stream) { SectionHeader.Read(stream); var reader = new BinaryReader(stream); FilterMode = (Filter)reader.ReadUInt16(); reader.ReadUInt16(); // Unknown TextureName = ReadSection <String>().Value; MaskName = ReadSection <String>().Value; }
public Extension(SectionHeader header, Stream stream) : base(header, stream) { var sections = new List <SectionData>(); while (stream.Position < stream.Length) { sections.Add(ReadSection <SectionData>(header.GetParent())); } Sections = sections.ToArray(); }
public GeometryList(SectionHeader header, Stream stream) : base(header, stream) { var data = ReadSection <Data>(); GeometryCount = BitConverter.ToUInt32(data.Value, 0); Geometry = new Geometry[GeometryCount]; for (var i = 0; i < GeometryCount; ++i) { Geometry[i] = ReadSection <Geometry>(); } }
public MaterialList(SectionHeader header, Stream stream) : base(header, stream) { var data = ReadSection <Data>(); MaterialCount = BitConverter.ToUInt32(data.Value, 0); Materials = new Material[MaterialCount]; for (var i = 0; i < MaterialCount; ++i) { Materials[i] = ReadSection <Material>(); } }
public TextureDictionary(SectionHeader header, Stream stream) : base(header, stream) { SectionHeader.Read(stream); var reader = new BinaryReader(stream); TextureCount = reader.ReadUInt16(); Textures = new TextureNative[TextureCount]; reader.ReadUInt16(); // Unknown for (var i = 0; i < TextureCount; ++i) { Textures[i] = ReadSection <TextureNative>(); } }
public MaterialSplitList(SectionHeader header, Stream stream) : base(header, stream) { var reader = new BinaryReader(stream); TriangleStrip = reader.ReadUInt32() == 1; SplitCount = reader.ReadUInt32(); MaterialSplits = new MaterialSplit[SplitCount]; FaceCount = reader.ReadUInt32(); for (var i = 0; i < SplitCount; ++i) { MaterialSplits[i] = new MaterialSplit(stream); } }
public Skin(SectionHeader header, Stream stream) : base(header, stream) { var reader = new BinaryReader(stream); Int32 boneCount = (Int32)reader.ReadByte(); Int32 boneIdCount = (Int32)reader.ReadByte(); UInt16 weightsPerVertex = reader.ReadUInt16(); byte[] boneIds = reader.ReadBytes(boneIdCount); var vertexCount = header.GetParent <Geometry>().VertexCount; VertexBoneIndices = new SkinBoneIndices[vertexCount]; VertexBoneWeights = new SkinBoneWeights[vertexCount]; for (int i = 0; i < vertexCount; ++i) { VertexBoneIndices[i] = new SkinBoneIndices(reader); } for (int i = 0; i < vertexCount; ++i) { VertexBoneWeights[i] = new SkinBoneWeights(reader); } SkinToBoneMatrices = new Matrix4x4[boneCount]; for (int i = 0; i < boneCount; ++i) { if (boneIdCount == 0) { reader.BaseStream.Seek(4, SeekOrigin.Current); } SkinToBoneMatrices[i] = new Matrix4x4(reader); } UInt32 boneLimit = reader.ReadUInt32(); UInt32 meshCount = reader.ReadUInt32(); UInt32 RLE = reader.ReadUInt32(); if (meshCount > 0) { MeshBoneRemapIndices = reader.ReadBytes((Int32)(boneCount + 2 * (RLE + meshCount))); } }
public static T Read <T>(SectionHeader header, Stream stream) where T : SectionData { if (_sDataCtors.Count == 0) { FindTypes(); } if (!_sDataCtors.ContainsKey(header.Type)) { if (typeof(T) == typeof(SectionData)) { return(null); } throw new Exception(string.Format("Unexpected section header {0}.", header.Type)); } return((T)_sDataCtors[header.Type](header, stream)); }
public HierarchyAnimation(SectionHeader header, Stream stream) : base(header, stream) { var reader = new BinaryReader(stream); Version = reader.ReadUInt32(); NodeId = reader.ReadUInt32(); NodeCount = reader.ReadUInt32(); Nodes = new HierarchyAnimationNode[NodeCount]; if (NodeCount > 0) { Flags = (HierarchyAnimationFlags)reader.ReadUInt32(); KeyFrameSize = reader.ReadUInt32(); for (int i = 0; i < NodeCount; ++i) { Nodes[i] = new HierarchyAnimationNode(reader); } var stack = new Stack <HierarchyAnimationNode>(); stack.Push(Root = Nodes[0]); foreach (var node in Nodes.Skip(1)) { stack.Peek().AddChild(node); if (node.Push) { stack.Push(node); } else if (node.Pop) { var n = node; do { n = stack.Pop(); } while (n.Pop); } } } }
public Clump(SectionHeader header, Stream stream) : base(header, stream) { var data = ReadSection <Data>(); // Struct if (data == null) { return; } var reader = new BinaryReader(new MemoryStream(data.Value)); AtomicCount = reader.ReadUInt32(); LightCount = reader.ReadUInt32(); CameraCount = reader.ReadUInt32(); FrameList = ReadSection <FrameList>(); // Frame List GeometryList = ReadSection <GeometryList>(); // Geometry List Atomics = new Atomic[AtomicCount]; for (int i = 0; i < AtomicCount; ++i) { Atomics[i] = ReadSection <Atomic>(); // Atomic } var section = ReadSection <SectionData>(); var extension = section as Extension; if (extension != null) { var collision = extension.FirstOrDefault <CollisionModel>(); if (collision != null) { Collision = collision.Collision; } } }
public CollisionModel(SectionHeader header, Stream stream) : base(header, stream) { Collision = CollisionFile.Load(stream); }
public Data(SectionHeader header, Stream stream) : base(header, stream) { Value = new byte[header.Size]; stream.Read(Value, 0, (int)header.Size); }
public static SectionData Read(SectionHeader header, Stream stream) { return(Read <SectionData>(header, stream)); }
public FrameName(SectionHeader header, Stream stream) : base(header, stream) { Name = new String(header, stream); }
protected SectionData(SectionHeader header, Stream stream) { _header = header; _stream = stream; }
public TextureNative(SectionHeader header, Stream stream) : base(header, stream) { SectionHeader.Read(stream); var reader = new BinaryReader(stream); PlatformID = reader.ReadUInt32(); FilterFlags = (Filter)reader.ReadUInt16(); WrapV = (WrapMode)reader.ReadByte(); WrapU = (WrapMode)reader.ReadByte(); DiffuseName = reader.ReadString(32); AlphaName = reader.ReadString(32); Format = (RasterFormat)reader.ReadUInt32(); if (PlatformID == 9) { var dxt = reader.ReadString(4); switch (dxt) { case "DXT1": Compression = CompressionMode.DXT1; break; case "DXT3": Compression = CompressionMode.DXT3; break; default: Compression = CompressionMode.None; break; } } else { Alpha = reader.ReadUInt32() == 0x1; } Width = reader.ReadUInt16(); Height = reader.ReadUInt16(); BPP = (byte)(reader.ReadByte() >> 3); MipMapCount = reader.ReadByte(); RasterType = reader.ReadByte(); if (RasterType != 0x4) { throw new Exception("Unexpected RasterType, expected 0x04."); } if (PlatformID == 9) { Alpha = (reader.ReadByte() & 0x1) == 0x1; } else { Compression = (CompressionMode)reader.ReadByte(); } ImageDataSize = reader.ReadInt32(); ImageData = reader.ReadBytes(ImageDataSize); if ((Format & RasterFormat.ExtMipMap) != 0) { var tot = ImageDataSize; for (var i = 0; i < MipMapCount; ++i) { tot += ImageDataSize >> (2 * i); } ImageLevelData = reader.ReadBytes(tot); } else { ImageLevelData = ImageData; } }
public Geometry(SectionHeader header, Stream stream) : base(header, stream) { var dataHeader = SectionHeader.Read(stream); var reader = new BinaryReader(stream); Flags = (GeometryFlag)reader.ReadUInt16(); var uvCount = reader.ReadByte(); // uv count reader.ReadByte(); // native flags FaceCount = reader.ReadUInt32(); VertexCount = reader.ReadUInt32(); FrameCount = reader.ReadUInt32(); if (dataHeader.Version == 4099) { Ambient = reader.ReadSingle(); Diffuse = reader.ReadSingle(); Specular = reader.ReadSingle(); } if ((Flags & GeometryFlag.Colors) != 0) { Colours = new Color4[VertexCount]; for (var i = 0; i < VertexCount; ++i) { Colours[i] = new Color4(reader); } } if ((Flags & (GeometryFlag.TexCoords | GeometryFlag.TexCoords2)) != 0) { TexCoords = new Vector2[uvCount][]; for (var j = 0; j < uvCount; ++j) { var uvs = TexCoords[j] = new Vector2[VertexCount]; for (var i = 0; i < VertexCount; ++i) { uvs[i] = new Vector2(reader); } } } Faces = new FaceInfo[FaceCount]; for (var i = 0; i < FaceCount; ++i) { Faces[i] = new FaceInfo(reader); } BoundingSphere = new BoundingSphere(reader); HasPosition = reader.ReadUInt32(); HasNormals = reader.ReadUInt32(); if (HasPosition > 1 || HasNormals > 1) { throw new Exception("Well there you go"); } if ((Flags & GeometryFlag.VertexTranslation) != 0) { Vertices = new Vector3[VertexCount]; for (var i = 0; i < VertexCount; ++i) { Vertices[i] = new Vector3(reader); } } if ((Flags & GeometryFlag.Normals) != 0) { Normals = new Vector3[VertexCount]; for (var i = 0; i < VertexCount; ++i) { Normals[i] = new Vector3(reader); } } Materials = ReadSection <MaterialList>().Materials; var extensions = ReadSection <Extension>(); MaterialSplits = extensions.FirstOrDefault <MaterialSplitList>().MaterialSplits; Skinning = extensions.FirstOrDefault <Skin>(); }
public String(SectionHeader header, Stream stream) : base(header, stream) { Value = Encoding.UTF8.GetString(stream.ReadBytes((int)header.Size)).TrimNullChars(); }