public float this[VoxelIndex index, int layer]
 {
     get
     {
         return(array[index.Value * voxelLayout.dataLayerCount + layer]);
     }
 }
Example #2
0
        IEnumerable <Plane> FindPlanes(Vector3 normal)
        {
            var voxelIndex = new VoxelIndex(normal, normalErrorValue);

            foreach (var x in GetSearch(voxelIndex, 0))
            {
                if (comparer.ContainsKey(x))
                {
                    foreach (var y in GetSearch(voxelIndex, 1))
                    {
                        if (comparer[x].ContainsKey(y))
                        {
                            foreach (var z in GetSearch(voxelIndex, 2))
                            {
                                if (comparer[x][y].ContainsKey(z))
                                {
                                    foreach (var plane in comparer[x][y][z])
                                    {
                                        yield return(plane);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
            public void Execute(int index)
            {
                var voxelIndex = new VoxelIndex
                {
                    Value = index
                };
                var rootCoordiante    = voxelLayout.GetCoordinatesFromVoxelIndex(voxelIndex);
                var originalSelfValue = sourceDiffusionValues[voxelIndex.Value];

                float newValue = originalSelfValue;

                for (int adjacencyIndex = 0; adjacencyIndex < adjacencyVectors.Length; adjacencyIndex++)
                {
                    var offset           = adjacencyVectors[adjacencyIndex];
                    var sampleCoordinate = offset + rootCoordiante;
                    var sampleIndex      = voxelLayout.GetVoxelIndexFromCoordinates(sampleCoordinate);

                    if (!sampleIndex.IsValid)
                    {
                        // if the index is outside of bounds, do no diffusion
                        //  this should have an effect of conserving all resources inside the bounds, none
                        //  should be lost or gained from the boundary conditions
                        continue;
                    }

                    var sampleValue         = sourceDiffusionValues[sampleIndex.Value];
                    var diffusionAdjustment = diffusionConstant;

                    var diffuseAmount = (sampleValue - originalSelfValue) * diffusionAdjustment;
                    newValue += diffuseAmount;
                }

                targetDiffusionValues[voxelIndex.Value] = newValue;
            }
Example #4
0
        private IEnumerable <int> GetSearch(VoxelIndex voxelIndex, int axis)
        {
            if (axis == 0)
            {
                if (voxelIndex.SideX == -1)
                {
                    yield return(voxelIndex.X - 1);

                    yield return(voxelIndex.X);
                }
                else if (voxelIndex.SideX == 1)
                {
                    yield return(voxelIndex.X);

                    yield return(voxelIndex.X + 1);
                }
                else
                {
                    yield return(voxelIndex.X);
                }
            }
            else if (axis == 1)
            {
                if (voxelIndex.SideY == -1)
                {
                    yield return(voxelIndex.Y - 1);

                    yield return(voxelIndex.Y);
                }
                else if (voxelIndex.SideY == 1)
                {
                    yield return(voxelIndex.Y);

                    yield return(voxelIndex.Y + 1);
                }
                else
                {
                    yield return(voxelIndex.Y);
                }
            }
            else
            {
                if (voxelIndex.SideZ == -1)
                {
                    yield return(voxelIndex.Z - 1);

                    yield return(voxelIndex.Z);
                }
                else if (voxelIndex.SideZ == 1)
                {
                    yield return(voxelIndex.Z);

                    yield return(voxelIndex.Z + 1);
                }
                else
                {
                    yield return(voxelIndex.Z);
                }
            }
        }
Example #5
0
        public Vector3Int GetCoordinatesFromVoxelIndex(VoxelIndex voxelIndex)
        {
            var x = voxelIndex.Value / (worldResolution.y * worldResolution.z);
            var y = (voxelIndex.Value / worldResolution.z) % worldResolution.y;
            var z = voxelIndex.Value % worldResolution.z;

            return(new Vector3Int(x, y, z));
        }
            public void Execute(int index)
            {
                if ((oneDimensionalKernel.Length - 1) % 2 != 0)
                {
                    throw new System.Exception("kernel must be odd number length");
                }

                Vector3Int axisVector;

                switch (diffuseAxis)
                {
                case DiffusionAxis.X:
                    axisVector = new Vector3Int(1, 0, 0);
                    break;

                case DiffusionAxis.Y:
                    axisVector = new Vector3Int(0, 1, 0);
                    break;

                case DiffusionAxis.Z:
                    axisVector = new Vector3Int(0, 0, 1);
                    break;

                default:
                    throw new System.Exception("must specify diffuse axis");
                }

                var voxelIndex = new VoxelIndex
                {
                    Value = index
                };
                var rootCoordiante = voxelLayout.GetCoordinatesFromVoxelIndex(voxelIndex);

                var   kernelOrigin = oneDimensionalKernel.Length / 2;
                float newValue     = 0;

                for (int kernelIndex = 0; kernelIndex < oneDimensionalKernel.Length; kernelIndex++)
                {
                    var offset       = axisVector * (kernelIndex - kernelOrigin);
                    var kernelWeight = oneDimensionalKernel[kernelIndex];

                    var sampleCoordinate = offset + rootCoordiante;
                    var sampleIndex      = voxelLayout.GetVoxelIndexFromCoordinates(sampleCoordinate);

                    float sampleValue;
                    if (!sampleIndex.IsValid)
                    {
                        sampleValue = boundaryValue;
                    }
                    else
                    {
                        sampleValue = sourceDiffusionValues[sampleIndex.Value];
                    }
                    newValue += sampleValue * kernelWeight;
                }

                targetDiffusionValues[voxelIndex.Value] = newValue;
            }
        public void Execute(int index)
        {
            var voxelIndex = new VoxelIndex
            {
                Value = index
            };

            layerData[voxelIndex, layerId] = sourceData[voxelIndex.Value];
        }
        public void Execute(int index)
        {
            var voxelIndex = new VoxelIndex
            {
                Value = index
            };

            targetData[voxelIndex.Value] = layerData[voxelIndex, layerId];
        }
        public void Execute(int index)
        {
            var voxelIndex = new VoxelIndex
            {
                Value = index
            };

            allBaseMarkers[voxelIndex, markerLayerIndex] = Mathf.Max(allBaseMarkers[voxelIndex, markerLayerIndex] + newMarkerLevels[index] - oldMarkerLevels[index], 0);
        }
        public void Execute(int index)
        {
            var voxelIndex = new VoxelIndex
            {
                Value = index
            };
            var change = layerToAdd[index] * layerMultiplier;

            allBaseMarkers[voxelIndex, markerLayerIndex] = Mathf.Max(allBaseMarkers[voxelIndex, markerLayerIndex] + change, 0);
        }
Example #11
0
            public void Execute(int index)
            {
                var voxelIndex = new VoxelIndex
                {
                    Value = index
                };

                var reductionAmount = voxelLayerData[voxelIndex, 0] * durabilityRegenerationFactor;

                volumetricDamageValues[voxelIndex.Value] = math.max(volumetricDamageValues[voxelIndex.Value] - reductionAmount, 0);
            }
Example #12
0
            public void Execute(int index)
            {
                //volumetricDestructionFlags[index] = false;
                var voxelIndex = new VoxelIndex
                {
                    Value = index
                };
                var durability = voxelLayerData[voxelIndex, flagCapLayerIndex];
                var damage     = volumetricDamageValues[voxelIndex.Value];

                if (Unity.Burst.CompilerServices.Hint.Unlikely(damage > 0 && damage > durability))
                {
                    volumetricDestructionTimestamps[voxelIndex.Value] = currentTime;
                    volumetricDamageValues[voxelIndex.Value]          = 0f;
                }
                else
                {
                    var reductionAmount = voxelLayerData[voxelIndex, flagCapLayerIndex] * durabilityRegenerationFactor;
                    volumetricDamageValues[voxelIndex.Value] = math.max(volumetricDamageValues[voxelIndex.Value] - reductionAmount, 0);
                }
            }
Example #13
0
        public SimilarPlaneFinder(IEnumerable <Plane> inputPlanes, double normalErrorValue = .0001)
        {
            this.normalErrorValue = normalErrorValue;
            comparer = new Dictionary <int, Dictionary <int, Dictionary <int, List <Plane> > > >();
            foreach (var plane in inputPlanes)
            {
                var voxelIndex = new VoxelIndex(plane.Normal, normalErrorValue);

                if (!comparer.ContainsKey(voxelIndex.X))
                {
                    comparer[voxelIndex.X] = new Dictionary <int, Dictionary <int, List <Plane> > >();
                }
                if (!comparer[voxelIndex.X].ContainsKey(voxelIndex.Y))
                {
                    comparer[voxelIndex.X][voxelIndex.Y] = new Dictionary <int, List <Plane> >();
                }
                if (!comparer[voxelIndex.X][voxelIndex.Y].ContainsKey(voxelIndex.Z))
                {
                    comparer[voxelIndex.X][voxelIndex.Y][voxelIndex.Z] = new List <Plane>();
                }

                comparer[voxelIndex.X][voxelIndex.Y][voxelIndex.Z].Add(plane);
            }
        }
Example #14
0
 public Vector3 GetWorldPositionFromVoxelIndex(VoxelIndex voxelIndex)
 {
     return(CoordinateToCenterOfVoxel(GetCoordinatesFromVoxelIndex(voxelIndex)));
 }