@@ -205,7 +205,7 @@ public FbxSurfaceMaterial ExportMaterial (Material unityMaterial, FbxScene fbxSc
205
205
/// Unconditionally export this mesh object to the file.
206
206
/// We have decided; this mesh is definitely getting exported.
207
207
/// </summary>
208
- public void ExportMesh ( MeshInfo meshInfo , FbxNode fbxNode , FbxScene fbxScene )
208
+ public void ExportMesh ( MeshInfo meshInfo , FbxNode fbxNode , FbxScene fbxScene , bool mergeVertices = true )
209
209
{
210
210
if ( ! meshInfo . IsValid )
211
211
return ;
@@ -220,26 +220,39 @@ public void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, FbxScene fbxScene)
220
220
Dictionary < Vector3 , int > ControlPointToIndex = new Dictionary < Vector3 , int > ( ) ;
221
221
222
222
int NumControlPoints = 0 ;
223
- for ( int v = 0 ; v < meshInfo . VertexCount ; v ++ ) {
224
- if ( ControlPointToIndex . ContainsKey ( meshInfo . Vertices [ v ] ) ) {
225
- continue ;
226
- }
227
- ControlPointToIndex [ meshInfo . Vertices [ v ] ] = NumControlPoints ;
228
-
229
- NumControlPoints ++ ;
230
- }
231
-
232
- NumVertices += NumControlPoints ;
223
+ if ( mergeVertices ) {
224
+ for ( int v = 0 ; v < meshInfo . VertexCount ; v ++ ) {
225
+ if ( ControlPointToIndex . ContainsKey ( meshInfo . Vertices [ v ] ) ) {
226
+ continue ;
227
+ }
228
+ ControlPointToIndex [ meshInfo . Vertices [ v ] ] = NumControlPoints ;
233
229
234
- fbxMesh . InitControlPoints ( NumControlPoints ) ;
230
+ NumControlPoints ++ ;
231
+ }
232
+ NumVertices += NumControlPoints ;
233
+ fbxMesh . InitControlPoints ( NumControlPoints ) ;
234
+
235
+ // copy control point data from Unity to FBX
236
+ foreach ( var controlPoint in ControlPointToIndex . Keys ) {
237
+ fbxMesh . SetControlPointAt ( new FbxVector4 (
238
+ - controlPoint . x ,
239
+ controlPoint . y ,
240
+ controlPoint . z
241
+ ) , ControlPointToIndex [ controlPoint ] ) ;
242
+ }
243
+ } else {
244
+ NumControlPoints = meshInfo . VertexCount ;
245
+ NumVertices += NumControlPoints ;
246
+ fbxMesh . InitControlPoints ( NumControlPoints ) ;
235
247
236
- // copy control point data from Unity to FBX
237
- foreach ( var controlPoint in ControlPointToIndex . Keys ) {
238
- fbxMesh . SetControlPointAt ( new FbxVector4 (
239
- - controlPoint . x ,
240
- controlPoint . y ,
241
- controlPoint . z
242
- ) , ControlPointToIndex [ controlPoint ] ) ;
248
+ for ( int v = 0 ; v < NumControlPoints ; v ++ )
249
+ {
250
+ fbxMesh . SetControlPointAt ( new FbxVector4 (
251
+ - meshInfo . Vertices [ v ] . x ,
252
+ meshInfo . Vertices [ v ] . y ,
253
+ meshInfo . Vertices [ v ] . z
254
+ ) , v ) ;
255
+ }
243
256
}
244
257
245
258
/*
@@ -262,8 +275,9 @@ public void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, FbxScene fbxScene)
262
275
// properly export UVs, normals, binormals, etc.
263
276
unmergedTriangles [ current ] = tri ;
264
277
265
- int index = ControlPointToIndex [ meshInfo . Vertices [ tri ] ] ;
266
- tri = index ;
278
+ if ( mergeVertices ) {
279
+ tri = ControlPointToIndex [ meshInfo . Vertices [ tri ] ] ;
280
+ }
267
281
fbxMesh . AddPolygon ( tri ) ;
268
282
269
283
current ++ ;
0 commit comments