Exemple #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);
        }
        public static float GetNoise(float[] noiseSet, int sideSize, int x, int y, int z, int max, float power)
        {
            // FastSIMD keeps things in x,y,z fashion but we have them ordered as y,z,x
            int   index = Helpers.GetIndex1DFrom3D(z, x, y, sideSize, sideSize);
            float n     = noiseSet[index] + 1f;

            n *= (max >> 1);

            if (Math.Abs(power - 1f) > float.Epsilon)
            {
                n = Mathf.Pow(n, power);
            }

            return(n);
        }