public int Main(KeyData keyData, string testName, string path) { if (!keyData.targetObject) { keyData.targetObject = CreateTargetObject(testName, keyData.componentType); } Animation animOrig = keyData.targetObject.AddComponent(typeof(Animation)) as Animation; AnimationClip animClipOriginal = new AnimationClip(); var animCurvesOriginal = new AnimationCurve[keyData.NumProperties]; animClipOriginal.legacy = true; animClipOriginal.name = "anim_" + testName; for (int id = 0; id < keyData.NumProperties; id++) { // initialize keys Keyframe [] keys = new Keyframe [keyData.NumKeys]; for (int idx = 0; idx < keyData.NumKeys; idx++) { keys [idx].time = keyData.keyTimes [idx]; keys [idx].value = keyData.GetKeyValues(id) [idx]; } animCurvesOriginal[id] = new AnimationCurve(keys); animClipOriginal.SetCurve("", keyData.componentType, keyData.GetPropertyName(id), animCurvesOriginal[id]); } animOrig.AddClip(animClipOriginal, animClipOriginal.name); animOrig.clip = animClipOriginal; // NOTE: when we first cached the curves the tangents wheren't set. foreach (EditorCurveBinding curveBinding in AnimationUtility.GetCurveBindings(animOrig.clip)) { int id = keyData.GetIndexOf(curveBinding.propertyName); if (id == -1) { continue; } animCurvesOriginal[id] = AnimationUtility.GetEditorCurve(animOrig.clip, curveBinding); } // TODO: add extra parent so that we can test export/import of transforms var goRoot = new GameObject(); goRoot.name = "Root_" + testName; keyData.targetObject.transform.parent = goRoot.transform; //export the object var exportedFilePath = ModelExporter.ExportObject(path, goRoot); Assert.That(exportedFilePath, Is.EqualTo(path)); // TODO: Uni-34492 change importer settings of (newly exported model) // so that it's not resampled and it is legacy animation AnimTester.ConfigureImportSettings(path, keyData.importSettings); // create a scene GO so we can compare. #if DEBUG_UNITTEST GameObject prefabGO = AssetDatabase.LoadMainAssetAtPath(path) as GameObject; GameObject sceneGO = Object.Instantiate(prefabGO, keyData.targetObject.transform.localPosition, keyData.targetObject.transform.localRotation); sceneGO.name = "Imported_" + testName; #endif //acquire imported object from exported file AnimationClip animClipImported = GetClipFromFbx(path); ClipPropertyTest(animClipOriginal, animClipImported); int result = 0; foreach (EditorCurveBinding curveBinding in AnimationUtility.GetCurveBindings(animClipImported)) { AnimationCurve animCurveImported = AnimationUtility.GetEditorCurve(animClipImported, curveBinding); Assert.That(animCurveImported, Is.Not.Null); string propertyBinding = curveBinding.propertyName; int id = keyData.GetIndexOf(propertyBinding); bool hasQuatBinding = MapEulerToQuaternionPropertyName.TryGetValue(propertyBinding, out propertyBinding); bool isRotation = AnimationTestDataClass.m_rotationEulerNames.Contains(curveBinding.propertyName) || AnimationTestDataClass.m_rotationQuaternionNames.Contains(curveBinding.propertyName); if (id == -1) { id = keyData.GetIndexOf(propertyBinding); } #if DEBUG_UNITTEST Debug.Log(string.Format("propertyBinding={0} mappedBinding={1} id={2}", curveBinding.propertyName, propertyBinding, id)); #endif if (id != -1) { if (keyData.compareOriginalKeys) { // NOTE: we cannot compare the keys that exported quaternion but are imported as euler. if (!hasQuatBinding) { // compare against original keydata KeysTest(keyData.keyTimes, keyData.GetKeyValues(id), animCurveImported, curveBinding.propertyName); // compare against original animCurve KeysTest(animCurvesOriginal[id], animCurveImported, curveBinding.propertyName, keyComparer); } else { // compare by sampled keyvalues against original keydata KeyValuesTest(keyData.keyTimes, keyData.GetAltKeyValues(id), animCurveImported, curveBinding.propertyName, isRotation); } } else { // compare by sampled keyvalues against original animCurve KeyValuesTest(animCurvesOriginal[id], animCurveImported, curveBinding.propertyName, isRotation); } result++; } } return(result); }