static void CreateColoredCubesVolume()
        {
            int width  = 256;
            int height = 32;
            int depth  = 256;

            ColoredCubesVolumeData data = VolumeDataAsset.CreateEmptyVolumeData <ColoredCubesVolumeData>(new Region(0, 0, 0, width - 1, height - 1, depth - 1));

            GameObject coloredCubesGameObject = ColoredCubesVolume.CreateGameObject(data, true, true);

            // And select it, so the user can get straight on with editing.
            Selection.activeGameObject = coloredCubesGameObject;

            int            floorThickness = 8;
            QuantizedColor floorColor     = new QuantizedColor(192, 192, 192, 255);

            for (int z = 0; z <= depth - 1; z++)
            {
                for (int y = 0; y < floorThickness; y++)
                {
                    for (int x = 0; x <= width - 1; x++)
                    {
                        data.SetVoxel(x, y, z, floorColor);
                    }
                }
            }
        }
        private void CreateAVolumeDB()
        {
            System.Random randomIntGenerator = new System.Random();
            int           randomInt          = randomIntGenerator.Next();
            string        saveLocation       = Paths.voxelDatabases + "/Matt-test" + randomInt + ".vdb";
            var           volumeBounds       = new Region(Vector3i.zero, size);

            ColoredCubesVolumeData data = VolumeData.CreateEmptyVolumeData <ColoredCubesVolumeData>(volumeBounds, null); // saveLocation);

            var coloredCubeVolume = GetComponent <ColoredCubesVolume>();

            coloredCubeVolume.data = data;

            float invRockScale = 1f / noiseScale;

            MaterialSet materialSet = new MaterialSet();

            // It's best to create these outside of the loop.
            QuantizedColor red   = new QuantizedColor(255, 0, 0, 255);
            QuantizedColor blue  = new QuantizedColor(122, 122, 255, 255);
            QuantizedColor gray  = new QuantizedColor(127, 127, 127, 255);
            QuantizedColor white = new QuantizedColor(255, 255, 255, 255);

            // Iterate over every voxel of our volume
            for (int z = 0; z < size.x; z++)
            {
                for (int y = 0; y < size.y; y++)
                {
                    for (int x = 0; x < size.z; x++)
                    {
                        // Simplex noise is quite high frequency. We scale the sample position to reduce this.
                        float sampleX = (float)x * invRockScale;
                        float sampleY = (float)y * invRockScale;
                        float sampleZ = (float)z * invRockScale;

                        // range -1 to +1
                        float simplexNoiseValue = SimplexNoise.Noise.Generate(sampleX, sampleY, sampleZ);

                        simplexNoiseValue -= y / size.y * .75f;
                        // mul by 5 and clamp?

                        //simplexNoiseValue *= 5f;
                        //simplexNoiseValue = Mathf.Clamp(simplexNoiseValue, -.5f, .5f);
                        //simplexNoiseValue += .5f;
                        //simplexNoiseValue *= 255;

                        if (simplexNoiseValue > 0f)
                        {
                            data.SetVoxel(x, y, z, blue);
                        }
                    }
                }
            }
            data.CommitChanges();

            Debug.Log("Voxel db saved to: " + saveLocation);
        }
Example #3
0
        void OnWizardCreate()
        {
            ColoredCubesVolumeData data = VolumeDataAsset.CreateEmptyVolumeData <ColoredCubesVolumeData>(new Region(0, 0, 0, width - 1, height - 1, depth - 1));

            if (generateFloor)
            {
                // Create a floor so the volume data is actually visible in the editor.
                int            floorThickness = 8;
                QuantizedColor floorColor     = new QuantizedColor(192, 192, 192, 255);

                for (int z = 0; z <= depth - 1; z++)
                {
                    for (int y = 0; y < floorThickness; y++)
                    {
                        for (int x = 0; x <= width - 1; x++)
                        {
                            data.SetVoxel(x, y, z, floorColor);
                        }
                    }
                }
            }
        }