/// <summary> /// Read a single texture from BIN. /// </summary> /// <param name="br">Binary Reader to use.</param> /// <param name="texturesOffset">Offset to textures.</param> public BinTexture(DhBinaryReader br, long texturesOffset) { // Read texture width. Width = br.ReadU16(); // Read texture height. Height = br.ReadU16(); // Read texture format. Format = br.ReadU8(); // Read texture unknown 1. (Flags?) Unknown1 = br.ReadU8(); // Read texture unknown 2. (Padding) Unknown2 = br.ReadU16(); // Read texture data offset. DataOffset = br.ReadU32(); // Save the current position. long currentPosition = br.Position(); // Go to the bin textures offset. br.Goto(texturesOffset); // Sail to the texture's data offset. br.Sail(DataOffset); // Read the texture's raw data. Data = br.Read((Width * Height) / 2); // Go to the previously saved offset. br.Goto(currentPosition); }
public MDLSampler(DhBinaryReader br) { TextureIndex = br.ReadU16(); UnknownIndex = br.ReadU16(); WrapU = (WrapMode)br.ReadU8(); WrapV = (WrapMode)br.ReadU8(); MinFilter = br.ReadU8(); MagFilter = br.ReadU8(); }
public MDLShape(DhBinaryReader br, List <MDLShapePacket> packets) { NormalFlag = br.ReadU8(); Unknown1 = br.ReadU8(); SurfaceFlag = br.ReadU8(); Unknown2 = br.ReadU8(); PacketCount = br.ReadU16(); PacketBeginIndex = br.ReadU16(); Packets = packets.GetRange(PacketBeginIndex, PacketCount); UseNbt = (NormalFlag > 0); }
public MDLMaterial(DhBinaryReader br, List <MDLSampler> samplers) { DiffuseColor = br.ReadClr4(); Unknown1 = br.ReadS16(); AlphaFlag = br.ReadU8(); TevStageCount = br.ReadU8(); Unknown2 = br.ReadU8(); br.Skip(23); TevStages = new List <MDLTevStage>(); for (int i = 0; i < 8; i++) { TevStages.Add(new MDLTevStage(br)); } }
/// <summary> /// Read a single field from JMP. /// </summary> /// <param name="br">Binary Reader to use.</param> public JField(DhBinaryReader br) { Hash = br.ReadU32(); Bitmask = br.ReadU32(); Offset = br.ReadU16(); Shift = br.ReadS8(); Type = (JFieldType)br.ReadU8(); Name = JMPUtils.HashToName(Hash); }
/// <summary> /// Read a single primitive from BIN. /// </summary> /// <param name="br">Binary Reader to use.</param> public Primitive(DhBinaryReader br, Attributes attributes, bool useNbt) { // Read Primitive Type. Type = (PrimitiveType)br.ReadU8(); // Read number of vertices. VerticeCount = br.ReadS16(); // Define new list to hold primitive vertices. Vertices = new List <Vertex>(); // Loop through primitive vertices. for (int i = 0; i < VerticeCount; i++) { // Read a primitive vertex and add it to the list. Vertices.Add(new Vertex(br, attributes, useNbt)); } }
/// <summary> /// Read a single field from JMP. /// </summary> /// <param name="br">Binary Reader to use.</param> public JField(DhBinaryReader br) { // Read field's hash. Hash = br.ReadU32(); // Read field's bitmask. Bitmask = br.ReadU32(); // Read field's offset. Offset = br.ReadU16(); // Read field's shift. Shift = br.ReadS8(); // Read field's type. Type = (JFieldType)br.ReadU8(); // Resolve field's hash to get field name. Name = JMPUtils.HashToName(Hash); }
/// <summary> /// Reads ANM from a data stream. /// </summary> /// <param name="stream">The stream containing the ANM data.</param> public ANM(Stream stream) { // Define a binary reader to read with. DhBinaryReader br = new DhBinaryReader(stream, DhEndian.Big); // Reader ANM's Header. Version = br.ReadU8(); Loop = br.ReadBool8(); Unknown1 = br.ReadS16(); KeyFrameCount = br.ReadU32(); KeyFrameOffset = br.ReadU32(); Unknown2 = br.ReadS32(); Unknown3 = br.ReadS32(); Unknown4 = br.ReadS32(); /* * Keyframes - Interpolation type list: * https://ia800802.us.archive.org/9/items/GCN_SDK_Documentation/Game%20Engine%20Programming.pdf */ }
public MDL(byte[] data) { // Define a binary reader to read with. DhBinaryReader br = new DhBinaryReader(data, DhEndian.Big); Header = new MDLHeader(br); br.Goto(Header.MatricesOffset); Matrices = new Mat4[Header.JointCount + Header.WeightCount]; for (int i = 0; i < Matrices.Length; i++) { Matrices[i] = Mat4.Identity; } for (int i = 0; i < Header.JointCount; i++) { float[] matrix = br.ReadF32s(12); Matrices[i] = new Mat4() { Row1 = new Vec4(matrix[0], matrix[1], matrix[2], matrix[3]), Row2 = new Vec4(matrix[4], matrix[5], matrix[6], matrix[7]), Row3 = new Vec4(matrix[8], matrix[9], matrix[10], matrix[11]), Row4 = new Vec4(0, 0, 0, 1), }; } br.Goto(Header.PositionOffset); Positions = br.ReadVec3s(Header.PositionCount).ToList(); br.Goto(Header.NormalOffset); Normals = br.ReadVec3s(Header.NormalCount).ToList(); br.Goto(Header.ColorOffset); Colors = br.ReadClr4s(Header.ColorCount).ToList(); br.Goto(Header.TextureCoordinateOffset); TextureCoordinates = br.ReadVec2s(Header.TextureCoordinateCount).ToList(); br.Goto(Header.PacketOffset); Packets = new List <MDLShapePacket>(); for (int i = 0; i < Header.PacketCount; i++) { Packets.Add(new MDLShapePacket(br)); } br.Goto(Header.ShapeOffset); Shapes = new List <MDLShape>(); for (int i = 0; i < Header.ShapeCount; i++) { Shapes.Add(new MDLShape(br, Packets)); } foreach (MDLShape shape in Shapes) { ushort[] matrixIndices = new ushort[10]; foreach (MDLShapePacket packet in shape.Packets) { for (int m = 0; m < packet.MatrixCount; m++) { if (packet.MatrixIndices[m] == ushort.MaxValue) { continue; } matrixIndices[m] = packet.MatrixIndices[m]; } DhBinaryReader reader = new DhBinaryReader(packet.Data, DhEndian.Big); while (reader.Position() < packet.DataSize) { ShapePacketData packetData = new ShapePacketData(); packetData.PrimitiveType = reader.ReadU8(); if (packetData.PrimitiveType == 0x00) { continue; } packetData.VertexCount = reader.ReadU16(); for (int i = 0; i < packetData.VertexCount; i++) { MDLVertex vertex = new MDLVertex(reader, Header, shape.UseNbt); if (vertex.MatrixIndex != -1) { vertex.MatrixDataIndex = matrixIndices[(vertex.MatrixIndex / 3)]; } packetData.Vertices.Add(vertex); } packet.PacketData.Add(packetData); } } } br.Goto(Header.TextureLocationOffset); Textures = new List <BTI>(); for (int i = 0; i < Header.TextureCount; i++) { uint offset = br.ReadU32(); long currentPosition = br.Position(); br.Goto(offset); BTI bti = new BTI(br, offset, Header.TextureLocationOffset); Textures.Add(bti); br.Goto(currentPosition); } br.Goto(Header.SamplerOffset); Samplers = new List <MDLSampler>(); for (int i = 0; i < Header.SamplerCount; i++) { Samplers.Add(new MDLSampler(br)); } br.Goto(Header.MaterialOffset); Materials = new List <MDLMaterial>(); for (int i = 0; i < Header.MaterialCount; i++) { Materials.Add(new MDLMaterial(br, Samplers)); } br.Goto(Header.DrawElementOffset); DrawElements = new List <MDLDrawElement>(); for (int i = 0; i < Header.DrawElementCount; i++) { DrawElements.Add(new MDLDrawElement(br, Materials, Shapes)); } br.Goto(Header.NodeOffset); Nodes = new List <MDLNode>(); for (int i = 0; i < Header.NodeCount; i++) { Nodes.Add(new MDLNode(br, DrawElements)); } }