Fixed importing.

This commit is contained in:
KirylTkachou 2019-07-23 23:48:36 +03:00
parent 9d53f74c4b
commit 68b3ddaaa1
3 changed files with 107 additions and 46 deletions

View File

@ -9,6 +9,16 @@ 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 //Editor
private static MA_TextureAtlasserProExportWindow thisWindow; private static MA_TextureAtlasserProExportWindow thisWindow;
public static MA_TextureAtlasserProWindow curWindow; public static MA_TextureAtlasserProWindow curWindow;
@ -16,7 +26,11 @@ namespace MA_TextureAtlasserPro
//Data //Data
private static bool isLoaded = false; //Make sure we wait a frame at the start to setup and don't draw. 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 exportObjDefault = false;
private bool _replaceMeshes = false;
private bool exportPngDefault = false; private bool exportPngDefault = false;
private bool exportSprite = false; private bool exportSprite = false;
private bool exportSliceSprite = false; private bool exportSliceSprite = false;
@ -26,8 +40,8 @@ namespace MA_TextureAtlasserPro
{ {
GetCurrentWindow(); GetCurrentWindow();
thisWindow.minSize = new Vector2(420, 200); thisWindow.minSize = new Vector2(420, WindowHeight);
thisWindow.maxSize = new Vector2(420, 200); thisWindow.maxSize = new Vector2(420, WindowHeight);
thisWindow.titleContent.text = "MA_ExportTextureAtlas"; thisWindow.titleContent.text = "MA_ExportTextureAtlas";
@ -40,8 +54,8 @@ namespace MA_TextureAtlasserPro
GetCurrentWindow(); GetCurrentWindow();
thisWindow.minSize = new Vector2(420, 200); thisWindow.minSize = new Vector2(420, WindowHeight);
thisWindow.maxSize = new Vector2(420, 200); thisWindow.maxSize = new Vector2(420, WindowHeight);
thisWindow.titleContent.text = "MA_ExportTextureAtlas"; thisWindow.titleContent.text = "MA_ExportTextureAtlas";
@ -101,45 +115,13 @@ namespace MA_TextureAtlasserPro
{ {
//Export //Export
GUILayout.BeginVertical(); GUILayout.BeginVertical();
GUILayout.BeginHorizontal(EditorStyles.helpBox);
if (GUILayout.Button("3D", GUILayout.ExpandWidth(false))) DrawExportModeEditor();
{ DrawAdvancedEditor();
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();
GUILayout.BeginHorizontal(EditorStyles.helpBox); GUILayout.BeginHorizontal(EditorStyles.helpBox);
GUI.enabled = _selectedExportMode != ExportMode.None;
if (GUILayout.Button("Export", GUILayout.ExpandWidth(true), GUILayout.Height(37))) if (GUILayout.Button("Export", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
{ {
if(exportObjDefault) if(exportObjDefault)
@ -147,6 +129,11 @@ namespace MA_TextureAtlasserPro
MA_TextureAtlasserProUtils.ExportAtlasMeshesObj(curWindow.textureAtlas); MA_TextureAtlasserProUtils.ExportAtlasMeshesObj(curWindow.textureAtlas);
} }
if (_replaceMeshes)
{
}
if(exportPngDefault) if(exportPngDefault)
{ {
if(exportSprite) if(exportSprite)
@ -160,6 +147,8 @@ namespace MA_TextureAtlasserPro
} }
} }
GUI.enabled = true;
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
GUILayout.EndVertical(); GUILayout.EndVertical();
} }
@ -187,6 +176,79 @@ namespace MA_TextureAtlasserPro
if(e.type == EventType.Repaint) if(e.type == EventType.Repaint)
isLoaded = true; 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 #endif

View File

@ -97,14 +97,14 @@ namespace MA_Mesh
{ {
if(flipY) 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] = 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))); (uvs[i].y / atlasSize.y * textureRect.height) + (1 / atlasSize.y * (atlasSize.y - textureRect.height - textureRect.y)));
//Debug.Log("02" + uvs[i].x);
} }
else else
{ {
//Debug.Log("01" + uvs[i].x); //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); //Debug.Log("02" + uvs[i].x);
} }
} }
@ -181,7 +181,6 @@ namespace MA_Mesh
using (StreamWriter sw = new StreamWriter(savePath + filename + ".obj")) using (StreamWriter sw = new StreamWriter(savePath + filename + ".obj"))
{ {
sw.Write(MeshToString(mesh)); sw.Write(MeshToString(mesh));
Debug.Log(savePath + filename);
} }
} }
//End //End

View File

@ -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. //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--) 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 else