public static void ExportAtlasObj(MA_TextureAtlasserProAtlas atlas, string savePath = EXPORTASSETPATH)
        {
            if (atlas == null || atlas.textureQuads == null)
            {
                return;
            }

            foreach (MA_TextureAtlasserProQuad ta in atlas.textureQuads)
            {
                //Export Mesh
                if (ta.meshes != null)
                {
                    for (int m = 0; m < ta.meshes.Count; m++)
                    {
                        if (ta.meshes[m] != null)
                        {
                            //Create new mesh
                            Mesh newMesh = new Mesh();
                            //Duplicate it from the current one
                            newMesh = MA_MeshUtils.MA_DuplicateMesh(ta.meshes[m]);
                            //Remap UV's
                            newMesh = MA_MeshUtils.MA_UVReMap(newMesh, atlas.textureAtlasSize, ta.guiRect);
                            //Save it
                            string modelName = string.IsNullOrEmpty(ta.name) ? "": ta.name + "-";
                            modelName += ta.meshes[m].name;
                            int n = m + 1;
                            modelName += "_" + n.ToString("#000");

                            MA_MeshUtils.MeshToFile(newMesh, modelName, savePath);
                        }
                    }
                }
            }
        }
 public static void ExportAtlasMeshesObj(MA_TextureAtlasserProAtlas atlas, string savePath = EXPORTASSETPATH)
 {
     if (atlas != null && atlas.textureQuads != null)
     {
         foreach (MA_TextureAtlasserProQuad ta in atlas.textureQuads)
         {
             //Export Mesh
             if (ta.meshes != null)
             {
                 for (int m = 0; m < ta.meshes.Count; m++)
                 {
                     if (ta.meshes[m] != null)
                     {
                         //Create new mesh
                         Mesh newMesh = new Mesh();
                         //Duplicate it from the current one
                         newMesh = MA_MeshUtils.MA_DuplicateMesh(ta.meshes[m]);
                         //Remap uvs
                         newMesh = MA_MeshUtils.MA_UVReMap(newMesh, atlas.textureAtlasSize, ta.guiRect);
                         //Save it
                         MA_MeshUtils.MeshToFile(newMesh, "MA_" + ta.name, savePath);
                     }
                 }
             }
         }
     }
 }
Example #3
0
        private static void ReplaceAtlasMesh(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, 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();
        }
Example #4
0
        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());
        }
Example #5
0
        private static string[] ExportAtlasUnityMeshPrefab(MA_TextureAtlasserProAtlas atlas, ModelExportSettings modelExportSettings, string materialPath = null, 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)
            {
                foreach (MA_ModelGroup mg in quad.modelGroups)
                {
                    //Validate name.
                    if (string.IsNullOrEmpty(mg.name) || string.IsNullOrWhiteSpace(mg.name))
                    {
                        mg.name = MA_StringUtils.RandomAlphabetString(6);
                        Debug.LogWarning("No valid model name assigned!");
                    }

                    //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);
                }
            }

            return(assetPaths.ToArray());
        }