Example #1
0
        private ColoredCubesVolumeData CreateOrOverwriteVolumeDatabase()
        {
            var volumeBounds = new Region(Vector3i.zero, size);

            ColoredCubesVolumeData data = null;

            if (!File.Exists(saveLocation))
            {
                data = VolumeData.CreateEmptyVolumeData <ColoredCubesVolumeData>(volumeBounds, saveLocation);
            }
            else
            {
                data = VolumeData.CreateFromVoxelDatabase <ColoredCubesVolumeData>(
                    saveLocation,
                    VolumeData.WritePermissions.ReadWrite);
            }

            MakeChunk(data);


            data.CommitChanges();



            return(data);
        }
Example #2
0
    IEnumerator CreateMap()
    {
        int[,] map = LoadImage(textureLocation);
        ColoredCubesVolumeData cubesData = VolumeData.CreateEmptyVolumeData <ColoredCubesVolumeData>(new Region(0, 0, 0, width, maxHeight, depth));

        color = new QuantizedColor(255, 255, 255, 255);

//		coloredCubesVolume = cubesHolder.AddComponent<ColoredCubesVolume>();
//		coloredCubesVolume.data = cubesData;
//		cubesHolder.AddComponent<ColoredCubesVolumeRenderer>();
//		cubesHolder.AddComponent <ColoredCubesVolumeCollider>();

        for (int z = 0; z < depth; z++)
        {
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < (int)(((float)map[x, z] / 255f) * maxHeight); y++)
                {
                    //if(map[x,z] > VoxelThresHold){
                    cubesData.SetVoxel(x, y, z, color);
                    //cubesData.SetVoxel(x, y, z, color);
                    //}
                }
            }
            loadPercentage = (float)z / (float)depth;
            yield return(null);
        }
        Debug.Log("Finish");
        cubesData.CommitChanges();
        coloredCubesVolume      = cubesHolder.AddComponent <ColoredCubesVolume>();
        coloredCubesVolume.data = cubesData;
        cubesHolder.AddComponent <ColoredCubesVolumeRenderer>();
        cubesHolder.AddComponent <ColoredCubesVolumeCollider>();
        CreateTerrain();

        cubesHolder.transform.localScale = new Vector3(3f, 3f, 3f);
        transform.localScale            *= 1f / 3f;
    }