Exemplo n.º 1
0
        public override void LoadRaw()
        {
            if (RawLoaded) return;

            var bb = BoundingBoxes[0];
            var IH = (Halo1PC.CacheFile.CacheIndexHeader)cache.IndexHeader;
            var reader = cache.Reader;

            for (int i = 0; i < ModelSections.Count; i++)
            {
                var section = ModelSections[i];

                List<int> tIndices = new List<int>();
                List<Vertex> tVertices = new List<Vertex>();

                for (int j = 0; j < section.Submeshes.Count; j++)
                {
                    var submesh = (Halo1PC.gbxmodel.ModelSection.Submesh)section.Submeshes[j];

                    #region Read Indices
                    submesh.FaceIndex = tIndices.Count;
                    var strip = new List<int>();

                    reader.SeekTo(submesh.FaceOffset + IH.vertDataOffset + IH.indexDataOffset);
                    for (int k = 0; k < submesh.FaceCount; k++)
                        strip.Add(reader.ReadUInt16() + tVertices.Count);

                    strip = ModelFunctions.GetTriangleList(strip.ToArray(), 0, strip.Count, 5);
                    strip.Reverse();
                    submesh.FaceCount = strip.Count;
                    tIndices.AddRange(strip);
                    #endregion

                    #region Read Vertices
                    reader.SeekTo(submesh.VertOffset + IH.vertDataOffset);
                    for (int k = 0; k < submesh.VertexCount; k++)
                    {
                        var v = new Vertex() { FormatName = "Halo1PC_Skinned" };
                        var position = new Vector(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        var normal = new Vector(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        var binormal = new Vector(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        var tangent = new Vector(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        var texcoord = new Vector(reader.ReadSingle() * uScale, 1f - reader.ReadSingle() * vScale);
                        var nodes = (Flags.Values[1]) ?
                            new Vector(submesh.LocalNodes[reader.ReadInt16()], submesh.LocalNodes[reader.ReadInt16()], 0, 0) :
                            new Vector(reader.ReadInt16(), reader.ReadInt16(), 0, 0);
                        var weights = new Vector(reader.ReadSingle(), reader.ReadSingle(), 0, 0);

                        v.Values.Add(new VertexValue(position, VertexValue.ValueType.Float32_3, "position", 0));
                        v.Values.Add(new VertexValue(normal, VertexValue.ValueType.Float32_3, "normal", 0));
                        v.Values.Add(new VertexValue(binormal, VertexValue.ValueType.Float32_3, "binormal", 0));
                        v.Values.Add(new VertexValue(tangent, VertexValue.ValueType.Float32_3, "tangent", 0));
                        v.Values.Add(new VertexValue(texcoord, VertexValue.ValueType.Float32_2, "texcoords", 0));
                        v.Values.Add(new VertexValue(nodes, VertexValue.ValueType.Int16_N2, "blendindices", 0));
                        v.Values.Add(new VertexValue(weights, VertexValue.ValueType.Float32_2, "blendweight", 0));

                        tVertices.Add(v);

                        bb.XBounds = new Range<float>(
                            Math.Min(bb.XBounds.Min, position.X),
                            Math.Max(bb.XBounds.Max, position.X));

                        bb.YBounds = new Range<float>(
                            Math.Min(bb.YBounds.Min, position.Y),
                            Math.Max(bb.YBounds.Max, position.Y));

                        bb.ZBounds = new Range<float>(
                            Math.Min(bb.ZBounds.Min, position.Z),
                            Math.Max(bb.ZBounds.Max, position.Z));
                    }
                    #endregion
                }

                section.Indices = tIndices.ToArray();
                section.Vertices = tVertices.ToArray();

                IndexInfoList.Add(new IndexBufferInfo() { FaceFormat = 3 });
                VertInfoList.Add(new VertexBufferInfo() { VertexCount = section.TotalVertexCount });
            }

            RawLoaded = true;
        }
Exemplo n.º 2
0
        public override void LoadRaw()
        {
            if (RawLoaded) return;

            var reader = cache.Reader;

            #region Read Indices
            int[] indices = new int[indexCount];
            reader.SeekTo(indexOffset);
            for (int i = 0; i < indexCount; i++)
                indices[i] = reader.ReadUInt16();
            #endregion

            for (int i = 0; i < ModelSections.Count; i++)
            {
                var section = ModelSections[i];
                var tempVerts = new List<Vertex>();

                if (section.Submeshes.Count == 0) continue;

                #region Read Vertices
                for (int j = 0; j < section.Submeshes.Count; j++)
                {
                    var mesh = (Lightmap.Material)section.Submeshes[j];

                    reader.SeekTo(mesh.vertsOffset);
                    for (int k = 0; k < mesh.VertexCount; k++)
                    {
                        var v = new Vertex() { FormatName = "Halo1PC_World" };
                        var position = new Vector(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        var normal = new Vector(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        var binormal = new Vector(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        var tangent = new Vector(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        var texcoord = new Vector(reader.ReadSingle(), 1f - reader.ReadSingle());

                        v.Values.Add(new VertexValue(position, VertexValue.ValueType.Float32_3, "position", 0));
                        v.Values.Add(new VertexValue(normal, VertexValue.ValueType.Float32_3, "normal", 0));
                        v.Values.Add(new VertexValue(binormal, VertexValue.ValueType.Float32_3, "binormal", 0));
                        v.Values.Add(new VertexValue(tangent, VertexValue.ValueType.Float32_3, "tangent", 0));
                        v.Values.Add(new VertexValue(texcoord, VertexValue.ValueType.Float32_2, "texcoords", 0));

                        tempVerts.Add(v);
                    }
                }
                #endregion

                #region Copy & Translate Indices
                int offset = section.Submeshes[0].FaceIndex;
                section.Indices = new int[section.TotalFaceCount];
                Array.Copy(indices, offset, section.Indices, 0, section.TotalFaceCount);
                section.Vertices = tempVerts.ToArray();

                int pos = 0;
                for (int j = 0; j < section.Submeshes.Count; j++)
                {
                    var mesh = section.Submeshes[j];
                    mesh.FaceIndex -= offset;

                    for (int k = 0; k < mesh.FaceCount; k++)
                        section.Indices[k + mesh.FaceIndex] += pos;

                    Array.Reverse(section.Indices, mesh.FaceIndex, mesh.FaceCount);
                    pos += mesh.VertexCount;
                }
                #endregion

                IndexInfoList.Add(new mode.IndexBufferInfo() { FaceFormat = 3 });
                VertInfoList.Add(new mode.VertexBufferInfo() { VertexCount = section.TotalVertexCount });
            }

            RawLoaded = true;
        }
Exemplo n.º 3
0
        public UVDataBlock_3001(EndianReader reader, bool loadMesh, Vertex[] Vertices)
            : base(reader, 0x3001)
        {
            DataCount = reader.ReadInt32(); //vCount

            x2E00 = reader.ReadInt16(); //2E00
            reader.Format = EndianFormat.Big;

            unkUV0 = reader.ReadInt16(); //flags? 0x1C00 when world
            unkUV1 = reader.ReadByte();
            unkUV2 = reader.ReadByte();
            unkUV3 = reader.ReadByte();
            unkUV4 = reader.ReadByte(); //0x00 when world, else 0x20
            DataSize = reader.ReadByte();

            if (!loadMesh) reader.SeekTo(EOBOffset);
            else for (int i = 0; i < DataCount; i++)
            {
                Vector tex0 = new Vector();

                #region switch
                switch (DataSize)
                {
                    case 8:
                        tex0 = Vector.FromUByteN4(reader.ReadUInt32());
                        reader.Skip(0);
                        break;
                    case 12:
                        reader.Skip(4);
                        break;
                    case 16:
                        reader.Skip(12);
                        break;
                    case 20:
                        reader.Skip(16);
                        break;
                    case 24:
                        reader.Skip(16);
                        break;
                    case 28:
                        reader.Skip(20);
                        break;
                    case 32:
                        reader.Skip(16);
                        break;
                    case 36:
                        reader.Skip(24);
                        break;
                    case 44:
                        reader.Skip(28);
                        break;
                }
                #endregion

                int u = reader.ReadInt16();
                int v = reader.ReadInt16();

                //var tex0 = new RealQuat(((float)a + (float)0) / (float)0xFFFF, ((float)b + (float)0) / (float)0xFFFF);
                var tex1 = new Vector((float)u / (float)(0x7FFF), (float)v / (float)(0x7FFF));

                #region switch
                switch (DataSize)
                {
                    case 8:
                        reader.Skip(0);
                        break;
                    case 12:
                        reader.Skip(4);
                        break;
                    case 16:
                        reader.Skip(0);
                        break;
                    case 20:
                        reader.Skip(0);
                        break;
                    case 24:
                        reader.Skip(4);
                        break;
                    case 28:
                        reader.Skip(4);
                        break;
                    case 32:
                        reader.Skip(12);
                        break;
                    case 36:
                        reader.Skip(8);
                        break;
                    case 44:
                        reader.Skip(12);
                        break;
                }
                #endregion

                //Vertices[i].Values.Add(new VertexValue(tex0, 0, "normal", 0));
                Vertices[i].Values.Add(new VertexValue(tex1, VertexValue.ValueType.Int16_N2, "texcoords", 0));
            }

            reader.Format = EndianFormat.Little;
        }
Exemplo n.º 4
0
        public Block_3301(EndianReader reader, bool loadSkin, Vertex[] Vertices)
            : base(reader, 0x3301)
        {
            FirstNodeID = reader.ReadInt16();
            NodeCount = reader.ReadInt16();

            if (!loadSkin) reader.Skip(Vertices.Length * 4);
            else foreach (var v in Vertices)
                {
                    var val = Vector.FromUByte4(reader.ReadUInt32());
                    nodes.Add(val);
                    v.Values.Add(new VertexValue(val, VertexValue.ValueType.UInt8_4, "blendindices", 0));
                }
        }
Exemplo n.º 5
0
 public Block_1A01(EndianReader reader, bool loadSkin, Vertex[] Vertices)
     : base(reader, 0x1A01)
 {
     if (!loadSkin) reader.Skip(Vertices.Length * 4);
     else foreach (var v in Vertices)
         {
             var val = Vector.FromUByteN4(reader.ReadUInt32());
             v.Values.Add(new VertexValue(val, VertexValue.ValueType.UInt8_4, "blendweight", 0));
         }
 }
Exemplo n.º 6
0
        public VertexBlock_F100(EndianReader reader, bool loadMesh, int geomUnk01)
            : base(reader, 0xF100)
        {
            DataCount = reader.ReadInt32();
            Data = new Vertex[DataCount];
            if (DataCount == 0) return;

            if (geomUnk01 != 134 && geomUnk01 != 142)
            {
                CentreX = reader.ReadInt16();
                CentreY = reader.ReadInt16();
                CentreZ = reader.ReadInt16();
                RadiusX = reader.ReadInt16();
                RadiusY = reader.ReadInt16();
                RadiusZ = reader.ReadInt16();
            }

            if (!loadMesh) reader.SeekTo(EOBOffset);
            else for (int i = 0; i < DataCount; i++)
            {
                Vertex v;

                if (geomUnk01 == 134 || geomUnk01 == 142)
                {
                    v = new Vertex() { FormatName = "S3D_World" };
                    var data = new Vector(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                    v.Values.Add(new VertexValue(data, VertexValue.ValueType.Float32_3, "position", 0));
                }
                else
                {
                    v = new Vertex() { FormatName = "S3D_Compressed" };
                    var data = new Vector(reader.ReadInt16(), reader.ReadInt16(), reader.ReadInt16(), reader.ReadInt16());
                    v.Values.Add(new VertexValue(data, VertexValue.ValueType.Int16_N4, "position", 0));
                }
                Data[i] = v;
            }
        }