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); } } }
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; } } } }
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); }
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); }
public static void ProcessMask_Invert(SWTexture2DEx tex) { SWUndo.RegisterCompleteObjectUndo(tex); SWTexThread_Invert t = new SWTexThread_Invert(tex, null); t.Process(null); }
public static void ProcessTexture_Clean(SWTexture2DEx tex) { SWUndo.RegisterCompleteObjectUndo(tex); Color[] colors = new Color[tex.width * tex.height]; tex.SetPixels(colors); tex.Apply(); }
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; } }
public SWTexThread_Tex(SWTexture2DEx _tex, SWBrush _brush) : base() { tex = _tex; texWidth = tex.width; texHeight = tex.height; brush = _brush; }
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); }
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; }
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); }
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); }
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); }
public override void AfterLoad() { base.AfterLoad(); if (GetChildTexture() != null) { texChildOrigin = GetChildTexture(); texChildResized = SWTextureProcess.TextureResize(texChildOrigin, 512, 512); } DrawNodeWindowEnd(); }
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); } }
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); } }
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); } }
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); }
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); } }
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); } } }
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(); }
/// <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); }
// 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); }
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); }
/// <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); } } }
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(); } } }
public TexThread_RemapLine(SWTexture2DEx _tex, SWBrush _brush) : base(_tex, _brush) { texColorBuffer = tex.GetPixels(); displayProgress = true; }
public SWTexThread_TexDrawPoint(SWTexture2DEx _tex, SWBrush _brush) : base(_tex, _brush) { texColorBuffer = tex.GetPixels(); }
public SWTexThread_RemapDir(SWTexture2DEx _tex, SWTexture2DEx _texSrc, SWBrush _brush) : base(_tex, _texSrc, _brush) { texColorBuffer = new Color[texSrcColorBuffer.Length]; displayProgress = true; }
public static void ProcessRemap_LineStitch(SWTexture2DEx tex, RemapLineInfo info, float size) { TexThread_RemapLineStitch t = new TexThread_RemapLineStitch(tex, null); t.Process(info, size); }