From 68b3ddaaa1adac4b8d82b0fd40f01d194a73f525 Mon Sep 17 00:00:00 2001 From: KirylTkachou Date: Tue, 23 Jul 2019 23:48:36 +0300 Subject: [PATCH] Fixed importing. --- .../MA_TextureAtlasserProExportWindow.cs | 142 +++++++++++++----- .../MA_Utilities/MeshUtils/MA_MeshUtils.cs | 9 +- .../TextureUtils/MA_TextureUtils.cs | 2 +- 3 files changed, 107 insertions(+), 46 deletions(-) diff --git a/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProExportWindow.cs b/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProExportWindow.cs index ecf7f76..48110a5 100644 --- a/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProExportWindow.cs +++ b/MA_ToolBox/MA_TextureAtlasserPro/Scripts/Editor/Windows/MA_TextureAtlasserProExportWindow.cs @@ -7,8 +7,18 @@ using MA_Editor; namespace MA_TextureAtlasserPro { - public class MA_TextureAtlasserProExportWindow : EditorWindow + public class MA_TextureAtlasserProExportWindow : EditorWindow { + private const int WindowHeight = 215; + + private enum ExportMode + { + None, + D3, + D2, + Meshes, + } + //Editor private static MA_TextureAtlasserProExportWindow thisWindow; public static MA_TextureAtlasserProWindow curWindow; @@ -16,7 +26,11 @@ namespace MA_TextureAtlasserPro //Data private static bool isLoaded = false; //Make sure we wait a frame at the start to setup and don't draw. + private ExportMode _selectedExportMode; + private bool _showAdvancedEditor; + private bool exportObjDefault = false; + private bool _replaceMeshes = false; private bool exportPngDefault = false; private bool exportSprite = false; private bool exportSliceSprite = false; @@ -26,8 +40,8 @@ namespace MA_TextureAtlasserPro { GetCurrentWindow(); - thisWindow.minSize = new Vector2(420, 200); - thisWindow.maxSize = new Vector2(420, 200); + thisWindow.minSize = new Vector2(420, WindowHeight); + thisWindow.maxSize = new Vector2(420, WindowHeight); thisWindow.titleContent.text = "MA_ExportTextureAtlas"; @@ -40,8 +54,8 @@ namespace MA_TextureAtlasserPro GetCurrentWindow(); - thisWindow.minSize = new Vector2(420, 200); - thisWindow.maxSize = new Vector2(420, 200); + thisWindow.minSize = new Vector2(420, WindowHeight); + thisWindow.maxSize = new Vector2(420, WindowHeight); thisWindow.titleContent.text = "MA_ExportTextureAtlas"; @@ -101,45 +115,13 @@ namespace MA_TextureAtlasserPro { //Export GUILayout.BeginVertical(); - GUILayout.BeginHorizontal(EditorStyles.helpBox); - if (GUILayout.Button("3D", GUILayout.ExpandWidth(false))) - { - exportObjDefault = true; - exportPngDefault = true; - exportSprite = false; - exportSliceSprite = false; - } - - if (GUILayout.Button("2D", GUILayout.ExpandWidth(false))) - { - exportObjDefault = false; - exportPngDefault = true; - exportSprite = true; - exportSliceSprite = true; - } - - GUILayout.EndHorizontal(); - - GUILayout.Label("Meshes:"); - exportObjDefault = GUILayout.Toggle(exportObjDefault, "OBJ default."); - - GUILayout.Label("Textures:"); - GUILayout.BeginHorizontal(); - exportPngDefault = GUILayout.Toggle(exportPngDefault, "PNG default."); - if(exportPngDefault) - { - exportSprite = GUILayout.Toggle(exportSprite, "Sprite."); - if (exportSprite) - { - exportSliceSprite = GUILayout.Toggle(exportSliceSprite, "Slice sprites."); - } - } - GUILayout.FlexibleSpace(); - GUILayout.EndHorizontal(); + DrawExportModeEditor(); + DrawAdvancedEditor(); GUILayout.BeginHorizontal(EditorStyles.helpBox); + GUI.enabled = _selectedExportMode != ExportMode.None; if (GUILayout.Button("Export", GUILayout.ExpandWidth(true), GUILayout.Height(37))) { if(exportObjDefault) @@ -147,6 +129,11 @@ namespace MA_TextureAtlasserPro MA_TextureAtlasserProUtils.ExportAtlasMeshesObj(curWindow.textureAtlas); } + if (_replaceMeshes) + { + + } + if(exportPngDefault) { if(exportSprite) @@ -160,6 +147,8 @@ namespace MA_TextureAtlasserPro } } + GUI.enabled = true; + GUILayout.EndHorizontal(); GUILayout.EndVertical(); } @@ -187,6 +176,79 @@ namespace MA_TextureAtlasserPro if(e.type == EventType.Repaint) isLoaded = true; } + + private void DrawExportModeEditor() + { + GUILayout.BeginHorizontal(EditorStyles.helpBox); + GUILayout.FlexibleSpace(); + var value = GUILayout.Toggle(_selectedExportMode == ExportMode.D3, "3D", EditorStyles.miniButtonLeft, + GUILayout.ExpandWidth(false)); + if (value && _selectedExportMode != ExportMode.D3) + { + _selectedExportMode = ExportMode.D3; + exportObjDefault = true; + _replaceMeshes = false; + exportPngDefault = true; + exportSprite = false; + exportSliceSprite = false; + } + value = GUILayout.Toggle(_selectedExportMode == ExportMode.D2, "2D", EditorStyles.miniButtonMid, + GUILayout.ExpandWidth(false)); + if (value && _selectedExportMode != ExportMode.D2) + { + _selectedExportMode = ExportMode.D2; + exportObjDefault = false; + _replaceMeshes = false; + exportPngDefault = true; + exportSprite = true; + exportSliceSprite = true; + } + value = GUILayout.Toggle(_selectedExportMode == ExportMode.Meshes, "Replace source meshes", EditorStyles.miniButtonRight, + GUILayout.ExpandWidth(false)); + if (value && _selectedExportMode != ExportMode.Meshes) + { + _selectedExportMode = ExportMode.Meshes; + exportObjDefault = false; + _replaceMeshes = true; + exportPngDefault = true; + exportSprite = false; + exportSliceSprite = false; + } + GUILayout.FlexibleSpace(); + GUILayout.EndHorizontal(); + } + + private void DrawAdvancedEditor() + { + EditorGUILayout.BeginVertical(EditorStyles.helpBox); + _showAdvancedEditor = EditorGUILayout.Foldout(_showAdvancedEditor, "Advanced editor"); + if (!_showAdvancedEditor) + { + EditorGUILayout.EndVertical(); + return; + } + + GUILayout.Label("Meshes:", EditorStyles.miniBoldLabel); + EditorGUILayout.BeginHorizontal(); + exportObjDefault = GUILayout.Toggle(exportObjDefault, "OBJ default."); + _replaceMeshes = GUILayout.Toggle(_replaceMeshes, "Replace meshes"); + EditorGUILayout.EndHorizontal(); + + GUILayout.Label("Textures:", EditorStyles.miniBoldLabel); + GUILayout.BeginHorizontal(); + exportPngDefault = GUILayout.Toggle(exportPngDefault, "PNG default."); + if(exportPngDefault) + { + exportSprite = GUILayout.Toggle(exportSprite, "Sprite."); + if (exportSprite) + { + exportSliceSprite = GUILayout.Toggle(exportSliceSprite, "Slice sprites."); + } + } + GUILayout.FlexibleSpace(); + GUILayout.EndHorizontal(); + EditorGUILayout.EndVertical(); + } } } #endif \ No newline at end of file diff --git a/MA_ToolBox/MA_Utilities/MeshUtils/MA_MeshUtils.cs b/MA_ToolBox/MA_Utilities/MeshUtils/MA_MeshUtils.cs index 596d05f..58fb8db 100644 --- a/MA_ToolBox/MA_Utilities/MeshUtils/MA_MeshUtils.cs +++ b/MA_ToolBox/MA_Utilities/MeshUtils/MA_MeshUtils.cs @@ -97,14 +97,14 @@ namespace MA_Mesh { if(flipY) { - //Debug.Log("01" + uvs[i].x); - uvs[i] = new Vector2((uvs[i].x / atlasSize.x * textureRect.width) + (1 / atlasSize.x * textureRect.x), (uvs[i].y / atlasSize.y * textureRect.height) + (1 / atlasSize.y * (atlasSize.y - textureRect.height - textureRect.y))); - //Debug.Log("02" + uvs[i].x); + uvs[i] = new Vector2((uvs[i].x / atlasSize.x * textureRect.width) + (1 / atlasSize.x * textureRect.x), + (uvs[i].y / atlasSize.y * textureRect.height) + (1 / atlasSize.y * (atlasSize.y - textureRect.height - textureRect.y))); } else { //Debug.Log("01" + uvs[i].x); - uvs[i] = new Vector2((uvs[i].x / atlasSize.x * textureRect.width) + (1 / atlasSize.x * textureRect.x), (uvs[i].y / atlasSize.y * textureRect.height) + (1 / atlasSize.y * textureRect.y)); + uvs[i] = new Vector2((uvs[i].x / atlasSize.x * textureRect.width) + (1 / atlasSize.x * textureRect.x), + (uvs[i].y / atlasSize.y * textureRect.height) + (1 / atlasSize.y * textureRect.y)); //Debug.Log("02" + uvs[i].x); } } @@ -181,7 +181,6 @@ namespace MA_Mesh using (StreamWriter sw = new StreamWriter(savePath + filename + ".obj")) { sw.Write(MeshToString(mesh)); - Debug.Log(savePath + filename); } } //End diff --git a/MA_ToolBox/MA_Utilities/TextureUtils/MA_TextureUtils.cs b/MA_ToolBox/MA_Utilities/TextureUtils/MA_TextureUtils.cs index e344c1e..38641df 100644 --- a/MA_ToolBox/MA_Utilities/TextureUtils/MA_TextureUtils.cs +++ b/MA_ToolBox/MA_Utilities/TextureUtils/MA_TextureUtils.cs @@ -191,7 +191,7 @@ namespace MA_Texture //Y is 'flipped' because textures are made from left to right, bottom to top. We want to draw from left to right and top to bottom. for (int y = combineTexture.height; y > 0; y--) { - texture.SetPixel(x + offsetX, texture.height - y - offsetY, combineTexture.GetPixel(x, texture.height - y)); + texture.SetPixel(x + offsetX, y + (texture.height - offsetY - combineTexture.height), combineTexture.GetPixel(x, y)); } } else