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);
                    }
                }
            }
        }
        public override void OnInspectorGUI()
        {
            ColoredCubesVolumeData data = target as ColoredCubesVolumeData;

            EditorGUILayout.LabelField("Full path to voxel database:", EditorStyles.boldLabel);
            EditorGUILayout.HelpBox(data.fullPathToVoxelDatabase, MessageType.None);
        }
Пример #3
0
        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);
        }
Пример #4
0
		/// Convinience method for creating a GameObject with a set of colored cubes components attached.
		/**
		 * Adding a volume to a scene requires creating a GameObject and then attching the required Cubiquity components such a renderer and a
		 * collider. This method simply automates the process and also attaches the provided volume data.
		 * 
		 * \param data The volume data which should be attached to the construced volume.
		 * \param addRenderer Specifies whether a renderer component should be added so that the volume is displayed.
		 * \param addCollider Specifies whether a collider component should be added so that the volume can participate in collisions.
		 */
		public static GameObject CreateGameObject(ColoredCubesVolumeData data, bool addRenderer, bool addCollider)
		{
			// Create our main game object representing the volume.
			GameObject coloredCubesVolumeGameObject = new GameObject("Colored Cubes Volume");
			
			//Add the required volume component.
			ColoredCubesVolume coloredCubesVolume = coloredCubesVolumeGameObject.GetOrAddComponent<ColoredCubesVolume>();
			
			// Set the provided data.
			coloredCubesVolume.data = data;
			
			// Add the renderer and collider if desired.
			if(addRenderer) { coloredCubesVolumeGameObject.AddComponent<ColoredCubesVolumeRenderer>(); }
			if(addCollider) { coloredCubesVolumeGameObject.AddComponent<ColoredCubesVolumeCollider>(); }
			
			// Return the created object
			return coloredCubesVolumeGameObject;
		}
Пример #5
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);
                        }
                    }
                }
            }
        }
Пример #6
0
        /// Convinience method for creating a GameObject with a set of colored cubes components attached.

        /**
         * Adding a volume to a scene requires creating a GameObject and then attching the required Cubiquity components such a renderer and a
         * collider. This method simply automates the process and also attaches the provided volume data.
         *
         * \param data The volume data which should be attached to the construced volume.
         * \param addRenderer Specifies whether a renderer component should be added so that the volume is displayed.
         * \param addCollider Specifies whether a collider component should be added so that the volume can participate in collisions.
         */
        public static GameObject CreateGameObject(ColoredCubesVolumeData data, bool addRenderer, bool addCollider)
        {
            // Create our main game object representing the volume.
            GameObject coloredCubesVolumeGameObject = new GameObject("Colored Cubes Volume");

            //Add the required volume component.
            ColoredCubesVolume coloredCubesVolume = coloredCubesVolumeGameObject.GetOrAddComponent <ColoredCubesVolume>();

            // Set the provided data.
            coloredCubesVolume.data = data;

            // Add the renderer and collider if desired.
            if (addRenderer)
            {
                coloredCubesVolumeGameObject.AddComponent <ColoredCubesVolumeRenderer>();
            }
            if (addCollider)
            {
                coloredCubesVolumeGameObject.AddComponent <ColoredCubesVolumeCollider>();
            }

            // Return the created object
            return(coloredCubesVolumeGameObject);
        }