예제 #1
0
 public void Test_Int_Size_Constructor_Negative_Throws(int size)
 {
     Assert.Throws <System.ArgumentException>(() =>
     {
         voxelDataVolume = new VoxelDataVolume(size, Allocator.Temp);
     });
 }
        private void TestSetGetVoxelData(Func <float> function, float newVoxelData)
        {
            voxelDataVolume = new VoxelDataVolume <float>(5, Allocator.Temp);
            float actualVoxelData = function();

            Assert.IsTrue(AreVoxelDatasSame(newVoxelData, actualVoxelData), $"Expected {newVoxelData}, actual was {actualVoxelData}");
        }
예제 #3
0
 public void Test_Voxel_Datas_Are_Initialized_To_0()
 {
     voxelDataVolume = new VoxelDataVolume(5, Allocator.Temp);
     for (int i = 0; i < voxelDataVolume.Length; i++)
     {
         Assert.AreEqual(0, voxelDataVolume.GetVoxelData(i));
     }
 }
예제 #4
0
        public void Test_SetGetVoxelData_Int3([Random(0, 1f, 5)] float newVoxelData, [Random(0, 4, 3)] int x, [Random(0, 4, 3)] int y, [Random(0, 4, 3)] int z)
        {
            voxelDataVolume = new VoxelDataVolume(5, Allocator.Temp);

            voxelDataVolume.SetVoxelData(newVoxelData, new int3(x, y, z));
            float actualVoxelData = voxelDataVolume.GetVoxelData(new int3(x, y, z));

            Assert.IsTrue(AreVoxelDatasSame(newVoxelData, actualVoxelData), $"Expected {newVoxelData}, actual was {actualVoxelData}");
        }
예제 #5
0
        public void Test_SetGetVoxelData_Index([Random(0, 1f, 5)] float newVoxelData, [Random(0, 5 * 5 * 5 - 1, 5)] int index)
        {
            voxelDataVolume = new VoxelDataVolume(5, Allocator.Temp);

            voxelDataVolume.SetVoxelData(newVoxelData, index);
            float actualVoxelData = voxelDataVolume.GetVoxelData(index);

            Assert.IsTrue(AreVoxelDatasSame(newVoxelData, actualVoxelData), $"Expected {newVoxelData}, actual was {actualVoxelData}");
        }
예제 #6
0
        public void Test_IncreaseVoxelData_Index(float increaseAmount, float originalVoxelData, float expectedVoxelData)
        {
            voxelDataVolume = new VoxelDataVolume(5, Allocator.Temp);
            int index = 36; // Just some arbitrary index to set the voxel data at

            voxelDataVolume.SetVoxelData(originalVoxelData, index);
            voxelDataVolume.IncreaseVoxelData(increaseAmount, index);

            float actualVoxelData = voxelDataVolume.GetVoxelData(index);

            Assert.IsTrue(AreVoxelDatasSame(expectedVoxelData, actualVoxelData), $"Expected {expectedVoxelData}, actual was {actualVoxelData}");
        }
예제 #7
0
        /// <summary>
        /// Gets the voxel data of a custom volume in the world
        /// </summary>
        /// <param name="worldSpaceQuery">The world-space volume to get the voxel data for</param>
        /// <param name="allocator">How the new voxel data array should be allocated</param>
        /// <returns>The voxel data array inside the bounds</returns>
        public VoxelDataVolume <T> GetVoxelDataCustom(BoundsInt worldSpaceQuery, Allocator allocator)
        {
            VoxelDataVolume <T> voxelDataArray = new VoxelDataVolume <T>(worldSpaceQuery.CalculateVolume(), allocator);

            ForEachVoxelDataArrayInQuery(worldSpaceQuery, (chunkCoordinate, voxelDataChunk) =>
            {
                ForEachVoxelDataInQueryInChunk(worldSpaceQuery, chunkCoordinate, voxelDataChunk, (voxelDataWorldPosition, voxelDataLocalPosition, voxelDataIndex, voxelData) =>
                {
                    voxelDataArray.SetVoxelData(voxelData, voxelDataWorldPosition - worldSpaceQuery.min.ToInt3());
                });
            });

            return(voxelDataArray);
        }
        /// <summary>
        /// Gets a cube-shaped volume of voxel data from <paramref name="voxelDataArray"/>. The size of the cube is 1 unit.
        /// </summary>
        /// <param name="voxelDataArray">The voxel data array to get the voxel data from</param>
        /// <param name="localPosition">The origin of the cube</param>
        /// <returns>A cube-shaped volume of voxel data. The size of the cube is 1 unit.</returns>
        public static VoxelCorners <T> GetVoxelDataUnitCube <T>(this VoxelDataVolume <T> voxelDataArray, int3 localPosition) where T : struct
        {
            VoxelCorners <T> voxelDataCorners = new VoxelCorners <T>();

            for (int i = 0; i < 8; i++)
            {
                int3 voxelCorner = localPosition + LookupTables.CubeCorners[i];
                if (voxelDataArray.TryGetVoxelData(voxelCorner, out T voxelData))
                {
                    voxelDataCorners[i] = voxelData;
                }
            }

            return(voxelDataCorners);
        }
        /// <summary>
        /// Gets a cube-shaped volume of voxel data from <paramref name="voxelDataVolume"/>. The size of the cube is 1 unit.
        /// </summary>
        /// <param name="voxelDataVolume">The voxel data volume to get the voxel data from</param>
        /// <param name="localPosition">The origin of the cube</param>
        /// <returns>A cube-shaped volume of voxel data. The size of the cube is 1 unit.</returns>
        public static VoxelCorners <float> GetVoxelDataUnitCube(this VoxelDataVolume voxelDataVolume, int3 localPosition)
        {
            VoxelCorners <float> voxelDataCorners = new VoxelCorners <float>();

            for (int i = 0; i < 8; i++)
            {
                int3 voxelCorner = localPosition + LookupTables.CubeCorners[i];
                if (voxelDataVolume.TryGetVoxelData(voxelCorner.x, voxelCorner.y, voxelCorner.z, out float voxelData))
                {
                    voxelDataCorners[i] = voxelData;
                }
            }

            return(voxelDataCorners);
        }
예제 #10
0
        /// <summary>
        /// Sets the chunk data of the chunk at <paramref name="chunkCoordinate"/> without checking if data already exists at <paramref name="chunkCoordinate"/>
        /// </summary>
        /// <param name="chunkCoordinate">The coordinate of the chunk</param>
        /// <param name="newData">The data to set the chunk's data to</param>
        /// <param name="dataExistsAtCoordinate">Does data already exist at <paramref name="chunkCoordinate"/></param>
        public virtual void SetDataChunkUnchecked(int3 chunkCoordinate, VoxelDataVolume <T> newData, bool dataExistsAtCoordinate)
        {
            if (dataExistsAtCoordinate)
            {
                _chunks[chunkCoordinate].CopyFrom(newData);
                newData.Dispose();
            }
            else
            {
                _chunks.Add(chunkCoordinate, newData);
            }

            if (VoxelWorld.ChunkStore.TryGetDataChunk(chunkCoordinate, out ChunkProperties chunkProperties))
            {
                chunkProperties.HasChanges = true;
            }
        }
예제 #11
0
        /// <summary>
        /// Sets the voxel data for a volume in the world
        /// </summary>
        /// <param name="voxelDataArray">The new voxel data array</param>
        /// <param name="originPosition">The world position of the origin where the voxel data should be set</param>
        public void SetVoxelDataCustom(VoxelDataVolume <T> voxelDataArray, int3 originPosition)
        {
            BoundsInt worldSpaceQuery = new BoundsInt(originPosition.ToVectorInt(), (voxelDataArray.Size - new int3(1, 1, 1)).ToVectorInt());

            ForEachVoxelDataArrayInQuery(worldSpaceQuery, (chunkCoordinate, voxelDataChunk) =>
            {
                ForEachVoxelDataInQueryInChunk(worldSpaceQuery, chunkCoordinate, voxelDataChunk, (voxelDataWorldPosition, voxelDataLocalPosition, voxelDataIndex, voxelData) =>
                {
                    voxelDataChunk.SetVoxelData(voxelData, voxelDataWorldPosition - chunkCoordinate * VoxelWorld.WorldSettings.ChunkSize);
                });

                if (VoxelWorld.ChunkStore.TryGetDataChunk(chunkCoordinate, out ChunkProperties chunkProperties))
                {
                    chunkProperties.HasChanges = true;
                }
            });
        }
예제 #12
0
        /// <summary>
        /// Sets the chunk data of the chunk at <paramref name="chunkCoordinate"/>
        /// </summary>
        /// <param name="chunkCoordinate">The coordinate of the chunk</param>
        /// <param name="newData">The data to set the chunk's data to</param>
        public virtual void SetDataChunk(int3 chunkCoordinate, VoxelDataVolume <T> newData)
        {
            bool dataExistsAtCoordinate = DoesChunkExistAtCoordinate(chunkCoordinate);

            SetDataChunkUnchecked(chunkCoordinate, newData, dataExistsAtCoordinate);
        }
예제 #13
0
 public void Test_Default_Constructor_IsNotCreated()
 {
     voxelDataVolume = new VoxelDataVolume();
     Assert.AreEqual(false, voxelDataVolume.IsCreated);
 }
예제 #14
0
 public void Test_Xyz_Constructor_Length(int width, int height, int depth)
 {
     voxelDataVolume = new VoxelDataVolume(width, height, depth, Allocator.Temp);
     Assert.AreEqual(width * height * depth, voxelDataVolume.Length);
 }
예제 #15
0
 public void Test_Xyz_Constructor_IsCreated(int width, int height, int depth)
 {
     voxelDataVolume = new VoxelDataVolume(width, height, depth, Allocator.Temp);
     Assert.AreEqual(true, voxelDataVolume.IsCreated);
 }
예제 #16
0
 public void Test_Int_Size_Constructor_Size(int size)
 {
     voxelDataVolume = new VoxelDataVolume(size, Allocator.Temp);
     Assert.AreEqual(new int3(size, size, size), voxelDataVolume.Size);
 }
예제 #17
0
 public void Test_Xyz_Constructor_Height(int width, int height, int depth)
 {
     voxelDataVolume = new VoxelDataVolume(width, height, depth, Allocator.Temp);
     Assert.AreEqual(height, voxelDataVolume.Height);
 }
예제 #18
0
        /// <summary>
        /// Loops through each voxel data point that is contained in <paramref name="dataChunk"/> AND in <paramref name="worldSpaceQuery"/>, and performs <paramref name="function"/> on it
        /// </summary>
        /// <param name="worldSpaceQuery">The query that determines whether or not a voxel data point is contained.</param>
        /// <param name="chunkCoordinate">The coordinate of <paramref name="dataChunk"/></param>
        /// <param name="dataChunk">The voxel datas of the chunk</param>
        /// <param name="function">The function that will be performed on each voxel data point. The arguments are as follows: 1) The world space position of the voxel data point, 2) The chunk space position of the voxel data point, 3) The index of the voxel data point inside of <paramref name="dataChunk"/>, 4) The value of the voxel data</param>
        public void ForEachVoxelDataInQueryInChunk(BoundsInt worldSpaceQuery, int3 chunkCoordinate, VoxelDataVolume <T> dataChunk, Action <int3, int3, int, T> function)
        {
            int3 chunkBoundsSize       = VoxelWorld.WorldSettings.ChunkSize;
            int3 chunkWorldSpaceOrigin = chunkCoordinate * VoxelWorld.WorldSettings.ChunkSize;

            BoundsInt chunkWorldSpaceBounds = new BoundsInt(chunkWorldSpaceOrigin.ToVectorInt(), chunkBoundsSize.ToVectorInt());

            BoundsInt intersectionVolume    = IntersectionUtilities.GetIntersectionVolume(worldSpaceQuery, chunkWorldSpaceBounds);
            int3      intersectionVolumeMin = intersectionVolume.min.ToInt3();
            int3      intersectionVolumeMax = intersectionVolume.max.ToInt3();

            for (int voxelDataWorldPositionX = intersectionVolumeMin.x; voxelDataWorldPositionX <= intersectionVolumeMax.x; voxelDataWorldPositionX++)
            {
                for (int voxelDataWorldPositionY = intersectionVolumeMin.y; voxelDataWorldPositionY <= intersectionVolumeMax.y; voxelDataWorldPositionY++)
                {
                    for (int voxelDataWorldPositionZ = intersectionVolumeMin.z; voxelDataWorldPositionZ <= intersectionVolumeMax.z; voxelDataWorldPositionZ++)
                    {
                        int3 voxelDataWorldPosition = new int3(voxelDataWorldPositionX, voxelDataWorldPositionY, voxelDataWorldPositionZ);

                        int3 voxelDataLocalPosition = voxelDataWorldPosition - chunkWorldSpaceOrigin;
                        int  voxelDataIndex         = IndexUtilities.XyzToIndex(voxelDataLocalPosition, chunkBoundsSize.x + 1, chunkBoundsSize.y + 1);
                        if (dataChunk.TryGetVoxelData(voxelDataIndex, out T voxelData))
                        {
                            function(voxelDataWorldPosition, voxelDataLocalPosition, voxelDataIndex, voxelData);
                        }
                    }
                }
            }
        }
예제 #19
0
        /// <inheritdoc/>
        public override void GenerateDataForChunkUnchecked(int3 chunkCoordinate)
        {
            VoxelDataVolume <T> data = new VoxelDataVolume <T>(VoxelWorld.WorldSettings.ChunkSize + 1, Allocator.Persistent);

            GenerateDataForChunkUnchecked(chunkCoordinate, data);
        }
 public void Test_Xyz_Constructor_Depth(int width, int height, int depth)
 {
     voxelDataVolume = new VoxelDataVolume <float>(width, height, depth, Allocator.Temp);
     Assert.AreEqual(depth, voxelDataVolume.Depth);
 }