Beispiel #1
0
        public void Add(VoxelVolume volume, ref Colort color)
        {
            int    colorIndex = GetColorIndex(color.R, color.G, color.B);
            double hash       = 0;

            // for all inner points in volume...
            for (int z = volume.minz + 1; z <= volume.maxz - 1; z++)
            {
                for (int y = volume.miny + 1; y <= volume.maxy - 1; y++)
                {
                    for (int x = volume.minx + 1; x <= volume.maxx - 1; x++)
                    {
                        hash = GetHash(x, y, z);
                        if (!voxels.TryGetValue(hash, out voxel))
                        {
                            // alphamask = 1 because we know we're this point is inside the voxel volume
                            Voxel voxel = new Voxel(x, y, z, (byte)1, colorIndex);
                            voxel.dirty = true;
                            voxels.TryAdd(hash, voxel);

                            // since this is new voxel we don't need to update any visible geometry
                            // (again it is interior voxel)
                        }
                        // we have a voxel here already
                        else
                        {
                            // nuke all visible geometry of voxel
                            voxel.alphamask = 1;
                            voxel.dirty     = true;
                            UpdateVoxel();
                        }
                    }
                }
            }

            var insideVolume = new VoxelVolume()
            {
                minx = volume.minx + 1,
                miny = volume.miny + 1,
                minz = volume.minz + 1,
                maxx = volume.maxx - 1,
                maxy = volume.maxy - 1,
                maxz = volume.maxz - 1,
            };

            // for all exterior voxels
            for (int z = volume.minz; z <= volume.maxz; z++)
            {
                for (int y = volume.miny; y <= volume.maxy; y++)
                {
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        if (!insideVolume.ContainsPoint(x, y, z))
                        {
                            Add(x, y, z, color);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        public void CleanLastVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, Dictionary <double, VoxelUndoData> modifiedVoxels)
        {
            VoxelUndoData removed = new VoxelUndoData();

            for (int z = volume.minz; z <= volume.maxz; z++)
            {
                for (int y = volume.miny; y <= volume.maxy; y++)
                {
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        if (!currentVolume.ContainsPoint(x, y, z))
                        {
                            if (modifiedVoxels.TryGetValue(matrix.GetHash(x, y, z), out removed))
                            {
                                if (removed.alphamask > 1)
                                {
                                    matrix.Add(x, y, z, matrix.colors[removed.colorindex]);
                                }
                                modifiedVoxels.Remove(matrix.GetHash(x, y, z));
                            }
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public UndoData(VoxelBrushType type, QbMatrix matrix, VoxelVolume volume, Colort color, Dictionary <double, VoxelUndoData> data)
        {
            this.brush  = type;
            this.matrix = matrix;
            this.volume = volume;
            this.color  = color;
            this.data   = new Dictionary <double, VoxelUndoData>();

            foreach (var c in data)
            {
                this.data.Add(c.Key, c.Value);
            }
        }
Beispiel #4
0
        public bool OnRaycastHitchanged(Input input, QbMatrix matrix, RaycastHit hit, ref Colort color, MouseButtonEventArgs e)
        {
            lastmatrix = matrix;
            switch (state)
            {
            case ToolState.Start:
                if ((e != null && e.IsPressed && e.Button == MouseButton.Left) || (e == null && input.mousedown(MouseButton.Left)))
                {
                    state = ToolState.Base;
                    Singleton <Raycaster> .INSTANCE.testdirt = true;
                    startPosition = new VoxelLocation(hit, false);
                    endPosition   = new VoxelLocation(hit, false);
                    volume        = new VoxelVolume(startPosition, endPosition);
                    modifiedVoxels.Clear();
                    EnumerateVolume(volume, lastvolume, matrix, ref color, modifiedVoxels);
                    lastvolume = volume;
                    return(true);
                }
                break;

            case ToolState.Base:
                if ((e != null && e.IsPressed && e.Button == MouseButton.Left) || (e == null && input.mousedown(MouseButton.Left)))
                {
                    endPosition = new VoxelLocation(hit, false);
                    volume      = new VoxelVolume(startPosition, endPosition);

                    EnumerateVolume(volume, lastvolume, matrix, ref color, modifiedVoxels);
                    CleanLastVolume(lastvolume, volume, matrix, modifiedVoxels);
                    lastvolume = volume;

                    return(true);
                }
                else if ((e != null && !e.IsPressed && e.Button == MouseButton.Left) || (e == null && input.mouseup(MouseButton.Left)))

                {
                    state      = ToolState.Start;
                    lastvolume = VoxelVolume.NEGATIVE_ZERO;
                    Singleton <UndoRedo> .INSTANCE.AddUndo(BrushType, matrix, volume, color, modifiedVoxels);

                    return(true);
                }
                break;

            case ToolState.Limit:
                break;
            }
            return(false);
        }
Beispiel #5
0
 public void EnumerateVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, ref Colort color, Dictionary <double, VoxelUndoData> modifiedVoxels)
 {
     for (int z = currentVolume.minz; z <= currentVolume.maxz; z++)
     {
         for (int y = currentVolume.miny; y <= currentVolume.maxy; y++)
         {
             for (int x = currentVolume.minx; x <= currentVolume.maxx; x++)
             {
                 if (!volume.ContainsPoint(x, y, z) && !modifiedVoxels.ContainsKey(matrix.GetHash(x, y, z)))
                 {
                     modifiedVoxels.Add(matrix.GetHash(x, y, z), new VoxelUndoData(matrix.Add(x, y, z, color)));
                 }
             }
         }
     }
 }
Beispiel #6
0
        public bool OnRaycastHitchanged(Input input, QbMatrix matrix, RaycastHit hit, ref Colort color, MouseButtonEventArgs e)
        {
            lastmatrix = matrix;
            switch (state)
            {
                case ToolState.Start:
                    if ((e != null && e.IsPressed && e.Button == MouseButton.Left) || (e == null && input.mousedown(MouseButton.Left)))
                    {
                        state = ToolState.Base;
                        Singleton<Raycaster>.INSTANCE.testdirt = true;
                        startPosition = new VoxelLocation(hit, false);
                        endPosition = new VoxelLocation(hit, false);
                        volume = new VoxelVolume(startPosition, endPosition);
                        modifiedVoxels.Clear();
                        EnumerateVolume(volume, lastvolume, matrix, ref color, modifiedVoxels);
                        lastvolume = volume;
                        return true;
                    }
                    break;
                case ToolState.Base:
                    if ((e != null && e.IsPressed && e.Button == MouseButton.Left) || (e == null && input.mousedown(MouseButton.Left)))
                    {
                        endPosition = new VoxelLocation(hit, false);
                        volume = new VoxelVolume(startPosition, endPosition);

                        EnumerateVolume(volume, lastvolume, matrix, ref color, modifiedVoxels);
                        CleanLastVolume(lastvolume, volume, matrix, modifiedVoxels);
                        lastvolume = volume;

                        return true;
                    }
                    else if ((e != null && !e.IsPressed && e.Button == MouseButton.Left) || (e == null && input.mouseup(MouseButton.Left)))

                    {
                        state = ToolState.Start;
                        lastvolume = VoxelVolume.NEGATIVE_ZERO;
                        Singleton<UndoRedo>.INSTANCE.AddUndo(BrushType, matrix, volume, color, modifiedVoxels);
                        return true;
                    }
                    break;
                case ToolState.Limit:
                    break;
            }
            return false;
        }
Beispiel #7
0
        public void RemoveVolume(VoxelVolume volume, QbMatrix matrix, Dictionary <double, VoxelUndoData> modifiedVoxels)
        {
            VoxelUndoData _temp;

            for (int z = volume.minz; z <= volume.maxz; z++)
            {
                for (int y = volume.miny; y <= volume.maxy; y++)
                {
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        if (modifiedVoxels.TryGetValue(matrix.GetHash(x, y, z), out _temp) && _temp.changed)
                        {
                            matrix.Remove(x, y, z, false, false);
                            modifiedVoxels.Remove(matrix.GetHash(x, y, z));
                        }
                    }
                }
            }
        }
Beispiel #8
0
        public void AddVolume(VoxelVolume volume, QbMatrix matrix, ref Colort color, Dictionary <double, VoxelUndoData> modifiedVoxels)
        {
            double hash;

            for (int z = volume.minz; z <= volume.maxz; z++)
            {
                for (int y = volume.miny; y <= volume.maxy; y++)
                {
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        hash = matrix.GetHash(x, y, z);
                        if (!modifiedVoxels.ContainsKey(hash))
                        {
                            modifiedVoxels.Add(hash, new VoxelUndoData(matrix.Add(x, y, z, color)));
                        }
                    }
                }
            }
        }
Beispiel #9
0
 public void CleanLastVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, Dictionary <double, VoxelUndoData> modifiedVoxels)
 {
     for (int z = volume.minz; z <= volume.maxz; z++)
     {
         for (int y = volume.miny; y <= volume.maxy; y++)
         {
             for (int x = volume.minx; x <= volume.maxx; x++)
             {
                 if (!currentVolume.ContainsPoint(x, y, z))
                 {
                     if (modifiedVoxels[matrix.GetHash(x, y, z)].changed)
                     {
                         matrix.Remove(x, y, z, false, false);
                         modifiedVoxels.Remove(matrix.GetHash(x, y, z));
                     }
                 }
             }
         }
     }
 }
Beispiel #10
0
        public void RemoveVolume(VoxelVolume volume, QbMatrix matrix, Dictionary <double, VoxelUndoData> modifiedVoxels)
        {
            double        hash;
            VoxelUndoData voxel = new VoxelUndoData();

            for (int z = volume.minz; z <= volume.maxz; z++)
            {
                for (int y = volume.miny; y <= volume.maxy; y++)
                {
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        hash = matrix.GetHash(x, y, z);
                        if (modifiedVoxels.TryGetValue(hash, out voxel))
                        {
                            matrix.Color(x, y, z, voxel.colorindex, false, true);
                            modifiedVoxels.Remove(hash);
                        }
                    }
                }
            }
        }
Beispiel #11
0
        public void AddVolume(VoxelVolume volume, QbMatrix matrix, ref Colort color, Dictionary <double, VoxelUndoData> modifiedVoxels)
        {
            double hash;
            Voxel  voxel = null;

            for (int z = volume.minz; z <= volume.maxz; z++)
            {
                for (int y = volume.miny; y <= volume.maxy; y++)
                {
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        hash = matrix.GetHash(x, y, z);

                        if (!modifiedVoxels.ContainsKey(hash) && matrix.voxels.TryGetValue(hash, out voxel) && voxel.alphamask > 1)
                        {
                            modifiedVoxels.Add(hash, new VoxelUndoData(matrix.voxels[hash].colorindex, 0));
                            matrix.Color(x, y, z, color);
                        }
                    }
                }
            }
        }
Beispiel #12
0
        public void AddVolume(VoxelVolume volume, QbMatrix matrix, ref Colort color, Dictionary <double, VoxelUndoData> modifiedVoxels)
        {
            VoxelUndoData removed = new VoxelUndoData();

            for (int z = volume.minz; z <= volume.maxz; z++)
            {
                for (int y = volume.miny; y <= volume.maxy; y++)
                {
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        if (!modifiedVoxels.ContainsKey(matrix.GetHash(x, y, z)))
                        {
                            if (matrix.GetColorIndex_Alphamask(x, y, z, out removed.colorindex, out removed.alphamask))
                            {
                                if (matrix.Remove(x, y, z, true, false))
                                {
                                    modifiedVoxels.Add(matrix.GetHash(x, y, z), removed);
                                }
                            }
                        }
                    }
                }
            }
        }
 public void RemoveVolume(VoxelVolume volume, QbMatrix matrix, Dictionary <double, VoxelUndoData> modifiedVoxels)
 {
 }
 public void AddVolume(VoxelVolume volume, QbMatrix matrix, ref Colort color, Dictionary <double, VoxelUndoData> modifiedVoxels)
 {
 }
Beispiel #15
0
 void CleanForToolReset()
 {
     RemoveVolume(volume, lastmatrix, modifiedVoxels);
     modifiedVoxels.Clear();
     lastvolume = VoxelVolume.NEGATIVE_ZERO;
 }
Beispiel #16
0
 public void EnumerateVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, ref Colort color, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
     throw new NotImplementedException();
 }
Beispiel #17
0
 public void CleanLastVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
     for (int z = volume.minz; z <= volume.maxz; z++)
         for (int y = volume.miny; y <= volume.maxy; y++)
             for (int x = volume.minx; x <= volume.maxx; x++)
             {
                 if (!currentVolume.ContainsPoint(x, y, z))
                 {
                     if (modifiedVoxels[matrix.GetHash(x, y, z)].changed)
                     {
                         matrix.Remove(x, y, z, false, false);
                         modifiedVoxels.Remove(matrix.GetHash(x, y, z));
                     }
                 }
             }
 }
Beispiel #18
0
 public void AddVolume(VoxelVolume volume, QbMatrix matrix, ref Colort color, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
 }
Beispiel #19
0
 public void EnumerateVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, ref Colort color, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
 }
Beispiel #20
0
 public void RemoveVolume(VoxelVolume volume, QbMatrix matrix, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
     VoxelUndoData _temp;
     for (int z = volume.minz; z <= volume.maxz; z++)
         for (int y = volume.miny; y <= volume.maxy; y++)
             for (int x = volume.minx; x <= volume.maxx; x++)
             {
                 if (modifiedVoxels.TryGetValue(matrix.GetHash(x, y, z), out _temp) && _temp.changed)
                 {
                     matrix.Remove(x, y, z, false, false);
                     modifiedVoxels.Remove(matrix.GetHash(x, y, z));
                 }
             }
 }
Beispiel #21
0
 public void RemoveVolume(VoxelVolume volume, QbMatrix matrix, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
     double hash;
     VoxelUndoData voxel = new VoxelUndoData();
     for (int z = volume.minz; z <= volume.maxz; z++)
         for (int y = volume.miny; y <= volume.maxy; y++)
             for (int x = volume.minx; x <= volume.maxx; x++)
             {
                 hash = matrix.GetHash(x, y, z);
                 if (modifiedVoxels.TryGetValue(hash, out voxel))
                 {
                     matrix.Color(x, y, z, voxel.colorindex, false, true);
                     modifiedVoxels.Remove(hash);
                 }
             }
 }
Beispiel #22
0
        public void Add(VoxelVolume volume, VoxelVolume preVolume, ref Colort color)
        {
            int colorIndex = GetColorIndex(color.R, color.G, color.B);
            double hash = 0;
            // for all inner points in volume...
            for (int z = volume.minz + 1; z <= volume.maxz - 1; z++)
                for (int y = volume.miny + 1; y <= volume.maxy - 1; y++)
                    for (int x = volume.minx + 1; x <= volume.maxx - 1; x++)
                    {
                        // if point not inside prevoius volume
                        if (!preVolume.ContainsPoint(x, y, z))
                        {
                            hash = GetHash(x, y, z);
                            if (!voxels.TryGetValue(hash, out voxel))
                            {
                                // alphamask = 1 because we know we're this point is inside the voxel volume
                                Voxel voxel = new Voxel(x, y, z, (byte)1, colorIndex);
                                voxels.TryAdd(hash, voxel);

                                // since this is new voxel we don't need to update any visible geometry
                                // (again it is interior voxel)
                            }
                            // we have a voxel here already
                            else
                            {
                                // nuke all visible geometry of voxel
                                voxel.alphamask = 1;
                                UpdateVoxel();
                            }
                        }
                    }

        }
 public void EnumerateVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, ref Colort color, Dictionary <double, VoxelUndoData> modifiedVoxels)
 {
     throw new NotImplementedException();
 }
Beispiel #24
0
 public void AddUndo(VoxelBrushType type, QbMatrix matrix, VoxelVolume volume, Colort color, Dictionary <double, VoxelUndoData> data)
 {
     redos.Clear();
     undos.Push(new UndoData(type, matrix, volume, color, data));
 }
 public void RemoveVolume(VoxelVolume volume, QbMatrix matrix, Dictionary <double, VoxelUndoData> modifiedVoxels)
 {
     throw new NotImplementedException();
 }
Beispiel #26
0
 public void AddVolume(VoxelVolume volume, QbMatrix matrix, ref Colort color, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
     double hash;
     for (int z = volume.minz; z <= volume.maxz; z++)
         for (int y = volume.miny; y <= volume.maxy; y++)
             for (int x = volume.minx; x <= volume.maxx; x++)
             {
                 hash = matrix.GetHash(x, y, z);
                 if (!modifiedVoxels.ContainsKey(hash))
                     modifiedVoxels.Add(hash, new VoxelUndoData(matrix.Add(x, y, z, color)));
             }
 }
Beispiel #27
0
 void CleanForToolReset()
 {
     RemoveVolume(volume, lastmatrix, modifiedVoxels);
     modifiedVoxels.Clear();
     lastvolume = VoxelVolume.NEGATIVE_ZERO;
 }
 public void EnumerateVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, ref Colort color, Dictionary <double, VoxelUndoData> modifiedVoxels)
 {
 }
Beispiel #29
0
        public void AddVolume(VoxelVolume volume, QbMatrix matrix, ref Colort color, Dictionary<double, VoxelUndoData> modifiedVoxels)
        {
            double hash;
            Voxel voxel = null;
            for (int z = volume.minz; z <= volume.maxz; z++)
                for (int y = volume.miny; y <= volume.maxy; y++)
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        hash = matrix.GetHash(x, y, z);

                        if (!modifiedVoxels.ContainsKey(hash) && matrix.voxels.TryGetValue(hash, out voxel) && voxel.alphamask > 1)
                        {
                            modifiedVoxels.Add(hash, new VoxelUndoData(matrix.voxels[hash].colorindex, 0));
                            matrix.Color(x, y, z, color);
                        }
                    }
        }
 public void CleanLastVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, Dictionary <double, VoxelUndoData> modifiedVoxels)
 {
 }
Beispiel #31
0
 public void CleanLastVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
 }
Beispiel #32
0
        public void RemoveVolume(VoxelVolume volume, QbMatrix matrix, Dictionary<double, VoxelUndoData> modifiedVoxels)
        {
            VoxelUndoData removed = new VoxelUndoData();

            for (int z = volume.minz; z <= volume.maxz; z++)
                for (int y = volume.miny; y <= volume.maxy; y++)
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        if (modifiedVoxels.TryGetValue(matrix.GetHash(x, y, z), out removed))
                        {
                            if (removed.alphamask > 1)
                                matrix.Add(x, y, z, matrix.colors[removed.colorindex]);
                            modifiedVoxels.Remove(matrix.GetHash(x, y, z));
                        }
                    }
        }
Beispiel #33
0
 public void RemoveVolume(VoxelVolume volume, QbMatrix matrix, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
 }
Beispiel #34
0
        public void AddVolume(VoxelVolume volume, QbMatrix matrix, ref Colort color, Dictionary<double, VoxelUndoData> modifiedVoxels)
        {
            VoxelUndoData removed = new VoxelUndoData();

            for (int z = volume.minz; z <= volume.maxz; z++)
                for (int y = volume.miny; y <= volume.maxy; y++)
                    for (int x = volume.minx; x <= volume.maxx; x++)
                    {
                        if (!modifiedVoxels.ContainsKey(matrix.GetHash(x, y, z)))
                        {
                            if (matrix.GetColorIndex_Alphamask(x, y, z, out removed.colorindex, out removed.alphamask))
                            {
                                if (matrix.Remove(x, y, z, true, false))
                                    modifiedVoxels.Add(matrix.GetHash(x, y, z), removed);
                            }
                        }
                    }
        }
Beispiel #35
0
 public void RemoveVolume(VoxelVolume volume, QbMatrix matrix, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
     throw new NotImplementedException();
 }
Beispiel #36
0
 public void EnumerateVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, ref Colort color, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
     for (int z = currentVolume.minz; z <= currentVolume.maxz; z++)
         for (int y = currentVolume.miny; y <= currentVolume.maxy; y++)
             for (int x = currentVolume.minx; x <= currentVolume.maxx; x++)
             {
                 if (!volume.ContainsPoint(x,y,z) && !modifiedVoxels.ContainsKey(matrix.GetHash(x,y,z)))
                     modifiedVoxels.Add(matrix.GetHash(x, y, z), new VoxelUndoData(matrix.Add(x, y, z, color)));
             }
 }