@@ -1984,15 +1984,16 @@ public class UnityToMayaConvertSceneHelper
1984
1984
{
1985
1985
bool convertDistance = false ;
1986
1986
bool convertLtoR = false ;
1987
+ bool convertToRadian = false ;
1987
1988
1988
1989
float unitScaleFactor = 1f ;
1989
1990
1990
1991
public UnityToMayaConvertSceneHelper ( string uniPropertyName )
1991
1992
{
1992
1993
System . StringComparison cc = System . StringComparison . CurrentCulture ;
1993
1994
1994
- bool partT = uniPropertyName . StartsWith ( "m_LocalPosition." , cc ) || uniPropertyName . StartsWith ( "m_TranslationOffset. " , cc ) ;
1995
- bool partTx = uniPropertyName . EndsWith ( "Position.x" , cc ) || uniPropertyName . EndsWith ( "T.x" , cc ) || uniPropertyName . EndsWith ( "TranslationOffset .x" , cc ) ;
1995
+ bool partT = uniPropertyName . StartsWith ( "m_LocalPosition." , cc ) || uniPropertyName . StartsWith ( "m_TranslationOffset" , cc ) ;
1996
+ bool partTx = uniPropertyName . EndsWith ( "Position.x" , cc ) || uniPropertyName . EndsWith ( "T.x" , cc ) || ( uniPropertyName . StartsWith ( "m_TranslationOffset" ) && uniPropertyName . EndsWith ( ".x" , cc ) ) ;
1996
1997
bool partRyz = uniPropertyName . StartsWith ( "m_RotationOffset" , cc ) && ( uniPropertyName . EndsWith ( ".y" ) || uniPropertyName . EndsWith ( ".z" ) ) ;
1997
1998
1998
1999
convertLtoR |= partTx ;
@@ -2002,11 +2003,19 @@ public UnityToMayaConvertSceneHelper(string uniPropertyName)
2002
2003
convertDistance |= uniPropertyName . StartsWith ( "m_Intensity" , cc ) ;
2003
2004
convertDistance |= uniPropertyName . ToLower ( ) . EndsWith ( "weight" , cc ) ;
2004
2005
2005
- if ( convertDistance )
2006
+ // The ParentConstraint's source Rotation Offsets are read in as radians, so make sure they are exported as radians
2007
+ convertToRadian = uniPropertyName . StartsWith ( "m_RotationOffsets.Array.data" , cc ) ;
2008
+
2009
+ if ( convertDistance )
2006
2010
unitScaleFactor = ModelExporter . UnitScaleFactor ;
2007
2011
2008
2012
if ( convertLtoR )
2009
2013
unitScaleFactor = - unitScaleFactor ;
2014
+
2015
+ if ( convertToRadian )
2016
+ {
2017
+ unitScaleFactor *= ( Mathf . PI / 180 ) ;
2018
+ }
2010
2019
}
2011
2020
2012
2021
public float Convert ( float value )
@@ -2066,43 +2075,57 @@ struct FbxPropertyChannelPair {
2066
2075
{ "field of view" , "FieldOfView" } ,
2067
2076
{ "m_Weight" , "Weight" }
2068
2077
} ;
2078
+ private static Dictionary < string , string > NullChannel = new Dictionary < string , string > ( ) { { "" , null } } ;
2069
2079
private static Dictionary < string , string > ConstraintSourceProperties = new Dictionary < string , string > ( )
2070
2080
{
2071
- { "m_Sources\\ .Array\\ .data\\ [(\\ d+)\\ ]\\ .weight" , "{0}.Weight" } ,
2081
+ { "m_Sources\\ .Array\\ .data\\ [(\\ d+)\\ ]\\ .weight" , "{0}.Weight" }
2082
+ } ;
2083
+ private static Dictionary < string , string > ConstraintSourceTransformProperties = new Dictionary < string , string > ( )
2084
+ {
2072
2085
{ "m_TranslationOffsets\\ .Array\\ .data\\ [(\\ d+)\\ ]" , "{0}.Offset T" } ,
2073
- { "m_RotationOffsets\\ .Array\\ .data\\ [\\ d+)\\ ]" , "{0}.Offset R" }
2086
+ { "m_RotationOffsets\\ .Array\\ .data\\ [( \\ d+)\\ ]" , "{0}.Offset R" }
2074
2087
} ;
2075
2088
2076
2089
public FbxPropertyChannelPair ( string p , string c ) : this ( ) {
2077
2090
Property = p ;
2078
2091
Channel = c ;
2079
2092
}
2080
2093
2081
- private static bool TryGetChannelPairs ( string uniPropertyName , string propFormat , Dictionary < string , string > properties , Dictionary < string , string > channels , ref FbxPropertyChannelPair [ ] channelPairs )
2094
+ private static bool TryGetChannel ( string uniPropertyName , string uniName , string propFormat , Dictionary < string , string > channels , out string outChannel )
2082
2095
{
2083
- System . StringComparison ct = System . StringComparison . CurrentCulture ;
2096
+ outChannel = null ;
2097
+ foreach ( var channel in channels )
2098
+ {
2099
+ var uniChannel = channel . Key ;
2100
+ var fbxChannel = channel . Value ;
2101
+ if ( uniPropertyName . EndsWith ( string . Format ( propFormat , uniName , uniChannel ) ) )
2102
+ {
2103
+ outChannel = fbxChannel ;
2104
+ return true ;
2105
+ }
2106
+ }
2107
+ return false ;
2108
+ }
2084
2109
2110
+ private static bool TryGetChannelPairs ( string uniPropertyName , string propFormat , Dictionary < string , string > properties , Dictionary < string , string > channels , ref FbxPropertyChannelPair [ ] channelPairs )
2111
+ {
2085
2112
foreach ( var item in properties )
2086
2113
{
2087
2114
var uniName = item . Key ;
2088
2115
var fbxName = item . Value ;
2089
- foreach ( var entry in channels )
2090
- {
2091
- var uniChannel = entry . Key ;
2092
- var fbxChannel = entry . Value ;
2093
- if ( uniPropertyName . EndsWith ( string . Format ( propFormat , uniName , uniChannel ) , ct ) )
2094
- {
2095
- channelPairs = new FbxPropertyChannelPair [ ] { new FbxPropertyChannelPair ( fbxName , fbxChannel ) } ;
2096
- return true ;
2097
- }
2116
+
2117
+ string channel ;
2118
+ if ( TryGetChannel ( uniPropertyName , uniName , propFormat , channels , out channel ) ) {
2119
+ channelPairs = new FbxPropertyChannelPair [ ] { new FbxPropertyChannelPair ( fbxName , channel ) } ;
2120
+ return true ;
2098
2121
}
2099
2122
}
2100
2123
return false ;
2101
2124
}
2102
2125
2103
- private static bool TryGetConstraintSourceChannelPairs ( string uniPropertyName , FbxConstraint constraint , ref FbxPropertyChannelPair [ ] channelPairs )
2126
+ private static bool TryGetConstraintSourceChannelPairs ( string uniPropertyName , FbxConstraint constraint , Dictionary < string , string > properties , Dictionary < string , string > channels , ref FbxPropertyChannelPair [ ] channelPairs )
2104
2127
{
2105
- foreach ( var prop in ConstraintSourceProperties )
2128
+ foreach ( var prop in properties )
2106
2129
{
2107
2130
var match = System . Text . RegularExpressions . Regex . Match ( uniPropertyName , prop . Key ) ;
2108
2131
if ( match . Success && match . Groups . Count > 0 )
@@ -2115,8 +2138,12 @@ private static bool TryGetConstraintSourceChannelPairs(string uniPropertyName, F
2115
2138
}
2116
2139
var source = constraint . GetConstraintSource ( index ) ;
2117
2140
var fbxName = string . Format ( prop . Value , source . GetName ( ) ) ;
2118
- channelPairs = new FbxPropertyChannelPair [ ] { new FbxPropertyChannelPair ( fbxName , null ) } ;
2119
- return true ;
2141
+ string channel ;
2142
+ // we've already matched with the property name, just get the channel
2143
+ if ( TryGetChannel ( uniPropertyName , "" , "{1}" , channels , out channel ) ) {
2144
+ channelPairs = new FbxPropertyChannelPair [ ] { new FbxPropertyChannelPair ( fbxName , channel ) } ;
2145
+ return true ;
2146
+ }
2120
2147
}
2121
2148
}
2122
2149
return false ;
@@ -2131,9 +2158,31 @@ public static bool TryGetValue(string uniPropertyName, out FbxPropertyChannelPai
2131
2158
System . StringComparison ct = System . StringComparison . CurrentCulture ;
2132
2159
2133
2160
prop = new FbxPropertyChannelPair [ ] { } ;
2161
+ var propFormat = "{0}.{1}" ;
2162
+
2163
+ if ( constraint != null )
2164
+ {
2165
+ // Aim constraint shares the RotationOffset property with RotationConstraint, so make sure that the correct FBX property is returned
2166
+ if ( constraint . GetConstraintType ( ) == FbxConstraint . EType . eAim )
2167
+ {
2168
+ if ( TryGetChannelPairs ( uniPropertyName , propFormat , AimConstraintProperties , TransformChannels , ref prop ) )
2169
+ {
2170
+ return true ;
2171
+ }
2172
+ }
2173
+
2174
+ if ( TryGetConstraintSourceChannelPairs ( uniPropertyName , constraint , ConstraintSourceProperties , NullChannel , ref prop ) )
2175
+ {
2176
+ return true ;
2177
+ }
2178
+
2179
+ if ( TryGetConstraintSourceChannelPairs ( uniPropertyName , constraint , ConstraintSourceTransformProperties , TransformChannels , ref prop ) )
2180
+ {
2181
+ return true ;
2182
+ }
2183
+ }
2134
2184
2135
2185
// Transform Properties
2136
- var propFormat = "{0}.{1}" ;
2137
2186
if ( TryGetChannelPairs ( uniPropertyName , propFormat , TransformProperties , TransformChannels , ref prop ) )
2138
2187
{
2139
2188
return true ;
@@ -2146,7 +2195,7 @@ public static bool TryGetValue(string uniPropertyName, out FbxPropertyChannelPai
2146
2195
}
2147
2196
2148
2197
// Other Properties
2149
- if ( TryGetChannelPairs ( uniPropertyName , "{0}" , OtherProperties , new Dictionary < string , string > ( ) { { "" , null } } , ref prop ) )
2198
+ if ( TryGetChannelPairs ( uniPropertyName , "{0}" , OtherProperties , NullChannel , ref prop ) )
2150
2199
{
2151
2200
return true ;
2152
2201
}
@@ -2161,23 +2210,6 @@ public static bool TryGetValue(string uniPropertyName, out FbxPropertyChannelPai
2161
2210
return true ;
2162
2211
}
2163
2212
2164
- if ( constraint != null )
2165
- {
2166
- // Aim constraint shares the RotationOffset property with RotationConstraint, so make sure that the correct FBX property is returned
2167
- if ( constraint . GetConstraintType ( ) == FbxConstraint . EType . eAim )
2168
- {
2169
- if ( TryGetChannelPairs ( uniPropertyName , propFormat , AimConstraintProperties , TransformChannels , ref prop ) )
2170
- {
2171
- return true ;
2172
- }
2173
- }
2174
-
2175
- if ( TryGetConstraintSourceChannelPairs ( uniPropertyName , constraint , ref prop ) )
2176
- {
2177
- return true ;
2178
- }
2179
- }
2180
-
2181
2213
return false ;
2182
2214
}
2183
2215
}
0 commit comments