Пример #1
0
        public override void LoadRaw()
        {
            if (RawLoaded) return;

            var data = cache.GetRawFromID(geomRawID);

            var ms = new MemoryStream(data);
            var reader = new EndianReader(ms, EndianFormat.Big);

            var validParts = new Dictionary<int, mode.ModelSection>();

            LoadFixups();

            #region Read Vertices
            for (int i = 0; i < ModelSections.Count; i++)
            {
                var section = ModelSections[i];
                if (section.Submeshes.Count == 0) continue;

                if (section.VertsIndex >= 0 && section.VertsIndex < VertInfoList.Count) reader.SeekTo(VertInfoList[section.VertsIndex].Offset);

                if (cache.vertexNode == null) throw new NotSupportedException("No vertex definitions found for " + cache.Version.ToString());

                #region Get Vertex Definition
                XmlNode formatNode = null;
                foreach (XmlNode node in cache.vertexNode.ChildNodes)
                {
                    if (Convert.ToInt32(node.Attributes["type"].Value, 16) == section.VertexFormat)
                    {
                        formatNode = node;
                        break;
                    }
                }

                if (formatNode == null) throw new NotSupportedException("Format " + section.VertexFormat.ToString() + " not found in definition for " + cache.Version.ToString());
                #endregion

                mode.ModelSection validPart;
                if (validParts.TryGetValue(section.VertsIndex, out validPart))
                {
                    section.Vertices = validPart.Vertices;
                    continue;
                }
                else
                    validParts.Add(section.VertsIndex, section);

                section.Vertices = new Vertex[VertInfoList[section.VertsIndex].VertexCount];

                #region Get Vertices
                for (int j = 0; j < VertInfoList[section.VertsIndex].VertexCount; j++)
                {
                    mode.BoundingBox bb;
                    section.Vertices[j] = new Vertex(reader, formatNode);
                    if (i >= BoundingBoxes.Count)
                    {
                        bb = new mode.BoundingBox();
                        bb.XBounds = bb.YBounds = bb.ZBounds =
                        bb.UBounds = bb.VBounds = new Range<float>(0, 0);
                    }
                    else
                        bb = BoundingBoxes[i];

                    ModelFunctions.DecompressVertex(ref section.Vertices[j], bb);
                }
                #endregion
            }
            #endregion

            validParts.Clear();

            #region Read Indices
            for (int i = 0; i < ModelSections.Count; i++)
            {
                var section = ModelSections[i];
                if (section.Submeshes.Count == 0) continue;

                if (section.FacesIndex >= 0 && section.FacesIndex < IndexInfoList.Count) reader.SeekTo(IndexInfoList[section.FacesIndex].Offset);

                mode.ModelSection validPart;
                if (validParts.TryGetValue(section.FacesIndex, out validPart))
                {
                    section.Indices = validPart.Indices;
                    continue;
                }
                else
                    validParts.Add(section.FacesIndex, section);

                section.Indices = new int[section.TotalFaceCount];
                for (int j = 0; j < section.TotalFaceCount; j++)
                    section.Indices[j] = (VertInfoList[section.VertsIndex].VertexCount > 0xFFFF) ? reader.ReadInt32() : reader.ReadUInt16();
            }
            #endregion

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

            var data = cache.GetRawFromID(geomRawID);

            var ms     = new MemoryStream(data);
            var reader = new EndianReader(ms, EndianFormat.Big);

            var validParts = new Dictionary <int, mode.ModelSection>();

            LoadFixups();

            #region Read Vertices
            for (int i = 0; i < ModelSections.Count; i++)
            {
                var section = ModelSections[i];
                if (section.Submeshes.Count == 0)
                {
                    continue;
                }

                if (section.VertsIndex >= 0 && section.VertsIndex < VertInfoList.Count)
                {
                    reader.SeekTo(VertInfoList[section.VertsIndex].Offset);
                }

                if (cache.vertexNode == null)
                {
                    throw new NotSupportedException("No vertex definitions found for " + cache.Version.ToString());
                }

                #region Get Vertex Definition
                XmlNode formatNode = null;
                foreach (XmlNode node in cache.vertexNode.ChildNodes)
                {
                    if (Convert.ToInt32(node.Attributes["type"].Value, 16) == section.VertexFormat)
                    {
                        formatNode = node;
                        break;
                    }
                }

                if (formatNode == null)
                {
                    throw new NotSupportedException("Format " + section.VertexFormat.ToString() + " not found in definition for " + cache.Version.ToString());
                }
                #endregion

                mode.ModelSection validPart;
                if (validParts.TryGetValue(section.VertsIndex, out validPart))
                {
                    section.Vertices = validPart.Vertices;
                    continue;
                }
                else
                {
                    validParts.Add(section.VertsIndex, section);
                }

                section.Vertices = new Vertex[VertInfoList[section.VertsIndex].VertexCount];

                #region Get Vertices
                for (int j = 0; j < VertInfoList[section.VertsIndex].VertexCount; j++)
                {
                    mode.BoundingBox bb;
                    section.Vertices[j] = new Vertex(reader, formatNode);
                    if (i >= BoundingBoxes.Count)
                    {
                        bb             = new mode.BoundingBox();
                        bb.XBounds     = bb.YBounds = bb.ZBounds =
                            bb.UBounds = bb.VBounds = new Range <float>(0, 0);
                    }
                    else
                    {
                        bb = BoundingBoxes[i];
                    }

                    ModelFunctions.DecompressVertex(ref section.Vertices[j], bb);
                }
                #endregion
            }
            #endregion

            validParts.Clear();

            #region Read Indices
            for (int i = 0; i < ModelSections.Count; i++)
            {
                var section = ModelSections[i];
                if (section.Submeshes.Count == 0)
                {
                    continue;
                }

                if (section.FacesIndex >= 0 && section.FacesIndex < IndexInfoList.Count)
                {
                    reader.SeekTo(IndexInfoList[section.FacesIndex].Offset);
                }

                mode.ModelSection validPart;
                if (validParts.TryGetValue(section.FacesIndex, out validPart))
                {
                    section.Indices = validPart.Indices;
                    continue;
                }
                else
                {
                    validParts.Add(section.FacesIndex, section);
                }

                section.Indices = new int[section.TotalFaceCount];
                for (int j = 0; j < section.TotalFaceCount; j++)
                {
                    section.Indices[j] = (VertInfoList[section.VertsIndex].VertexCount > 0xFFFF) ? reader.ReadInt32() : reader.ReadUInt16();
                }
            }
            #endregion

            RawLoaded = true;
        }