@@ -242,13 +242,17 @@ public void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, FbxScene fbxScene)
242
242
243
243
// copy control point data from Unity to FBX
244
244
for ( int v = 0 ; v < meshInfo . VertexCount ; v ++ ) {
245
+ // convert from left to right-handed by negating x (Unity negates x again on import)
245
246
fbxMesh . SetControlPointAt ( new FbxVector4 (
246
247
- meshInfo . Vertices [ v ] . x ,
247
248
meshInfo . Vertices [ v ] . y ,
248
249
meshInfo . Vertices [ v ] . z
249
250
) , v ) ;
250
251
}
251
252
253
+ var fbxMaterial = ExportMaterial ( meshInfo . Material , fbxScene ) ;
254
+ fbxNode . AddMaterial ( fbxMaterial ) ;
255
+
252
256
/*
253
257
* Triangles have to be added in reverse order,
254
258
* or else they will be inverted on import
@@ -259,6 +263,8 @@ meshInfo.Vertices [v].z
259
263
for ( int f = 0 ; f < meshInfo . Triangles . Length / 3 ; f ++ ) {
260
264
fbxMesh . BeginPolygon ( ) ;
261
265
266
+ // triangle vertices have to be reordered to be 0,2,1 instead
267
+ // of 0,1,2, as this gets flipped back during import
262
268
foreach ( int val in new int [ ] { 0 , 2 , 1 } ) {
263
269
int tri = meshInfo . Triangles [ 3 * f + val ] ;
264
270
fbxMesh . AddPolygon ( tri ) ;
@@ -273,9 +279,6 @@ meshInfo.Vertices [v].z
273
279
274
280
ExportUVsAndNormals ( meshInfo , fbxMesh , fbxTriangles ) ;
275
281
276
- var fbxMaterial = ExportMaterial ( meshInfo . Material , fbxScene ) ;
277
- fbxNode . AddMaterial ( fbxMaterial ) ;
278
-
279
282
// set the fbxNode containing the mesh
280
283
fbxNode . SetNodeAttribute ( fbxMesh ) ;
281
284
fbxNode . SetShadingMode ( FbxNode . EShadingMode . eWireFrame ) ;
0 commit comments