Model groups.

Added model group support, you can now have multiple meshes in one export.
Removed OBJ and mesh replace export options.
Mesh replace didn't work, might get added again in the feature.
OBJ needs to be rewritten as well to support the multiple meshes, and Unity now has model export options in engine.
Version 1.8.0+ is now only supports Unity2018.3+.
This commit is contained in:
max 2020-04-20 22:30:08 +02:00
parent 3532465e69
commit 8ff2db7e87
20 changed files with 469 additions and 453 deletions

View File

@ -0,0 +1,15 @@
#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MA_TextureAtlasserPro
{
[System.Serializable]
public class MA_ModelGroup
{
public string name = "Model";
public List<Mesh> meshes = new List<Mesh>();
}
}
#endif

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1f74ddc7d8c9c30429ec163b4fc801c4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -15,7 +15,7 @@ namespace MA_TextureAtlasserPro
public List<MA_TextureAtlasserProQuad> textureQuads;
public MA_TextureAtlasserProQuad selectedTextureQuad;
private Rect editorWorkRect;
public bool showTextures = false;
public bool showTextures = true;
public MA_TextureAtlasserProExportSettings exportSettings;
//Data

View File

@ -50,9 +50,7 @@ namespace MA_TextureAtlasserPro
public enum ModelFormat
{
None,
UnityMeshPrefab,
ReplaceMesh,
Obj
UnityMeshPrefab
}
public enum TextureFormat

View File

@ -11,22 +11,28 @@ namespace MA_TextureAtlasserPro
public class MA_TextureAtlasserProQuad : ScriptableObject
{
//Editor
[HideInInspector]
public bool isSelected = false; //Is this thing selected
public Rect rect; //The internal rect
[HideInInspector]
public Rect guiRect; //The visual clamped and snapped rect
[HideInInspector]
public bool debugMode = false; //Are we debugging, for showing some other things (like handles)
private bool isDragging = false; //Are we editing the pos or size
private bool isDraggingRectHeigt = false;
[HideInInspector]
public Rect dragRectHeight;
private bool isDraggingRectWidth = false;
[HideInInspector]
public Rect dragRectWidth;
private bool isDraggingRectPos = false;
[HideInInspector]
public Rect dragRectPos;
//Data
public List<MA_TextureGroup> textureGroups;
public List<Mesh> meshes;
public List<MA_ModelGroup> modelGroups;
public void UpdateTextureQuad(Event e, Rect editorViewRect, Rect editorWorkRect, Vector2 zoomCoordsOrigin, bool useEvents, bool showTexture)
{

View File

@ -23,7 +23,6 @@ namespace MA_TextureAtlasserPro
public KeyCode zoomOutHotKey = KeyCode.Minus;
[Header("Duplication:")]
public bool copySelectedQuadData = true;
public string duplicatedQuadNamePrefix = "new ";
[Header("Selection")]

View File

@ -5,6 +5,8 @@ using UnityEngine;
using UnityEditor;
using MA_Mesh;
using MA_Texture;
using MA_Toolbox.Utils.Editor;
using MA_Toolbox.Utils;
namespace MA_TextureAtlasserPro
{
@ -259,25 +261,16 @@ namespace MA_TextureAtlasserPro
}
}
public static void DuplicateTextureQuad(MA_TextureAtlasserProAtlas atlas, bool focus = true, bool copyData = false, string namePrefix = "new ")
public static void DuplicateTextureQuad(MA_TextureAtlasserProAtlas atlas, bool focus = true, string namePrefix = "new ")
{
if (atlas != null && atlas.selectedTextureQuad != null)
{
MA_TextureAtlasserProQuad q = CreateTextureQuad(atlas, namePrefix + atlas.selectedTextureQuad.name, atlas.selectedTextureQuad.rect, false);
//MA_TextureAtlasserProQuad q = CreateTextureQuad(atlas, namePrefix + atlas.selectedTextureQuad.name, atlas.selectedTextureQuad.rect, false);
MA_TextureAtlasserProQuad q = Object.Instantiate(atlas.selectedTextureQuad);
q.name = string.Format("{0}{1}", namePrefix, atlas.selectedTextureQuad.name);
atlas.textureQuads.Add(q);
if (copyData)
{
q.meshes = new List<Mesh>();
for (int i = 0; i < atlas.selectedTextureQuad.meshes.Count; i++)
{
q.meshes.Add(atlas.selectedTextureQuad.meshes[i]);
}
for (int i = 0; i < atlas.selectedTextureQuad.textureGroups.Count; i++)
{
q.textureGroups[i].texture = atlas.selectedTextureQuad.textureGroups[i].texture;
}
}
AssetDatabase.AddObjectToAsset(q, atlas);
if (focus)
{
@ -365,6 +358,12 @@ namespace MA_TextureAtlasserPro
if (!AssetDatabase.IsValidFolder(folderPath))
{
string parentPath = folderPath.Substring(0, folderPath.LastIndexOf('/'));
if(!AssetDatabase.IsValidFolder(parentPath))
{
CreateFolder(parentPath);
}
string folderName = folderPath.Substring(folderPath.LastIndexOf('/') + 1);
AssetDatabase.CreateFolder(parentPath, folderName);
@ -387,19 +386,16 @@ namespace MA_TextureAtlasserPro
}
#region Export
public static string[] ExportAtlasModels(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string material = null, string savePath = EXPORT_ASSET_PATH)
public static string[] ExportAtlasModels(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string materialPath = null, string savePath = EXPORT_ASSET_PATH)
{
switch (modelExportSettings.modelFormat)
{
case ModelFormat.None:
break;
case ModelFormat.ReplaceMesh:
ReplaceAtlasMesh(atlas, modelExportSettings, savePath: savePath);
break;
case ModelFormat.UnityMeshPrefab:
return ExportAtlasUnityMeshPrefab(atlas, modelExportSettings, material: material, savePath: savePath);
case ModelFormat.Obj:
return ExportAtlasObj(atlas, modelExportSettings, savePath: savePath);
return ExportAtlasUnityMeshPrefab(atlas, modelExportSettings, materialPath: materialPath, savePath: savePath);
//case ModelFormat.Obj:
// return ExportAtlasObj(atlas, modelExportSettings, savePath: savePath);
default:
break;
}
@ -407,103 +403,78 @@ namespace MA_TextureAtlasserPro
return null;
}
private static void ReplaceAtlasMesh(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string savePath = EXPORT_ASSET_PATH)
private static string[] ExportAtlasUnityMeshPrefab(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string materialPath = null, string savePath = EXPORT_ASSET_PATH)
{
if (atlas == null || atlas.textureQuads == null)
return;
var quads = atlas.textureQuads;
for (var index = 0; index < quads.Count; index++)
{
var quad = quads[index];
if (quad.meshes == null)
continue;
var meshes = quad.meshes;
for (var meshIndex = 0; meshIndex < quad.meshes.Count; meshIndex++)
{
if (meshes[meshIndex] == null)
continue;
MA_MeshUtils.MA_UVReMap(meshes[meshIndex], atlas.textureAtlasSize, quad.guiRect, modelExportSettings.uvChannel, modelExportSettings.uvFlipY, modelExportSettings.uvWrap);
EditorUtility.SetDirty(meshes[meshIndex]);
}
}
AssetDatabase.SaveAssets();
}
private static string[] ExportAtlasUnityMeshPrefab(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string material = null, string savePath = EXPORT_ASSET_PATH)
{
if (atlas == null || atlas.textureQuads == null)
return null;
}
List<string> assetPaths = new List<string>();
foreach (MA_TextureAtlasserProQuad quad in atlas.textureQuads)
{
//Export Mesh
if (quad.meshes != null)
{
for (int m = 0; m < quad.meshes.Count; m++)
{
if (quad.meshes[m] != null)
{
//Create new mesh
Mesh newMesh = new Mesh();
//Duplicate it from the current one
newMesh = MA_MeshUtils.MA_DuplicateMesh(quad.meshes[m]);
//Remap UV's
newMesh = MA_MeshUtils.MA_UVReMap(newMesh, atlas.textureAtlasSize, quad.guiRect, modelExportSettings.uvChannel, modelExportSettings.uvFlipY, modelExportSettings.uvWrap);
//Set name
string meshName = string.IsNullOrEmpty(quad.name) ? "" : quad.name + "-";
meshName += quad.meshes[m].name;
int n = m + 1;
meshName += "_" + n.ToString("#000");
newMesh.name = meshName;
//Save it
string asset = MA_MeshUtils.MA_SaveMeshPrefab(newMesh, meshName, savePath, materialPath: material);
assetPaths.Add(asset);
}
}
}
}
return assetPaths.ToArray();
}
private static string[] ExportAtlasObj(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string savePath = EXPORT_ASSET_PATH)
{
if (atlas == null || atlas.textureQuads == null)
return null;
List<string> assetPaths = new List<string>();
//Directories.
string savePathPrefab = savePath + atlas.name + "/";
string savePathMeshes = savePathPrefab + "Meshes/";
CreateFolder(savePathPrefab);
CreateFolder(savePathMeshes);
foreach (MA_TextureAtlasserProQuad quad in atlas.textureQuads)
{
//Export Mesh
if (quad.meshes != null)
foreach (MA_ModelGroup mg in quad.modelGroups)
{
for (int m = 0; m < quad.meshes.Count; m++)
//Validate name.
if (string.IsNullOrEmpty(mg.name) || string.IsNullOrWhiteSpace(mg.name))
{
if (quad.meshes[m] != null)
{
//Create new mesh
Mesh newMesh = new Mesh();
//Duplicate it from the current one
newMesh = MA_MeshUtils.MA_DuplicateMesh(quad.meshes[m]);
//Remap UV's
newMesh = MA_MeshUtils.MA_UVReMap(newMesh, atlas.textureAtlasSize, quad.guiRect, modelExportSettings.uvChannel, modelExportSettings.uvFlipY, modelExportSettings.uvWrap);
//Save it
string meshName = string.IsNullOrEmpty(quad.name) ? "" : quad.name + "-";
meshName += quad.meshes[m].name;
int n = m + 1;
meshName += "_" + n.ToString("#000");
mg.name = MA_StringUtils.RandomAlphabetString(6);
Debug.LogWarning("No valid model name assigned!");
}
string asset = MA_MeshUtils.MeshToFile(newMesh, meshName, savePath);
assetPaths.Add(asset);
//Create new prefab asset.
string newPrefabPath = MA_PrefabUtils.CreatePrefab(mg.name, savePathPrefab);
GameObject newPrefab = AssetDatabase.LoadAssetAtPath<GameObject>(newPrefabPath);
foreach (Mesh m in mg.meshes)
{
if(m != null)
{
//Validate name.
if (string.IsNullOrEmpty(m.name) || string.IsNullOrWhiteSpace(m.name))
{
m.name = MA_StringUtils.RandomAlphabetString(6);
Debug.LogWarning("No valid mesh name assigned!");
}
//Create new mesh.
//Duplicate it from the current one.
Mesh newMesh = MA_MeshUtils.MA_DuplicateMesh(m);
//Remap UV's.
newMesh = MA_MeshUtils.MA_UVReMap(newMesh, atlas.textureAtlasSize, quad.guiRect, modelExportSettings.uvChannel, modelExportSettings.uvFlipY, modelExportSettings.uvWrap);
//Set name.
newMesh.name = string.Format("{0}_{1}", mg.name, m.name);
//Save mesh.
string savedMeshPath = MA_MeshUtils.MA_SaveMeshAsset(newMesh, savePathMeshes);
//Load mesh.
Mesh savedMesh = AssetDatabase.LoadAssetAtPath<Mesh>(savedMeshPath);
//Load material.
Material savedMaterial = AssetDatabase.LoadAssetAtPath<Material>(materialPath);
//Create gameObject.
GameObject newGameObject = new GameObject(m.name);
//Add mesh filter.
MeshFilter mf = newGameObject.AddComponent<MeshFilter>();
mf.mesh = savedMesh;
//Add mesh renderer.
MeshRenderer mr = newGameObject.AddComponent<MeshRenderer>();
mr.material = savedMaterial;
//Add to parent gameObject (prefab).
MA_PrefabUtils.AddChild(newPrefab, newGameObject);
Object.DestroyImmediate(newGameObject);
}
}
assetPaths.Add(newPrefabPath);
}
}
@ -528,10 +499,16 @@ namespace MA_TextureAtlasserPro
private static string[] ExportAtlasPNG(MA_TextureAtlasserProAtlas atlas, TextureExportSettings textureExportSettings, string savePath = EXPORT_ASSET_PATH, string tempPath = TEMP_ASSET_PATH)
{
if (atlas == null || atlas.textureQuads == null || atlas.textureGroupRegistration == null)
{
return null;
}
string[] assetPaths = new string[atlas.textureGroupRegistration.Count];
//Directories.
string savePathTextures = savePath + atlas.name + "/Textures/";
CreateFolder(savePathTextures);
//Create temp folder
CreateFolder(tempPath);
@ -582,25 +559,24 @@ namespace MA_TextureAtlasserPro
}
//Save it
newTexture.MA_Save2D(newTexture.name, savePath);
assetPaths[i] = (savePath + newTexture.name + '.' + textureExportSettings.textureFormat.ToString());
newTexture.MA_Save2D(newTexture.name, savePathTextures);
assetPaths[i] = (savePathTextures + newTexture.name + '.' + textureExportSettings.textureFormat.ToString());
//Set settings.
switch (textureExportSettings.textureType)
{
case TextureType.Default:
{
TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(savePath + newTexture.name + '.' + textureExportSettings.textureFormat.ToString());
TextureImporter textureImporter = (TextureImporter)AssetImporter.GetAtPath(savePathTextures + newTexture.name + '.' + textureExportSettings.textureFormat.ToString());
textureImporter.textureType = TextureImporterType.Default;
textureImporter.SaveAndReimport();
}
break;
case TextureType.Sprite:
SetAtlasSpriteSettings(atlas, textureExportSettings, savePath);
SetAtlasSpriteSettings(atlas, textureExportSettings, savePathTextures);
break;
case TextureType.SpriteSliced:
SetAtlasSpriteSettings(atlas, textureExportSettings, savePath);
SetAtlasSpriteSettings(atlas, textureExportSettings, savePathTextures);
break;
default:
break;
@ -616,7 +592,7 @@ namespace MA_TextureAtlasserPro
return assetPaths;
}
private static void SetAtlasSpriteSettings(MA_TextureAtlasserProAtlas atlas, TextureExportSettings textureExportSettings, string savePath = EXPORT_ASSET_PATH)
private static void SetAtlasSpriteSettings(MA_TextureAtlasserProAtlas atlas, TextureExportSettings textureExportSettings, string savePath)
{
//Foreach texture group
for (int i = 0; i < atlas.textureGroupRegistration.Count; i++)
@ -663,9 +639,13 @@ namespace MA_TextureAtlasserPro
public static string ExportAtlasMaterial(MA_TextureAtlasserProAtlas atlas, MaterialExportSettings materialExportSettings, string[] textures = null, string savePath = EXPORT_ASSET_PATH)
{
if (atlas == null || atlas.textureQuads == null || atlas.textureGroupRegistration == null)
{
return null;
}
string assetPath = "";
//Directories.
string savePathMaterial = savePath + atlas.name + "/Materials/";
CreateFolder(savePathMaterial);
Shader shader = materialExportSettings.shader;
if (shader)
@ -687,15 +667,17 @@ namespace MA_TextureAtlasserPro
}
}
assetPath = savePath + material.name + ".mat";
string assetPath = savePathMaterial + material.name + ".mat";
//Save material
AssetDatabase.CreateAsset(material, assetPath);
AssetDatabase.Refresh();
}
return assetPath;
}
return null;
}
#endregion
}
}

View File

@ -4,19 +4,16 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using MA_Editor;
using MA_Toolbox.Utils;
namespace MA_TextureAtlasserPro
{
public class MA_TextureAtlasserProInspectorView : MA_TextureAtlasserProViewBase
{
private MA_TextureAtlasserProQuad lastSelectedQuad;
private bool isEditing = false;
private GUIStyle labelStyle = new GUIStyle(GUI.skin.label);
bool useAddMeshButton = false;
public MA_TextureAtlasserProInspectorView(MA_TextureAtlasserProWindow currentEditorWindow, string title) : base(currentEditorWindow, title)
{
@ -32,19 +29,6 @@ namespace MA_TextureAtlasserPro
//Draw inspector
if (curWindow.textureAtlas != null && curWindow.textureAtlas.selectedTextureQuad != null)
{
//Change layout during layout event to prevent gui errors
if (e.type == EventType.Layout)
{
if (curWindow.textureAtlas.selectedTextureQuad.meshes != null && curWindow.textureAtlas.selectedTextureQuad.meshes.Count == 0)
{
useAddMeshButton = true;
}
else
{
useAddMeshButton = false;
}
}
//Deselect GUI elements when we are focusing on a new quad
if (lastSelectedQuad != curWindow.textureAtlas.selectedTextureQuad)
{
@ -100,39 +84,71 @@ namespace MA_TextureAtlasserPro
GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET / 2);
//Meshes
GUILayout.Label("Meshes");
if (useAddMeshButton)
//Models
GUILayout.Label("Models");
SerializedObject serializedObject = new SerializedObject(curWindow.textureAtlas.selectedTextureQuad);
serializedObject.Update();
if (curWindow.textureAtlas.selectedTextureQuad.modelGroups != null)
{
if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
SerializedProperty modelGroupsSP = serializedObject.FindProperty("modelGroups");
for (int i = 0; i < curWindow.textureAtlas.selectedTextureQuad.modelGroups.Count; i++)
{
curWindow.textureAtlas.selectedTextureQuad.meshes.Add(null);
using (new GUILayout.VerticalScope(EditorStyles.helpBox))
{
using (new GUILayout.HorizontalScope())
{
curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].name = EditorGUILayout.TextField(curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].name);
if (GUILayout.Button("-", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{
curWindow.textureAtlas.selectedTextureQuad.modelGroups.RemoveAt(i);
break;
}
}
if (curWindow.textureAtlas.selectedTextureQuad.meshes != null)
SerializedProperty meshesSP = modelGroupsSP.GetArrayElementAtIndex(i).FindPropertyRelative("meshes");
EditorGUILayout.PropertyField(meshesSP, false, GUILayout.ExpandWidth(false), GUILayout.MaxWidth(editorViewRect.width * 0.5f));
if (meshesSP.isExpanded)
{
for (int i = 0; i < curWindow.textureAtlas.selectedTextureQuad.meshes.Count; i++)
for (int j = 0; j < curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes.Count; j++)
{
GUILayout.BeginHorizontal();
curWindow.textureAtlas.selectedTextureQuad.meshes[i] = (Mesh)EditorGUILayout.ObjectField(curWindow.textureAtlas.selectedTextureQuad.meshes[i], typeof(Mesh), false);
if(GUILayout.Button("-", EditorStyles.miniButtonLeft, GUILayout.ExpandWidth(false)))
using (new GUILayout.HorizontalScope())
{
curWindow.textureAtlas.selectedTextureQuad.meshes.RemoveAt(i);
curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes[j] = (Mesh)EditorGUILayout.ObjectField(curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes[j], typeof(Mesh), false);
if (GUILayout.Button("-", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{
curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes.RemoveAt(j);
break;
}
if(GUILayout.Button("+", EditorStyles.miniButtonRight, GUILayout.ExpandWidth(false)))
{
curWindow.textureAtlas.selectedTextureQuad.meshes.Insert(i + 1, null);
}
GUILayout.EndHorizontal();
}
}
if (GUILayout.Button("+", EditorStyles.miniButton))
{
curWindow.textureAtlas.selectedTextureQuad.modelGroups[i].meshes.Add(null);
}
}
}
if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.ExpandWidth(true)))
{
curWindow.textureAtlas.selectedTextureQuad.modelGroups.Add(new MA_ModelGroup() { name = MA_StringUtils.RandomAlphabetString(6) });
}
}
else
{
curWindow.textureAtlas.selectedTextureQuad.meshes = new List<Mesh>();
curWindow.textureAtlas.selectedTextureQuad.modelGroups = new List<MA_ModelGroup>();
}
serializedObject.ApplyModifiedProperties();
GUILayout.Space(MA_TextureAtlasserProUtils.VIEW_OFFSET / 2);
//x, y, w, h.
GUILayout.FlexibleSpace();
if (!MA_TextureAtlasserProUtils.IsPowerOfTwo((int)curWindow.textureAtlas.selectedTextureQuad.guiRect.width) || !MA_TextureAtlasserProUtils.IsPowerOfTwo((int)curWindow.textureAtlas.selectedTextureQuad.guiRect.height))
{

View File

@ -63,7 +63,7 @@ namespace MA_TextureAtlasserPro
if (curWindow.textureAtlas.selectedTextureQuad != null && GUILayout.Button(MA_TextureAtlasserProGuiLoader.duplicateQuadGC, GUILayout.ExpandWidth(false), GUILayout.ExpandHeight(true)))
{
if (curWindow.textureAtlas.selectedTextureQuad != null)
MA_TextureAtlasserProUtils.DuplicateTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus, curWindow.settings.copySelectedQuadData, curWindow.settings.duplicatedQuadNamePrefix);
MA_TextureAtlasserProUtils.DuplicateTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus, curWindow.settings.duplicatedQuadNamePrefix);
}
}

View File

@ -91,7 +91,7 @@ namespace MA_TextureAtlasserPro
e.Use();
}
//Hotkeys.
//HotKeys.
if (curWindow.settings.useHotkeys)
{
if(curWindow.textureAtlas != null)
@ -123,7 +123,7 @@ namespace MA_TextureAtlasserPro
if (curWindow.settings.GetHotKey(e, curWindow.settings.duplicateHotKey))
{
MA_TextureAtlasserProUtils.DuplicateTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus, curWindow.settings.copySelectedQuadData, curWindow.settings.duplicatedQuadNamePrefix);
MA_TextureAtlasserProUtils.DuplicateTextureQuad(curWindow.textureAtlas, curWindow.settings.autoFocus, curWindow.settings.duplicatedQuadNamePrefix);
e.Use();
}
}

View File

@ -153,22 +153,6 @@ namespace MA_TextureAtlasserPro
}
if (GUILayout.Button("Export", GUILayout.ExpandWidth(true), GUILayout.Height(37)))
{
bool export = false;
if(curWindow.textureAtlas.exportSettings.modelExportSettings.modelFormat == ModelFormat.ReplaceMesh)
{
if(EditorUtility.DisplayDialog("Replace original models?", "Are you sure you want to replace the original models, this can't be undone!", "Replace", "Cancel"))
{
export = true;
}
}
else
{
export = true;
}
if(export)
{
string[] textures = null;
string material = null;
@ -186,8 +170,7 @@ namespace MA_TextureAtlasserPro
if (curWindow.textureAtlas.exportSettings.exportModels)
{
models = MA_TextureAtlasserProUtils.ExportAtlasModels(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.modelExportSettings, material: material);
}
models = MA_TextureAtlasserProUtils.ExportAtlasModels(curWindow.textureAtlas, curWindow.textureAtlas.exportSettings.modelExportSettings, materialPath: material);
}
}

View File

@ -62,25 +62,8 @@ namespace MA_Mesh
assetPath = savePath + prefabName + ".prefab";
#if UNITY_2018_3_OR_NEWER
PrefabUtility.SaveAsPrefabAsset(gameObject, assetPath);
#else
GameObject go = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
if (go != null)
{
PrefabUtility.ReplacePrefab(gameObject, go, ReplacePrefabOptions.ReplaceNameBased);
}
else
{
PrefabUtility.CreatePrefab(assetPath, gameObject, ReplacePrefabOptions.ReplaceNameBased);
}
#endif
UnityEngine.GameObject.DestroyImmediate(gameObject);
UnityEngine.Object.DestroyImmediate(gameObject);
}
return assetPath;
@ -186,88 +169,6 @@ namespace MA_Mesh
val = val + max - min;
return val;
}
//Start http://wiki.unity3d.com/index.php?title=ObjExporter
public static string MeshToString(Mesh mesh)
{
int vertexOffset = 0;
int normalOffset = 0;
int uvOffset = 0;
Material material = new Material(Shader.Find("Standard"));
StringBuilder sb = new StringBuilder();
sb.Append("g ").Append(mesh.name).Append("\n");
foreach (Vector3 v in mesh.vertices)
{
//This is sort of ugly - inverting x-component since we're in
//a different coordinate system than "everyone" is "used to".
sb.Append(string.Format("v {0} {1} {2}\n", -v.x, v.y, v.z));
}
sb.Append("\n");
foreach (Vector3 v in mesh.normals)
{
sb.Append(string.Format("vn {0} {1} {2}\n", -v.x, v.y, v.z));
}
sb.Append("\n");
foreach (Vector3 v in mesh.uv)
{
sb.Append(string.Format("vt {0} {1}\n", v.x, v.y));
}
for (int m = 0; m < mesh.subMeshCount; m++)
{
sb.Append("\n");
sb.Append("usemtl ").Append(material.name + m).Append("\n");
sb.Append("usemap ").Append(material.name + m).Append("\n");
// int[] triangles = mesh.GetTriangles(m);
// for (int i = 0; i < triangles.Length; i += 3)
// {
// sb.Append(string.Format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n", triangles[i]+1, triangles[i+1]+1, triangles[i+2]+1));
// }
int[] triangles = mesh.GetTriangles(m);
for (int i = 0; i < triangles.Length; i += 3)
{
//Because we inverted the x-component, we also needed to alter the triangle winding.
sb.Append(string.Format("f {1}/{1}/{1} {0}/{0}/{0} {2}/{2}/{2}\n", triangles[i] + 1 + vertexOffset, triangles[i + 1] + 1 + normalOffset, triangles[i + 2] + 1 + uvOffset));
}
}
//vertexOffset += mesh.vertices.Length;
//normalOffset += mesh.normals.Length;
//uvOffset += mesh.uv.Length;
return sb.ToString();
}
public static string MeshToFile(Mesh mesh, string filename, string savePath)
{
string assetPath = savePath + filename + ".obj";
using (StreamWriter sw = new StreamWriter(assetPath))
{
sw.Write(MeshToString(mesh));
}
AssetDatabase.Refresh();
return assetPath;
}
//End
}
//struct ObjMaterial
//{
// public string name;
// public string textureName;
//}
}
#endif

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9946d57c8e1c3714183228268fff08a5
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,41 @@
//-
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
namespace MA_Toolbox.Utils.Editor
{
public static class MA_PrefabUtils
{
public static string CreatePrefab(string prefabName, string savePath)
{
if(string.IsNullOrEmpty(prefabName) || string.IsNullOrWhiteSpace(prefabName))
{
Debug.LogError("Invalid prefab name.");
return null;
}
GameObject gameObject = new GameObject
{
name = prefabName
};
string assetPath = savePath + prefabName + ".prefab";
PrefabUtility.SaveAsPrefabAsset(gameObject, assetPath);
UnityEngine.Object.DestroyImmediate(gameObject);
return assetPath;
}
public static void AddChild(GameObject prefab, GameObject child)
{
GameObject p = PrefabUtility.InstantiatePrefab(prefab) as GameObject;
child.transform.SetParent(p.transform);
PrefabUtility.ApplyPrefabInstance(p, InteractionMode.AutomatedAction);
UnityEngine.Object.DestroyImmediate(p);
}
}
}
#endif

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 04e1a62b7d6bb434eb0314336ac94f8f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f38cac7c10bd77748ab01c8642751035
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,28 @@
//-
using UnityEditor;
using UnityEngine;
namespace MA_Toolbox.Utils
{
public static class MA_StringUtils
{
private const string ALPHABET = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ";
public static string RandomAlphabetString(int length)
{
string s = "";
for (int i = 0; i < length; i++)
{
s += RandomAlphabetChar();
}
return s;
}
public static char RandomAlphabetChar()
{
return ALPHABET[Random.Range(0, ALPHABET.Length)];
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fc1a5e241141bb549b81ad11dfdc0962
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,4 +1,4 @@
[![Image](https://maxartz15.com/wp-content/uploads/2019/04/MA_TextureAtlas.png)]()
[![Image](https://maxartz15.com/wp-content/uploads/2020/04/MA_TextureAtlas2.png)](https://maxartz15.com/wp-content/uploads/2020/04/MA_TextureAtlas2.png)
# MA_TextureAtlasser
Texture atlas creator tool for Unity. <br> This tool is made to combine textures and/or remap the UVs for 3D models. The tool can also be used to make 2D sprite sheets. The visual editor gives you the ability to set and prioritize the sizes and positions in the texture atlas/sprite sheet.
@ -6,17 +6,15 @@ Texture atlas creator tool for Unity. <br> This tool is made to combine textures
- Automatically adjusts the UV's of the assigned meshes to match the new texture atlas.
### Download unitypackage
https://github.com/maxartz15/MA_TextureAtlasser/releases <br>
[![Github All Releases](https://img.shields.io/github/downloads/maxartz15/MA_TextureAtlasser/total.svg)]()
[![Github All Releases](https://img.shields.io/github/downloads/maxartz15/MA_TextureAtlasser/total.svg)](https://github.com/maxartz15/MA_TextureAtlasser/releases)
### Tested Unity versions
[![Image](https://img.shields.io/badge/Unity-2017.4-green)]() [![Image](https://img.shields.io/badge/Unity-2018.4-green)]() [![Image](https://img.shields.io/badge/Unity-2019.3-green)]()
### Unity versions
- Latest release requires Unity 2018.3 or higher.
- Releases before 1.8 should work with older Unity versions.
## Export options
### Meshes
- UnityMesh (with prefab setup)
- OBJ
- Replace orginal (this will replace the orginal model, make sure to backup before doing this!)
### Textures
- PNG
- PNG (sliced) sprite sheet