protected void ThreadMission_Pixel2(int i, int j)
        {
            base.ThreadMission_Pixel(i, j);
            Vector2 uv = SWTextureProcess.TexUV(texWidth, texHeight, i, j);

            for (int k = 0; k < info.pts.Count; k++)
            {
                var   p0  = info.pts [SWTextureProcess.LoopID(k - 1, info.pts.Count)];
                var   p1  = info.pts [SWTextureProcess.LoopID(k, info.pts.Count)];
                var   p2  = info.pts [SWTextureProcess.LoopID(k + 1, info.pts.Count)];
                float pcg = SWTextureProcess.PointOnSegPcgSign(uv, p1.uv, p2.uv);
                pcg = p1.pcg + (p2.pcg - p1.pcg) * pcg;
//				float innerDis = 0;
//				bool seg = SWTextureProcess.Point2SegOnlyDisSign (uv, p1.after, p2.pre,ref innerDis);

                if (texColorBuffer [(texHeight - j - 1) * texWidth + i].b <= 0.5)
                {
                    float dis1 = SWTextureProcess.Point2SegDis(uv, p0.uv, p1.uv);
                    float dis2 = SWTextureProcess.Point2SegDis(uv, p1.uv, p2.uv);


                    bool e1 = Vector2.Dot(uv - p1.pre, p0.uv - p1.pre) < 0;
                    bool e2 = Vector2.Dot(uv - p1.after, p2.uv - p1.after) < 0;


                    if (e1 && e2 && (dis1 <= size || dis2 <= size))
                    {
                        Vector2 v1 = p1.pre - p1.center;
                        Vector2 v2 = uv - p1.center;
                        Vector2 v3 = p1.after - p1.center;

                        float angle1   = Vector2.Angle(v2, v1);
                        float angleAll = Vector2.Angle(v1, v3);

                        pcg = p1.prePcg + (p1.afterPcg - p1.prePcg) * angle1 / angleAll;



//						float disSigned1 = -SWTextureProcess.Point2LineDisSign (uv, p0.uv, p1.uv);
//						float disSigned2 = -SWTextureProcess.Point2LineDisSign (uv, p1.uv, p2.uv);
//						float disSigned = disSigned1 + (disSigned2 - disSigned1) * angle1 /angleAll;
                        //float g =  ( disSigned / size+1)*0.5f;
                        float g = 0;
                        if (SWCommon.AngleSigned(v3, v1, new Vector3(0, 0, 1)) < 0)
                        {
                            g = Vector2.Distance(uv, p1.center) / (size * 2);
                        }
                        else
                        {
                            g = 1 - Vector2.Distance(uv, p1.center) / (size * 2);
                        }
                        float b = (pcg > 0.995f || pcg < 0.005f)? 1:0;
                        float a = GreenToAlpha(g);
                        texColorBuffer [(texHeight - j - 1) * texWidth + i] = new Color(pcg, g, b, a);
                    }
                }
            }
        }
Пример #2
0
 void CalUV()
 {
     uv = Event.current.mousePosition;
     //deviation:draw point is a little bit looks like below mouse center
     uv += new Vector2(0, -1f);
     uv  = uv - drawRect.position;
     SWTexThread_Tex.centerX = Mathf.RoundToInt(uv.x);
     SWTexThread_Tex.centerY = Mathf.RoundToInt(uv.y);
     uv = SWTextureProcess.TexUV(texWidth, texHeight, uv.x, uv.y);
 }
        void DrawLine()
        {
            //Add Point
            if (SWCommon.GetMouseDown(0) && al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY)))
            {
                if (!al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY)))
                {
                    return;
                }
                if (!drawRect.Contains(mousePos))
                {
                    return;
                }

                SWUndo.Record(info);
                Vector2 m = Event.current.mousePosition;
                m = m - drawRect.position;
                m = SWTextureProcess.TexUV(size, size, (int)m.x, (int)m.y);

                RemapWayPoint pt = new RemapWayPoint();
                pt.uv       = m;
                pt.mousePos = mousePos;
                pt.matArrow = new Material(SWEditorUI.GetShader("RectTRS"));
                info.pts.Add(pt);
            }

            DrawPoints();

            //Draw Cursor
            if (focusedWindow == this)
            {
                if (al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY)) && drawRect.Contains(mousePos))
                {
                    GUI.DrawTexture(new Rect(mousePos.x - brushSize * 1f, mousePos.y - brushSize * 1f, brushSize * 2f, brushSize * 2f), SWEditorUI.Texture(SWUITex.cursor));
                    GUI.DrawTexture(new Rect(mousePos.x - 8, mousePos.y - 8, 16, 16), SWEditorUI.Texture(SWUITex.cursorCenter));
                    Cursor.visible = false;
                }
                else
                {
                    Cursor.visible = true;
                }
            }
            //Key Command
            if (Event.current.type == EventType.keyDown)
            {
                if (Event.current.keyCode == KeyCode.Return)
                {
                    node.data.dirty = true;
                    SWTextureProcess.ProcessRemap_Line(node.textureEx, info, brushSizeUV);
                }
            }
        }
Пример #4
0
        protected override void ThreadMission_Pixel(int i, int j)
        {
            base.ThreadMission_Pixel(i, j);
            Vector2 _uv   = SWTextureProcess.TexUV(texWidth, texHeight, i, j);
            float   dis   = SWTextureProcess.Point2SegDis(_uv, startUV, endUV);
            float   isize = (float)brush.size / (float)SWWindowDrawMask.size;

            if (dis < isize)
            {
                float disPcg = dis / isize;
                SWTextureProcess.Brush_Apply(ref texColorBuffer [(texHeight - j - 1) * texWidth + i], brush, disPcg, i, j);
            }
        }
Пример #5
0
 protected static Color[] TextureResizeBase(Color[] colorsOrigin, int oldW, int oldH, int newW, int newH)
 {
     Color[] colorsNew = new Color[newW * newH];
     for (int i = 0; i < newW; i++)
     {
         for (int j = 0; j < newH; j++)
         {
             int     index = XYtoIndex(newW, newH, i, j);
             Vector2 uv    = SWTextureProcess.TexUV(newW, newH, i, j);
             colorsNew[index] = SWTextureProcess.GetColor_UV(oldW, oldH, colorsOrigin, uv);
         }
     }
     return(colorsNew);
 }
Пример #6
0
        public static SWTexture2DEx TextureResize(Texture2D tex, int newWidth, int newHeight)
        {
            SWTexture2DEx newTex       = SWCommon.TextureCreate(newWidth, newHeight, TextureFormat.ARGB32);
            var           colorsOrigin = tex.GetPixels();
            var           colors       = newTex.GetPixels();

            for (int i = 0; i < newWidth; i++)
            {
                for (int j = 0; j < newHeight; j++)
                {
                    Vector2 uv    = SWTextureProcess.TexUV(newWidth, newHeight, i, j);
                    int     index = TexUV2Index(newTex.width, newTex.height, uv);
                    colors[index] = SWTextureProcess.GetColor_UV(tex.width, tex.height, colorsOrigin, uv);
                }
            }
            newTex.SetPixels(colors);
            newTex.Apply();
            return(newTex);
        }
        protected override void ThreadMission_Pixel(int i, int j)
        {
            base.ThreadMission_Pixel(i, j);
            Vector2 uv     = SWTextureProcess.TexUV(texSrcWidth, texSrcHeight, i, j);
            Vector2 fromUV = uv - offset;
            Vector2 dis    = fromUV - uv;
            float   alpha  = 0;
            float   pcg    = 0;
            Color   c      = SWTextureProcess.GetColor_UV(texSrcWidth, texSrcHeight, texSrcColorBuffer, uv);
            Color   c2     = SWTextureProcess.GetColor_UV(texSrcWidth, texSrcHeight, texSrcColorBuffer, uv - dis.normalized * 3f / 512f);
            Vector2 newUV  = uv - dis.normalized * pixelBack / 512f;
            int     newI   = 0;
            int     newJ   = 0;

            SWTextureProcess.TexUV2Index(texSrcWidth, texSrcHeight, newUV, ref newI, ref newJ);
            if (!IsImage(c) && !IsImage(c2))
            {
//				int index = 0;
                while (pcg <= 1)
                {
                    Vector2 xuv    = uv + dis * pcg;
                    Color   xColor = SWTextureProcess.GetColor_UV(texSrcWidth, texSrcHeight, texSrcColorBuffer, xuv);
                    Vector2 xpos   = uv;
                    xpos -= center;
                    xpos  = matrix.MultiplyPoint(xpos);
                    xpos += center;
                    if (xColor.a > 0)
                    {
                        alpha = pcg;
                        float g = alpha;
                        float b = 0;
                        float a = GreenToAlpha(g);
                        texColorBuffer [(texSrcHeight - newJ - 1) * texSrcWidth + newI] = new Color(xpos.x, alpha, b, a);
                        break;
                    }


                    pcg += accuracyUnit;
                }
            }
        }
        protected override void ThreadMission_Pixel(int i, int j)
        {
            base.ThreadMission_Pixel(i, j);
            if (brush.size == 1)
            {
                if (i == centerX && j == centerY)
                {
                    SWTextureProcess.Brush_Apply(ref texColorBuffer [(texHeight - j - 1) * texWidth + i], brush, 0, i, j);
                }
                return;
            }

            Vector2 _uv   = SWTextureProcess.TexUV(texWidth, texHeight, i, j);
            float   dis   = Vector2.Distance(uv, _uv);
            float   isize = (float)brush.size / (float)SWWindowDrawMask.size;

            if (dis < isize)
            {
                float disPcg = dis / isize;
                SWTextureProcess.Brush_Apply(ref texColorBuffer [(texHeight - j - 1) * texWidth + i], brush, disPcg, i, j);
            }
        }
        void ThreadMission_Pixel2(int i, int j)
        {
            int     index = SWTextureProcess.XYtoIndex(texWidth, texHeight, i, j);
            Vector2 uv    = SWTextureProcess.TexUV(texWidth, texHeight, i, j);
            Color   c     = texColorBuffer [index];

            float dis   = offset.magnitude * threhold;
            float alpha = -1;

            for (float v = 0; v < 1; v += 0.01f)
            {
                Vector2 newUV    = uv + dirHor * v * dis;
                int     newIndex = SWTextureProcess.TexUV2Index(texWidth, texHeight, newUV);
                Color   newC     = texColorBuffer[newIndex];
                if (newC.a == 0)
                {
                    alpha = v;
                    break;
                }


                newUV    = uv - dirHor * v * dis;
                newIndex = SWTextureProcess.TexUV2Index(texWidth, texHeight, newUV);
                newC     = texColorBuffer[newIndex];
                if (newC.a == 0)
                {
                    alpha = v;
                    break;
                }
            }

//			if (alpha < 0.5f)
//				alpha = 0;

            if (alpha >= 0)
            {
                texColorBuffer [index] = new Color(c.r, c.g, c.b, c.a * alpha);
            }
        }
Пример #10
0
        protected override void ThreadMission_Pixel(int i, int j)
        {
            base.ThreadMission_Pixel(i, j);
            Vector2 uv = SWTextureProcess.TexUV(texWidth, texHeight, i, j);

            for (int k = 0; k < info.pts.Count - 1; k++)
            {
                var   p0  = info.pts [SWTextureProcess.LoopID(k - 1, info.pts.Count)];
                var   p1  = info.pts [SWTextureProcess.LoopID(k, info.pts.Count)];
                var   p2  = info.pts [SWTextureProcess.LoopID(k + 1, info.pts.Count)];
                float pcg = SWTextureProcess.PointOnSegPcgSign(uv, p1.uv, p2.uv);
                pcg = p1.pcg + (p2.pcg - p1.pcg) * pcg;
                float disSeg      = SWTextureProcess.Point2SegDis(uv, p1.uv, p2.uv);
                float disLineSign = SWTextureProcess.Point2LineDisSign(uv, p1.uv, p2.uv);
                disLineSign = -disLineSign;
                float g = (disLineSign / size + 1) * 0.5f;
                float b = 0;
                float a = GreenToAlpha(g);
                //first seg cap
                if (k == 0)
                {
                    if (disSeg <= size)
                    {
                        if (Vector2.Dot(uv - p2.pre, p1.uv - p2.pre) >= 0)
                        {
                            texColorBuffer [(texHeight - j - 1) * texWidth + i] = new Color(pcg, g, b, a);
                        }
                    }
                }
                //last seg cap
                else if (k == info.pts.Count - 2)
                {
                    if (disSeg <= size)
                    {
                        if (Vector2.Dot(uv - p1.after, p2.uv - p1.after) >= 0)
                        {
                            texColorBuffer [(texHeight - j - 1) * texWidth + i] = new Color(pcg, g, b, a);
                        }
                    }
                }
                else
                {
                    if (SWTextureProcess.PointInSeg(uv, p1.after, p2.pre, size))
                    {
                        texColorBuffer [(texHeight - j - 1) * texWidth + i] = new Color(pcg, g, b, a);
                    }
                }

                if (k == 0)
                {
                    if (disSeg <= size)
                    {
                        if (Vector2.Dot(uv - p1.uv, p2.uv - p1.uv) <= 0)
                        {
                            float disCenter = (uv - p1.uv).magnitude;
                            if (disCenter / size > 1 - threhold * 2)
                            {
                                a = 1 - (disCenter / size - (1 - threhold * 2)) / (threhold * 2);
                                texColorBuffer [(texHeight - j - 1) * texWidth + i] = new Color(
                                    texColorBuffer [(texHeight - j - 1) * texWidth + i].r,
                                    texColorBuffer [(texHeight - j - 1) * texWidth + i].g,
                                    texColorBuffer [(texHeight - j - 1) * texWidth + i].b,
                                    a
                                    );
                            }
                        }
                    }
                }
                if (k == info.pts.Count - 2 || info.pts.Count == 2)
                {
                    if (disSeg <= size)
                    {
                        if (Vector2.Dot(uv - p2.uv, p1.uv - p2.uv) <= 0)
                        {
                            float disCenter = (uv - p2.uv).magnitude;
                            if (disCenter / size > 1 - threhold * 2)
                            {
                                a = 1 - (disCenter / size - (1 - threhold * 2)) / (threhold * 2);
                                texColorBuffer [(texHeight - j - 1) * texWidth + i] = new Color(
                                    texColorBuffer [(texHeight - j - 1) * texWidth + i].r,
                                    texColorBuffer [(texHeight - j - 1) * texWidth + i].g,
                                    texColorBuffer [(texHeight - j - 1) * texWidth + i].b,
                                    a
                                    );
                            }
                        }
                    }
                }
            }
        }
        protected override void ThreadMission_Pixel(int i, int j)
        {
            base.ThreadMission_Pixel(i, j);
            Vector2 uv = SWTextureProcess.TexUV(texWidth, texHeight, i, j);

            for (int k = 0; k < info.pts.Count; k++)
            {
                if (k == 0)
                {
                    var   p0  = info.pts [SWTextureProcess.LoopID(k - 1, info.pts.Count)];
                    var   p1  = info.pts [SWTextureProcess.LoopID(k, info.pts.Count)];
                    var   p2  = info.pts [SWTextureProcess.LoopID(k + 1, info.pts.Count)];
                    float pcg = SWTextureProcess.PointOnSegPcgSign(uv, p1.after, p2.uv);


                    if (k == info.pts.Count - 1)
                    {
                        pcg = p1.pcg + (1 - p1.pcg) * pcg;
                    }
                    else
                    {
                        pcg = p1.pcg + (p2.pcg - p1.pcg) * pcg;
                    }
                    float innerDis = 0;
                    bool  seg      = SWTextureProcess.Point2SegOnlyDisSign(uv, p1.after, p2.pre, ref innerDis);
                    innerDis = -innerDis;

                    if (seg && (Mathf.Abs(innerDis) <= size))
                    {
                        float g = (innerDis / size + 1) * 0.5f;
                        float b = (pcg > 0.995f || pcg < 0.005f)? 1:0;
                        float a = GreenToAlpha(g);
                        texColorBuffer [(texHeight - j - 1) * texWidth + i] = new Color(pcg, g, b, a);
                    }
                }
                else
                {
                    var   p0  = info.pts [SWTextureProcess.LoopID(k - 1, info.pts.Count)];
                    var   p1  = info.pts [SWTextureProcess.LoopID(k, info.pts.Count)];
                    var   p2  = info.pts [SWTextureProcess.LoopID(k + 1, info.pts.Count)];
                    float pcg = SWTextureProcess.PointOnSegPcgSign(uv, p1.uv, p2.uv);


                    if (k == info.pts.Count - 1)
                    {
                        pcg = p1.pcg + (1 - p1.pcg) * pcg;
                    }
                    else
                    {
                        pcg = p1.pcg + (p2.pcg - p1.pcg) * pcg;
                    }
                    float innerDis = 0;
                    bool  seg      = SWTextureProcess.Point2SegOnlyDisSign(uv, p1.after, p2.pre, ref innerDis);
                    innerDis = -innerDis;

                    if (seg && (Mathf.Abs(innerDis) <= size))
                    {
                        float g = (innerDis / size + 1) * 0.5f;
                        float b = (pcg > 0.995f || pcg < 0.005f)? 1:0;
                        float a = GreenToAlpha(g);
                        texColorBuffer [(texHeight - j - 1) * texWidth + i] = new Color(pcg, g, b, a);
                    }
                }
            }
        }