Пример #1
0
        private static int ReadXYZI(BinaryReader br, MagicaVoxelMainChunk mainChunk)
        {
            int chunkSize    = br.ReadInt32();
            int childrenSize = br.ReadInt32();

            if (childrenSize > 0)
            {
                br.ReadBytes(childrenSize);
                Debug.LogWarning("MV: Nested chunks not supported");
                return(-1);
            }

            MagicaVoxelChunk chunk = mainChunk.chunk;

            int numVoxels = br.ReadInt32();

            for (int i = 0; i < numVoxels; ++i)
            {
                int x = br.ReadByte();
                int z = br.ReadByte(); // Magica has Z and Y swapped
                int y = br.ReadByte();

                chunk.data[Helpers.GetIndex1DFrom3D(x, y, z, chunk.sizeX, chunk.sizeZ)] = br.ReadByte();
            }

            return(chunkSize + childrenSize + 4 * 3);
        }
Пример #2
0
        private static int ReadSize(BinaryReader br, MagicaVoxelMainChunk mainChunk)
        {
            int chunkSize    = br.ReadInt32();
            int childrenSize = br.ReadInt32();

            if (childrenSize > 0)
            {
                br.ReadBytes(childrenSize);
                Debug.LogError("MV: Nested chunks not supported");
                return(-1);
            }

            MagicaVoxelChunk chunk = mainChunk.chunk = new MagicaVoxelChunk();

            chunk.sizeX = br.ReadInt32();
            chunk.sizeZ = br.ReadInt32(); // Magica has Z and Y swapped
            chunk.sizeY = br.ReadInt32();
            chunk.data  = new byte[chunk.sizeX * chunk.sizeY * chunk.sizeZ];

            return(chunkSize + childrenSize + 4 * 3);
        }