Skip to content

Commit ce77b18

Browse files
committed
add option to merge vertices or not when exporting
1 parent bc113cb commit ce77b18

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public FbxSurfaceMaterial ExportMaterial (Material unityMaterial, FbxScene fbxSc
205205
/// Unconditionally export this mesh object to the file.
206206
/// We have decided; this mesh is definitely getting exported.
207207
/// </summary>
208-
public void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, FbxScene fbxScene)
208+
public void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, FbxScene fbxScene, bool mergeVertices = true)
209209
{
210210
if (!meshInfo.IsValid)
211211
return;
@@ -220,26 +220,39 @@ public void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, FbxScene fbxScene)
220220
Dictionary<Vector3, int> ControlPointToIndex = new Dictionary<Vector3, int> ();
221221

222222
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;
233229

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);
235247

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+
}
243256
}
244257

245258
/*
@@ -262,8 +275,9 @@ public void ExportMesh (MeshInfo meshInfo, FbxNode fbxNode, FbxScene fbxScene)
262275
// properly export UVs, normals, binormals, etc.
263276
unmergedTriangles [current] = tri;
264277

265-
int index = ControlPointToIndex [meshInfo.Vertices [tri]];
266-
tri = index;
278+
if (mergeVertices) {
279+
tri = ControlPointToIndex [meshInfo.Vertices [tri]];
280+
}
267281
fbxMesh.AddPolygon (tri);
268282

269283
current++;

0 commit comments

Comments
 (0)