Exemple #1
0
            /// <summary>
            /// Configure FbxCameras from GameCamera
            /// </summary>
            private static void ConfigureGameCamera(FbxCamera fbxCamera, Camera unityCamera)
            {
                // Configure FilmBack settings as a 35mm TV Projection (0.816 x 0.612)
                float aspectRatio = unityCamera.aspect;

                float apertureHeightInInches = 0.612f;
                float apertureWidthInInches  = aspectRatio * apertureHeightInInches;

                FbxCamera.EProjectionType projectionType =
                    unityCamera.orthographic ? FbxCamera.EProjectionType.eOrthogonal : FbxCamera.EProjectionType.ePerspective;

                fbxCamera.ProjectionType.Set(projectionType);
                fbxCamera.FilmAspectRatio.Set(aspectRatio);
                fbxCamera.SetApertureWidth(apertureWidthInInches);
                fbxCamera.SetApertureHeight(apertureHeightInInches);
                fbxCamera.SetApertureMode(FbxCamera.EApertureMode.eVertical);

                // Focal Length
                double focalLength = fbxCamera.ComputeFocalLength(unityCamera.fieldOfView);

                fbxCamera.FocalLength.Set(focalLength);

                // Field of View
                fbxCamera.FieldOfView.Set(unityCamera.fieldOfView);

                // NearPlane
                fbxCamera.SetNearPlane(unityCamera.nearClipPlane.Meters().ToCentimeters());

                // FarPlane
                fbxCamera.SetFarPlane(unityCamera.farClipPlane.Meters().ToCentimeters());

                return;
            }
            /// <summary>
            /// Exports camera component
            /// </summary>
            protected FbxCamera ExportCamera(Camera unityCamera, FbxScene fbxScene, FbxNode fbxNode)
            {
                FbxCamera fbxCamera = FbxCamera.Create(fbxScene.GetFbxManager(), unityCamera.name);

                bool  perspective = unityCamera.orthographic != true;
                float aspectRatio = unityCamera.aspect;

                // Configure FilmBack settings: 35mm TV Projection (0.816 x 0.612)
                float apertureHeightInInches = 0.612f;
                float apertureWidthInInches  = aspectRatio * apertureHeightInInches;

                FbxCamera.EProjectionType projectionType =
                    perspective ? FbxCamera.EProjectionType.ePerspective : FbxCamera.EProjectionType.eOrthogonal;

                fbxCamera.ProjectionType.Set(projectionType);
                fbxCamera.SetAspect(FbxCamera.EAspectRatioMode.eFixedRatio, aspectRatio, 1.0f);
                fbxCamera.FilmAspectRatio.Set(aspectRatio);
                fbxCamera.SetApertureWidth(apertureWidthInInches);
                fbxCamera.SetApertureHeight(apertureHeightInInches);
                fbxCamera.SetApertureMode(FbxCamera.EApertureMode.eFocalLength);

                // FOV / Focal Length
                fbxCamera.FocalLength.Set(fbxCamera.ComputeFocalLength(unityCamera.fieldOfView));

                // NearPlane
                fbxCamera.SetNearPlane(unityCamera.nearClipPlane);

                // FarPlane
                fbxCamera.SetFarPlane(unityCamera.farClipPlane);

                // Export backgroundColor as a custom property
                // NOTE: export on fbxNode so that it will show up in Maya
                ExportColorProperty(fbxNode, unityCamera.backgroundColor,
                                    MakeName("backgroundColor"),
                                    "The color with which the screen will be cleared.");

                // Export clearFlags as a custom property
                // NOTE: export on fbxNode so that it will show up in Maya
                ExportIntProperty(fbxNode, (int)unityCamera.clearFlags,
                                  MakeName("clearFlags"),
                                  "How the camera clears the background.");


                return(fbxCamera);
            }