// Update is called once per frame
        private void Update()
        {
            if (voxelObject == null)
            {
                return;
            }

            currentTime += Time.deltaTime;
            if (currentTime >= Interval)
            {
                currentTime = 0;

                for (int i = 0; i < NumVoxels; i++)
                {
                    PicaVoxelPoint p =
                        new PicaVoxelPoint(
                            ConstrainToBox
                                ? Random.Range(ConstrainBox.BottomLeftFront.X, ConstrainBox.TopRightBack.X)
                                : Random.Range(0, voxelObject.XSize),
                            ConstrainToBox
                                ? Random.Range(ConstrainBox.BottomLeftFront.Y, ConstrainBox.TopRightBack.Y)
                                : Random.Range(0, voxelObject.YSize),
                            ConstrainToBox
                                ? Random.Range(ConstrainBox.BottomLeftFront.Z, ConstrainBox.TopRightBack.Z)
                                : Random.Range(0, voxelObject.ZSize));

                    voxelObject.SetVoxelAtArrayPosition(p,
                                                        new Voxel()
                    {
                        State = AddVoxels?VoxelState.Active : VoxelState.Hidden,
                        Color = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f))
                    });
                }
            }
        }
Beispiel #2
0
        private void AddChunkToUpdateList(int x, int y, int z)
        {
            var pvp = new PicaVoxelPoint(x, y, z);

            if (chunksToUpdate.Contains(pvp))
            {
                return;
            }

            chunks[x, y, z].IsUpdated = true;
            chunksToUpdate.Add(pvp);
        }
Beispiel #3
0
        public void SetChunkAtVoxelPositionDirty(int x, int y, int z)
        {
            if (x < 0 || y < 0 || z < 0 || x >= ParentVolume.XSize || y >= ParentVolume.YSize || z >= ParentVolume.ZSize)
            {
                return;
            }

            PicaVoxelPoint chunkPos = new PicaVoxelPoint((int)(x / ParentVolume.XChunkSize), (int)(y / ParentVolume.YChunkSize),
                                                         (int)(z / ParentVolume.ZChunkSize));

            if (chunks[chunkPos.X, chunkPos.Y, chunkPos.Z] != null)
            {
                AddChunkToUpdateList(chunkPos.X, chunkPos.Y, chunkPos.Z);
            }
        }
Beispiel #4
0
        public static void RotateVoxelArrayY(ref Voxel[] source, PicaVoxelPoint srcSize)
        {
            Voxel[] dest = new Voxel[srcSize.Z * srcSize.Y * srcSize.X];
            for (int x = 0; x < srcSize.X; x++)
            {
                for (int y = 0; y < srcSize.Y; y++)
                {
                    for (int z = 0; z < srcSize.Z; z++)
                    {
                        dest[z + srcSize.Z * (y + srcSize.Y * (srcSize.X - 1 - x))] = source[x + srcSize.X * (y + srcSize.Y * z)];
                    }
                }
            }

            source = dest;
        }
Beispiel #5
0
 /// <summary>
 /// Attempts to set a voxel's state within this volume's current frame, at a specified array position
 /// </summary>
 /// <param name="pos">A PicaVoxelPoint location within the 3D array of voxels</param>
 /// <param name="state">The new state to set to</param>
 public void SetVoxelStateAtArrayPosition(PicaVoxelPoint pos, VoxelState state)
 {
     Frames[CurrentFrame].SetVoxelStateAtArrayPosition(pos, state);
 }
Beispiel #6
0
 /// <summary>
 /// Attempts to set a voxel within this volume's current frame, at a specified array position
 /// </summary>
 /// <param name="pos">A PicaVoxelPoint location within the 3D array of voxels</param>
 /// <param name="vox">The new voxel to set to</param>
 public void SetVoxelAtArrayPosition(PicaVoxelPoint pos, Voxel vox)
 {
     Frames[CurrentFrame].SetVoxelAtArrayPosition(pos, vox);
 }
Beispiel #7
0
 public void Add(Voxel voxel, PicaVoxelPoint arrayPoint, Vector3 worldPos)
 {
     Voxels.Add(new BatchVoxel(voxel, arrayPoint, worldPos));
 }
Beispiel #8
0
 public BatchVoxel(Voxel voxel, PicaVoxelPoint arrayPoint, Vector3 worldPos)
 {
     Voxel         = voxel;
     ArrayPosition = arrayPoint;
     WorldPosition = worldPos;
 }
Beispiel #9
0
 /// <summary>
 /// Attempts to set a voxel's state within this frame, at a specified array position
 /// </summary>
 /// <param name="pos">A PicaVoxelPoint location within the 3D array of voxels</param>
 /// <param name="state">The new state to set to</param>
 public void SetVoxelStateAtArrayPosition(PicaVoxelPoint pos, VoxelState state)
 {
     SetVoxelStateAtArrayPosition(pos.X, pos.Y, pos.Z, state);
 }
Beispiel #10
0
 /// <summary>
 /// Attempts to set a voxel within this frame, at a specified array position
 /// </summary>
 /// <param name="pos">A PicaVoxelPoint location within the 3D array of voxels</param>
 /// <param name="vox">The new voxel to set to</param>
 public void SetVoxelAtArrayPosition(PicaVoxelPoint pos, Voxel vox)
 {
     SetVoxelAtArrayPosition(pos.X, pos.Y, pos.Z, vox);
 }
Beispiel #11
0
        public static void CopyVoxelsInBox(ref Voxel[] source, ref Voxel[] dest,
                                           PicaVoxelBox sourceBox, PicaVoxelBox destBox, PicaVoxelPoint srcSize, PicaVoxelPoint destSize, bool activeOnly)
        {
            int dx = destBox.BottomLeftFront.X;
            int dy = destBox.BottomLeftFront.Y;
            int dz = destBox.BottomLeftFront.Z;

            for (int x = sourceBox.BottomLeftFront.X; x <= sourceBox.TopRightBack.X; x++)
            {
                dy = destBox.BottomLeftFront.Y;
                for (int y = sourceBox.BottomLeftFront.Y; y <= sourceBox.TopRightBack.Y; y++)
                {
                    dz = destBox.BottomLeftFront.Z;
                    for (int z = sourceBox.BottomLeftFront.Z; z <= sourceBox.TopRightBack.Z; z++)
                    {
                        if (x >= 0 && y >= 0 && z >= 0 && x < srcSize.X && y < srcSize.Y && z < srcSize.Z)
                        {
                            if (source[x + srcSize.X * (y + srcSize.Y * z)].Active || !activeOnly)
                            {
                                if (dx >= 0 && dy >= 0 && dz >= 0 && dx < destSize.X && dy < destSize.Y && dz < destSize.Z)
                                {
                                    dest[dx + destSize.X * (dy + destSize.Y * dz)] = source[x + srcSize.X * (y + srcSize.Y * z)];
                                }
                            }
                        }
                        dz++;
                    }
                    dy++;
                }
                dx++;
            }
        }
Beispiel #12
0
 public static void CopyVoxelsInBox(ref Voxel[] source, ref Voxel[] dest, PicaVoxelPoint srcSize, PicaVoxelPoint destSize, bool activeOnly)
 {
     CopyVoxelsInBox(ref source, ref dest,
                     new PicaVoxelBox(0, 0, 0, srcSize.X - 1, srcSize.Y - 1, srcSize.Z - 1),
                     new PicaVoxelBox(0, 0, 0, destSize.X - 1, destSize.Y - 1, destSize.Z - 1), srcSize, destSize, activeOnly);
 }
Beispiel #13
0
 public PicaVoxelBox(int x1, int y1, int z1, int x2, int y2, int z2)
 {
     BottomLeftFront = new PicaVoxelPoint(x2 < x1 ? x2 : x1, y2 < y1 ? y2 : y1, z2 < z1 ? z2 : z1);
     TopRightBack    = new PicaVoxelPoint(x2 >= x1 ? x2 : x1, y2 >= y1 ? y2 : y1, z2 >= z1 ? z2 : z1);
 }
Beispiel #14
0
 public PicaVoxelBox(PicaVoxelPoint corner1, PicaVoxelPoint corner2)
     : this(corner1.X, corner1.Y, corner1.Z, corner2.X, corner2.Y, corner2.Z)
 {
 }