mirror of
https://github.com/maxartz15/MA_TextureAtlasser.git
synced 2025-06-23 11:06:03 +02:00
Export options/settings, material export, prefab export.
Moved/changed replace OBJ to ReplaceMesh. Optional model/texture/material export. Added Material export option, set shader and shader properties to assign exported textures. Added Prefab export option, exports mesh as an Unity .asset file and creates a prefab to link it to the mesh filter/renderer, added the option for auto assignment of the exported material (New default).
This commit is contained in:
@ -17,12 +17,9 @@ namespace MA_Mesh
|
||||
{
|
||||
public static class MA_MeshUtils
|
||||
{
|
||||
public static void MA_SaveMeshAsset(Mesh mesh, string savePath, string meshName = "")
|
||||
public static string MA_SaveMeshAsset(Mesh mesh, string meshName, string savePath)
|
||||
{
|
||||
Mesh newMesh = new Mesh();
|
||||
newMesh.SetVertices(new List<Vector3>(mesh.vertices));
|
||||
newMesh.SetTriangles(mesh.triangles, 0);
|
||||
newMesh.SetUVs(0, new List<Vector2>(mesh.uv));
|
||||
Mesh newMesh = mesh;
|
||||
|
||||
if(meshName == "")
|
||||
{
|
||||
@ -33,10 +30,51 @@ namespace MA_Mesh
|
||||
newMesh.name = meshName;
|
||||
}
|
||||
|
||||
AssetDatabase.CreateAsset(newMesh, savePath);
|
||||
AssetDatabase.SaveAssets();
|
||||
string assetPath = savePath + newMesh.name + ".asset";
|
||||
|
||||
AssetDatabase.CreateAsset(newMesh, assetPath);
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
return assetPath;
|
||||
}
|
||||
|
||||
public static string MA_SaveMeshPrefab(Mesh mesh, string meshName, string savePath, string material)
|
||||
{
|
||||
string assetPath = "";
|
||||
|
||||
if (meshName == "")
|
||||
{
|
||||
meshName = mesh.name;
|
||||
}
|
||||
|
||||
string meshPath = MA_SaveMeshAsset(mesh, meshName, savePath);
|
||||
Mesh curMesh = AssetDatabase.LoadAssetAtPath<Mesh>(meshPath);
|
||||
|
||||
if (curMesh != null)
|
||||
{
|
||||
GameObject gameObject = new GameObject
|
||||
{
|
||||
name = meshName
|
||||
};
|
||||
|
||||
gameObject.AddComponent<MeshFilter>().mesh = curMesh;
|
||||
gameObject.AddComponent<MeshRenderer>();
|
||||
|
||||
Material curMaterial = AssetDatabase.LoadAssetAtPath<Material>(material);
|
||||
if (curMaterial != null)
|
||||
{
|
||||
gameObject.GetComponent<MeshRenderer>().material = curMaterial;
|
||||
}
|
||||
|
||||
assetPath = savePath + meshName + ".prefab";
|
||||
PrefabUtility.SaveAsPrefabAsset(gameObject, assetPath);
|
||||
|
||||
UnityEngine.GameObject.DestroyImmediate(gameObject);
|
||||
}
|
||||
|
||||
return assetPath;
|
||||
}
|
||||
|
||||
public static Mesh MA_DuplicateMesh(Mesh mesh)
|
||||
{
|
||||
Mesh newMesh = new Mesh
|
||||
@ -199,12 +237,18 @@ namespace MA_Mesh
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static void MeshToFile(Mesh mesh, string filename, string savePath)
|
||||
public static string MeshToFile(Mesh mesh, string filename, string savePath)
|
||||
{
|
||||
using (StreamWriter sw = new StreamWriter(savePath + filename + ".obj"))
|
||||
string assetPath = savePath + filename + ".obj";
|
||||
|
||||
using (StreamWriter sw = new StreamWriter(assetPath))
|
||||
{
|
||||
sw.Write(MeshToString(mesh));
|
||||
}
|
||||
}
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
return assetPath;
|
||||
}
|
||||
//End
|
||||
}
|
||||
|
Reference in New Issue
Block a user