示例#1
0
        public static void LoadMeshGenerationData(string filePath, MeshGenerationData output)
        {
            output.Clear();

            var size   = new FileInfo(filePath).Length;
            var stride = sizeof(int) + 3 * sizeof(float);
            var count  = (size - 3 * sizeof(int)) / stride;

            using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (var mmf = MemoryMappedFile.CreateFromFile(fs, null, size, MemoryMappedFileAccess.Read, HandleInheritability.None, false))
                {
                    using (var accessor = mmf.CreateViewAccessor(0, size, MemoryMappedFileAccess.Read))
                    {
                        long pos = 0;

                        for (var i = 0; i < 3; ++i)
                        {
                            accessor.Read(pos, out int tmp);
                            output.gridSize[i] = tmp;
                            pos += sizeof(int);
                        }

                        for (var i = 0; i < count; ++i)
                        {
                            accessor.Read(pos, out int key);
                            pos += sizeof(int);
                            var val = TreeUtility.MmvaReadVector3(accessor, ref pos);
                            output.cells.Add(key, val);
                        }
                    }
                }
            }
        }