diff --git a/package/com.unity.formats.usd/Tests/Common/CustomAsserts/ExportAssert.cs b/package/com.unity.formats.usd/Tests/Common/CustomAsserts/ExportAssert.cs new file mode 100644 index 000000000..8db301475 --- /dev/null +++ b/package/com.unity.formats.usd/Tests/Common/CustomAsserts/ExportAssert.cs @@ -0,0 +1,31 @@ +using UnityEngine; +using NUnit.Framework; + +namespace Unity.Formats.USD.Tests +{ + public static class ExportAssert + { + public static void IsDataStructureKeptInUsdz(GameObject importedObject, string expectedObjectName, string expectedRootPrimName, string expectedMaterialsName) + { + Assert.AreEqual(importedObject.name, expectedObjectName); + + var rootPrim = importedObject.transform.Find(expectedRootPrimName); + var materials = importedObject.transform.Find(expectedMaterialsName); + + Assert.IsNotNull(rootPrim, string.Format("Root Prim was not found under expected name '{0}'", expectedRootPrimName)); + Assert.IsNotNull(materials, string.Format("Materials was not found under expected name '{0}'", expectedMaterialsName)); + + Assert.IsNotNull(rootPrim.GetComponent(), "Root Prim GameObject did not contain UsdPrimSource component"); + Assert.IsNotNull(materials.GetComponent(), "Materials GameObject did not contain UsdPrimSource component"); + + var materialsData = materials.transform.Find(expectedObjectName); + var rootPrimData = rootPrim.transform.Find(expectedObjectName); + + Assert.IsNotNull(rootPrimData, string.Format("Root Prim Data was not found under expected name '{0}'", expectedObjectName)); + Assert.IsNotNull(materialsData, string.Format("Materials Data was not found under expected name '{0}'", expectedObjectName)); + + Assert.IsNotNull(rootPrimData.GetComponent(), "Root Prim Data GameObject did not contain UsdPrimSource component"); + Assert.IsNotNull(materialsData.GetComponent(), "Materials Data GameObject did not contain UsdPrimSource component"); + } + } +} diff --git a/package/com.unity.formats.usd/Tests/Common/CustomAsserts/ExportAssert.cs.meta b/package/com.unity.formats.usd/Tests/Common/CustomAsserts/ExportAssert.cs.meta new file mode 100644 index 000000000..8d393bbcd --- /dev/null +++ b/package/com.unity.formats.usd/Tests/Common/CustomAsserts/ExportAssert.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d5a3ec5d050a6c64197a4333979de0bb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package/com.unity.formats.usd/Tests/Editor/ExportTests.cs b/package/com.unity.formats.usd/Tests/Editor/ExportTests.cs index f470e90af..4cfae41f7 100644 --- a/package/com.unity.formats.usd/Tests/Editor/ExportTests.cs +++ b/package/com.unity.formats.usd/Tests/Editor/ExportTests.cs @@ -117,5 +117,40 @@ public void ExportMultipleSiblingGameObjectsWithSameName_AllGameObjectsHaveCorre } Assert.AreEqual(cubes.Length, exportedPrims.Count, "One or more GameObjects don't have a corresponding Prim"); } + + [Test] + [Ignore("[USDU-275] | [USDU-279]")] + public void ExportAsUsdz_DataStructureKeptOnImport() + { + var scene = ImportHelpers.InitForOpen(GetTestAssetPath(TestAssetData.FileName.TexturedOpaque)); + var importedUsdObject = ImportHelpers.ImportSceneAsGameObject(scene, importOptions: + new SceneImportOptions() + { + materialImportMode = MaterialImportMode.ImportPreviewSurface + } + ); + + var usdzPath = GetUSDScenePath(importedUsdObject.name + ".usdz"); + UsdzExporter.ExportUsdz(usdzPath, importedUsdObject); + + var usdObjectRootPath = importedUsdObject.GetComponent().m_usdRootPath; + + var usdzScene = ImportHelpers.InitForOpen(usdzPath); + var usdzObject = ImportHelpers.ImportSceneAsGameObject(usdzScene, importOptions: + new SceneImportOptions() + { + materialImportMode = MaterialImportMode.ImportPreviewSurface + } + ); + + Assert.AreEqual(usdzObject.GetComponent().m_usdRootPath, usdObjectRootPath); + + ExportAssert.IsDataStructureKeptInUsdz( + usdzObject, + expectedMaterialsName: TestAssetData.ImportGameObjectName.Material, + expectedRootPrimName: TestAssetData.ImportGameObjectName.RootPrim, + expectedObjectName: TestAssetData.FileName.TexturedOpaque + ); + } } }