Skip to content

Commit 1d411df

Browse files
committed
move property channel pair to a new file
1 parent 3a824e5 commit 1d411df

File tree

3 files changed

+274
-225
lines changed

3 files changed

+274
-225
lines changed

Assets/FbxExporters/Editor/FbxExporter.cs

Lines changed: 0 additions & 225 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,231 +2000,6 @@ public float Convert(float value)
20002000

20012001
}
20022002

2003-
/// <summary>
2004-
/// Store FBX property name and channel name
2005-
/// Default constructor added because it needs to be called before autoimplemented properties can be assigned. Otherwise we get build errors
2006-
/// </summary>
2007-
struct FbxPropertyChannelPair {
2008-
public string Property { get; private set; }
2009-
public string Channel { get; private set; }
2010-
2011-
/// <summary>
2012-
/// Map of Unity transform properties to their FBX equivalent.
2013-
/// </summary>
2014-
private static Dictionary<string, string> TransformProperties = new Dictionary<string, string>()
2015-
{
2016-
{ "m_LocalScale", "Lcl Scaling" },
2017-
{ "S", "Lcl Scaling" },
2018-
{ "m_LocalPosition", "Lcl Translation" },
2019-
{ "T", "Lcl Translation" },
2020-
{ "m_TranslationOffset", "Translation" },
2021-
{ "m_ScaleOffset", "Scaling" },
2022-
{ "m_RotationOffset", "Rotation" }
2023-
};
2024-
2025-
/// <summary>
2026-
/// Map of Unity Aim constraint properties to their FBX equivalent.
2027-
/// </summary>
2028-
private static Dictionary<string, string> AimConstraintProperties = new Dictionary<string, string>()
2029-
{
2030-
{ "m_AimVector", "AimVector" },
2031-
{ "m_UpVector", "UpVector" },
2032-
{ "m_WorldUpVector", "WorldUpVector" },
2033-
{ "m_RotationOffset", "RotationOffset" }
2034-
};
2035-
2036-
/// <summary>
2037-
/// Map of Unity transform channels to their FBX equivalent.
2038-
/// </summary>
2039-
private static Dictionary<string, string> TransformChannels = new Dictionary<string, string>()
2040-
{
2041-
{ "x", Globals.FBXSDK_CURVENODE_COMPONENT_X },
2042-
{ "y", Globals.FBXSDK_CURVENODE_COMPONENT_Y },
2043-
{ "z", Globals.FBXSDK_CURVENODE_COMPONENT_Z }
2044-
};
2045-
2046-
/// <summary>
2047-
/// Map of Unity color properties to their FBX equivalent.
2048-
/// </summary>
2049-
private static Dictionary<string, string> ColorProperties = new Dictionary<string, string>()
2050-
{
2051-
{ "m_Color", "Color" }
2052-
};
2053-
2054-
/// <summary>
2055-
/// Map of Unity color channels to their FBX equivalent.
2056-
/// </summary>
2057-
private static Dictionary<string, string> ColorChannels = new Dictionary<string, string>()
2058-
{
2059-
{ "b", Globals.FBXSDK_CURVENODE_COLOR_BLUE },
2060-
{ "g", Globals.FBXSDK_CURVENODE_COLOR_GREEN },
2061-
{ "r", Globals.FBXSDK_CURVENODE_COLOR_RED }
2062-
};
2063-
2064-
/// <summary>
2065-
/// Map of Unity properties to their FBX equivalent.
2066-
/// </summary>
2067-
private static Dictionary<string, string> OtherProperties = new Dictionary<string, string>()
2068-
{
2069-
{ "m_Intensity", "Intensity" },
2070-
{ "field of view", "FieldOfView" },
2071-
{ "m_Weight", "Weight" }
2072-
};
2073-
2074-
/// <summary>
2075-
/// Map of empty string to null, used for properties that don't need a channel.
2076-
/// </summary>
2077-
private static Dictionary<string, string> NullChannel = new Dictionary<string, string>() { { "", null } };
2078-
2079-
/// <summary>
2080-
/// Map of Unity constraint source property name as a regular expression to the FBX property as a string format.
2081-
/// This is necessary because the Unity property contains an index in to an array, and the FBX property contains
2082-
/// the name of the source object.
2083-
/// </summary>
2084-
private static Dictionary<string, string> ConstraintSourceProperties = new Dictionary<string, string>()
2085-
{
2086-
{ @"m_Sources\.Array\.data\[(\d+)\]\.weight", "{0}.Weight" }
2087-
};
2088-
2089-
/// <summary>
2090-
/// Map of Unity constraint source transform property name as a regular expression to the FBX property as a string format.
2091-
/// This is necessary because the Unity property contains an index in to an array, and the FBX property contains
2092-
/// the name of the source object.
2093-
/// </summary>
2094-
private static Dictionary<string, string> ConstraintSourceTransformProperties = new Dictionary<string, string>()
2095-
{
2096-
{ @"m_TranslationOffsets\.Array\.data\[(\d+)\]", "{0}.Offset T" },
2097-
{ @"m_RotationOffsets\.Array\.data\[(\d+)\]", "{0}.Offset R" }
2098-
};
2099-
2100-
public FbxPropertyChannelPair(string p, string c) : this() {
2101-
Property = p;
2102-
Channel = c;
2103-
}
2104-
2105-
private static bool TryGetChannel(string uniPropertyName, string uniName, string propFormat, Dictionary<string, string> channels, out string outChannel)
2106-
{
2107-
outChannel = null;
2108-
foreach (var channel in channels)
2109-
{
2110-
var uniChannel = channel.Key;
2111-
var fbxChannel = channel.Value;
2112-
if (uniPropertyName.EndsWith(string.Format(propFormat, uniName, uniChannel)))
2113-
{
2114-
outChannel = fbxChannel;
2115-
return true;
2116-
}
2117-
}
2118-
return false;
2119-
}
2120-
2121-
private static bool TryGetChannelPairs(string uniPropertyName, string propFormat, Dictionary<string, string> properties, Dictionary<string, string> channels, ref FbxPropertyChannelPair[] channelPairs)
2122-
{
2123-
foreach (var item in properties)
2124-
{
2125-
var uniName = item.Key;
2126-
var fbxName = item.Value;
2127-
2128-
string channel;
2129-
if(TryGetChannel(uniPropertyName, uniName, propFormat, channels, out channel)) {
2130-
channelPairs = new FbxPropertyChannelPair[] { new FbxPropertyChannelPair(fbxName, channel) };
2131-
return true;
2132-
}
2133-
}
2134-
return false;
2135-
}
2136-
2137-
private static bool TryGetConstraintSourceChannelPairs(string uniPropertyName, FbxConstraint constraint, Dictionary<string, string> properties, Dictionary<string, string> channels, ref FbxPropertyChannelPair[] channelPairs)
2138-
{
2139-
foreach (var prop in properties)
2140-
{
2141-
var match = System.Text.RegularExpressions.Regex.Match(uniPropertyName, prop.Key);
2142-
if (match.Success && match.Groups.Count > 0)
2143-
{
2144-
var matchedStr = match.Groups[1].Value;
2145-
int index;
2146-
if (!int.TryParse(matchedStr, out index))
2147-
{
2148-
continue;
2149-
}
2150-
var source = constraint.GetConstraintSource(index);
2151-
var fbxName = string.Format(prop.Value, source.GetName());
2152-
string channel;
2153-
// we've already matched with the property name, just get the channel
2154-
if(TryGetChannel(uniPropertyName, "", "{1}", channels, out channel)){
2155-
channelPairs = new FbxPropertyChannelPair[] { new FbxPropertyChannelPair(fbxName, channel) };
2156-
return true;
2157-
}
2158-
}
2159-
}
2160-
return false;
2161-
}
2162-
2163-
/// <summary>
2164-
/// Map a Unity property name to the corresponding FBX property and
2165-
/// channel names.
2166-
/// </summary>
2167-
public static bool TryGetValue(string uniPropertyName, out FbxPropertyChannelPair[] prop, FbxConstraint constraint = null)
2168-
{
2169-
System.StringComparison ct = System.StringComparison.CurrentCulture;
2170-
2171-
prop = new FbxPropertyChannelPair[] { };
2172-
var propFormat = "{0}.{1}";
2173-
2174-
if (constraint != null)
2175-
{
2176-
// Aim constraint shares the RotationOffset property with RotationConstraint, so make sure that the correct FBX property is returned
2177-
if (constraint.GetConstraintType() == FbxConstraint.EType.eAim)
2178-
{
2179-
if (TryGetChannelPairs(uniPropertyName, propFormat, AimConstraintProperties, TransformChannels, ref prop))
2180-
{
2181-
return true;
2182-
}
2183-
}
2184-
2185-
if (TryGetConstraintSourceChannelPairs(uniPropertyName, constraint, ConstraintSourceProperties, NullChannel, ref prop))
2186-
{
2187-
return true;
2188-
}
2189-
2190-
if(TryGetConstraintSourceChannelPairs(uniPropertyName, constraint, ConstraintSourceTransformProperties, TransformChannels, ref prop))
2191-
{
2192-
return true;
2193-
}
2194-
}
2195-
2196-
// Transform Properties
2197-
if(TryGetChannelPairs(uniPropertyName, propFormat, TransformProperties, TransformChannels, ref prop))
2198-
{
2199-
return true;
2200-
}
2201-
2202-
// Color Properties
2203-
if(TryGetChannelPairs(uniPropertyName, propFormat, ColorProperties, ColorChannels, ref prop))
2204-
{
2205-
return true;
2206-
}
2207-
2208-
// Other Properties
2209-
if(TryGetChannelPairs(uniPropertyName, "{0}", OtherProperties, NullChannel, ref prop))
2210-
{
2211-
return true;
2212-
}
2213-
2214-
// spot angle is a special case as it returns two channel pairs instead of one
2215-
if (uniPropertyName.StartsWith("m_SpotAngle", ct))
2216-
{
2217-
prop = new FbxPropertyChannelPair[]{
2218-
new FbxPropertyChannelPair ("OuterAngle", null),
2219-
new FbxPropertyChannelPair ("InnerAngle", null)
2220-
};
2221-
return true;
2222-
}
2223-
2224-
return false;
2225-
}
2226-
}
2227-
22282003
/// <summary>
22292004
/// Export an AnimationClip as a single take
22302005
/// </summary>

0 commit comments

Comments
 (0)