Skip to content

Commit d3ffcbe

Browse files
committed
call ExportCamera from ExportComponents
- return success of failure from ExportCamera - convert far and near plane to cm
1 parent 7391baa commit d3ffcbe

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -765,9 +765,17 @@ protected bool ExportInstance (GameObject unityGo, FbxNode fbxNode, FbxScene fbx
765765
/// <summary>
766766
/// Exports camera component
767767
/// </summary>
768-
protected FbxCamera ExportCamera (Camera unityCamera, FbxScene fbxScene, FbxNode fbxNode)
768+
protected bool ExportCamera (GameObject unityGO, FbxScene fbxScene, FbxNode fbxNode)
769769
{
770+
Camera unityCamera = unityGO.GetComponent<Camera> ();
771+
if (unityCamera == null) {
772+
return false;
773+
}
774+
770775
FbxCamera fbxCamera = FbxCamera.Create (fbxScene.GetFbxManager(), unityCamera.name);
776+
if (fbxCamera == null) {
777+
return false;
778+
}
771779

772780
float aspectRatio = unityCamera.aspect;
773781

@@ -789,10 +797,10 @@ protected FbxCamera ExportCamera (Camera unityCamera, FbxScene fbxScene, FbxNode
789797
fbxCamera.FocalLength.Set(fbxCamera.ComputeFocalLength (unityCamera.fieldOfView));
790798

791799
// NearPlane
792-
fbxCamera.SetNearPlane (unityCamera.nearClipPlane);
800+
fbxCamera.SetNearPlane (unityCamera.nearClipPlane*100);
793801

794802
// FarPlane
795-
fbxCamera.SetFarPlane (unityCamera.farClipPlane);
803+
fbxCamera.SetFarPlane (unityCamera.farClipPlane*100);
796804

797805
// Export backgroundColor as a custom property
798806
// NOTE: export on fbxNode so that it will show up in Maya
@@ -806,7 +814,12 @@ protected FbxCamera ExportCamera (Camera unityCamera, FbxScene fbxScene, FbxNode
806814
MakeName("clearFlags"),
807815
"How the camera clears the background.");
808816

809-
return fbxCamera;
817+
fbxNode.SetNodeAttribute (fbxCamera);
818+
819+
// make the last camera exported the default camera
820+
DefaultCamera = fbxNode.GetName ();
821+
822+
return true;
810823
}
811824

812825
/// <summary>
@@ -909,8 +922,8 @@ protected int ExportComponents (
909922

910923
ExportTransform ( unityGo.transform, fbxNode, newCenter, exportType);
911924

912-
// try exporting mesh as an instance, export regularly if we cannot
913-
if (!ExportInstance (unityGo, fbxNode, fbxScene)) {
925+
// try exporting mesh as an instance or camera, export regularly if we cannot
926+
if (!ExportInstance (unityGo, fbxNode, fbxScene) && !ExportCamera(unityGo, fbxScene, fbxNode)) {
914927
ExportMesh (unityGo, fbxNode);
915928
}
916929

0 commit comments

Comments
 (0)