Exemplo n.º 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);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public bool OnRaycastHitchanged(Input input, QbMatrix matrix, RaycastHit hit, ref Colort color, MouseButtonEventArgs e)
        {
            if ((e != null && e.IsPressed && e.Button == MouseButton.Left) || (e == null && input.mousedown(MouseButton.Left)))
            {
                QbMatrix mat = Singleton<QbManager>.INSTANCE.ActiveModel.matrices[hit.matrixIndex];
                if (mat != null)
                {
                    Voxel voxel;
                    if (mat.voxels.TryGetValue(mat.GetHash(hit.x, hit.y, hit.z), out voxel))
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            var colorpal = Singleton<GUI>.INSTANCE.Get<EmptyWidget>(GUIID.START_COLOR_SELECTORS + i);

                            if ((bool)colorpal.customData["active"])
                            {
                                colorpal.appearence.Get<PlainBackground>("background").color = mat.colors[voxel.colorindex];
                                Singleton<GUI>.INSTANCE.Dirty = true;

                                Singleton<BrushManager>.INSTANCE.brushColor = mat.colors[voxel.colorindex];

                                Color4 colorr = mat.colors[voxel.colorindex];
                                Singleton<Broadcaster>.INSTANCE.Broadcast(Message.ColorSelectionChanged, colorpal, colorr);
                            }
                        }
                    }
                }
                return true;
            }
            return false;
        }
Exemplo n.º 3
0
        public int GetColorIndex(float r, float g, float b)
        {
            Colort c;

            for (int i = 0; i < colors.Length; i++)
            {
                c = colors[i];
                if (c.R == r && c.G == g && c.B == b)
                {
                    return((int)i);
                }
            }

            if (colorindexholes.Count > 0)
            {
                matrixcolors[colorindexholes.Pop()] = new Colort(r, g, b);
            }
            else
            {
                matrixcolors[colorIndex] = new Colort(r, g, b);
            }

            // wireframes and outline....
            // right now my hsv to rbg is not working correctly and fails generating a few colors
            // later on this will be used over doing the conversion on a shader

            //Color4 color = new Color4(r, g, b, 1);

            //double hue, sat, vi;
            //ColorConversion.ColorToHSV(color.ToSystemDrawingColor(), out hue, out sat, out vi);

            //var outline = ColorConversion.ColorFromHSV(hue, (sat + .5d).Clamp(0, 1), vi );
            //outlinecolors[colorIndex] = outline.ToColor4();

            //var wireframe = ColorConversion.ColorFromHSV(hue, (sat + .1d).Clamp(0,1), (vi+.1d).Clamp(0,1));
            //wireframecolors[colorIndex] = wireframe.ToColor4();

            if (colorIndex + 1 >= colors.Length)
            {
                CleanUnsuedColorIndexs();

                if (colorindexholes.Count > 0)
                {
                    int newindex = colorindexholes.Pop();
                    matrixcolors[newindex] = new Colort(r, g, b);
                    return(newindex);
                }
                else
                {
                    MessageBox.Show("StoneVox only supports 128 active colors at once. This is quite the issue, try reducing the amount of colors you are using. Since there is no room the last color will now be overwritten with this new color.", "Out of Colors");
                    matrixcolors[matrixcolors.Length - 1] = new Colort(r, g, b);
                    return(matrixcolors.Length - 1);
                }
            }

            colorIndex++;

            return(colorIndex - 1);
        }
Exemplo n.º 4
0
        public Selection(GLWindow window, BrushManager tools, Input input, QbManager manager, Floor floor, GUI gui)
            : base()
        {
            this.brushes = tools;
            this.input   = input;
            this.manager = manager;
            this.floor   = floor;
            this.gui     = gui;

            window.Resize += (e, a) =>
            {
                statusStrip = null;
            };

            color = new Colort(1, 0, 0);

            buffer = new float[16];


            input.AddHandler(new InputHandler()
            {
                mousedownhandler = (e) =>
                {
                    if (Singleton <GUI> .INSTANCE.OverWidget)
                    {
                        return;
                    }

                    if (e.Button == MouseButton.Left && !dirty && handledselectionchange && Singleton <Raycaster> .INSTANCE.HasHit)
                    {
                        handledselectionchange = brushes.onselectionchanged(input, manager.ActiveMatrix, lasthit, e);

                        if (handledselectionchange)
                        {
                            needscleaning = true;
                        }
                    }
                },
                mouseuphandler = (e) =>
                {
                    if (e.Button == MouseButton.Left && !dirty && handledselectionchange)
                    {
                        handledselectionchange = brushes.onselectionchanged(input, manager.ActiveMatrix, lasthit, e);

                        if (handledselectionchange)
                        {
                            needscleaning = true;
                        }
                    }
                }
            });
        }
Exemplo n.º 5
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);
            }
        }
Exemplo n.º 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;
        }
Exemplo n.º 7
0
        public QbMatrix()
        {
            highlight = new Colort(1f, 1f, 1f);
            matrixcolors = new Colort[128];
            colors = matrixcolors;
            colorindexholes = new Stack<int>();
            //wireframecolors = new Colort[64];
            //outlinecolors = new Colort[64];
            voxels = new ConcurrentDictionary<double, Voxel>();
            modifiedvoxels = new ConcurrentStack<VoxelModifier>();

            left = new QbMatrixSide(Side.Left);
            right = new QbMatrixSide(Side.Right);
            top = new QbMatrixSide(Side.Top);
            bottom = new QbMatrixSide(Side.Bottom);
            front = new QbMatrixSide(Side.Front);
            back = new QbMatrixSide(Side.Back);
        }
Exemplo n.º 8
0
        public QbMatrix()
        {
            highlight       = new Colort(1f, 1f, 1f);
            matrixcolors    = new Colort[128];
            colors          = matrixcolors;
            colorindexholes = new Stack <int>();
            //wireframecolors = new Colort[64];
            //outlinecolors = new Colort[64];
            voxels         = new ConcurrentDictionary <double, Voxel>();
            modifiedvoxels = new ConcurrentStack <VoxelModifier>();

            left   = new QbMatrixSide(Side.Left);
            right  = new QbMatrixSide(Side.Right);
            top    = new QbMatrixSide(Side.Top);
            bottom = new QbMatrixSide(Side.Bottom);
            front  = new QbMatrixSide(Side.Front);
            back   = new QbMatrixSide(Side.Back);
        }
Exemplo n.º 9
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)));
                        }
                    }
                }
            }
        }
Exemplo n.º 10
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);
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        public bool OnRaycastHitchanged(Input input, QbMatrix matrix, RaycastHit hit, ref Colort color, MouseButtonEventArgs e)
        {
            if (matrix == null)
            {
                if (lastmatrix != null)
                {
                    lastmatrix.highlight = Color4.White;
                    lastmatrix = null;
                    Singleton<GUI>.INSTANCE.Get<Label>(GUIID.STATUS_TEXT).text = "";
                }
                return true;
            }

            if(matrix != lastmatrix)
            {
                if (lastmatrix != null)
                    lastmatrix.highlight = Color4.White;
                matrix.highlight = new Colort(1.5f, 1.5f, 1.5f);

                lastmatrix = matrix;
                Singleton<GUI>.INSTANCE.Get<Label>(GUIID.STATUS_TEXT).text = $"Over Matrix : {matrix.name}";
            }
            return true;
        }
Exemplo n.º 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);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 13
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)));
                 }
             }
         }
     }
 }
Exemplo n.º 14
0
 public void Color(Vector3 location, Colort color)
 {
     Color((int)location.X, (int)location.Y, (int)location.Z, color);
 }
Exemplo n.º 15
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)));
             }
 }
Exemplo n.º 16
0
        public void write(string path, string name, QbModel model)
        {
            Client.OpenGLContextThread.Add(() =>
            {
                int Wwidth  = Client.window.Width;
                int Wheight = Client.window.Height;

                int framebuffer = GL.GenBuffer();
                GL.BindFramebuffer(FramebufferTarget.FramebufferExt, framebuffer);

                int color = GL.GenTexture();
                GL.BindTexture(TextureTarget.Texture2D, color);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, Wwidth, Wheight, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
                GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, color, 0);

                int depth = GL.GenTexture();
                GL.BindTexture(TextureTarget.Texture2D, depth);
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.DepthComponent24, Wwidth, Wheight, 0, PixelFormat.DepthComponent, PixelType.UnsignedByte, IntPtr.Zero);
                GL.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.DepthAttachmentExt, TextureTarget.Texture2D, depth, 0);

                GL.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);

                GL.BindFramebuffer(FramebufferTarget.FramebufferExt, framebuffer);
                GL.DrawBuffers(1, new DrawBuffersEnum[] { DrawBuffersEnum.ColorAttachment0 });

                GL.ClearColor(0, 0, 0, 0);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

                int minx  = 10000;
                int miny  = 10000;
                int minz  = 10000;
                int maxx  = 0;
                int maxy  = 0;
                int maxz  = 0;
                int sizex = 0;
                int sizey = 0;
                int sizez = 0;

                foreach (var matrix in model.matrices)
                {
                    if (!matrix.Visible)
                    {
                        continue;
                    }
                    if (matrix.minx < minx)
                    {
                        minx = matrix.minx;
                    }
                    if (matrix.maxx > maxx)
                    {
                        maxx = matrix.maxx;
                    }

                    if (matrix.miny < miny)
                    {
                        miny = matrix.miny;
                    }
                    if (matrix.maxy > maxy)
                    {
                        maxy = matrix.maxy;
                    }

                    if (matrix.minz < minz)
                    {
                        minz = matrix.minz;
                    }
                    if (matrix.maxz > maxz)
                    {
                        maxz = matrix.maxz;
                    }
                }

                sizex = maxx - minx;
                sizey = maxy - miny;
                sizez = maxz - minz;

                float backup = 0;

                if (sizey * 1.5f > 20)
                {
                    backup = sizey * 1.5f;
                }
                else if (sizex * 1.5f > 20)
                {
                    backup = sizex * 1.5f;
                }
                else
                {
                    backup = 20;
                }

                var centerpos = new Vector3((minx + ((maxx - minx) / 2)), (miny + ((maxy - miny) / 2)), (minz + ((maxz - minz) / 2)));
                var position  = centerpos + new Vector3(.5f, sizey * .65f, backup);
                Vector3 direction;

                Vector3.Subtract(ref centerpos, ref position, out direction);
                direction.Normalize();

                var cameraright = Vector3.Cross(direction, VectorUtils.UP);
                var cameraup    = Vector3.Cross(cameraright, direction);

                var view = Matrix4.LookAt(position, position + direction, cameraup);
                var modelviewprojection = view * Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(45), (float)Wwidth / (float)Wheight, 1, 300);

                Shader voxelShader = ShaderUtil.GetShader("qb");

                voxelShader.UseShader();
                voxelShader.WriteUniform("modelview", modelviewprojection);

                GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                model.RenderAll(voxelShader);

                string fullpath = Path.Combine(path, name + extension);
                using (FileStream f = new FileStream(fullpath, FileMode.OpenOrCreate))
                {
                    var bit       = Screenshot.ScreenShot(ReadBufferMode.ColorAttachment0);
                    bit           = cropImage(bit, new Rectangle(Wwidth / 4, 0, Wwidth - ((Wwidth / 4) * 2), Wheight));
                    bit           = bit.ResizeImage(ResizeKeepAspect(bit.Size, 400, 400));
                    byte[] buffer = new byte[0];
                    using (MemoryStream m = new MemoryStream())
                    {
                        bit.Save(m, System.Drawing.Imaging.ImageFormat.Png);
                        buffer = m.ToArray();
                    }

                    using (BinaryWriter w = new BinaryWriter(f))
                    {
                        w.Write(version);
                        w.Write((int)buffer.Length);
                        w.Write(buffer);

                        // note - just in case i allow extending the color pattet
                        // which i probably will
                        w.Write(colorpalletflag);
                        for (int i = 0; i < 10; i++)
                        {
                            var c = Singleton <GUI> .INSTANCE.Get <EmptyWidget>(GUIID.START_COLOR_SELECTORS + i).appearence.Get <PlainBackground>("background").color;
                            w.Write(c.R);
                            w.Write(c.G);
                            w.Write(c.B);
                        }

                        w.Write(model.version);
                        w.Write(model.colorFormat);
                        w.Write(model.zAxisOrientation);
                        w.Write(model.compressed);
                        w.Write(model.visibilityMaskEncoded);

                        w.Write((uint)model.matrices.Count);

                        for (int i = 0; i < model.numMatrices; i++)
                        {
                            QbMatrix m = model.matrices[i];
                            if (!m.Visible)
                            {
                                continue;
                            }

                            int startx = Math.Min(0, m.minx);
                            int starty = Math.Min(0, m.miny);
                            int startz = Math.Min(0, m.minz);

                            int width  = (int)(Math.Abs(Math.Min(0, m.minx)) + m.maxx + 1);
                            int height = (int)(Math.Abs(Math.Min(0, m.miny)) + m.maxy + 1);
                            int length = (int)(Math.Abs(Math.Min(0, m.minz)) + m.maxz + 1);

                            if (width < m.size.X)
                            {
                                width = (int)m.size.X;
                            }

                            if (height < m.size.Y)
                            {
                                height = (int)m.size.Y;
                            }

                            if (length < m.size.Z)
                            {
                                length = (int)m.size.Z;
                            }

                            w.Write(m.name);
                            w.Write((uint)width);
                            w.Write((uint)height);
                            w.Write((uint)length);

                            w.Write((int)m.position.X);
                            w.Write((int)m.position.Y);
                            w.Write((int)m.position.Z);

                            if (model.compressed == 0)
                            {
                                Voxel voxel;
                                for (int z = startz; z < startz + length; z++)
                                {
                                    for (int y = starty; y < starty + height; y++)
                                    {
                                        for (int x = startx; x < startx + width; x++)
                                        {
                                            int zz = model.zAxisOrientation == (int)0 ? z : (int)(length - z - 1);

                                            if (m.voxels.TryGetValue(m.GetHash(x, y, zz), out voxel))
                                            {
                                                Colort c = m.colors[voxel.colorindex];
                                                w.Write((byte)(c.R * 255));
                                                w.Write((byte)(c.G * 255));
                                                w.Write((byte)(c.B * 255));
                                                w.Write(voxel.alphamask);
                                            }
                                            else
                                            {
                                                w.Write((byte)0);
                                                w.Write((byte)0);
                                                w.Write((byte)0);
                                                w.Write((byte)0);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    GL.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
                    GL.DeleteTexture(color);
                    GL.DeleteTexture(depth);
                    GL.DeleteFramebuffer(framebuffer);
                }
            });
        }
Exemplo n.º 17
0
 public void Color(int x, int y, int z, Colort color)
 {
     Color(x, y, z, GetColorIndex(color.R, color.G, color.B));
 }
Exemplo n.º 18
0
 public void EnumerateVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, ref Colort color, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
        public void write(string path, string name, QbModel dataType)
        {
            Dictionary <int, string> colorlookup = new Dictionary <int, string>();
            int colorindex = 0;

            using (FileStream material = new FileStream(path + "\\" + name + ".mtl", FileMode.OpenOrCreate))
            {
                using (StreamWriter _out = new StreamWriter(material))
                {
                    for (int t = 0; t < dataType.matrices.Count; t++)
                    {
                        //color index, to string for usemlt value
                        QbMatrix m = dataType.matrices[t];
                        if (!m.Visible)
                        {
                            continue;
                        }
                        foreach (var color in m.colors)
                        {
                            float r = color.R;
                            float g = color.G;
                            float b = color.B;
                            if (r < 0.0F)
                            {
                                r = 0.0F;
                            }
                            if (r > 1.0F)
                            {
                                r = 1.0F;
                            }
                            if (r <= 0.03928F)
                            {
                                r /= 12.92F;
                            }
                            else
                            {
                                r = (float)Math.Exp(2.4D * Math.Log((r + 0.055D) / 1.055D));
                            }
                            if (g < 0.0F)
                            {
                                g = 0.0F;
                            }
                            if (g > 1.0F)
                            {
                                g = 1.0F;
                            }
                            if (g <= 0.03928F)
                            {
                                g /= 12.92F;
                            }
                            else
                            {
                                g = (float)Math.Exp(2.4D * Math.Log((g + 0.055D) / 1.055D));
                            }
                            if (b < 0.0F)
                            {
                                b = 0.0F;
                            }
                            if (b > 1.0F)
                            {
                                b = 1.0F;
                            }
                            if (b <= 0.03928F)
                            {
                                b /= 12.92F;
                            }
                            else
                            {
                                b = (float)Math.Exp(2.4D * Math.Log((b + 0.055D) / 1.055D));
                            }

                            if (colorlookup.Values.Contains($"{color.R}_{color.G}_{color.B}"))
                            {
                                continue;
                            }

                            _out.WriteLine("newmtl " + color.R + "_" + color.G + "_" + color.B);
                            _out.WriteLine("illum 0");
                            _out.WriteLine("Kd " + color.R + " " + color.G + " " + color.B);
                            _out.WriteLine("");

                            colorlookup.Add(colorindex, $"{color.R}_{color.G}_{color.B}");

                            colorindex++;
                        }
                    }
                }
            }

            using (FileStream obj = new FileStream(path + "\\" + name + ".obj", FileMode.OpenOrCreate))
            {
                using (StreamWriter _out = new StreamWriter(obj))
                {
                    _out.WriteLine($"mtllib {name}.mtl");
                    Dictionary <int, string> vertexcolors = new Dictionary <int, string>();

                    int indexcount = 0;
                    int index      = 0;
                    for (int t = 0; t < dataType.matrices.Count; t++)
                    {
                        QbMatrix m = dataType.matrices[t];
                        if (!m.Visible)
                        {
                            continue;
                        }
                        foreach (var c in m.voxels.Values)
                        {
                            if (c.alphamask <= 1)
                            {
                                continue;
                            }
                            float cubesize = .5f;
                            float x        = c.x;
                            float y        = c.y;
                            float z        = c.z;
                            //front
                            if ((c.alphamask & 32) == 32)
                            {
                                indexcount++;

                                _out.WriteLine(string.Format("v {0} {1} {2}", -cubesize + x,
                                                             -cubesize + y,
                                                             cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", cubesize + x,
                                                             -cubesize + y,
                                                             cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", cubesize + x,
                                                             cubesize + y,
                                                             cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", -cubesize + x,
                                                             cubesize + y,
                                                             cubesize + z));

                                Colort color = m.colors[c.colorindex];
                                vertexcolors.Add(index, $"{color.R}_{color.G}_{color.B}");
                                index++;
                            }

                            //back
                            if ((c.alphamask & 64) == 64)
                            {
                                indexcount++;

                                _out.WriteLine(string.Format("v {0} {1} {2}", -cubesize + x,
                                                             cubesize + y,
                                                             -cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", cubesize + x,
                                                             cubesize + y,
                                                             -cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", cubesize + x,
                                                             -cubesize + y,
                                                             -cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", -cubesize + x,
                                                             -cubesize + y,
                                                             -cubesize + z));

                                Colort color = m.colors[c.colorindex];
                                vertexcolors.Add(index, $"{color.R}_{color.G}_{color.B}");
                                index++;
                            }

                            //top
                            if ((c.alphamask & 8) == 8)
                            {
                                indexcount++;

                                _out.WriteLine(string.Format("v {0} {1} {2}", -cubesize + x,
                                                             cubesize + y,
                                                             cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", cubesize + x,
                                                             cubesize + y,
                                                             cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", cubesize + x,
                                                             cubesize + y,
                                                             -cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", -cubesize + x,
                                                             cubesize + y,
                                                             -cubesize + z));

                                Colort color = m.colors[c.colorindex];
                                vertexcolors.Add(index, $"{color.R}_{color.G}_{color.B}");
                                index++;
                            }

                            //bottom
                            if ((c.alphamask & 16) == 16)
                            {
                                indexcount++;

                                _out.WriteLine(string.Format("v {0} {1} {2}", -cubesize + x,
                                                             -cubesize + y,
                                                             -cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", cubesize + x,
                                                             -cubesize + y,
                                                             -cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", cubesize + x,
                                                             -cubesize + y,
                                                             cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", -cubesize + x,
                                                             -cubesize + y,
                                                             cubesize + z));

                                Colort color = m.colors[c.colorindex];
                                vertexcolors.Add(index, $"{color.R}_{color.G}_{color.B}");
                                index++;
                            }

                            //left
                            if ((c.alphamask & 2) == 2)
                            {
                                indexcount++;

                                _out.WriteLine(string.Format("v {0} {1} {2}", cubesize + x,
                                                             cubesize + y,
                                                             -cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", cubesize + x,
                                                             cubesize + y,
                                                             cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", cubesize + x,
                                                             -cubesize + y,
                                                             cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", cubesize + x,
                                                             -cubesize + y,
                                                             -cubesize + z));

                                Colort color = m.colors[c.colorindex];
                                vertexcolors.Add(index, $"{color.R}_{color.G}_{color.B}");
                                index++;
                            }

                            //right
                            if ((c.alphamask & 4) == 4)
                            {
                                indexcount++;

                                _out.WriteLine(string.Format("v {0} {1} {2}", -cubesize + x,
                                                             -cubesize + y,
                                                             -cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", -cubesize + x,
                                                             -cubesize + y,
                                                             cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", -cubesize + x,
                                                             cubesize + y,
                                                             cubesize + z));

                                _out.WriteLine(string.Format("v {0} {1} {2}", -cubesize + x,
                                                             cubesize + y,
                                                             -cubesize + z));

                                Colort color = m.colors[c.colorindex];
                                vertexcolors.Add(index, $"{color.R}_{color.G}_{color.B}");
                                index++;
                            }
                        }
                    }
                    index = 0;
                    for (int i = 1; i < indexcount * 4; i += 4)
                    {
                        _out.WriteLine($"usemtl {vertexcolors[index]}");
                        _out.WriteLine(string.Format("f {0} {1} {2}", i, i + 1, i + 2));
                        _out.WriteLine(string.Format("f {0} {1} {2}", i, i + 2, i + 3));
                        index++;
                    }
                }
            }
        }
Exemplo n.º 21
0
 public bool OnRaycastHitchanged(Input input, QbMatrix matrix, RaycastHit hit, ref Colort color, MouseButtonEventArgs e)
 {
     return(true);
 }
Exemplo n.º 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();
                            }
                        }
                    }

        }
Exemplo n.º 23
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));
 }
Exemplo n.º 24
0
 public void EnumerateVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, ref Colort color, Dictionary <double, VoxelUndoData> modifiedVoxels)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 25
0
        public bool Add(int x, int y, int z, Colort color)
        {
            if (voxels.TryGetValue(GetHash(x, y, z), out voxel))
            {
                if (voxel.alphamask != 0)
                {
                    return(false);
                }
                else
                {
                    if (!voxels.TryRemove(GetHash(x, y, z), out voxel))
                    {
                        return(false);
                    }
                    voxel = new Voxel(x, y, z, GetAlphaMask(x, y, z), GetColorIndex(color.R, color.G, color.B));
                    if (voxels.TryAdd(GetHash(x, y, z), voxel))
                    {
                        voxel.dirty = true;
                        UpdateVoxel();

                        if (voxels.TryGetValue(GetHash(x, y, z + 1), out voxel))
                        {
                            if ((voxel.alphamask & 64) == 64)
                            {
                                voxel.alphamask -= 64;
                                UpdateVoxel();
                            }
                        }

                        if (voxels.TryGetValue(GetHash(x, y, z - 1), out voxel))
                        {
                            if ((voxel.alphamask & 32) == 32)
                            {
                                voxel.alphamask -= 32;
                                UpdateVoxel();
                            }
                        }

                        if (voxels.TryGetValue(GetHash(x, y + 1, z), out voxel))
                        {
                            if ((voxel.alphamask & 16) == 16)
                            {
                                voxel.alphamask -= 16;
                                UpdateVoxel();
                            }
                        }

                        if (voxels.TryGetValue(GetHash(x, y - 1, z), out voxel))
                        {
                            if ((voxel.alphamask & 8) == 8)
                            {
                                voxel.alphamask -= 8;
                                UpdateVoxel();
                            }
                        }

                        if (voxels.TryGetValue(GetHash(x + 1, y, z), out voxel))
                        {
                            if ((voxel.alphamask & 4) == 4)
                            {
                                voxel.alphamask -= 4;
                                UpdateVoxel();
                            }
                        }

                        if (voxels.TryGetValue(GetHash(x - 1, y, z), out voxel))
                        {
                            if ((voxel.alphamask & 2) == 2)
                            {
                                voxel.alphamask -= 2;
                                UpdateVoxel();
                            }
                        }

                        return(true);
                    }
                    return(false);
                }
            }
            else
            {
                voxel = new Voxel(x, y, z, GetAlphaMask(x, y, z), GetColorIndex(color.R, color.G, color.B));
                if (voxels.TryAdd(GetHash(x, y, z), voxel))
                {
                    voxel.dirty = true;
                    UpdateVoxel();

                    if (voxels.TryGetValue(GetHash(x, y, z + 1), out voxel))
                    {
                        if ((voxel.alphamask & 64) == 64)
                        {
                            voxel.alphamask -= 64;
                            UpdateVoxel();
                        }
                    }

                    if (voxels.TryGetValue(GetHash(x, y, z - 1), out voxel))
                    {
                        if ((voxel.alphamask & 32) == 32)
                        {
                            voxel.alphamask -= 32;
                            UpdateVoxel();
                        }
                    }

                    if (voxels.TryGetValue(GetHash(x, y + 1, z), out voxel))
                    {
                        if ((voxel.alphamask & 16) == 16)
                        {
                            voxel.alphamask -= 16;
                            UpdateVoxel();
                        }
                    }

                    if (voxels.TryGetValue(GetHash(x, y - 1, z), out voxel))
                    {
                        if ((voxel.alphamask & 8) == 8)
                        {
                            voxel.alphamask -= 8;
                            UpdateVoxel();
                        }
                    }

                    if (voxels.TryGetValue(GetHash(x + 1, y, z), out voxel))
                    {
                        if ((voxel.alphamask & 4) == 4)
                        {
                            voxel.alphamask -= 4;
                            UpdateVoxel();
                        }
                    }

                    if (voxels.TryGetValue(GetHash(x - 1, y, z), out voxel))
                    {
                        if ((voxel.alphamask & 2) == 2)
                        {
                            voxel.alphamask -= 2;
                            UpdateVoxel();
                        }
                    }

                    return(true);
                }

                return(false);
            }
        }
Exemplo n.º 26
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);
                            }
                        }
                    }
        }
Exemplo n.º 27
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);
                        }
                    }
        }
Exemplo n.º 28
0
 public void AddVolume(VoxelVolume volume, QbMatrix matrix, ref Colort color, Dictionary <double, VoxelUndoData> modifiedVoxels)
 {
 }
Exemplo n.º 29
0
 public void EnumerateVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, ref Colort color, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
 }
Exemplo n.º 30
0
 public void EnumerateVolume(VoxelVolume volume, VoxelVolume currentVolume, QbMatrix matrix, ref Colort color, Dictionary <double, VoxelUndoData> modifiedVoxels)
 {
 }
Exemplo n.º 31
0
        public bool OnRaycastHitchanged(Input input, QbMatrix matrix, RaycastHit hit, ref Colort color, MouseButtonEventArgs e)
        {
            if (matrix == null)
            {
                if (lastmatrix != null)
                {
                    lastmatrix.highlight = Color4.White;
                    lastmatrix           = null;
                    Singleton <GUI> .INSTANCE.Get <Label>(GUIID.STATUS_TEXT).text = "";
                }
                return(true);
            }

            if (matrix != lastmatrix)
            {
                if (lastmatrix != null)
                {
                    lastmatrix.highlight = Color4.White;
                }
                matrix.highlight = new Colort(1.5f, 1.5f, 1.5f);

                lastmatrix = matrix;
                Singleton <GUI> .INSTANCE.Get <Label>(GUIID.STATUS_TEXT).text = $"Over Matrix : {matrix.name}";
            }
            return(true);
        }
Exemplo n.º 32
0
        public void write(string path, string name, QbModel model)
        {
            string fullpath = Path.Combine(path, name + extension);

            using (FileStream f = new FileStream(fullpath, FileMode.OpenOrCreate))
            {
                using (BinaryWriter w = new BinaryWriter(f))
                {
                    w.Write(model.version);
                    w.Write(model.colorFormat);
                    w.Write(model.zAxisOrientation);
                    w.Write(model.compressed);
                    w.Write(model.visibilityMaskEncoded);

                    w.Write((uint)model.matrices.Count);

                    for (int i = 0; i < model.numMatrices; i++)
                    {
                        QbMatrix m = model.matrices[i];
                        if (!m.Visible)
                        {
                            continue;
                        }

                        int startx = Math.Min(0, m.minx);
                        int starty = Math.Min(0, m.miny);
                        int startz = Math.Min(0, m.minz);

                        int width  = (int)(Math.Abs(Math.Min(0, m.minx)) + m.maxx + 1);
                        int height = (int)(Math.Abs(Math.Min(0, m.miny)) + m.maxy + 1);
                        int length = (int)(Math.Abs(Math.Min(0, m.minz)) + m.maxz + 1);

                        if (width < m.size.X)
                        {
                            width = (int)m.size.X;
                        }

                        if (height < m.size.Y)
                        {
                            height = (int)m.size.Y;
                        }

                        if (length < m.size.Z)
                        {
                            length = (int)m.size.Z;
                        }

                        w.Write(m.name);
                        w.Write((uint)width);
                        w.Write((uint)height);
                        w.Write((uint)length);

                        w.Write((int)m.position.X);
                        w.Write((int)m.position.Y);
                        w.Write((int)m.position.Z);

                        if (model.compressed == 0)
                        {
                            Voxel voxel;
                            for (int z = startz; z < startz + length; z++)
                            {
                                for (int y = starty; y < starty + height; y++)
                                {
                                    for (int x = startx; x < startx + width; x++)
                                    {
                                        int zz = model.zAxisOrientation == (int)0 ? z : (int)(length - z - 1);

                                        if (m.voxels.TryGetValue(m.GetHash(x, y, zz), out voxel))
                                        {
                                            Colort c = m.colors[voxel.colorindex];

                                            int r = (int)(c.R * 255f);
                                            int g = (int)(c.G * 255f);
                                            int b = (int)(c.B * 255f);

                                            w.Write((byte)r);
                                            w.Write((byte)g);
                                            w.Write((byte)b);
                                            w.Write(voxel.alphamask);
                                        }
                                        else
                                        {
                                            w.Write((byte)0);
                                            w.Write((byte)0);
                                            w.Write((byte)0);
                                            w.Write((byte)0);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 33
0
        public bool Add(int x, int y, int z, Colort color)
        {
            if (voxels.TryGetValue(GetHash(x, y, z), out voxel))
            {
                if (voxel.alphamask != 0) return false;
                else
                {
                    if (!voxels.TryRemove(GetHash(x, y, z), out voxel)) return false;
                    voxel = new Voxel(x, y, z, GetAlphaMask(x, y, z), GetColorIndex(color.R, color.G, color.B));
                    if (voxels.TryAdd(GetHash(x, y, z), voxel))
                    {
                        voxel.dirty = true;
                        UpdateVoxel();

                        if (voxels.TryGetValue(GetHash(x, y, z + 1), out voxel))
                        {
                            if ((voxel.alphamask & 64) == 64)
                            {
                                voxel.alphamask -= 64;
                                UpdateVoxel();
                            }
                        }

                        if (voxels.TryGetValue(GetHash(x, y, z - 1), out voxel))
                        {
                            if ((voxel.alphamask & 32) == 32)
                            {
                                voxel.alphamask -= 32;
                                UpdateVoxel();
                            }
                        }

                        if (voxels.TryGetValue(GetHash(x, y + 1, z), out voxel))
                        {
                            if ((voxel.alphamask & 16) == 16)
                            {
                                voxel.alphamask -= 16;
                                UpdateVoxel();
                            }
                        }

                        if (voxels.TryGetValue(GetHash(x, y - 1, z), out voxel))
                        {
                            if ((voxel.alphamask & 8) == 8)
                            {
                                voxel.alphamask -= 8;
                                UpdateVoxel();
                            }
                        }

                        if (voxels.TryGetValue(GetHash(x + 1, y, z), out voxel))
                        {
                            if ((voxel.alphamask & 4) == 4)
                            {
                                voxel.alphamask -= 4;
                                UpdateVoxel();
                            }
                        }

                        if (voxels.TryGetValue(GetHash(x - 1, y, z), out voxel))
                        {
                            if ((voxel.alphamask & 2) == 2)
                            {
                                voxel.alphamask -= 2;
                                UpdateVoxel();
                            }
                        }

                        return true;
                    }
                    return false;
                }
            }
            else
            {
                voxel = new Voxel(x, y, z, GetAlphaMask(x, y, z), GetColorIndex(color.R, color.G, color.B));
                if (voxels.TryAdd(GetHash(x, y, z), voxel))
                {
                    voxel.dirty = true;
                    UpdateVoxel();

                    if (voxels.TryGetValue(GetHash(x, y, z + 1), out voxel))
                    {
                        if ((voxel.alphamask & 64) == 64)
                        {
                            voxel.alphamask -= 64;
                            UpdateVoxel();
                        }
                    }

                    if (voxels.TryGetValue(GetHash(x, y, z - 1), out voxel))
                    {
                        if ((voxel.alphamask & 32) == 32)
                        {
                            voxel.alphamask -= 32;
                            UpdateVoxel();
                        }
                    }

                    if (voxels.TryGetValue(GetHash(x, y + 1, z), out voxel))
                    {
                        if ((voxel.alphamask & 16) == 16)
                        {
                            voxel.alphamask -= 16;
                            UpdateVoxel();
                        }
                    }

                    if (voxels.TryGetValue(GetHash(x, y - 1, z), out voxel))
                    {
                        if ((voxel.alphamask & 8) == 8)
                        {
                            voxel.alphamask -= 8;
                            UpdateVoxel();
                        }
                    }

                    if (voxels.TryGetValue(GetHash(x + 1, y, z), out voxel))
                    {
                        if ((voxel.alphamask & 4) == 4)
                        {
                            voxel.alphamask -= 4;
                            UpdateVoxel();
                        }
                    }

                    if (voxels.TryGetValue(GetHash(x - 1, y, z), out voxel))
                    {
                        if ((voxel.alphamask & 2) == 2)
                        {
                            voxel.alphamask -= 2;
                            UpdateVoxel();
                        }
                    }

                    return true;
                }

                return false;
            }
        }
Exemplo n.º 34
0
 public void AddVolume(VoxelVolume volume, QbMatrix matrix, ref Colort color, Dictionary<double, VoxelUndoData> modifiedVoxels)
 {
 }
Exemplo n.º 35
0
        public int GetColorIndex(float r, float g, float b)
        {
            Colort c;
            for (int i = 0; i < colors.Length; i++)
            {
                c = colors[i];
                if (c.R == r && c.G == g && c.B == b)
                    return (int)i;
            }

            if (colorindexholes.Count > 0)
            {
                matrixcolors[colorindexholes.Pop()] = new Colort(r, g, b);
            }
            else
                matrixcolors[colorIndex] = new Colort(r, g, b);

            // wireframes and outline....
            // right now my hsv to rbg is not working correctly and fails generating a few colors
            // later on this will be used over doing the conversion on a shader

            //Color4 color = new Color4(r, g, b, 1);

            //double hue, sat, vi;
            //ColorConversion.ColorToHSV(color.ToSystemDrawingColor(), out hue, out sat, out vi);

            //var outline = ColorConversion.ColorFromHSV(hue, (sat + .5d).Clamp(0, 1), vi );
            //outlinecolors[colorIndex] = outline.ToColor4();

            //var wireframe = ColorConversion.ColorFromHSV(hue, (sat + .1d).Clamp(0,1), (vi+.1d).Clamp(0,1));
            //wireframecolors[colorIndex] = wireframe.ToColor4();

            if (colorIndex + 1 >= colors.Length)
            {
                CleanUnsuedColorIndexs();

                if (colorindexholes.Count > 0)
                {
                    int newindex = colorindexholes.Pop();
                    matrixcolors[newindex] = new Colort(r, g, b);
                    return newindex;
                }
                else
                {
                    MessageBox.Show("StoneVox only supports 128 active colors at once. This is quite the issue, try reducing the amount of colors you are using. Since there is no room the last color will now be overwritten with this new color.", "Out of Colors");
                    matrixcolors[matrixcolors.Length - 1] = new Colort(r, g, b);
                    return matrixcolors.Length - 1;
                }
            }

            colorIndex++;

            return colorIndex - 1;
        }
Exemplo n.º 36
0
 public bool OnRaycastHitchanged(Input input, QbMatrix matrix, RaycastHit hit, ref Colort color, MouseButtonEventArgs e)
 {
     return true;
 }
Exemplo n.º 37
0
 public void Color(Vector3 location, Colort color)
 {
     Color((int)location.X, (int)location.Y, (int)location.Z, color);
 }
Exemplo n.º 38
0
 public void Color(int x, int y, int z, Colort color)
 {
     Color(x, y, z, GetColorIndex(color.R, color.G, color.B));
 }
Exemplo n.º 39
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)));
             }
 }