Пример #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 RealQuat(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        var normal   = new RealQuat(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        var binormal = new RealQuat(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        var tangent  = new RealQuat(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
                        var texcoord = new RealQuat(reader.ReadSingle() * uScale, 1f - reader.ReadSingle() * vScale);
                        var nodes    = (Flags.Values[1]) ?
                                       new RealQuat(submesh.LocalNodes[reader.ReadInt16()], submesh.LocalNodes[reader.ReadInt16()], 0, 0) :
                                       new RealQuat(reader.ReadInt16(), reader.ReadInt16(), 0, 0);
                        var weights = new RealQuat(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.Min = Math.Min(bb.XBounds.Min, position.x);
                        bb.XBounds.Max = Math.Max(bb.XBounds.Max, position.x);
                        bb.YBounds.Min = Math.Min(bb.YBounds.Min, position.y);
                        bb.YBounds.Max = Math.Max(bb.YBounds.Max, position.y);
                        bb.ZBounds.Min = Math.Min(bb.ZBounds.Min, position.z);
                        bb.ZBounds.Max = 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;
        }
Пример #2
0
        public override void LoadRaw()
        {
            if (RawLoaded)
            {
                return;
            }

            for (int i = 0; i < ModelSections.Count; i++)
            {
                var section = (Halo2Xbox.render_model.ModelSection)ModelSections[i];
                var data    = cache.GetRawFromID(section.rawOffset, section.rawSize);
                var ms      = new MemoryStream(data);
                var reader  = new EndianReader(ms, IO.EndianFormat.Little);

                #region Read Submeshes
                for (int j = 0; j < section.rSize[0] / 72; j++)
                {
                    var mesh = new ModelSection.Submesh();
                    reader.SeekTo(section.hSize + section.rOffset[0] + j * 72 + 4);
                    mesh.ShaderIndex = reader.ReadUInt16();
                    mesh.FaceIndex   = reader.ReadUInt16();
                    mesh.FaceCount   = reader.ReadUInt16();
                    section.Submeshes.Add(mesh);
                }
                #endregion

                reader.SeekTo(40);
                section.Indices  = new int[reader.ReadUInt16()];
                section.Vertices = new Vertex[section.vertcount];

                var facetype = 5;
                if (section.facecount * 3 == section.Indices.Length)
                {
                    facetype = 3;
                }
                IndexInfoList.Add(new IndexBufferInfo()
                {
                    FaceFormat = facetype
                });
                VertInfoList.Add(new VertexBufferInfo()
                {
                    VertexCount = section.vertcount
                });

                #region Get Resource Indices
                int iIndex = 0, vIndex = 0, uIndex = 0, nIndex = 0, bIndex = 0;

                for (int j = 0; j < section.rType.Length; j++)
                {
                    switch (section.rType[j] & 0x0000FFFF)
                    {
                    case 32: iIndex = j;
                        break;

                    case 56:
                        switch ((section.rType[j] & 0xFFFF0000) >> 16)
                        {
                        case 0: vIndex = j;
                            break;

                        case 1: uIndex = j;
                            break;

                        case 2: nIndex = j;
                            break;
                        }
                        break;

                    case 100: bIndex = j;
                        break;
                    }
                }
                #endregion

                reader.SeekTo(108);
                int   bCount = reader.ReadUInt16();
                int[] bArr   = new int[bCount];
                if (bCount > 0)
                {
                    reader.SeekTo(section.hSize + section.rOffset[bIndex]);
                    for (int j = 0; j < bCount; j++)
                    {
                        bArr[j] = reader.ReadByte();
                    }
                }

                #region Read Vertices
                for (int j = 0; j < section.vertcount; j++)
                {
                    reader.SeekTo(section.hSize + section.rOffset[vIndex] + ((section.rSize[vIndex] / section.vertcount) * j));
                    var v = new Vertex()
                    {
                        FormatName = ""
                    };
                    var p = new Vector(
                        ((float)reader.ReadInt16() + (float)0x7FFF) / (float)0xFFFF,
                        ((float)reader.ReadInt16() + (float)0x7FFF) / (float)0xFFFF,
                        ((float)reader.ReadInt16() + (float)0x7FFF) / (float)0xFFFF, 0);

                    v.Values.Add(new VertexValue(p, 0, "position", 0));

                    var b = new Vector();
                    var w = new Vector();

                    switch (section.type)
                    {
                    case 1:
                        switch (section.bones)
                        {
                        case 0:
                            section.NodeIndex = 0;
                            break;

                        case 1:
                            section.NodeIndex = (bCount > 0) ? bArr[0] : 0;
                            break;
                        }
                        section.Vertices[j] = v;
                        continue;

                    case 2:
                        switch (section.bones)
                        {
                        case 1:
                            b = new Vector(reader.ReadByte(), reader.ReadByte(), 0, 0);
                            w = new Vector(1, 0, 0, 0);
                            break;
                        }
                        break;

                    case 3:
                        switch (section.bones)
                        {
                        case 2:
                            reader.ReadInt16();
                            b = new Vector(reader.ReadByte(), reader.ReadByte(), 0, 0);
                            w = new Vector((float)reader.ReadByte() / 255f, (float)reader.ReadByte() / 255f, 0, 0);
                            break;

                        case 3:
                            b = new Vector(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), 0);
                            w = new Vector((float)reader.ReadByte() / 255f, (float)reader.ReadByte() / 255f, (float)reader.ReadByte() / 255f, 0);
                            break;

                        case 4:
                            reader.ReadInt16();
                            b = new Vector(reader.ReadByte(), reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
                            w = new Vector((float)reader.ReadByte() / 255f, (float)reader.ReadByte() / 255f, (float)reader.ReadByte() / 255f, (float)reader.ReadByte() / 255f);
                            break;
                        }
                        break;
                    }

                    if (bCount > 0)
                    {
                        b.A = (w.A == 0) ? 0 : bArr[(int)b.A];
                        b.B = (w.B == 0) ? 0 : bArr[(int)b.B];
                        b.C = (w.C == 0) ? 0 : bArr[(int)b.C];
                        b.D = (w.D == 0) ? 0 : bArr[(int)b.D];
                    }

                    v.Values.Add(new VertexValue(b, 0, "blendindices", 0));
                    v.Values.Add(new VertexValue(w, 0, "blendweight", 0));

                    section.Vertices[j] = v;
                }
                #endregion

                #region Read UVs and Normals
                for (int j = 0; j < section.vertcount; j++)
                {
                    reader.SeekTo(section.hSize + section.rOffset[uIndex] + (4 * j));
                    var v  = section.Vertices[j];
                    var uv = new Vector(((float)reader.ReadInt16() + (float)0x7FFF) / (float)0xFFFF, ((float)reader.ReadInt16() + (float)0x7FFF) / (float)0xFFFF);
                    v.Values.Add(new VertexValue(uv, 0, "texcoords", 0));
                }

                for (int j = 0; j < section.vertcount; j++)
                {
                    reader.SeekTo(section.hSize + section.rOffset[nIndex] + (12 * j));
                    var v = section.Vertices[j];
                    var n = Vector.FromHenDN3(reader.ReadUInt32());
                    v.Values.Add(new VertexValue(n, 0, "normal", 0));
                }
                #endregion

                ModelFunctions.DecompressVertex(ref section.Vertices, BoundingBoxes[0]);

                reader.SeekTo(section.hSize + section.rOffset[iIndex]);
                for (int j = 0; j < section.Indices.Length; j++)
                {
                    section.Indices[j] = reader.ReadUInt16();
                }
            }

            RawLoaded = true;
        }
Пример #3
0
        public override void LoadRaw()
        {
            if (RawLoaded)
            {
                return;
            }

            #region Clusters
            for (int i = 0; i < Clusters.Count; i++)
            {
                var section = (Halo2Xbox.scenario_structure_bsp.ModelSection)ModelSections[i];

                if (section.rSize.Length == 0 || section.vertcount == 0)
                {
                    IndexInfoList.Add(new mode.IndexBufferInfo());
                    continue;
                }

                var data   = cache.GetRawFromID(section.rawOffset, section.rawSize);
                var ms     = new MemoryStream(data);
                var reader = new EndianReader(ms, IO.EndianFormat.Little);

                #region Read Submeshes
                for (int j = 0; j < section.rSize[0] / 72; j++)
                {
                    var mesh = new mode.ModelSection.Submesh();
                    reader.SeekTo(section.hSize + section.rOffset[0] + j * 72 + 4);
                    mesh.ShaderIndex = reader.ReadUInt16();
                    mesh.FaceIndex   = reader.ReadUInt16();
                    mesh.FaceCount   = reader.ReadUInt16();
                    section.Submeshes.Add(mesh);
                }
                #endregion

                #region Get Resource Indices
                int iIndex = 0, vIndex = 0, uIndex = 0, nIndex = 0, bIndex = 0;

                for (int j = 0; j < section.rType.Length; j++)
                {
                    switch (section.rType[j] & 0x0000FFFF)
                    {
                    case 32: iIndex = j;
                        break;

                    case 56:
                        switch ((section.rType[j] & 0xFFFF0000) >> 16)
                        {
                        case 0: vIndex = j;
                            break;

                        case 1: uIndex = j;
                            break;

                        case 2: nIndex = j;
                            break;
                        }
                        break;

                    case 100: bIndex = j;
                        break;
                    }
                }
                #endregion

                section.Vertices = new Vertex[section.vertcount];
                for (int j = 0; j < section.vertcount; j++)
                {
                    reader.SeekTo(section.hSize + section.rOffset[vIndex] + ((section.rSize[vIndex] / section.vertcount) * j));
                    var v = new Vertex();
                    var p = new Vector(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

                    v.Values.Add(new VertexValue(p, 0, "position", 0));
                    section.Vertices[j] = v;
                }

                #region Read UVs and Normals
                for (int j = 0; j < section.vertcount; j++)
                {
                    reader.SeekTo(section.hSize + section.rOffset[uIndex] + (8 * j));
                    var v  = section.Vertices[j];
                    var uv = new Vector(reader.ReadSingle(), 1 - reader.ReadSingle());
                    v.Values.Add(new VertexValue(uv, 0, "texcoords", 0));
                }

                for (int j = 0; j < section.vertcount; j++)
                {
                    reader.SeekTo(section.hSize + section.rOffset[uIndex + 1] + (12 * j));
                    var v = section.Vertices[j];
                    var n = Vector.FromHenDN3(reader.ReadUInt32());
                    v.Values.Add(new VertexValue(n, 0, "normal", 0));
                }
                #endregion

                reader.SeekTo(40);
                section.Indices = new int[reader.ReadUInt16()];
                reader.SeekTo(section.hSize + section.rOffset[iIndex]);
                for (int j = 0; j < section.Indices.Length; j++)
                {
                    section.Indices[j] = reader.ReadUInt16();
                }

                var facetype = 5;
                if (section.facecount * 3 == section.Indices.Length)
                {
                    facetype = 3;
                }
                IndexInfoList.Add(new mode.IndexBufferInfo()
                {
                    FaceFormat = facetype
                });
            }
            #endregion

            #region Instances
            if (GeomInstances.Count == 0)
            {
                RawLoaded = true; return;
            }
            for (int i = GeomInstances[0].SectionIndex; i < ModelSections.Count; i++)
            {
                var section   = (Halo2Xbox.scenario_structure_bsp.ModelSection)ModelSections[i];
                var geomIndex = i - Clusters.Count;

                if (section.rSize.Length == 0 || section.vertcount == 0)
                {
                    IndexInfoList.Add(new mode.IndexBufferInfo());
                    continue;
                }

                var data   = cache.GetRawFromID(section.rawOffset, section.rawSize);
                var ms     = new MemoryStream(data);
                var reader = new EndianReader(ms, IO.EndianFormat.Little);

                #region Read Submeshes
                for (int j = 0; j < section.rSize[0] / 72; j++)
                {
                    var mesh = new mode.ModelSection.Submesh();
                    reader.SeekTo(section.hSize + section.rOffset[0] + j * 72 + 4);
                    mesh.ShaderIndex = reader.ReadUInt16();
                    mesh.FaceIndex   = reader.ReadUInt16();
                    mesh.FaceCount   = reader.ReadUInt16();
                    section.Submeshes.Add(mesh);
                }
                #endregion

                #region Get Resource Indices
                int iIndex = 0, vIndex = 0, uIndex = 0, nIndex = 0, bIndex = 0;

                for (int j = 0; j < section.rType.Length; j++)
                {
                    switch (section.rType[j] & 0x0000FFFF)
                    {
                    case 32: iIndex = j;
                        break;

                    case 56:
                        switch ((section.rType[j] & 0xFFFF0000) >> 16)
                        {
                        case 0: vIndex = j;
                            break;

                        case 1: uIndex = j;
                            break;

                        case 2: nIndex = j;
                            break;
                        }
                        break;

                    case 100: bIndex = j;
                        break;
                    }
                }
                #endregion

                section.Vertices = new Vertex[section.vertcount];
                for (int j = 0; j < section.vertcount; j++)
                {
                    reader.SeekTo(section.hSize + section.rOffset[vIndex] + ((section.rSize[vIndex] / section.vertcount) * j));
                    var v = new Vertex();
                    var p = new Vector(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());

                    v.Values.Add(new VertexValue(p, 0, "position", 0));
                    section.Vertices[j] = v;
                }

                #region Read UVs and Normals
                for (int j = 0; j < section.vertcount; j++)
                {
                    reader.SeekTo(section.hSize + section.rOffset[uIndex] + (8 * j));
                    var v  = section.Vertices[j];
                    var uv = new Vector(reader.ReadSingle(), 1 - reader.ReadSingle());
                    v.Values.Add(new VertexValue(uv, 0, "texcoords", 0));
                    //DecompressVertex(ref v, BoundingBoxes[geomIndex]);
                }

                for (int j = 0; j < section.vertcount; j++)
                {
                    reader.SeekTo(section.hSize + section.rOffset[nIndex] + (12 * j));
                    var v = section.Vertices[j];
                    var n = Vector.FromHenDN3(reader.ReadUInt32());
                    v.Values.Add(new VertexValue(n, 0, "normal", 0));
                }
                #endregion

                reader.SeekTo(40);
                section.Indices = new int[reader.ReadUInt16()];
                reader.SeekTo(section.hSize + section.rOffset[iIndex]);
                for (int j = 0; j < section.Indices.Length; j++)
                {
                    section.Indices[j] = reader.ReadUInt16();
                }

                var facetype = 5;
                if (section.facecount * 3 == section.Indices.Length)
                {
                    facetype = 3;
                }
                IndexInfoList.Add(new mode.IndexBufferInfo()
                {
                    FaceFormat = facetype
                });
            }
            #endregion

            RawLoaded = true;
        }
Пример #4
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;
        }
        protected void LoadFixups()
        {
            var Entry = cache.zone.RawEntries[geomRawID & ushort.MaxValue];
            var reader = new EndianReader(new MemoryStream(cache.zone.FixupData), EndianFormat.BigEndian);

            reader.SeekTo(Entry.FixupOffset + (Entry.FixupSize - 24));
            int vCount = reader.ReadInt32();
            reader.Skip(8);
            int iCount = reader.ReadInt32();

            reader.SeekTo(Entry.FixupOffset);

            for (int i = 0; i < vCount; i++)
            {
                VertInfoList.Add(new mode.VertexBufferInfo()
                {
                    Offset = Entry.Fixups[i].Offset,
                    VertexCount = reader.ReadInt32(),
                    Unknown1 = reader.ReadInt32(),
                    DataLength = reader.ReadInt32(),
                    Unknown2 = reader.ReadInt32(), //blank from here so far
                    Unknown3 = reader.ReadInt32(),
                    Unknown4 = reader.ReadInt32(),
                    Unknown5 = reader.ReadInt32(),
                });
            }

            for (int i = 0; i < vCount; i++)
            {
                //assumed to be vertex related
                Unknown1List.Add(new mode.UnknownInfo1()
                {
                    Unknown1 = reader.ReadInt32(), //always 0 so far
                    Unknown2 = reader.ReadInt32(), //always 0 so far
                    Unknown3 = reader.ReadInt32(), //1350707457
                });
            }

            for (int i = 0; i < iCount; i++)
            {
                var data = new mode.IndexBufferInfo();
                data.Offset = Entry.Fixups[vCount * 2 + i].Offset;
                data.FaceFormat = reader.ReadInt32();

                //value exists only in reach beta and newer
                if (cache.Version >= DefinitionSet.HaloReachBeta) data.UnknownX = reader.ReadInt32();
                else data.UnknownX = -1;

                data.DataLength = reader.ReadInt32();
                data.Unknown0 = reader.ReadInt32(); //blank from here so far
                data.Unknown1 = reader.ReadInt32();
                data.Unknown2 = reader.ReadInt32();
                data.Unknown3 = reader.ReadInt32();

                IndexInfoList.Add(data);
            }

            for (int i = 0; i < iCount; i++)
            {
                //assumed to be index related
                Unknown2List.Add(new mode.UnknownInfo2()
                {
                    Unknown1 = reader.ReadInt32(), //always 0 so far
                    Unknown2 = reader.ReadInt32(), //always 0 so far
                    Unknown3 = reader.ReadInt32(), //1753688321
                });
            }

            for (int i = 0; i < 4; i++)
            {
                Unknown3List.Add(new mode.UnknownInfo3()
                {
                    Unknown1 = reader.ReadInt32(), //vCount in 3rd, iCount in 4th
                    Unknown2 = reader.ReadInt32(), //always 0 so far
                    Unknown3 = reader.ReadInt32(),
                });
            }

            reader.Close();
            reader.Dispose();
        }