diff --git a/TestProject/Packages/manifest.json b/TestProject/Packages/manifest.json index 58c35850d..a4eec6cd5 100644 --- a/TestProject/Packages/manifest.json +++ b/TestProject/Packages/manifest.json @@ -1,12 +1,10 @@ { "dependencies": { - "com.unity.ads": "2.0.8", - "com.unity.analytics": "3.2.2", - "com.unity.collab-proxy": "1.2.15", + "com.unity.analytics": "3.3.5", + "com.unity.ext.nunit": "1.0.0", "com.unity.formats.usd": "file:../../package/com.unity.formats.usd/", "com.unity.package-manager-ui": "2.0.3", - "com.unity.purchasing": "2.0.3", - "com.unity.textmeshpro": "1.3.0", + "com.unity.test-framework": "1.1.11", "com.unity.modules.ai": "1.0.0", "com.unity.modules.animation": "1.0.0", "com.unity.modules.assetbundle": "1.0.0", @@ -38,8 +36,7 @@ "com.unity.modules.wind": "1.0.0", "com.unity.modules.xr": "1.0.0" }, - "testables": - [ + "testables": [ "com.unity.formats.usd" ] } diff --git a/package/com.unity.formats.usd/CHANGELOG.md b/package/com.unity.formats.usd/CHANGELOG.md index 693e857f2..d0151b623 100644 --- a/package/com.unity.formats.usd/CHANGELOG.md +++ b/package/com.unity.formats.usd/CHANGELOG.md @@ -1,5 +1,9 @@ # Changes in usd-unitysdk for Unity +## [1.0.3-preview.1] - 2020-04-01 +### Changed +- Fix the "Slow and safe as FBX" loading mode to perform the basis change as the FBX importer (#129) + ## [1.0.2-preview.1] - 2019-11-06 ### Added - Option to handle basis conversion "as FBX" (#129) diff --git a/package/com.unity.formats.usd/Editor/Scripts/Behaviors/UsdMenu.cs b/package/com.unity.formats.usd/Editor/Scripts/Behaviors/UsdMenu.cs index fc8187e7e..c644f29a0 100644 --- a/package/com.unity.formats.usd/Editor/Scripts/Behaviors/UsdMenu.cs +++ b/package/com.unity.formats.usd/Editor/Scripts/Behaviors/UsdMenu.cs @@ -20,7 +20,7 @@ using USD.NET.Unity; namespace Unity.Formats.USD { - + public class UsdMenu : MonoBehaviour { public static Scene InitForSave(string defaultName, string fileExtension = "usd") { @@ -198,6 +198,12 @@ public static void MenuImportAsGameObjects() { if (scene == null) { return; } + ImportSceneAsGameObject(scene); + scene.Close(); + } + + public static GameObject ImportSceneAsGameObject(Scene scene, SceneImportOptions importOptions=null) + { string path = scene.FilePath; // Time-varying data is not supported and often scenes are written without "Default" time @@ -205,11 +211,16 @@ public static void MenuImportAsGameObjects() { // the time will be ignored and values will resolve to default time automatically). scene.Time = 1.0; - var importOptions = new SceneImportOptions(); - importOptions.projectAssetPath = GetSelectedAssetPath(); - importOptions.changeHandedness = BasisTransformation.SlowAndSafe; - importOptions.materialImportMode = MaterialImportMode.ImportDisplayColor; - importOptions.usdRootPath = GetDefaultRoot(scene); + if (importOptions == null) + { + importOptions = new SceneImportOptions(); + importOptions.changeHandedness = BasisTransformation.SlowAndSafe; + importOptions.materialImportMode = MaterialImportMode.ImportDisplayColor; + if (importOptions.usdRootPath == null) + { + importOptions.usdRootPath = GetDefaultRoot(scene); + } + } GameObject root = new GameObject(GetObjectName(importOptions.usdRootPath, path)); @@ -217,10 +228,15 @@ public static void MenuImportAsGameObjects() { root.transform.SetParent(Selection.gameObjects[0].transform); } - try { + try + { UsdToGameObject(root, scene, importOptions); - } finally { - scene.Close(); + return root; + } + catch (SceneImporter.ImportException) + { + GameObject.DestroyImmediate(root); + return null; } } diff --git a/package/com.unity.formats.usd/Runtime/Scripts/IO/Geometry/MeshImporter.cs b/package/com.unity.formats.usd/Runtime/Scripts/IO/Geometry/MeshImporter.cs index 1c9e9c170..f257b3977 100644 --- a/package/com.unity.formats.usd/Runtime/Scripts/IO/Geometry/MeshImporter.cs +++ b/package/com.unity.formats.usd/Runtime/Scripts/IO/Geometry/MeshImporter.cs @@ -264,7 +264,8 @@ private static void BuildMesh_(string path, // rely on the UnityEngine.Mesh API. Material mat = renderer.sharedMaterial; - bool changeHandedness = options.changeHandedness == BasisTransformation.SlowAndSafe; + bool changeHandedness = options.changeHandedness == BasisTransformation.SlowAndSafe || + options.changeHandedness == BasisTransformation.SlowAndSafeAsFBX; // // Points. diff --git a/package/com.unity.formats.usd/Runtime/Scripts/IO/Scene/SceneImporter.cs b/package/com.unity.formats.usd/Runtime/Scripts/IO/Scene/SceneImporter.cs index fe0162d6c..f2f92330b 100644 --- a/package/com.unity.formats.usd/Runtime/Scripts/IO/Scene/SceneImporter.cs +++ b/package/com.unity.formats.usd/Runtime/Scripts/IO/Scene/SceneImporter.cs @@ -582,6 +582,14 @@ public static IEnumerator BuildScene(Scene scene, GameObject go = primMap[pathAndSample.path]; NativeImporter.ImportObject(scene, go, scene.GetPrimAtPath(pathAndSample.path), importOptions); XformImporter.BuildXform(pathAndSample.path, pathAndSample.sample, go, importOptions, scene); + + // In order to match FBX importer buggy behavior, the camera xform need an extra rotation. + // FBX importer is fixed in 2020 though with an option to do an axis bake on import. + // If axis bake is used, no need to use the SlowAndSafeAsFBX mode. + if (importOptions.changeHandedness == BasisTransformation.SlowAndSafeAsFBX) + { + go.transform.localRotation *= Quaternion.Euler(180.0f, 0.0f, 180.0f); + } // The camera has many value-type parameters that need to be handled correctly when not // not animated. For now, only the camera transform will animate, until this is fixed. diff --git a/package/com.unity.formats.usd/Samples/ImportMaterials/ImportMaterialsExample.cs b/package/com.unity.formats.usd/Samples/ImportMaterials/ImportMaterialsExample.cs index 566cce4e3..a73944f08 100644 --- a/package/com.unity.formats.usd/Samples/ImportMaterials/ImportMaterialsExample.cs +++ b/package/com.unity.formats.usd/Samples/ImportMaterials/ImportMaterialsExample.cs @@ -241,7 +241,7 @@ static private Scene CreateSceneWithShading() { var detailNormalMapPath = "/Model/Materials/SimpleMat/DetailNormalMap"; var detailMaskPath = "/Model/Materials/SimpleMat/DetailMask"; - var textureFilePath = @"Assets/Samples/USD/1.0.2-preview.1/ImportMaterials/Textures/"; + var textureFilePath = @"Assets/Samples/USD/1.0.3-preview.1/ImportMaterials/Textures/"; var cube = new CubeSample(); cube.size = 7; diff --git a/package/com.unity.formats.usd/Samples/ImportMesh/ImportMesh.unity b/package/com.unity.formats.usd/Samples/ImportMesh/ImportMesh.unity index fa40ff4f2..242fe295b 100644 --- a/package/com.unity.formats.usd/Samples/ImportMesh/ImportMesh.unity +++ b/package/com.unity.formats.usd/Samples/ImportMesh/ImportMesh.unity @@ -373,7 +373,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c6b9422ac107eb345ba17ec50a29caf4, type: 3} m_Name: m_EditorClassIdentifier: - m_usdFile: Samples/USD/1.0.2-preview.1/ImportMesh/mesh.usd + m_usdFile: Samples/USD/1.0.3-preview.1/ImportMesh/mesh.usd m_material: {fileID: 2100000, guid: 5a4399f9b4f4d774dbc7921697839d7e, type: 2} m_usdTime: 0 m_changeHandedness: 0 diff --git a/package/com.unity.formats.usd/Samples/UsdTimelinePlayable/UsdTimelinePlayable.unity b/package/com.unity.formats.usd/Samples/UsdTimelinePlayable/UsdTimelinePlayable.unity index 9eefc2fe9..b82880e11 100644 --- a/package/com.unity.formats.usd/Samples/UsdTimelinePlayable/UsdTimelinePlayable.unity +++ b/package/com.unity.formats.usd/Samples/UsdTimelinePlayable/UsdTimelinePlayable.unity @@ -21113,7 +21113,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 4aff4833db8e2b14aa0f0b6071c41e5b, type: 3} m_Name: m_EditorClassIdentifier: - m_usdFile: Assets/Samples/USD/1.0.2-preview.1/UsdTimelinePlayable/mesh.usd + m_usdFile: Assets/Samples/USD/1.0.3-preview.1/UsdTimelinePlayable/mesh.usd m_projectAssetPath: Assets/ m_usdRootPath: / m_usdTimeOffset: 0 diff --git a/package/com.unity.formats.usd/Tests/.tests.json b/package/com.unity.formats.usd/Tests/.tests.json index 327abb29e..a6aae4db2 100644 --- a/package/com.unity.formats.usd/Tests/.tests.json +++ b/package/com.unity.formats.usd/Tests/.tests.json @@ -1,3 +1,3 @@ { - "createSeparatePackage": false + "createSeparatePackage": true } diff --git a/package/com.unity.formats.usd/Tests/Editor/EditorTests.cs b/package/com.unity.formats.usd/Tests/Editor/EditorTests.cs index 86b6cd164..87f771603 100644 --- a/package/com.unity.formats.usd/Tests/Editor/EditorTests.cs +++ b/package/com.unity.formats.usd/Tests/Editor/EditorTests.cs @@ -1,12 +1,71 @@ using NUnit.Framework; +using System.IO; +using UnityEditor; +using UnityEngine; +using Scene = USD.NET.Scene; +using Assert = UnityEngine.Assertions.Assert; namespace Unity.Formats.USD.Tests { - public class EditorTests + public class FBXHandednessModeTests { + const string fbxGUID = "86a597c63449d2541b7587ff90e75d91"; // GUID of withCamera.fbx + const string usdGUID = "f377c4260fb216d4dbe2f6e4d67091b5"; // GUID of withCamera.usd + + private GameObject fbxRoot; + private GameObject usdRoot; + + [SetUp] + public void SetUp() + { + var fbxPath = AssetDatabase.GUIDToAssetPath(fbxGUID); + var asset = AssetDatabase.LoadAssetAtPath(fbxPath); + fbxRoot = PrefabUtility.InstantiatePrefab(asset) as GameObject; + + InitUsd.Initialize(); + var usdPath = Path.GetFullPath(AssetDatabase.GUIDToAssetPath(usdGUID)); + var stage = pxr.UsdStage.Open(usdPath, pxr.UsdStage.InitialLoadSet.LoadNone); + var scene = Scene.Open(stage); + var importOptions = new SceneImportOptions(); + importOptions.changeHandedness = BasisTransformation.SlowAndSafeAsFBX; + importOptions.scale = 0.01f; + importOptions.materialImportMode = MaterialImportMode.ImportDisplayColor; + usdRoot = USD.UsdMenu.ImportSceneAsGameObject(scene, importOptions); + scene.Close(); + } + [Test] - public void DummyTest() + public void LoadAsFbxCompareCameraTransforms() { + // Compare camera transforms + var usdCamTr = usdRoot.transform.Find("group2/camera1"); + var fbxCamTr = fbxRoot.transform.Find("camera1"); + + Debug.Log("Comparing camera positions..."); + Assert.AreApproximatelyEqual(usdCamTr.position.x,fbxCamTr.position.x); + Assert.AreApproximatelyEqual(usdCamTr.position.y,fbxCamTr.position.y); + Assert.AreApproximatelyEqual(usdCamTr.position.z,fbxCamTr.position.z); + Debug.Log("Comparing camera rotations..."); + Assert.AreApproximatelyEqual(usdCamTr.localRotation.x,fbxCamTr.localRotation.x); + Assert.AreApproximatelyEqual(usdCamTr.localRotation.y,fbxCamTr.localRotation.y); + Assert.AreApproximatelyEqual(usdCamTr.localRotation.z,fbxCamTr.localRotation.z); + } + + [Test] + public void LoadAsFbxCompareMeshTransforms() + { + // Compare camera transforms + var usdMeshTr = usdRoot.transform.Find("group2/group1/pCube1"); + var fbxMeshTr = fbxRoot.transform.Find("group1/pCube1"); + + Debug.Log("Comparing mesh positions..."); + Assert.AreApproximatelyEqual(usdMeshTr.position.x,fbxMeshTr.position.x); + Assert.AreApproximatelyEqual(usdMeshTr.position.y,fbxMeshTr.position.y); + Assert.AreApproximatelyEqual(usdMeshTr.position.z,fbxMeshTr.position.z); + Debug.Log("Comparing mesh rotations..."); + Assert.AreApproximatelyEqual(usdMeshTr.localRotation.x,fbxMeshTr.localRotation.x); + Assert.AreApproximatelyEqual(usdMeshTr.localRotation.y,fbxMeshTr.localRotation.y); + Assert.AreApproximatelyEqual(usdMeshTr.localRotation.z,fbxMeshTr.localRotation.z); } } } diff --git a/package/com.unity.formats.usd/Tests/Editor/Unity.Formats.USD.Tests.Editor.asmdef b/package/com.unity.formats.usd/Tests/Editor/Unity.Formats.USD.Tests.Editor.asmdef index b40276e88..661a013ba 100644 --- a/package/com.unity.formats.usd/Tests/Editor/Unity.Formats.USD.Tests.Editor.asmdef +++ b/package/com.unity.formats.usd/Tests/Editor/Unity.Formats.USD.Tests.Editor.asmdef @@ -1,14 +1,17 @@ -{ - "name": "Unity.Formats.USD.Tests.Editor", - "references": [ - "Unity.Formats.USD.Runtime" - ], - "optionalUnityReferences": [ - "TestAssemblies" - ], - "includePlatforms": [ - "Editor" - ], - "excludePlatforms": [], - "allowUnsafeCode": false -} +{ + "name": "Unity.Formats.USD.Tests.Editor", + "references": [ + "Unity.Formats.USD.Runtime", + "Unity.Formats.USD.Editor" + ], + "optionalUnityReferences": [ + "TestAssemblies" + ], + "includePlatforms": [ + "Editor" + ], + "allowUnsafeCode": true, + "precompiledReferences": [ + "USD.NET.dll" + ] +} \ No newline at end of file diff --git a/package/com.unity.formats.usd/Tests/Runtime/Data.meta b/package/com.unity.formats.usd/Tests/Runtime/Data.meta new file mode 100644 index 000000000..012f372c1 --- /dev/null +++ b/package/com.unity.formats.usd/Tests/Runtime/Data.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bc489c73e288a4648a6cf32037f82188 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package/com.unity.formats.usd/Tests/Runtime/Data/withCamera.fbx b/package/com.unity.formats.usd/Tests/Runtime/Data/withCamera.fbx new file mode 100644 index 000000000..cb92444d2 Binary files /dev/null and b/package/com.unity.formats.usd/Tests/Runtime/Data/withCamera.fbx differ diff --git a/package/com.unity.formats.usd/Tests/Runtime/Data/withCamera.fbx.meta b/package/com.unity.formats.usd/Tests/Runtime/Data/withCamera.fbx.meta new file mode 100644 index 000000000..54bb6f80c --- /dev/null +++ b/package/com.unity.formats.usd/Tests/Runtime/Data/withCamera.fbx.meta @@ -0,0 +1,100 @@ +fileFormatVersion: 2 +guid: 86a597c63449d2541b7587ff90e75d91 +ModelImporter: + serializedVersion: 20100 + internalIDToNameTable: [] + externalObjects: {} + materials: + materialImportMode: 1 + materialName: 0 + materialSearch: 1 + materialLocation: 1 + animations: + legacyGenerateAnimations: 4 + bakeSimulation: 0 + resampleCurves: 1 + optimizeGameObjects: 0 + motionNodeName: + rigImportErrors: + rigImportWarnings: + animationImportErrors: + animationImportWarnings: + animationRetargetingWarnings: + animationDoRetargetingWarnings: 0 + importAnimatedCustomProperties: 0 + importConstraints: 0 + animationCompression: 1 + animationRotationError: 0.5 + animationPositionError: 0.5 + animationScaleError: 0.5 + animationWrapMode: 0 + extraExposedTransformPaths: [] + extraUserProperties: [] + clipAnimations: [] + isReadable: 0 + meshes: + lODScreenPercentages: [] + globalScale: 1 + meshCompression: 0 + addColliders: 0 + useSRGBMaterialColor: 1 + sortHierarchyByName: 1 + importVisibility: 1 + importBlendShapes: 1 + importCameras: 1 + importLights: 1 + swapUVChannels: 0 + generateSecondaryUV: 0 + useFileUnits: 1 + keepQuads: 0 + weldVertices: 1 + bakeAxisConversion: 0 + preserveHierarchy: 0 + skinWeightsMode: 0 + maxBonesPerVertex: 4 + minBoneWeight: 0.001 + meshOptimizationFlags: -1 + indexFormat: 0 + secondaryUVAngleDistortion: 8 + secondaryUVAreaDistortion: 15.000001 + secondaryUVHardAngle: 88 + secondaryUVMarginMethod: 1 + secondaryUVMinLightmapResolution: 40 + secondaryUVMinObjectScale: 1 + secondaryUVPackMargin: 4 + useFileScale: 1 + tangentSpace: + normalSmoothAngle: 60 + normalImportMode: 0 + tangentImportMode: 3 + normalCalculationMode: 4 + legacyComputeAllNormalsFromSmoothingGroupsWhenMeshHasBlendShapes: 0 + blendShapeNormalImportMode: 1 + normalSmoothingSource: 0 + referencedClips: [] + importAnimation: 1 + humanDescription: + serializedVersion: 3 + human: [] + skeleton: [] + armTwist: 0.5 + foreArmTwist: 0.5 + upperLegTwist: 0.5 + legTwist: 0.5 + armStretch: 0.05 + legStretch: 0.05 + feetSpacing: 0 + globalScale: 1 + rootMotionBoneName: + hasTranslationDoF: 0 + hasExtraRoot: 0 + skeletonHasParents: 1 + lastHumanDescriptionAvatarSource: {instanceID: 0} + autoGenerateAvatarMappingIfUnspecified: 1 + animationType: 2 + humanoidOversampling: 1 + avatarSetup: 0 + additionalBone: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/package/com.unity.formats.usd/Tests/Runtime/Data/withCamera.usd b/package/com.unity.formats.usd/Tests/Runtime/Data/withCamera.usd new file mode 100644 index 000000000..323ab08da Binary files /dev/null and b/package/com.unity.formats.usd/Tests/Runtime/Data/withCamera.usd differ diff --git a/package/com.unity.formats.usd/Tests/Runtime/Data/withCamera.usd.meta b/package/com.unity.formats.usd/Tests/Runtime/Data/withCamera.usd.meta new file mode 100644 index 000000000..172ec6770 --- /dev/null +++ b/package/com.unity.formats.usd/Tests/Runtime/Data/withCamera.usd.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: f377c4260fb216d4dbe2f6e4d67091b5 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package/com.unity.formats.usd/package.json b/package/com.unity.formats.usd/package.json index fd42044c6..4751904ee 100644 --- a/package/com.unity.formats.usd/package.json +++ b/package/com.unity.formats.usd/package.json @@ -29,5 +29,5 @@ }, "unity": "2018.3", "unityRelease": "4f1", - "version": "1.0.2-preview.1" + "version": "1.0.3-preview.1" }