@@ -542,17 +542,16 @@ private void AssignLayerElementMaterial(FbxMesh fbxMesh, Mesh mesh, int material
542
542
///
543
543
/// Use fbxNode.GetMesh() to access the exported mesh.
544
544
/// </summary>
545
- /// <param name="weldVertices">If set to <c>true</c>, combine identical vertices together into one Fbx vertex.</param>
546
- public void ExportMesh ( Mesh mesh , FbxNode fbxNode , bool weldVertices = true , Material [ ] materials = null )
545
+ public void ExportMesh ( Mesh mesh , FbxNode fbxNode , Material [ ] materials = null )
547
546
{
548
547
var meshInfo = new MeshInfo ( mesh , materials ) ;
549
- ExportMesh ( meshInfo , fbxNode , weldVertices ) ;
548
+ ExportMesh ( meshInfo , fbxNode ) ;
550
549
}
551
550
552
551
/// <summary>
553
552
/// Exports a unity mesh and attaches it to the node as an FbxMesh.
554
553
/// </summary>
555
- void ExportMesh ( MeshInfo meshInfo , FbxNode fbxNode , bool weldVertices )
554
+ void ExportMesh ( MeshInfo meshInfo , FbxNode fbxNode )
556
555
{
557
556
if ( ! meshInfo . IsValid ) {
558
557
return ;
@@ -567,31 +566,20 @@ void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, bool weldVertices)
567
566
568
567
// Create control points.
569
568
Dictionary < Vector3 , int > ControlPointToIndex = new Dictionary < Vector3 , int > ( ) ;
570
-
571
- int NumControlPoints = 0 ;
572
- if ( weldVertices ) {
573
- for ( int v = 0 ; v < meshInfo . VertexCount ; v ++ ) {
574
- if ( ControlPointToIndex . ContainsKey ( meshInfo . Vertices [ v ] ) ) {
569
+ {
570
+ var vertices = meshInfo . Vertices ;
571
+ for ( int v = 0 , n = meshInfo . VertexCount ; v < n ; v ++ ) {
572
+ if ( ControlPointToIndex . ContainsKey ( vertices [ v ] ) ) {
575
573
continue ;
576
574
}
577
- ControlPointToIndex [ meshInfo . Vertices [ v ] ] = NumControlPoints ;
578
-
579
- NumControlPoints ++ ;
580
- }
581
- fbxMesh . InitControlPoints ( NumControlPoints ) ;
582
-
583
- foreach ( var controlPoint in ControlPointToIndex . Keys ) {
584
- fbxMesh . SetControlPointAt ( ConvertPositionToRightHanded ( controlPoint ) ,
585
- ControlPointToIndex [ controlPoint ] ) ;
575
+ ControlPointToIndex [ vertices [ v ] ] = ControlPointToIndex . Count ( ) ;
586
576
}
587
- } else {
588
- NumControlPoints = meshInfo . VertexCount ;
589
- fbxMesh . InitControlPoints ( NumControlPoints ) ;
577
+ fbxMesh . InitControlPoints ( ControlPointToIndex . Count ( ) ) ;
590
578
591
- // copy control point data from Unity to FBX
592
- for ( int v = 0 ; v < NumControlPoints ; v ++ )
593
- {
594
- fbxMesh . SetControlPointAt ( ConvertPositionToRightHanded ( meshInfo . Vertices [ v ] ) , v ) ;
579
+ foreach ( var kvp in ControlPointToIndex ) {
580
+ var controlPoint = kvp . Key ;
581
+ var index = kvp . Value ;
582
+ fbxMesh . SetControlPointAt ( ConvertPositionToRightHanded ( controlPoint ) , index ) ;
595
583
}
596
584
}
597
585
@@ -636,9 +624,7 @@ void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, bool weldVertices)
636
624
// properly export UVs, normals, binormals, etc.
637
625
unmergedPolygons [ current ] = polyVert ;
638
626
639
- if ( weldVertices ) {
640
- polyVert = ControlPointToIndex [ meshInfo . Vertices [ polyVert ] ] ;
641
- }
627
+ polyVert = ControlPointToIndex [ meshInfo . Vertices [ polyVert ] ] ;
642
628
fbxMesh . AddPolygon ( polyVert ) ;
643
629
644
630
current ++ ;
@@ -746,8 +732,7 @@ protected bool ExportInstance (GameObject unityGo, FbxNode fbxNode, FbxScene fbx
746
732
747
733
if ( ! SharedMeshes . TryGetValue ( unityPrefabParent . name , out fbxMesh ) )
748
734
{
749
- bool weldVertices = ExportSettings . weldVertices ;
750
- ExportMesh ( unityGo , fbxNode , weldVertices ) ;
735
+ ExportMesh ( unityGo , fbxNode ) ;
751
736
if ( fbxNode . GetMesh ( ) != null ) {
752
737
SharedMeshes [ unityPrefabParent . name ] = fbxNode . GetMesh ( ) ;
753
738
}
@@ -812,8 +797,7 @@ protected int ExportComponents (
812
797
813
798
// try exporting mesh as an instance, export regularly if we cannot
814
799
if ( ! ExportInstance ( unityGo , fbxNode , fbxScene ) ) {
815
- bool weldVertices = ExportSettings . weldVertices ;
816
- ExportMesh ( unityGo , fbxNode , weldVertices ) ;
800
+ ExportMesh ( unityGo , fbxNode ) ;
817
801
}
818
802
819
803
if ( Verbose )
@@ -1494,7 +1478,7 @@ public static void UnRegisterMeshCallback(GetMeshForObject callback)
1494
1478
/// This goes through the callback system to find the right mesh and
1495
1479
/// allow plugins to substitute their own meshes.
1496
1480
/// </summary>
1497
- void ExportMesh ( GameObject gameObject , FbxNode fbxNode , bool weldVertices )
1481
+ void ExportMesh ( GameObject gameObject , FbxNode fbxNode )
1498
1482
{
1499
1483
// First allow the object-based callbacks to have a hack at it.
1500
1484
foreach ( var callback in MeshForObjectCallbacks ) {
@@ -1547,14 +1531,14 @@ void ExportMesh (GameObject gameObject, FbxNode fbxNode, bool weldVertices)
1547
1531
if ( meshFilter ) {
1548
1532
var renderer = gameObject . GetComponent < Renderer > ( ) ;
1549
1533
var materials = renderer ? renderer . sharedMaterials : null ;
1550
- ExportMesh ( new MeshInfo ( meshFilter . sharedMesh , materials ) , fbxNode , weldVertices ) ;
1534
+ ExportMesh ( new MeshInfo ( meshFilter . sharedMesh , materials ) , fbxNode ) ;
1551
1535
} else {
1552
1536
var smr = defaultComponent as SkinnedMeshRenderer ;
1553
1537
if ( smr ) {
1554
1538
var mesh = new Mesh ( ) ;
1555
1539
smr . BakeMesh ( mesh ) ;
1556
1540
var materials = smr . sharedMaterials ;
1557
- ExportMesh ( new MeshInfo ( mesh , materials ) , fbxNode , weldVertices ) ;
1541
+ ExportMesh ( new MeshInfo ( mesh , materials ) , fbxNode ) ;
1558
1542
Object . DestroyImmediate ( mesh ) ;
1559
1543
}
1560
1544
}
0 commit comments