Skip to content

Commit b0cc284

Browse files
committed
export animated focal length and lens shift
1 parent bfc855e commit b0cc284

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ private static void ConfigurePhysicalCamera (FbxCamera fbxCamera, Camera unityCa
109109

110110
// Lens Shift ( Film Offset ) as a percentage 0..1
111111
// FBX FilmOffset is in inches
112-
fbxCamera.FilmOffsetX.Set(apertureWidthInInches * Mathf.Clamp(unityCamera.lensShift.x, 0f, 1f));
113-
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));
114114

115115
// Focal Length
116116
fbxCamera.SetApertureMode (FbxCamera.EApertureMode.eFocalLength);
@@ -123,7 +123,6 @@ private static void ConfigurePhysicalCamera (FbxCamera fbxCamera, Camera unityCa
123123

124124
// FarPlane
125125
fbxCamera.SetFarPlane ((float)unityCamera.farClipPlane.Meters().ToCentimeters());
126-
127126
return ;
128127
}
129128
}

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,14 +1984,22 @@ private void ExportAnimationCurve (FbxNode fbxNode,
19841984
Debug.LogError (string.Format ("no fbx property {0} found on {1} node or nodeAttribute ", fbxPropertyChannelPair.Property, fbxNode.GetName ()));
19851985
return;
19861986
}
1987+
if (!fbxProperty.GetFlag(FbxPropertyFlags.EFlags.eAnimatable))
1988+
{
1989+
Debug.LogErrorFormat("fbx property {0} found on node {1} is not animatable", fbxPropertyChannelPair.Property, fbxNode.GetName());
1990+
}
19871991

19881992
// Create the AnimCurve on the channel
19891993
FbxAnimCurve fbxAnimCurve = fbxProperty.GetCurve (fbxAnimLayer, fbxPropertyChannelPair.Channel, true);
1994+
if(fbxAnimCurve == null)
1995+
{
1996+
return;
1997+
}
19901998

19911999
// create a convert scene helper so that we can convert from Unity to Maya
19922000
// AxisSystem (LeftHanded to RightHanded) and FBX's default units
19932001
// (Meters to Centimetres)
1994-
var convertSceneHelper = new UnityToMayaConvertSceneHelper (uniPropertyName);
2002+
var convertSceneHelper = new UnityToMayaConvertSceneHelper (uniPropertyName, fbxNode);
19952003

19962004
// TODO: we'll resample the curve so we don't have to
19972005
// configure tangents
@@ -2008,10 +2016,14 @@ internal class UnityToMayaConvertSceneHelper
20082016
bool convertDistance = false;
20092017
bool convertLtoR = false;
20102018
bool convertToRadian = false;
2019+
bool convertLensShiftX = false;
2020+
bool convertLensShiftY = false;
2021+
2022+
FbxCamera camera = null;
20112023

20122024
float unitScaleFactor = 1f;
20132025

2014-
public UnityToMayaConvertSceneHelper(string uniPropertyName)
2026+
public UnityToMayaConvertSceneHelper(string uniPropertyName, FbxNode fbxNode)
20152027
{
20162028
System.StringComparison cc = System.StringComparison.CurrentCulture;
20172029

@@ -2025,6 +2037,12 @@ public UnityToMayaConvertSceneHelper(string uniPropertyName)
20252037
convertDistance |= partT;
20262038
convertDistance |= uniPropertyName.StartsWith ("m_Intensity", cc);
20272039
convertDistance |= uniPropertyName.ToLower().EndsWith("weight", cc);
2040+
convertLensShiftX |= uniPropertyName.StartsWith("m_LensShift.x", cc);
2041+
convertLensShiftY |= uniPropertyName.StartsWith("m_LensShift.y", cc);
2042+
if (convertLensShiftX || convertLensShiftY)
2043+
{
2044+
camera = fbxNode.GetCamera();
2045+
}
20282046

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

20442062
public float Convert(float value)
20452063
{
2064+
float convertedValue = value;
2065+
if (convertLensShiftX || convertLensShiftY)
2066+
{
2067+
convertedValue = Mathf.Clamp(Mathf.Abs(value), 0f, 1f)*Mathf.Sign(value);
2068+
}
2069+
if (camera != null)
2070+
{
2071+
if (convertLensShiftX)
2072+
{
2073+
convertedValue *= (float)camera.GetApertureWidth();
2074+
}
2075+
else if (convertLensShiftY)
2076+
{
2077+
convertedValue *= (float)camera.GetApertureHeight();
2078+
}
2079+
}
2080+
20462081
// left handed to right handed conversion
20472082
// meters to centimetres conversion
2048-
return unitScaleFactor * value;
2083+
return unitScaleFactor * convertedValue;
20492084
}
20502085

20512086
}

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

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

9699
/// <summary>

0 commit comments

Comments
 (0)