Is it possible to add a exporting function to a game in unity. Just like blender has which asks the format and the address and name for exporting.
If so then how should I implement this in my game.
It depends on your requirements. Generating a basic .obj file from a Unity mesh is actually remarkably simple:
void ExportObj(Mesh mesh, string path) {
var actualCulture = System.Threading.Thread.CurrentThread.CurrentCulture;
var thread = System.Threading.Thread.CurrentThread;
thread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
var stream = new System.IO.FileStream(path, FileMode.CreateNew);
var writer = new System.IO.StreamWriter(stream, System.Text.Encoding.UTF8);
writer.WriteLine($"o {mesh.name}");
foreach (var vertex in mesh.vertices) {
writer.WriteLine($"v {vertex.x} {vertex.y} {vertex.z}");
}
foreach (var uv in mesh.uv) {
writer.WriteLine($"vt {uv.x} {uv.y}");
}
foreach (var normal in mesh.normals) {
writer.WriteLine($"vn {normal.x} {normal.y} {normal.z}");
}
var triangles = mesh.triangles;
for (int i = 0; i < triangles.Length; i += 3) {
var a = triangles[i + 0] + 1;
var b = triangles[i + 1] + 1;
var c = triangles[i + 2] + 1;
writer.WriteLine($"f {a}/{a}/{a} {b}/{b}/{b} {c}/{c}/{c}");
}
writer.Flush();
writer.Close();
thread.CurrentCulture = actualCulture;
}
hello I was just reading and I have to say yes unity doe have function to export models. in the package manager is an fbx pack
so far thats the only one I know of.