Skip to content

Commit 2ae52c3

Browse files
committed
Merge pull request #10208 from keveleigh/update-obj-exporter
Update obj exporter to fix coordinate space, winding order, and culture formatting
1 parent f7026a8 commit 2ae52c3

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

Assets/MRTK/Core/Utilities/OBJWriterUtility.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static IEnumerator<string> CreateOBJFileContentAsync(GameObject target, b
5757

5858
objBuffer.Append($"# {target.name}").AppendNewLine();
5959
var dt = DateTime.Now;
60-
objBuffer.Append($"# {dt.ToString(CultureInfo.InvariantCulture)}").AppendNewLine().AppendNewLine();
60+
objBuffer.Append($"# {dt.ToString(CultureInfo.InvariantCulture)}").AppendNewLine();
6161

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

101101
var transform = meshFilter.transform;
102102

103-
buffer.Append("g ").Append(transform.name).AppendNewLine();
103+
buffer.AppendNewLine().Append("g ").Append(transform.name).AppendNewLine();
104104

105105
foreach (Vector3 vertex in mesh.vertices)
106106
{
107107
Vector3 v = transform.TransformPoint(vertex);
108-
buffer.Append($"v {v.x} {v.y} {v.z}\n");
108+
buffer.Append(FormattableString.Invariant($"v {-1 * v.x} {v.y} {v.z}\n"));
109109
}
110110
buffer.AppendNewLine();
111111

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

118118
buffer.AppendNewLine();
119119
foreach (Vector3 uv in mesh.uv)
120120
{
121-
buffer.Append($"vt {uv.x} {uv.y}\n");
121+
buffer.Append(FormattableString.Invariant($"vt {uv.x} {uv.y}\n"));
122122
}
123123

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

Assets/MRTK/SDK/Features/Utilities/SpatialMeshExporter.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License.
33

44
using Microsoft.MixedReality.Toolkit.Utilities;
5-
using System;
65
using System.Collections;
76
using System.Collections.Generic;
87
using System.IO;

0 commit comments

Comments
 (0)