Skip to content

Commit f44fdbf

Browse files
committed
Merge branch 'master' into UT-3102-use-deepconvert
2 parents 86fd7a8 + 92a1af2 commit f44fdbf

20 files changed

+377
-12
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changes in Fbx Exporter
22

3+
## [3.0.0-preview.2] - 2020-01-13
4+
### Added
5+
- Added FBX Recorder to record animations from the Unity Recorder directly to FBX (adds dependency to Unity Recorder).
6+
- Export animated focal length and lens shift of cameras.
7+
8+
### Changed
9+
- Updated dependency to com.autodesk.fbx version 3.0.0-preview.1, which means we update to [FBX SDK 2020](http://help.autodesk.com/view/FBX/2020/ENU/).
10+
11+
### Fixed
12+
- Fixed camera aspect and gate fit exporting as incorrect values.
13+
14+
### Known Issues
15+
- Using the FBX Recorder to record animated characters is not supported yet, and fails in some cases.
316

417
## [2.0.3-preview.3] - 2019-09-24
518

com.unity.formats.fbx/Documentation~/TableOfContents.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* [FBX Linked Prefabs](prefabs)
44
* [Integration](integration)
55
* [FBX Export settings](options)
6+
* [FBX Recorder](recorder)
67
* [Limitations](knownissues)
78
* [Troubleshooting](troubleshooting)
89
* [Developer's guide](devguide)
18.4 KB
Loading
17.4 KB
Loading
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# FBX Recorder
2+
3+
With the FBX Exporter and the [Unity Recorder](https://docs.unity3d.com/Packages/[email protected]/index.html), it is possible to export animations (including [Cinemachine](https://docs.unity3d.com/Packages/[email protected]/manual/index.html) camera animations) directly to FBX in a few easy steps:
4+
5+
1. Open the Recorder window by selecting (Window > General > Recorder > Recorder Window)
6+
2. In the Recorder window add a new FBX recorder
7+
8+
![](images/FBXExporter_AddRecorder.png)
9+
10+
3. Set the GameObject to record as well as any other desired settings
11+
4. Click "Start Recording" in the Recorder Window
12+
13+
Alternatively, the FBX Recorder can be added as a track in the Timeline.
14+
15+
## Fbx Recorder Settings
16+
17+
![](images/FBXExporter_RecorderSettings.png)
18+
19+
| Property: | Function: |
20+
| :---------------------------- | :----------------------------------------------------------- |
21+
| __File Name__ | The filename for the exported FBX. |
22+
| __Path__ | The path to export the FBX to. Can be outside of the Assets folder. |
23+
| __Take Number__ | The take number can be set and used in the filename. It automatically increments after each recording. |
24+
| __Game Object__ | Set the Game Object in the scene to record. |
25+
| __Recorded Target(s)__ | Select which components of the selected GameObject to record. |
26+
| __Recorded Hierarchy__ | Check to record other objects in the hierarchy of the GameObject in addition to the selected GameObject. |

com.unity.formats.fbx/Documentation~/troubleshooting.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This section covers the following issues:
88
* [Overwriting FBX files](#OverwritingFiles)
99
* [Tree primitive no longer editable after conversion](#EditableTree)
1010
* [Trail and line particles lose material after being converted](#ParticlesLoseMaterial)
11+
* [Uninstalling FBX Exporter breaks Unity Recorder](#BrokenRecorder)
1112

1213

1314

@@ -71,3 +72,16 @@ To avoid this, make sure to convert only the Tree when finished editing. Otherwi
7172

7273
If you lose Materials when converting trail or line particles, you need to re-apply the Materials to the FBX Linked Prefab after conversion.
7374

75+
76+
77+
<a name="BrokenRecorder"></a>
78+
79+
## Uninstalling FBX Exporter breaks Unity Recorder
80+
81+
If you are uninstalling the FBX Exporter package but would like to continue using the Unity Recorder make sure to first remove all existing FBX Recorders.
82+
You can do this by right clicking on the FBX recorders in the Recorder Window or Timeline and selecting "Delete".
83+
84+
If you have already uninstalled the FBX Exporter package and are now having issues with the Unity Recorder, follow these steps:
85+
1. Reinstall the FBX Exporter package
86+
2. Find and remove all FBX recorder instances (right click and Delete from the Recorder Window and Timeline(s))
87+
3. Uninstall the FBX Exporter from the Package Manager

com.unity.formats.fbx/Editor/CameraVisitor.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
using UnityEngine;
22
using Autodesk.Fbx;
33
using UnityEditor.Formats.Fbx.Exporter.CustomExtensions;
4+
using System.Collections.Generic;
45

56
namespace UnityEditor.Formats.Fbx.Exporter
67
{
78
namespace Visitors
89
{
910
internal static class CameraVisitor
1011
{
12+
private static Dictionary<Camera.GateFitMode, FbxCamera.EGateFit> s_mapGateFit = new Dictionary<Camera.GateFitMode, FbxCamera.EGateFit>()
13+
{
14+
{ Camera.GateFitMode.Fill, FbxCamera.EGateFit.eFitFill },
15+
{ Camera.GateFitMode.Horizontal, FbxCamera.EGateFit.eFitHorizontal },
16+
{ Camera.GateFitMode.None, FbxCamera.EGateFit.eFitNone },
17+
{ Camera.GateFitMode.Overscan, FbxCamera.EGateFit.eFitOverscan },
18+
{ Camera.GateFitMode.Vertical, FbxCamera.EGateFit.eFitVertical }
19+
};
20+
1121
/// <summary>
1222
/// Visit Object and configure FbxCamera
1323
/// </summary>
@@ -56,6 +66,14 @@ private static void ConfigureGameCamera (FbxCamera fbxCamera, Camera unityCamera
5666
return ;
5767
}
5868

69+
public static Vector2 GetSizeOfMainGameView()
70+
{
71+
System.Type T = System.Type.GetType("UnityEditor.GameView,UnityEditor");
72+
System.Reflection.MethodInfo GetSizeOfMainGameView = T.GetMethod("GetSizeOfMainGameView", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
73+
System.Object Res = GetSizeOfMainGameView.Invoke(null, null);
74+
return (Vector2)Res;
75+
}
76+
5977
/// <summary>
6078
/// Configure FbxCameras from a Physical Camera
6179
/// </summary>
@@ -80,16 +98,19 @@ private static void ConfigurePhysicalCamera (FbxCamera fbxCamera, Camera unityCa
8098

8199
fbxCamera.ProjectionType.Set(projectionType);
82100
fbxCamera.FilmAspectRatio.Set(aspectRatio);
101+
102+
Vector2 gameViewSize = GetSizeOfMainGameView();
103+
fbxCamera.SetAspect(FbxCamera.EAspectRatioMode.eFixedRatio, gameViewSize.x/gameViewSize.y, 1.0);
83104
fbxCamera.SetApertureWidth (apertureWidthInInches);
84105
fbxCamera.SetApertureHeight (apertureHeightInInches);
85106

86107
// Fit the resolution gate horizontally within the film gate.
87-
fbxCamera.GateFit.Set(FbxCamera.EGateFit.eFitHorizontal);
108+
fbxCamera.GateFit.Set(s_mapGateFit[unityCamera.gateFit]);
88109

89110
// Lens Shift ( Film Offset ) as a percentage 0..1
90111
// FBX FilmOffset is in inches
91-
fbxCamera.FilmOffsetX.Set(apertureWidthInInches * Mathf.Clamp(unityCamera.lensShift.x, 0f, 1f));
92-
fbxCamera.FilmOffsetY.Set(apertureHeightInInches * Mathf.Clamp(unityCamera.lensShift.y, 0f, 1f));
112+
fbxCamera.FilmOffsetX.Set(apertureWidthInInches * Mathf.Clamp(Mathf.Abs(unityCamera.lensShift.x), 0f, 1f) * Mathf.Sign(unityCamera.lensShift.x));
113+
fbxCamera.FilmOffsetY.Set(apertureHeightInInches * Mathf.Clamp(Mathf.Abs(unityCamera.lensShift.y), 0f, 1f) * Mathf.Sign(unityCamera.lensShift.y));
93114

94115
// Focal Length
95116
fbxCamera.SetApertureMode (FbxCamera.EApertureMode.eFocalLength);
@@ -102,7 +123,6 @@ private static void ConfigurePhysicalCamera (FbxCamera fbxCamera, Camera unityCa
102123

103124
// FarPlane
104125
fbxCamera.SetFarPlane ((float)unityCamera.farClipPlane.Meters().ToCentimeters());
105-
106126
return ;
107127
}
108128
}

com.unity.formats.fbx/Editor/FbxExporter.cs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,14 +1939,22 @@ private void ExportAnimationCurve (FbxNode fbxNode,
19391939
Debug.LogError (string.Format ("no fbx property {0} found on {1} node or nodeAttribute ", fbxPropertyChannelPair.Property, fbxNode.GetName ()));
19401940
return;
19411941
}
1942+
if (!fbxProperty.GetFlag(FbxPropertyFlags.EFlags.eAnimatable))
1943+
{
1944+
Debug.LogErrorFormat("fbx property {0} found on node {1} is not animatable", fbxPropertyChannelPair.Property, fbxNode.GetName());
1945+
}
19421946

19431947
// Create the AnimCurve on the channel
19441948
FbxAnimCurve fbxAnimCurve = fbxProperty.GetCurve (fbxAnimLayer, fbxPropertyChannelPair.Channel, true);
1949+
if(fbxAnimCurve == null)
1950+
{
1951+
return;
1952+
}
19451953

19461954
// create a convert scene helper so that we can convert from Unity to Maya
19471955
// AxisSystem (LeftHanded to RightHanded) and FBX's default units
19481956
// (Meters to Centimetres)
1949-
var convertSceneHelper = new UnityToMayaConvertSceneHelper (uniPropertyName);
1957+
var convertSceneHelper = new UnityToMayaConvertSceneHelper (uniPropertyName, fbxNode);
19501958

19511959
if (ModelExporter.ExportSettings.BakeAnimationProperty) {
19521960
ExportAnimationSamples (uniAnimCurve, fbxAnimCurve, frameRate, convertSceneHelper);
@@ -1960,10 +1968,14 @@ internal class UnityToMayaConvertSceneHelper
19601968
{
19611969
bool convertDistance = false;
19621970
bool convertToRadian = false;
1971+
bool convertLensShiftX = false;
1972+
bool convertLensShiftY = false;
1973+
1974+
FbxCamera camera = null;
19631975

19641976
float unitScaleFactor = 1f;
19651977

1966-
public UnityToMayaConvertSceneHelper(string uniPropertyName)
1978+
public UnityToMayaConvertSceneHelper(string uniPropertyName, FbxNode fbxNode)
19671979
{
19681980
System.StringComparison cc = System.StringComparison.CurrentCulture;
19691981

@@ -1972,6 +1984,12 @@ public UnityToMayaConvertSceneHelper(string uniPropertyName)
19721984
convertDistance |= partT;
19731985
convertDistance |= uniPropertyName.StartsWith ("m_Intensity", cc);
19741986
convertDistance |= uniPropertyName.ToLower().EndsWith("weight", cc);
1987+
convertLensShiftX |= uniPropertyName.StartsWith("m_LensShift.x", cc);
1988+
convertLensShiftY |= uniPropertyName.StartsWith("m_LensShift.y", cc);
1989+
if (convertLensShiftX || convertLensShiftY)
1990+
{
1991+
camera = fbxNode.GetCamera();
1992+
}
19751993

19761994
// The ParentConstraint's source Rotation Offsets are read in as radians, so make sure they are exported as radians
19771995
convertToRadian = uniPropertyName.StartsWith("m_RotationOffsets.Array.data", cc);
@@ -1987,9 +2005,26 @@ public UnityToMayaConvertSceneHelper(string uniPropertyName)
19872005

19882006
public float Convert(float value)
19892007
{
2008+
float convertedValue = value;
2009+
if (convertLensShiftX || convertLensShiftY)
2010+
{
2011+
convertedValue = Mathf.Clamp(Mathf.Abs(value), 0f, 1f)*Mathf.Sign(value);
2012+
}
2013+
if (camera != null)
2014+
{
2015+
if (convertLensShiftX)
2016+
{
2017+
convertedValue *= (float)camera.GetApertureWidth();
2018+
}
2019+
else if (convertLensShiftY)
2020+
{
2021+
convertedValue *= (float)camera.GetApertureHeight();
2022+
}
2023+
}
2024+
19902025
// left handed to right handed conversion
19912026
// meters to centimetres conversion
1992-
return unitScaleFactor * value;
2027+
return unitScaleFactor * convertedValue;
19932028
}
19942029

19952030
}

com.unity.formats.fbx/Editor/FbxPropertyChannelPair.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ public PropertyChannelMap(Dictionary<string,string> propertyMap, Dictionary<stri
9191
{
9292
{ "m_Intensity", "Intensity" },
9393
{ "field of view", "FieldOfView" },
94-
{ "m_Weight", "Weight" }
94+
{ "m_Weight", "Weight" },
95+
{ "m_FocalLength", "FocalLength" },
96+
{ "m_LensShift.x", "FilmOffsetX" },
97+
{ "m_LensShift.y", "FilmOffsetY" }
9598
};
9699

97100
/// <summary>

com.unity.formats.fbx/Editor/Sources.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)