Example #1
0
        public VoxelChunk(Vector3 pos, int width, int height, int lod)
        {
            lodLevel = lod;
            //As we need some extra data to smooth the voxels and create the normals we need a extra 5 voxels
            //+1 one to create a seamless mesh. +2 to create smoothed normals and +2 to smooth the voxels
            //This is a little unoptimsed as it means some data is being generated that has alread been generated in other voxel chunks
            //but it is simpler as we dont need to access the data in the other voxels. You could try and copy the data
            //needed in for the other voxel chunks as a optimisation step

            //set voxel size and data
            Voxels    = new byte[width + 5, height + 5, width + 5];
            Materials = new byte[width + 5, height + 5, width + 5];
            x         = width + 5;
            y         = height + 5;
            z         = width + 5;
            //set position so that voxel position matches world position if translated
            m_pos   = pos - new Vector3(2f, 2f, 2f);
            m_pos  *= VoxelTerrainEngine.TriSize[lodLevel];
            RealPos = pos;
            //set file name for voxel saver

            FileName = "VoxelChunk " + m_pos;

            SaveName = "Saved Chunks";

            VoxelSaver = new SaverVoxel(FileName + ".txt", SaveName);

            VoxelSaver.fileName = SaveName + "/" + FileName + ".txt";
        }
        public VoxelChunk(Vector3 pos, int width, int height, int length, float surfaceLevel)
        {
            m_surfaceLevel = surfaceLevel;
            //As we need some extra data to smooth the voxels and create the normals we need a extra 5 voxels
            //+1 one to create a seamless mesh. +2 to create smoothed normals and +2 to smooth the voxels
            //This is a little unoptimsed as it means some data is being generated that has alread been generated in other voxel chunks
            //but it is simpler as we dont need to access the data in the other voxels. You could try and copy the data
            //needed in for the other voxel chunks as a optimisation step

            //set voxel size and data
            Voxels = new byte[width+5, height+5, length+5];

            //set position so that voxel position matches world position if translated
            m_pos = pos - new Vector3(2f,2f,2f);

            //set file name for voxel saver

            FileName = "VoxelChunk "+m_pos;

            SaveName = "Saved Chunks";

            VoxelSaver = new SaverVoxel(FileName+".txt",SaveName);

            VoxelSaver.fileName = SaveName + "/" + FileName+".txt";
        }