コード例 #1
0
ファイル: SWNodeRemap.cs プロジェクト: Hengle/ShaderWeaver
        public override void AfterLoad()
        {
            base.AfterLoad();
            if (GetChildTexture() != null)
            {
                texChildOrigin  = GetChildTexture();
                texChildResized = SWTextureProcess.TextureResize(texChildOrigin, data.resolution, data.resolution);
            }
            if (textureEx != null)
            {
                if (data.resolution != textureEx.width)
                {
                    data.reso = (SWTexResolution)SWDataNode.resoList.IndexOf(textureEx.width);
                }
            }


            if (data.rd != null && data.rd.l != null && data.rd.l.pts != null)
            {
                for (int i = 0; i < data.rd.l.pts.Count; i++)
                {
                    var           pData = data.rd.l.pts [i];
                    RemapWayPoint pt    = new RemapWayPoint();
                    pt.uv       = pData.uv;
                    pt.matArrow = new Material(SWEditorUI.GetShader("RectTRS"));
                    lineInfo.pts.Add(pt);
                }
            }
        }
コード例 #2
0
        public virtual void AfterLoad()
        {
            if (!string.IsNullOrEmpty(data.textureGUID))
            {
                texture = SWEditorTools.GUIDToObject <Texture2D>(data.textureGUID);
            }
            if (!string.IsNullOrEmpty(data.textureGUIDGray))
            {
                textureGray = SWEditorTools.GUIDToObject <Texture2D>(data.textureGUIDGray);
            }
            if (!string.IsNullOrEmpty(data.textureExGUID))
            {
                var tex = SWEditorTools.GUIDToObject <Texture2D>(data.textureExGUID);
                textureEx = new SWTexture2DEx(tex);
            }

            if (!string.IsNullOrEmpty(data.spriteGUID))
            {
                string   path = AssetDatabase.GUIDToAssetPath(data.spriteGUID);
                Object[] objs = AssetDatabase.LoadAllAssetsAtPath(path);
                foreach (var item in objs)
                {
                    if (item is Sprite && item.name == data.spriteName)
                    {
                        //Debug.Log ("Found");
                        sprite = (Sprite)item;
                    }
                }
            }
        }
コード例 #3
0
        public static void ProcessMask_DrawLine(SWTexture2DEx tex, Vector2 _startUV, Vector2 _endUV, SWBrush brush)
        {
            SWUndo.RegisterCompleteObjectUndo(tex);
            SWTexThread_TexDrawLine t = new SWTexThread_TexDrawLine(tex, brush);

            t.Process(_startUV, _endUV);
        }
コード例 #4
0
        public static void ProcessMask_Dropper(SWTexture2DEx tex, SWTexture2DEx texSource, Vector2 _uv, SWBrush _brush, float tolerance)
        {
            SWUndo.RegisterCompleteObjectUndo(tex);
            SWTexThread_ColorRange t = new SWTexThread_ColorRange(tex, texSource, _brush);

            t.Process(_uv, tolerance);
        }
コード例 #5
0
        public static void ProcessMask_Invert(SWTexture2DEx tex)
        {
            SWUndo.RegisterCompleteObjectUndo(tex);
            SWTexThread_Invert t = new SWTexThread_Invert(tex, null);

            t.Process(null);
        }
コード例 #6
0
 public static void ProcessTexture_Clean(SWTexture2DEx tex)
 {
     SWUndo.RegisterCompleteObjectUndo(tex);
     Color[] colors = new Color[tex.width * tex.height];
     tex.SetPixels(colors);
     tex.Apply();
 }
コード例 #7
0
        protected void ApplyWand_Dropper()
        {
            if (SWCommon.GetMouseDown(0, false) && al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY)))
            {
                CalUV();
                var firstNode = LayerMask_WandDropperNode(node);
                if (firstNode.texture == null)
                {
                    return;
                }

                //	SWTexture2DEx _tex = SWTextureProcess.TextureResize (firstNode.texture, texWidth, texHeight);
                SWTexture2DEx _tex = SWTextureProcess.TextureResizeTRS(firstNode.texture, texWidth, texHeight, firstNode.data.effectData);

                if (brush.mode == SWBrushMode.wand)
                {
                    SWTextureProcess.ProcessMask_Wand(node.texMask, _tex, uv, brush, tolerance);
                }
                else if (brush.mode == SWBrushMode.dropper)
                {
                    SWTextureProcess.ProcessMask_Dropper(node.texMask, _tex, uv, brush, tolerance);
                }
                lastUV          = uv;
                node.data.dirty = true;
                hasFirstPoint   = false;
            }
        }
コード例 #8
0
        public SWTexThread_Tex(SWTexture2DEx _tex, SWBrush _brush) : base()
        {
            tex       = _tex;
            texWidth  = tex.width;
            texHeight = tex.height;

            brush = _brush;
        }
コード例 #9
0
        public static void ProcessMask_Wand(SWTexture2DEx tex, SWTexture2DEx texSource, Vector2 _uv, SWBrush _brush, float tolerance)
        {
            SWUndo.RegisterCompleteObjectUndo(tex);
            texSource.filterMode = FilterMode.Point;
            SWTexThread_Wand t = new SWTexThread_Wand(tex, texSource, _brush);

            t.Process(_uv, tolerance);
        }
コード例 #10
0
        public SWTexThread_SrcTex(SWTexture2DEx _tex, SWTexture2DEx _texSrc, SWBrush _brush) : base(_tex, _brush)
        {
            texColorBuffer = _tex.GetPixels();

            texSrc            = _texSrc;
            texSrcColorBuffer = _texSrc.GetPixels();
            texSrcWidth       = texSrc.width;
            texSrcHeight      = texSrc.height;
        }
コード例 #11
0
        public static SWTexture2DEx TextureResize(Texture2D tex, int newWidth, int newHeight)
        {
            SWTexture2DEx newTex = SWCommon.TextureCreate(newWidth, newHeight, TextureFormat.ARGB32);
            var           colors = TextureResizeBase(tex.GetPixels(), tex.width, tex.height, newWidth, newHeight);

            newTex.SetPixels(colors);
            newTex.Apply();
            return(newTex);
        }
コード例 #12
0
ファイル: SWCommon.cs プロジェクト: Hengle/ShaderWeaver
        public static SWTexture2DEx Texture2dResave(SWTexture2DEx t, string adbPath)
        {
            var    bs       = t.EncodeToPNG();
            string path     = AssetDBPath2Path(adbPath);
            string fullPath = Path2FullPath(path);

            File.WriteAllBytes(fullPath, bs);
            return(t);
        }
コード例 #13
0
        public static void ProcessMask_DrawPoint(SWTexture2DEx tex, Vector2 _uv, SWBrush _brush)
        {
            colorStartBuffer = tex.GetPixels();
            brushBuffer      = new float[tex.width, tex.height];

            SWUndo.RegisterCompleteObjectUndo(tex);
            SWTexThread_TexDrawPoint t = new SWTexThread_TexDrawPoint(tex, _brush);

            t.Process(_uv);
        }
コード例 #14
0
 public override void AfterLoad()
 {
     base.AfterLoad();
     if (GetChildTexture() != null)
     {
         texChildOrigin  = GetChildTexture();
         texChildResized = SWTextureProcess.TextureResize(texChildOrigin, 512, 512);
     }
     DrawNodeWindowEnd();
 }
コード例 #15
0
 public static void ProcessRemap_Line(SWTexture2DEx tex, RemapLineInfo info, float size)
 {
     SWUndo.RegisterCompleteObjectUndo(tex);
     if (info.stitch)
     {
         ProcessRemap_LineStitch(tex, info, size);
     }
     else
     {
         ProcessRemap_LineNormal(tex, info, size);
     }
 }
コード例 #16
0
 public static void ProcessRemap_Line(SWTexture2DEx tex, RemapLineInfo info, float size)
 {
     SWUndo.RegisterCompleteObjectUndo(tex);
     //if (info.stitch)
     if (SWWindowDrawRemap.Instance.rData.l.st)
     {
         ProcessRemap_LineStitch(tex, info, size);
     }
     else
     {
         ProcessRemap_LineNormal(tex, info, size);
     }
 }
コード例 #17
0
        public static void ProcessRemap_Dir(SWTexture2DEx tex, SWTexture2DEx texSource, Vector2 offset, bool precise, int _pixelBack)
        {
            SWUndo.RegisterCompleteObjectUndo(tex);
            SWTexThread_RemapDir d = new SWTexThread_RemapDir(tex, texSource, null);

            if (precise)
            {
                d.Process(offset, 0.01f, _pixelBack);
            }
            else
            {
                d.Process(offset, 0.1f, _pixelBack);
            }
        }
コード例 #18
0
ファイル: SWCommon.cs プロジェクト: Hengle/ShaderWeaver
        public static SWTexture2DEx SaveReloadTexture2d(SWTexture2DEx t, string path, bool alphaIsTransparency = true)
        {
            var    bs       = t.EncodeToPNG();
            string fullPath = Path2FullPath(path);
            string adbPath  = Path2AssetDBPath(path);

            File.WriteAllBytes(fullPath, bs);
            AssetDatabase.Refresh();
            TextureReImport(adbPath, alphaIsTransparency);
            var tex = AssetDatabase.LoadAssetAtPath <Texture2D> (adbPath);

            t.Texture = tex;
            return(t);
        }
コード例 #19
0
 public override void Init(SWDataNode _data, SWWindowMain _window)
 {
     styleID = 1;
     base.Init(_data, _window);
     data.outputType.Add(SWDataType._Color);
     data.outputType.Add(SWDataType._UV);
     data.outputType.Add(SWDataType._Alpha);
     data.inputType.Add(SWDataType._Color);
     data.inputType.Add(SWDataType._UV);
     data.inputType.Add(SWDataType._Alpha);
     if (texMask.IsNull)
     {
         texMask = SWCommon.TextureCreate(512, 512, TextureFormat.ARGB32);
     }
 }
コード例 #20
0
 public void GrayApply()
 {
     if (data.useGray)
     {
         data.dirty = true;
         if (textureGray != null)
         {
             texMask = SWTextureProcess.TextureResize(textureGray, 512, 512);
         }
         else
         {
             texMask = SWCommon.TextureCreate(512, 512, TextureFormat.ARGB32);
         }
     }
 }
コード例 #21
0
        void DrawWinCustom(int id)
        {
            base.DrawNodeWindow(id);
            SelectTextureGray();

            if (GUI.Button(rectBotButton, "Switch", SWEditorUI.MainSkin.button))
            {
                data.useGray = !data.useGray;
                if (!data.useGray)
                {
                    texMask = SWCommon.TextureCreate(512, 512, TextureFormat.ARGB32);
                }
            }
            DrawNodeWindowEnd();
        }
コード例 #22
0
        /// <summary>
        /// Resize for editing
        /// </summary>
        public static bool TextureResize(SWTexture2DEx tex, int size)
        {
            if (size != tex.Texture.width)
            {
                var cs   = tex.Texture.GetPixels();
                var oldW = tex.width;
                var oldH = tex.height;

                var colorsNew = TextureResizeBase(cs, oldW, oldH, size, size);
                tex.Texture.Resize(size, size);
                tex.SetPixels(colorsNew);
                tex.Apply();
                return(true);
            }
            return(false);
        }
コード例 #23
0
ファイル: SWCommon.cs プロジェクト: Hengle/ShaderWeaver
//		public static SWTexture2DEx TextureCopy(SWTexture2DEx f)
//		{
//			SWTexture2DEx t = TextureCreate (f.width, f.height, f.format, f.alphaIsTransparency);
//			var colors = f.GetPixels ();
//			for(int i =0;i<colors.Length;i++) {
//				colors[i].a *= 0.6f;
//			}
//			t.SetPixels (colors);
//			t.Apply ();
//			return t;
//		}

        public static SWTexture2DEx TextureCreate(int w, int h, TextureFormat format)
        {
            SWTexture2DEx t = new SWTexture2DEx(w, h, format, false, false);

            t.filterMode = FilterMode.Trilinear;

            var colors = t.GetPixels();

            for (int i = 0; i < colors.Length; i++)
            {
                colors [i] = new Color(0, 0, 0, 0);
            }
            t.SetPixels(colors);
            t.Apply();
            return(t);
        }
コード例 #24
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);
        }
コード例 #25
0
 /// <summary>
 /// Apply just before Update
 /// </summary>
 public void GrayApply()
 {
     if (data.useGray)
     {
         data.dirty = true;
         if (textureGray != null)
         {
             if (textureGray.width == textureGray.height && SWDataNode.resoList.Contains(textureGray.width))
             {
                 texMask = new SWTexture2DEx(textureGray);
             }
             else
             {
                 texMask = SWTextureProcess.TextureResize(textureGray, SWGlobalSettings.TexDefaultSize, SWGlobalSettings.TexDefaultSize);
             }
         }
         else
         {
             texMask = SWCommon.TextureCreate(SWGlobalSettings.TexDefaultSize, SWGlobalSettings.TexDefaultSize, TextureFormat.ARGB32);
         }
     }
 }
コード例 #26
0
 void Op()
 {
     //			Debug.Log (Event.current.type);
     brush.mode = (SWBrushMode)slotBox_left.selection;
     if (!al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY)))
     {
         return;
     }
     if (Event.current.control || Event.current.alt)
     {
         return;
     }
     if (!drawRect.Contains(mousePos))
     {
         return;
     }
     if (brush.mode == SWBrushMode.dropper)
     {
         if (SWWindowMain.Instance.nRoot.texture != null &&
             SWCommon.GetMouseDown(0, false) && al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY)))
         {
             CalUV();
             SWTexture2DEx _tex = SWTextureProcess.TextureResize(SWWindowMain.Instance.nRoot.texture, texWidth, texHeight);
             SWTextureProcess.ProcessMask_Dropper(node.texMask, _tex, uv, brush, tolerance);
             lastUV          = uv;
             node.data.dirty = true;
             hasFirstPoint   = false;
         }
     }
     else if (brush.mode == SWBrushMode.wand)
     {
         if (SWWindowMain.Instance.nRoot.texture != null &&
             SWCommon.GetMouseDown(0, false) && al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY)))
         {
             CalUV();
             SWTexture2DEx _tex = SWTextureProcess.TextureResize(SWWindowMain.Instance.nRoot.texture, texWidth, texHeight);
             SWTextureProcess.ProcessMask_Wand(node.texMask, _tex, uv, brush, tolerance);
             lastUV          = uv;
             node.data.dirty = true;
             hasFirstPoint   = false;
         }
     }
     else if (brush.mode == SWBrushMode.brush || brush.mode == SWBrushMode.erase)
     {
         if (SWCommon.GetMouseDown(0, false) && al_rectMain.Contains(mousePosOut + new Vector2(0, al_startY)))
         {
             if (Event.current.shift && hasFirstPoint)
             {
                 GoLine();
             }
             else
             {
                 GoPoint();
             }
         }
         else if (SWCommon.GetMouse(0))
         {
             GoLine();
         }
     }
 }
コード例 #27
0
 public TexThread_RemapLine(SWTexture2DEx _tex, SWBrush _brush) : base(_tex, _brush)
 {
     texColorBuffer  = tex.GetPixels();
     displayProgress = true;
 }
コード例 #28
0
 public SWTexThread_TexDrawPoint(SWTexture2DEx _tex, SWBrush _brush) : base(_tex, _brush)
 {
     texColorBuffer = tex.GetPixels();
 }
コード例 #29
0
 public SWTexThread_RemapDir(SWTexture2DEx _tex, SWTexture2DEx _texSrc, SWBrush _brush) : base(_tex, _texSrc, _brush)
 {
     texColorBuffer  = new Color[texSrcColorBuffer.Length];
     displayProgress = true;
 }
コード例 #30
0
        public static void ProcessRemap_LineStitch(SWTexture2DEx tex, RemapLineInfo info, float size)
        {
            TexThread_RemapLineStitch t = new TexThread_RemapLineStitch(tex, null);

            t.Process(info, size);
        }