Exemplo n.º 1
0
        public bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y)
        {
            ColorPixel   c        = pixels[x, y];
            ColorManager oldColor = ColorManager.FromRGBA(c.Red, c.Green, c.Blue, c.Alpha);

            if ((Control.ModifierKeys & Keys.Shift) != 0)
            {
                Editor.MainForm.ColorPanel.UnselectedColor = oldColor;
            }
            else
            {
                Editor.MainForm.ColorPanel.SelectedColor = oldColor;
            }
            return(false);
        }
Exemplo n.º 2
0
        private void FloodFill(int x, int y, Color oldColor, ColorManager newColor, ColorGrabber pixels)
        {
            Queue q = new Queue();

            q.Enqueue(new Point(x, y));

            while (q.Count != 0)
            {
                Point pop = (Point)q.Dequeue();

                ColorPixel c    = pixels[pop.X, pop.Y];
                Color      real = Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue);

                if (!SimilarColor2(oldColor, real, _threshold))
                {
                    continue;
                }

                if (!_undo.Points.ContainsKey(pop))
                {
                    _undo.Points.Add(pop, Tuple.MakeTuple(real, new ColorAlpha(newColor.RGB, 0)));

                    pixels[pop.X, pop.Y] =
                        new ColorPixel(newColor.RGB.R | (newColor.RGB.G << 8) | (newColor.RGB.B << 16) | (newColor.RGB.A << 24));

                    if (_boundBox.Contains(pop.X - 1, pop.Y))
                    {
                        q.Enqueue(new Point(pop.X - 1, pop.Y));
                    }
                    if (_boundBox.Contains(pop.X + 1, pop.Y))
                    {
                        q.Enqueue(new Point(pop.X + 1, pop.Y));
                    }
                    if (_boundBox.Contains(pop.X, pop.Y - 1))
                    {
                        q.Enqueue(new Point(pop.X, pop.Y - 1));
                    }
                    if (_boundBox.Contains(pop.X, pop.Y + 1))
                    {
                        q.Enqueue(new Point(pop.X, pop.Y + 1));
                    }
                }
            }
        }
Exemplo n.º 3
0
        public virtual bool RequestPreview(ColorGrabber pixels, Skin skin, int x, int y)
        {
            if (x == -1)
            {
                return(false);
            }

            Brush brush  = Brushes.SelectedBrush;
            int   startX = x - (brush.Width / 2);
            int   startY = y - (brush.Height / 2);

            IsPreview = true;

            for (int ry = 0; ry < brush.Height; ++ry)
            {
                for (int rx = 0; rx < brush.Width; ++rx)
                {
                    int xx = startX + rx;
                    int yy = startY + ry;

                    if (xx < 0 || xx >= skin.Width ||
                        yy < 0 || yy >= skin.Height)
                    {
                        continue;
                    }

                    if (brush[rx, ry] == 0.0f)
                    {
                        continue;
                    }

                    ColorPixel c        = pixels[xx, yy];
                    Color      oldColor = Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue);
                    Color      color    = GetLeftColor();
                    color = Color.FromArgb((byte)(brush[rx, ry] * 255 * (color.A / 255.0f)), color);

                    Color newColor = BlendColor(color, oldColor);
                    pixels[xx, yy] = new ColorPixel(newColor.R | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24));
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        public static ColorPixel[,] convertBitmapToColorPixel(Bitmap bmp)
        {
            int width  = bmp.Width;
            int height = bmp.Height;

            ColorPixel[,] result = new ColorPixel[height, width];

            for (int row = 0; row < height; row++)
            {
                for (int col = 0; col < width; col++)
                {
                    int value = bmp.GetPixel(col, row).ToArgb();
                    result[row, col] = ColorPixel.create(bmp.GetPixel(col, row).ToArgb());
                }
            }

            //UtilsFile.exportFileWithColorPixel(@"C:\Users\dell\Desktop\colorpixel.txt", result, width, height);

            return(result);
        }
Exemplo n.º 5
0
        public void CommitChanges(Texture currentSkin, bool save)
        {
            using (var grabber = new ColorGrabber(currentSkin, Width, Height))
            {
                grabber.Load();

                if (currentSkin != GLImage)
                {
                    grabber.Texture = GLImage;
                    grabber.Save();
                }

                if (save)
                {
                    var newBitmap = new Bitmap(Width, Height);

                    using (var fp = new FastPixel(newBitmap, true))
                    {
                        for (int y = 0; y < Height; ++y)
                        {
                            for (int x = 0; x < Width; ++x)
                            {
                                ColorPixel c = grabber[x, y];
                                fp.SetPixel(x, y, Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue));
                            }
                        }
                    }

                    newBitmap.Save(File.FullName);
                    newBitmap.Dispose();

                    var md = new Dictionary <string, string>();
                    md.Add("Model", Model.Path);
                    PNGMetadata.WriteMetadata(File.FullName, md);

                    SetImages(true);

                    Dirty = false;
                }
            }
        }
Exemplo n.º 6
0
    //IEnumerator Refresh()
    //{
    //    while (true)
    //    {
    //        yield return new WaitForSeconds(10f);
    //        if (!refreshStarted)
    //        {
    //            firebaseRefresh();
    //            refreshStarted = true;
    //            unsubStarted = false;
    //        }
    //        yield return new WaitForSeconds(3f);
    //        if (!unsubStarted)
    //        {
    //            unsubscribe();
    //            unsubStarted = true;
    //            refreshStarted = false;
    //        }
    //    }
    //}

    // Update is called once per frame
    void Update()
    {
        FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://canvas-f8087.firebaseio.com");
        DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference;

        ////InvokeRepeating("firebaseRefresh", 3.0f, 8.0f);
        //StartCoroutine("Refresh");


        if (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Began)
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
            RaycastHit Hit;
            if (Physics.Raycast(ray, out Hit))
            {
                if (Hit.transform.gameObject.transform.name == canvasPixel.transform.name)
                {
                    Debug.Log("Hit " + canvasPixel.transform.name);
                    Globals.pixelColor.a    = 100; // reset alpha of pixelColor to be 100
                    renderer.material.color = Globals.pixelColor;
                    string targetMatName = renderer.material.name;
                    Debug.Log(targetMatName + " get updated!");

                    ColorPixel pixelIns = new ColorPixel();

                    pixelIns.r = Globals.pixelColor.r;
                    pixelIns.g = Globals.pixelColor.g;
                    pixelIns.b = Globals.pixelColor.b;
                    pixelIns.a = Globals.pixelColor.a;


                    string jsonString = JsonUtility.ToJson(pixelIns);

                    reference.Child(targetMatName).SetRawJsonValueAsync(jsonString);

                    // update canvas pixel color using renderer material color attributes
                    Globals.selected = true;
                }
            }
        }
    }
Exemplo n.º 7
0
        public bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y)
        {
            if (_done)
            {
                return(false);
            }

            var curve = new BezierCurveQuadric(new Vector2(1, 0), new Vector2(0, 1), new Vector2(1, 2));

            _threshold = (byte)((1 - (curve.CalculatePoint(Threshold)).X) * 255);
            //(byte)((1 - Math.Sin((1 - Threshold) * (Math.PI / 2))) * 255);

            ColorPixel   c        = pixels[x, y];
            Color        oldColor = Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue);
            ColorManager newColor = ((Control.ModifierKeys & Keys.Shift) != 0)
                                                        ? Editor.MainForm.ColorPanel.UnselectedColor
                                                        : Editor.MainForm.ColorPanel.SelectedColor;

            FloodFill(x, y, oldColor, newColor, pixels);
            _done = true;
            return(true);
        }
Exemplo n.º 8
0
        public void CheckTransparentPart(ColorGrabber grabber, int index)
        {
            foreach (Face f in Model.Meshes[index].Faces)
            {
                var bounds = new Bounds(new Point(9999, 9999), new Point(-9999, -9999));

                foreach (Vector2 c in f.TexCoords)
                {
                    var coord = new Vector2(c.X * Width, c.Y * Height);
                    bounds.AddPoint(new Point((int)coord.X, (int)coord.Y));
                }

                Rectangle rect   = bounds.ToRectangle();
                bool      gotOne = false;

                for (int y = rect.Y; !gotOne && y < rect.Y + rect.Height; ++y)
                {
                    for (int x = rect.X; x < rect.X + rect.Width; ++x)
                    {
                        ColorPixel pixel = grabber[x, y];

                        if (pixel.Alpha != 255)
                        {
                            gotOne = true;
                            break;
                        }
                    }
                }

                if (gotOne)
                {
                    TransparentParts[index] = gotOne;
                    return;
                }
            }

            TransparentParts[index] = false;
        }
Exemplo n.º 9
0
        public bool RequestPreview(ColorGrabber pixels, Skin skin, int x, int y)
        {
            if (x == -1)
            {
                return(false);
            }

            var  highlightPoint = new Point(x, y);
            bool doHighlight    = ((Control.ModifierKeys & Keys.Control) != 0);

            Color newColor;

            if (doHighlight)
            {
                Rectangle part = Editor.CurrentModel.GetTextureFaceBounds(highlightPoint, skin);

                for (int ry = part.Y; ry < part.Y + part.Height; ++ry)
                {
                    for (int rx = part.X; rx < part.X + part.Width; ++rx)
                    {
                        ColorPixel px      = pixels[rx, ry];
                        Color      c       = Color.FromArgb(px.Alpha, px.Red, px.Green, px.Blue);
                        Color      blendMe = Color.FromArgb(64, Color.Green);
                        newColor = (Color)ColorBlending.AlphaBlend(blendMe, c);

                        pixels[rx, ry] = new ColorPixel((newColor.R << 0) | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24));
                    }
                }
            }

            newColor =
                (((Control.ModifierKeys & Keys.Shift) != 0)
                                        ? Editor.MainForm.ColorPanel.UnselectedColor
                                        : Editor.MainForm.ColorPanel.SelectedColor).RGB;
            pixels[x, y] = new ColorPixel(newColor.R | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24));
            return(true);
        }
Exemplo n.º 10
0
 private void PixelWritten(Point p, ColorPixel c)
 {
     if (!_paintedPixels.ContainsKey(p))
         _paintedPixels.Add(p, true);
 }
Exemplo n.º 11
0
        public virtual bool RequestPreview(ColorGrabber pixels, Skin skin, int x, int y)
        {
            if (x == -1)
                return false;

            Brush brush = Brushes.SelectedBrush;
            int startX = x - (brush.Width / 2);
            int startY = y - (brush.Height / 2);
            IsPreview = true;

            for (int ry = 0; ry < brush.Height; ++ry)
            {
                for (int rx = 0; rx < brush.Width; ++rx)
                {
                    int xx = startX + rx;
                    int yy = startY + ry;

                    if (xx < 0 || xx >= skin.Width ||
                        yy < 0 || yy >= skin.Height)
                        continue;

                    if (brush[rx, ry] == 0.0f)
                        continue;

                    ColorPixel c = pixels[xx, yy];
                    Color oldColor = Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue);
                    Color color = GetLeftColor();
                    color = Color.FromArgb((byte) (brush[rx, ry] * 255 * (color.A / 255.0f)), color);

                    Color newColor = BlendColor(color, oldColor);
                    pixels[xx, yy] = new ColorPixel(newColor.R | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24));
                }
            }

            return true;
        }
Exemplo n.º 12
0
 private void Awake()
 {
     colorPixel = GameObject.Find("Drawable").GetComponent <ColorPixel>();
     colorPixel.abilityController = this;
 }
Exemplo n.º 13
0
        public bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y, bool incremental)
        {
            Brush brush = Brushes.SelectedBrush;

            if (_brushThatWasStamped != brush)
            {
                _stampedBrush = null;
            }

            if (x == _oldPixel.X && y == _oldPixel.Y)
            {
                return(false);
            }
            if (_stampedBrush == null && !HoldingShift)
            {
                return(false);
            }

            IsPreview = false;

            int startX = x - (brush.Width / 2);
            int startY = y - (brush.Height / 2);

            for (int ry = 0; ry < brush.Height; ++ry)
            {
                for (int rx = 0; rx < brush.Width; ++rx)
                {
                    int xx = startX + rx;
                    int yy = startY + ry;

                    if (xx < 0 || xx >= skin.Width ||
                        yy < 0 || yy >= skin.Height)
                    {
                        continue;
                    }

                    if (brush[rx, ry] == 0.0f)
                    {
                        continue;
                    }

                    ColorPixel c = pixels[xx, yy];

                    if (HoldingShift)
                    {
                        if (_stampedBrush == null)
                        {
                            _stampedBrush = new ColorPixel[brush.Width, brush.Height];
                        }

                        _brushThatWasStamped  = brush;
                        _stampedBrush[rx, ry] = c;
                        continue;
                    }

                    Color oldColor = Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue);
                    Color color    = Color.FromArgb(_stampedBrush[rx, ry].Alpha, _stampedBrush[rx, ry].Red, _stampedBrush[rx, ry].Green,
                                                    _stampedBrush[rx, ry].Blue);

                    byte maxAlpha   = color.A;
                    var  alphaToAdd =
                        (float)
                        (byte)(brush[rx, ry] * 255 * ((Editor.MainForm.ColorPanel.SelectedColor.RGB.A / 255.0f) * (color.A / 255.0f)));

                    if (!incremental && _undo.Points.ContainsKey(new Point(xx, yy)) &&
                        _undo.Points[new Point(xx, yy)].Item2.TotalAlpha >= maxAlpha)
                    {
                        continue;
                    }

                    if (!incremental && _undo.Points.ContainsKey(new Point(xx, yy)) &&
                        _undo.Points[new Point(xx, yy)].Item2.TotalAlpha + alphaToAdd >= maxAlpha)
                    {
                        alphaToAdd = maxAlpha - _undo.Points[new Point(xx, yy)].Item2.TotalAlpha;
                    }

                    color = Color.FromArgb((byte)(alphaToAdd), color);

                    Color newColor = BlendColor(color, oldColor);

                    if (oldColor == newColor)
                    {
                        continue;
                    }

                    if (_undo.Points.ContainsKey(new Point(xx, yy)))
                    {
                        Tuple <Color, ColorAlpha> tupl = _undo.Points[new Point(xx, yy)];

                        tupl.Item2 = new ColorAlpha(newColor, tupl.Item2.TotalAlpha + alphaToAdd);
                        _undo.Points[new Point(xx, yy)] = tupl;
                    }
                    else
                    {
                        _undo.Points.Add(new Point(xx, yy), Tuple.MakeTuple(oldColor, new ColorAlpha(newColor, alphaToAdd)));
                    }

                    pixels[xx, yy] = new ColorPixel(newColor.R | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24));
                }
            }

            _oldPixel = new Point(x, y);

            return(!HoldingShift);
        }
Exemplo n.º 14
0
        public bool RequestPreview(ColorGrabber pixels, Skin skin, int x, int y)
        {
            if (x == -1)
                return false;

            var highlightPoint = new Point(x, y);
            bool doHighlight = ((Control.ModifierKeys & Keys.Control) != 0);

            Color newColor;
            if (doHighlight)
            {
                Rectangle part = Editor.CurrentModel.GetTextureFaceBounds(highlightPoint, skin);

                for (int ry = part.Y; ry < part.Y + part.Height; ++ry)
                {
                    for (int rx = part.X; rx < part.X + part.Width; ++rx)
                    {
                        ColorPixel px = pixels[rx, ry];
                        Color c = Color.FromArgb(px.Alpha, px.Red, px.Green, px.Blue);
                        Color blendMe = Color.FromArgb(64, Color.Green);
                        newColor = (Color) ColorBlending.AlphaBlend(blendMe, c);

                        pixels[rx, ry] = new ColorPixel((newColor.R << 0) | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24));
                    }
                }
            }

            newColor =
                (((Control.ModifierKeys & Keys.Shift) != 0)
                 	? Editor.MainForm.ColorPanel.UnselectedColor
                 	: Editor.MainForm.ColorPanel.SelectedColor).RGB;
            pixels[x, y] = new ColorPixel(newColor.R | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24));
            return true;
        }
Exemplo n.º 15
0
 private void Start()
 {
     ac = GameObject.Find("AbilityController").GetComponent <AbilityController>();
     cp = GameObject.Find("Drawable").GetComponent <ColorPixel>();
 }
Exemplo n.º 16
0
        public bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y, bool incremental)
        {
            if (x == _oldPixel.X && y == _oldPixel.Y)
                return false;
            IsPreview = false;

            Brush brush = Brushes.SelectedBrush;
            int startX = x - (brush.Width / 2);
            int startY = y - (brush.Height / 2);

            for (int ry = 0; ry < brush.Height; ++ry)
            {
                for (int rx = 0; rx < brush.Width; ++rx)
                {
                    int xx = startX + rx;
                    int yy = startY + ry;

                    if (xx < 0 || xx >= skin.Width ||
                        yy < 0 || yy >= skin.Height)
                        continue;

                    if (brush[rx, ry] == 0.0f)
                        continue;

                    ColorPixel c = pixels[xx, yy];
                    Color oldColor = Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue);
                    ColorManager.RGBColor color =
                        (((Control.ModifierKeys & Keys.Shift) != 0)
                         	? Editor.MainForm.ColorPanel.UnselectedColor
                         	: Editor.MainForm.ColorPanel.SelectedColor).RGB;

                    byte maxAlpha = color.A;
                    var alphaToAdd = (float) (byte) (brush[rx, ry] * 255 * (Editor.MainForm.ColorPanel.SelectedColor.RGB.A / 255.0f));

                    if (!incremental && _undo.Points.ContainsKey(new Point(xx, yy)) &&
                        _undo.Points[new Point(xx, yy)].Item2.TotalAlpha >= maxAlpha)
                        continue;

                    if (!incremental && _undo.Points.ContainsKey(new Point(xx, yy)) &&
                        _undo.Points[new Point(xx, yy)].Item2.TotalAlpha + alphaToAdd >= maxAlpha)
                        alphaToAdd = maxAlpha - _undo.Points[new Point(xx, yy)].Item2.TotalAlpha;

                    color = Color.FromArgb((byte) (alphaToAdd), color);

                    Color newColor = BlendColor(color, oldColor);

                    if (oldColor == newColor)
                        continue;

                    if (_undo.Points.ContainsKey(new Point(xx, yy)))
                    {
                        Tuple<Color, ColorAlpha> tupl = _undo.Points[new Point(xx, yy)];

                        tupl.Item2 = new ColorAlpha(newColor, tupl.Item2.TotalAlpha + alphaToAdd);
                        _undo.Points[new Point(xx, yy)] = tupl;
                    }
                    else
                        _undo.Points.Add(new Point(xx, yy), Tuple.MakeTuple(oldColor, new ColorAlpha(newColor, alphaToAdd)));

                    pixels[xx, yy] = new ColorPixel(newColor.R | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24));
                }
            }

            _oldPixel = new Point(x, y);

            return true;
        }
Exemplo n.º 17
0
        public bool MouseMoveOnSkin(ColorGrabber pixels, Skin skin, int x, int y, bool incremental)
        {
            if (x == _oldPixel.X && y == _oldPixel.Y)
            {
                return(false);
            }
            IsPreview = false;

            Brush brush  = Brushes.SelectedBrush;
            int   startX = x - (brush.Width / 2);
            int   startY = y - (brush.Height / 2);

            for (int ry = 0; ry < brush.Height; ++ry)
            {
                for (int rx = 0; rx < brush.Width; ++rx)
                {
                    int xx = startX + rx;
                    int yy = startY + ry;

                    if (xx < 0 || xx >= skin.Width ||
                        yy < 0 || yy >= skin.Height)
                    {
                        continue;
                    }

                    if (brush[rx, ry] == 0.0f)
                    {
                        continue;
                    }

                    ColorPixel            c        = pixels[xx, yy];
                    Color                 oldColor = Color.FromArgb(c.Alpha, c.Red, c.Green, c.Blue);
                    ColorManager.RGBColor color    =
                        (((Control.ModifierKeys & Keys.Shift) != 0)
                                                        ? Editor.MainForm.ColorPanel.UnselectedColor
                                                        : Editor.MainForm.ColorPanel.SelectedColor).RGB;

                    byte maxAlpha   = color.A;
                    var  alphaToAdd = (float)(byte)(brush[rx, ry] * 255 * (Editor.MainForm.ColorPanel.SelectedColor.RGB.A / 255.0f));

                    if (!incremental && _undo.Points.ContainsKey(new Point(xx, yy)) &&
                        _undo.Points[new Point(xx, yy)].Item2.TotalAlpha >= maxAlpha)
                    {
                        continue;
                    }

                    if (!incremental && _undo.Points.ContainsKey(new Point(xx, yy)) &&
                        _undo.Points[new Point(xx, yy)].Item2.TotalAlpha + alphaToAdd >= maxAlpha)
                    {
                        alphaToAdd = maxAlpha - _undo.Points[new Point(xx, yy)].Item2.TotalAlpha;
                    }

                    color = Color.FromArgb((byte)(alphaToAdd), color);

                    Color newColor = BlendColor(color, oldColor);

                    if (oldColor == newColor)
                    {
                        continue;
                    }

                    if (_undo.Points.ContainsKey(new Point(xx, yy)))
                    {
                        Tuple <Color, ColorAlpha> tupl = _undo.Points[new Point(xx, yy)];
                        _undo.Points[new Point(xx, yy)] = Tuple.Create(tupl.Item1, new ColorAlpha(newColor, tupl.Item2.TotalAlpha + alphaToAdd));
                    }
                    else
                    {
                        _undo.Points.Add(new Point(xx, yy), Tuple.Create(oldColor, new ColorAlpha(newColor, alphaToAdd)));
                    }

                    pixels[xx, yy] = new ColorPixel(newColor.R | (newColor.G << 8) | (newColor.B << 16) | (newColor.A << 24));
                }
            }

            _oldPixel = new Point(x, y);

            return(true);
        }