@@ -169,93 +169,85 @@ private static UnityPropertyChannelPair GetUnityPropertyChannelPair(string fullP
169
169
return new UnityPropertyChannelPair ( property , channel ) ;
170
170
}
171
171
172
- private static FbxPropertyChannelPair [ ] GetChannelPairs ( string uniPropertyName , PropertyChannelMap propertyChannelMap )
172
+ private static string GetFbxProperty ( string uniProperty , Dictionary < string , string > propertyMap )
173
173
{
174
- // Unity property name is of the format "property.channel". Split by the last '.' and search for the property in the property dict, and channel in the channel dict.
175
- // If the property name is just "property" then the channel is null.
176
-
177
- var properties = propertyChannelMap . MapUnityPropToFbxProp ;
178
- var channels = propertyChannelMap . MapUnityChannelToFbxChannel ;
174
+ string fbxProperty ;
175
+ if ( ! propertyMap . TryGetValue ( uniProperty , out fbxProperty ) ) {
176
+ return null ;
177
+ }
178
+ return fbxProperty ;
179
+ }
179
180
180
- // First handle case where there's no channels.
181
- if ( channels == null )
181
+ private static string GetFbxConstraintSourceProperty ( string uniProperty , FbxConstraint constraint , Dictionary < string , string > propertyMap )
182
+ {
183
+ foreach ( var prop in propertyMap )
182
184
{
183
- string fbxProperty ;
184
- if ( properties . TryGetValue ( uniPropertyName , out fbxProperty ) )
185
+ var match = System . Text . RegularExpressions . Regex . Match ( uniProperty , prop . Key ) ;
186
+ if ( match . Success && match . Groups . Count > 0 )
185
187
{
186
- return new FbxPropertyChannelPair [ ] { new FbxPropertyChannelPair ( fbxProperty , null ) } ;
188
+ var matchedStr = match . Groups [ 1 ] . Value ;
189
+ int index ;
190
+ if ( ! int . TryParse ( matchedStr , out index ) )
191
+ {
192
+ continue ;
193
+ }
194
+ var source = constraint . GetConstraintSource ( index ) ;
195
+ return string . Format ( prop . Value , source . GetName ( ) ) ;
187
196
}
188
- return null ;
189
197
}
198
+ return null ;
199
+ }
190
200
191
- var uniPropChannelPair = GetUnityPropertyChannelPair ( uniPropertyName ) ;
192
- if ( uniPropChannelPair . channel == null )
201
+ private static string GetFbxChannel ( string uniChannel , Dictionary < string , string > channelMap )
202
+ {
203
+ string fbxChannel ;
204
+ if ( ! channelMap . TryGetValue ( uniChannel , out fbxChannel ) )
193
205
{
194
- // We've already checked the case where there are no channels
195
206
return null ;
196
207
}
208
+ return fbxChannel ;
209
+ }
197
210
198
- var property = uniPropChannelPair . property ;
199
- var channel = uniPropChannelPair . channel ;
211
+ private static FbxPropertyChannelPair [ ] GetChannelPairs ( string uniPropertyName , PropertyChannelMap propertyChannelMap , FbxConstraint constraint = null )
212
+ {
213
+ // Unity property name is of the format "property.channel" or "property". Handle both cases.
214
+ var possibleUniPropChannelPairs = new List < UnityPropertyChannelPair > ( ) ;
200
215
201
- string fbxProp ;
202
- if ( ! properties . TryGetValue ( property , out fbxProp ) )
216
+ // could give same result as already in the list, avoid checking this case twice
217
+ var propChannelPair = GetUnityPropertyChannelPair ( uniPropertyName ) ;
218
+ possibleUniPropChannelPairs . Add ( propChannelPair ) ;
219
+ if ( propChannelPair . property != uniPropertyName )
203
220
{
204
- return null ;
221
+ possibleUniPropChannelPairs . Add ( new UnityPropertyChannelPair ( uniPropertyName , null ) ) ;
205
222
}
206
223
207
- string fbxChannel ;
208
- if ( ! channels . TryGetValue ( channel , out fbxChannel ) )
224
+ foreach ( var uniPropChannelPair in possibleUniPropChannelPairs )
209
225
{
210
- return null ;
211
- }
212
-
213
- return new FbxPropertyChannelPair [ ] { new FbxPropertyChannelPair ( fbxProp , fbxChannel ) } ;
214
- }
215
-
216
- private static FbxPropertyChannelPair [ ] GetConstraintSourceChannelPairs ( string uniPropertyName , FbxConstraint constraint , PropertyChannelMap propertyChannelMap )
217
- {
218
- var properties = propertyChannelMap . MapUnityPropToFbxProp ;
219
- var channels = propertyChannelMap . MapUnityChannelToFbxChannel ;
226
+ // try to match property
227
+ var fbxProperty = GetFbxProperty ( uniPropChannelPair . property , propertyChannelMap . MapUnityPropToFbxProp ) ;
228
+ if ( string . IsNullOrEmpty ( fbxProperty ) && constraint != null )
229
+ {
230
+ // check if it's a constraint source property
231
+ fbxProperty = GetFbxConstraintSourceProperty ( uniPropChannelPair . property , constraint , propertyChannelMap . MapUnityPropToFbxProp ) ;
232
+ }
233
+ if ( string . IsNullOrEmpty ( fbxProperty ) )
234
+ {
235
+ continue ;
236
+ }
220
237
221
- foreach ( var prop in properties )
222
- {
223
- var match = System . Text . RegularExpressions . Regex . Match ( uniPropertyName , prop . Key ) ;
224
- if ( match . Success && match . Groups . Count > 0 )
238
+ // matched property, now try to match channel
239
+ string fbxChannel = null ;
240
+ if ( ! string . IsNullOrEmpty ( uniPropChannelPair . channel ) && propertyChannelMap . MapUnityChannelToFbxChannel != null )
225
241
{
226
- var matchedStr = match . Groups [ 1 ] . Value ;
227
- int index ;
228
- if ( ! int . TryParse ( matchedStr , out index ) )
242
+ fbxChannel = GetFbxChannel ( uniPropChannelPair . channel , propertyChannelMap . MapUnityChannelToFbxChannel ) ;
243
+ if ( string . IsNullOrEmpty ( fbxChannel ) )
229
244
{
245
+ // couldn't match the Unity channel to the fbx channel
230
246
continue ;
231
247
}
232
- var source = constraint . GetConstraintSource ( index ) ;
233
- var fbxName = string . Format ( prop . Value , source . GetName ( ) ) ;
234
-
235
- // Have the fbx name, now need the channel
236
- if ( channels == null )
237
- {
238
- // no channel, we have what we need
239
- return new FbxPropertyChannelPair [ ] { new FbxPropertyChannelPair ( fbxName , null ) } ;
240
- }
241
-
242
- var uniPropChannelPair = GetUnityPropertyChannelPair ( uniPropertyName ) ;
243
- if ( uniPropChannelPair . channel == null )
244
- {
245
- // We've already checked the case where there are no channels
246
- return null ;
247
- }
248
-
249
- var channel = uniPropChannelPair . channel ;
250
- string fbxChannel ;
251
- if ( ! channels . TryGetValue ( channel , out fbxChannel ) )
252
- {
253
- return null ;
254
- }
255
- return new FbxPropertyChannelPair [ ] { new FbxPropertyChannelPair ( fbxName , fbxChannel ) } ;
256
248
}
249
+ return new FbxPropertyChannelPair [ ] { new FbxPropertyChannelPair ( fbxProperty , fbxChannel ) } ;
257
250
}
258
-
259
251
return null ;
260
252
}
261
253
@@ -278,52 +270,34 @@ public static bool TryGetValue(string uniPropertyName, out FbxPropertyChannelPai
278
270
return true ;
279
271
}
280
272
273
+ var propertyMaps = new List < PropertyChannelMap > ( ) ;
274
+
281
275
// Try get constraint specific channel pairs first as we know this is a constraint
282
276
if ( constraint != null )
283
277
{
284
278
// Aim constraint shares the RotationOffset property with RotationConstraint, so make sure that the correct FBX property is returned
285
279
if ( constraint . GetConstraintType ( ) == FbxConstraint . EType . eAim )
286
280
{
287
- prop = GetChannelPairs ( uniPropertyName , AimConstraintPropertyMap ) ;
288
- if ( prop != null )
289
- {
290
- return true ;
291
- }
281
+ propertyMaps . Add ( AimConstraintPropertyMap ) ;
292
282
}
293
283
294
- var constraintPropertyMaps = new List < PropertyChannelMap > ( )
295
- {
296
- ConstraintSourcePropertyMap ,
297
- ConstraintSourceTransformPropertyMap
298
- } ;
299
-
300
- foreach ( var propMap in constraintPropertyMaps )
301
- {
302
- prop = GetConstraintSourceChannelPairs ( uniPropertyName , constraint , propMap ) ;
303
- if ( prop != null )
304
- {
305
- return true ;
306
- }
307
- }
284
+ propertyMaps . Add ( ConstraintSourcePropertyMap ) ;
285
+ propertyMaps . Add ( ConstraintSourceTransformPropertyMap ) ;
308
286
}
309
287
310
288
// Check if this is a transform, color, or other property and return the channel pairs if they match.
311
- var propertyMaps = new List < PropertyChannelMap > ( )
312
- {
313
- TransformPropertyMap ,
314
- ColorPropertyMap ,
315
- OtherPropertyMap
316
- } ;
289
+ propertyMaps . Add ( TransformPropertyMap ) ;
290
+ propertyMaps . Add ( ColorPropertyMap ) ;
291
+ propertyMaps . Add ( OtherPropertyMap ) ;
317
292
318
293
foreach ( var propMap in propertyMaps )
319
294
{
320
- prop = GetChannelPairs ( uniPropertyName , propMap ) ;
295
+ prop = GetChannelPairs ( uniPropertyName , propMap , constraint ) ;
321
296
if ( prop != null )
322
297
{
323
298
return true ;
324
299
}
325
300
}
326
-
327
301
return false ;
328
302
}
329
303
}
0 commit comments