@@ -9,7 +9,7 @@ namespace ZO.ImportExport {
99 public class ZOExportOBJ {
1010
1111 public enum Orientation {
12- URDF ,
12+ URDF ,
1313 Unity // Unity Default direction
1414 }
1515
@@ -49,7 +49,7 @@ protected string MeshToString(Mesh mesh, ZOExportOBJ.Orientation orientation) {
4949
5050 StringBuilder sb = new StringBuilder ( ) ;
5151
52- foreach ( Vector3 vv in mesh . vertices ) {
52+ foreach ( Vector3 vv in mesh . vertices ) {
5353 Vector3 v = vv ;
5454 numVertices ++ ;
5555 if ( orientation == Orientation . Unity ) {
@@ -106,7 +106,7 @@ protected string MeshFilterToString(MeshFilter meshFilter, Transform transform,
106106
107107 StringBuilder sb = new StringBuilder ( ) ;
108108
109- foreach ( Vector3 vv in mesh . vertices ) {
109+ foreach ( Vector3 vv in mesh . vertices ) {
110110 Vector3 v = vv ;
111111 if ( applyLocalTransform == true ) {
112112 v = transform . TransformPoint ( vv ) ;
@@ -115,7 +115,7 @@ protected string MeshFilterToString(MeshFilter meshFilter, Transform transform,
115115 if ( orientation == Orientation . Unity ) {
116116 sb . AppendLine ( $ "v { v . x } { v . y } { v . z } ") ;
117117 } else if ( orientation == Orientation . URDF ) {
118- sb . AppendLine ( $ "v { v . z } { v . x } { v . y } ") ;
118+ sb . AppendLine ( $ "v { v . z } { - v . x } { v . y } ") ;
119119 }
120120 }
121121 sb . AppendLine ( ) ;
@@ -124,7 +124,7 @@ protected string MeshFilterToString(MeshFilter meshFilter, Transform transform,
124124 if ( orientation == Orientation . Unity ) {
125125 sb . AppendLine ( $ "vn { v . x } { v . y } { v . z } ") ;
126126 } else if ( orientation == Orientation . URDF ) {
127- sb . AppendLine ( $ "vn { v . z } { v . x } { v . y } ") ;
127+ sb . AppendLine ( $ "vn { v . z } { - v . x } { v . y } ") ;
128128 }
129129 }
130130 sb . AppendLine ( ) ;
@@ -139,10 +139,19 @@ protected string MeshFilterToString(MeshFilter meshFilter, Transform transform,
139139
140140 int [ ] triangles = mesh . GetTriangles ( material ) ;
141141 for ( int i = 0 ; i < triangles . Length ; i += 3 ) {
142- sb . Append ( string . Format ( "f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n " ,
143- triangles [ i ] + 1 + _startIndex ,
144- triangles [ i + 1 ] + 1 + _startIndex ,
145- triangles [ i + 2 ] + 1 + _startIndex ) ) ;
142+
143+ if ( orientation == Orientation . Unity ) {
144+ sb . Append ( string . Format ( "f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n " ,
145+ triangles [ i ] + 1 + _startIndex ,
146+ triangles [ i + 1 ] + 1 + _startIndex ,
147+ triangles [ i + 2 ] + 1 + _startIndex ) ) ;
148+ } else if ( orientation == Orientation . URDF ) {
149+ sb . Append ( string . Format ( "f {2}/{2}/{2} {1}/{1}/{1} {0}/{0}/{0}\n " ,
150+ triangles [ i ] + 1 + _startIndex ,
151+ triangles [ i + 1 ] + 1 + _startIndex ,
152+ triangles [ i + 2 ] + 1 + _startIndex ) ) ;
153+ }
154+
146155
147156 }
148157 }
@@ -301,7 +310,7 @@ public void ExportToDirectory(GameObject gameObject, string directoryPath, bool
301310 }
302311
303312 // copy the textures
304- foreach ( string sourceTexturePath in TextureAssetPaths ) {
313+ foreach ( string sourceTexturePath in TextureAssetPaths ) {
305314 File . Copy ( sourceTexturePath , Path . Combine ( directoryPath , Path . GetFileName ( sourceTexturePath ) ) , true ) ;
306315 }
307316
0 commit comments