Пример #1
0
        /// <summary>
        /// Reads data from the aara file.
        /// </summary>
        /// <param name="count">Number of elements to read.</param>
        /// <param name="startPos">Position of first element to read in the data block (header will be skipped).</param>
        /// <returns></returns>
        public Array LoadElements(int count, int startPos = 0)
        {
            using (s_cpu_AaraDataReadMemoryStream.Timer)
            {
                if ((count + startPos) > ElementCount)
                {
                    Report.Warn("AaraData tried reading over end of file '" + SourceFileName + "'");
                    return(CreateEmptyArray[DataTypeAsSymbol]());
                }
                else if (startPos < 0)
                {
                    Report.Warn("AaraData tried indexing < 0 in file '" + SourceFileName + "'");
                    return(CreateEmptyArray[DataTypeAsSymbol]());
                }

                var countInByte    = count * s_sizeTable[DataTypeAsSymbol];
                var startPosInByte = startPos * s_sizeTable[DataTypeAsSymbol];
                var readFun        = s_readBigFuncs[DataTypeAsSymbol];

                // load from file to memory
                var memStream = Load.AsMemoryStream(SourceFileName, HeaderSize + startPosInByte, countInByte);

                // convert from memory stream to actual data
                return(readFun(new StreamCodeReader(memStream), count));
            }
        }
Пример #2
0
        /// <summary>
        /// Reads full patch.xml into and returns a PatchFileInfo
        /// </summary>
        public static PatchFileInfo FromFile(string patchFilePath)
        {
            if (Path.GetFileName(patchFilePath) != "patch.xml")
            {
                patchFilePath = Path.Combine(patchFilePath, "patch.xml");
            }

            //var patch = XElement.Load(patchFilePath, LoadOptions.None).Element("Patch");
            var patch = XElement.Load(Load.AsMemoryStream(patchFilePath)).Element("Patch");

            var info = new PatchFileInfo()
            {
                TagList             = ReadStringList(patch, "TagList"),
                GeometryType        = ReadString(patch, "GeometryType"),
                QuadVertexSortOrder = ReadString(patch, "QuadVertexSortOrder", PatchFileInfo.QuadVertexSortOrderType.ColumnMajor),

                Local2Global      = ReadM44d(patch, "Local2Global"),
                GlobalBoundingBox = ReadBox3d(patch, "GlobalBoundingBox"),
                LocalBoundingBox  = ReadBox3d(patch, "LocalBoundingBox"),

                Positions = ReadString(patch, "Positions"),

                Coordinates = ReadStringList(patch, "Coordinates"),
                Textures    = ReadStringList(patch, "Textures"),
            };

            if (HasNormalsAndOffsets(patch))
            {
                info.Normals = ReadString(patch, "Normals");
                info.Offsets = ReadString(patch, "Offsets");
            }

            //var x = patch.Element("Local2Global2D");
            //Report.Line(x.ToString());
            //   //e.Element("GlobalBoundingBox2d") != null &&
            //   //e.Element("LocalBoundingBox2d") != null &&
            //   //e.Element("Positions2d") != null;

            if (XmlHas2dData(patch))
            {
                info.Local2Global2d      = ReadM44d(patch, "Local2Global2D");
                info.GlobalBoundingBox2d = ReadBox3d(patch, "GlobalBoundingBox2D");
                info.LocalBoundingBox2d  = ReadBox3d(patch, "LocalBoundingBox2D");
                info.Positions2d         = ReadString(patch, "Positions2D");
            }

            if (!info.LocalBoundingBox2d.IsValid)
            {
                Report.Warn("LocalBoundingBox2d is not valid");
            }

            return(info);
        }
Пример #3
0
        /// <summary>
        /// Returns a column in the range of rowStart to rowEnd. Warning: This is slow, because elemnts have to been seeked out.
        /// </summary>
        /// <param name="columnPos">Column to read.</param>
        /// <param name="rowStart"></param>
        /// <param name="rowEnd"></param>
        /// <returns></returns>
        public Array LoadColumn(int columnPos, int rowStart, int rowEnd)
        {
            using (s_cpu_AaraDataReadMemoryStream.Timer)
            {
                var readFun  = s_readBigFuncs[DataTypeAsSymbol];
                var byteSize = s_sizeTable[DataTypeAsSymbol];

                var rowCount   = rowEnd - rowStart;
                var byteOffset = HeaderSize + byteSize * columnPos;
                var byteStride = byteSize * NumOfColumns;

                // load from file to memory
                var chunks    = Enumerable.Range(0, rowCount).Select(i => Tup.Create((long)(byteOffset + i * byteStride), (long)byteSize));
                var memStream = Load.AsMemoryStream(SourceFileName, chunks);

                // convert from memory stream to actual data
                var r = readFun(new StreamCodeReader(memStream), rowCount);
                return(r);
            }
        }