Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update obj exporter to fix coordinate space, winding order, and culture formatting #10208

Merged
merged 4 commits into from Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions Assets/MRTK/Core/Utilities/OBJWriterUtility.cs
Expand Up @@ -57,7 +57,7 @@ public static IEnumerator<string> CreateOBJFileContentAsync(GameObject target, b

objBuffer.Append($"# {target.name}").AppendNewLine();
var dt = DateTime.Now;
objBuffer.Append($"# {dt.ToString(CultureInfo.InvariantCulture)}").AppendNewLine().AppendNewLine();
objBuffer.Append($"# {dt.ToString(CultureInfo.InvariantCulture)}").AppendNewLine();

Stack<Transform> processStack = new Stack<Transform>();
processStack.Push(target.transform);
Expand Down Expand Up @@ -100,25 +100,25 @@ private static void CreateOBJDataForMesh(MeshFilter meshFilter, StringBuilder bu

var transform = meshFilter.transform;

buffer.Append("g ").Append(transform.name).AppendNewLine();
buffer.AppendNewLine().Append("g ").Append(transform.name).AppendNewLine();

foreach (Vector3 vertex in mesh.vertices)
{
Vector3 v = transform.TransformPoint(vertex);
buffer.Append($"v {v.x} {v.y} {v.z}\n");
buffer.Append(FormattableString.Invariant($"v {-1 * v.x} {v.y} {v.z}\n"));
}
buffer.AppendNewLine();

foreach (Vector3 normal in mesh.normals)
{
Vector3 vn = transform.TransformDirection(normal);
buffer.Append($"vn {vn.x} {vn.y} {vn.z}\n");
buffer.Append(FormattableString.Invariant($"vn {-1 * vn.x} {vn.y} {vn.z}\n"));
}

buffer.AppendNewLine();
foreach (Vector3 uv in mesh.uv)
{
buffer.Append($"vt {uv.x} {uv.y}\n");
buffer.Append(FormattableString.Invariant($"vt {uv.x} {uv.y}\n"));
}

for (int idx = 0; idx < mesh.subMeshCount; idx++)
Expand All @@ -129,7 +129,7 @@ private static void CreateOBJDataForMesh(MeshFilter meshFilter, StringBuilder bu
for (int i = 0; i < triangles.Length; i += 3)
{
buffer.Append(string.Format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n",
triangles[i] + 1 + startVertexIndex, triangles[i + 1] + 1 + startVertexIndex, triangles[i + 2] + 1 + startVertexIndex));
triangles[i + 2] + 1 + startVertexIndex, triangles[i + 1] + 1 + startVertexIndex, triangles[i] + 1 + startVertexIndex));
}
}

Expand Down
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License.

using Microsoft.MixedReality.Toolkit.Utilities;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
Expand Down