Skip to content

Commit 84e4a16

Browse files
committed
[USDU-275] Adds testcase for checking if export keeps the original data structure
1 parent 6bd5bd1 commit 84e4a16

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using UnityEngine;
2+
using NUnit.Framework;
3+
4+
namespace Unity.Formats.USD.Tests
5+
{
6+
public static class ExportAssert
7+
{
8+
public static class Runtime
9+
{
10+
public static void IsDataStructureKeptInUsdz(GameObject importedObject, string expectedObjectName, string expectedRootPrimName, string expectedMaterialsName)
11+
{
12+
Assert.AreEqual(importedObject.name, expectedObjectName);
13+
14+
var rootPrim = importedObject.transform.Find(expectedRootPrimName);
15+
var materials = importedObject.transform.Find(expectedMaterialsName);
16+
17+
Assert.IsNotNull(rootPrim, string.Format("Root Prim was not found under expected name '{0}'", expectedRootPrimName));
18+
Assert.IsNotNull(materials, string.Format("Materials was not found under expected name '{0}'", expectedMaterialsName));
19+
20+
Assert.IsNotNull(rootPrim.GetComponent<UsdPrimSource>(), "Root Prim GameObject did not contain UsdPrimSource component");
21+
Assert.IsNotNull(materials.GetComponent<UsdPrimSource>(), "Materials GameObject did not contain UsdPrimSource component");
22+
23+
var materialsData = materials.transform.Find(expectedObjectName);
24+
var rootPrimData = rootPrim.transform.Find(expectedObjectName);
25+
26+
Assert.IsNotNull(rootPrimData, string.Format("Root Prim Data was not found under expected name '{0}'", expectedObjectName));
27+
Assert.IsNotNull(materialsData, string.Format("Materials Data was not found under expected name '{0}'", expectedObjectName));
28+
29+
Assert.IsNotNull(rootPrimData.GetComponent<UsdPrimSource>(), "Root Prim Data GameObject did not contain UsdPrimSource component");
30+
Assert.IsNotNull(materialsData.GetComponent<UsdPrimSource>(), "Materials Data GameObject did not contain UsdPrimSource component");
31+
}
32+
}
33+
}
34+
}

package/com.unity.formats.usd/Tests/Common/CustomAsserts/ExportAssert.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/com.unity.formats.usd/Tests/Runtime/ExportHelpersTests.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,42 @@ public void ExportGameObjects_SceneClosedAfterExport()
110110
ExportHelpers.ExportGameObjects(new[] { new GameObject("test") }, scene, BasisTransformation.SlowAndSafe);
111111
Assert.IsNull(scene.Stage);
112112
}
113+
114+
[Ignore("[USDU-275] | [USDU-279]")]
115+
[Test]
116+
public void ExportAsUsdz_DataStructureKept()
117+
{
118+
var scene = ImportHelpers.InitForOpen(GetTestAssetPath(TestAssetData.FileName.TexturedOpaque));
119+
var importedUsdObject = ImportHelpers.ImportSceneAsGameObject(scene, importOptions:
120+
new SceneImportOptions()
121+
{
122+
materialImportMode = MaterialImportMode.ImportPreviewSurface
123+
}
124+
);
125+
126+
var usdzPath = GetUSDScenePath(importedUsdObject.name + ".usdz");
127+
UsdzExporter.ExportUsdz(usdzPath, importedUsdObject);
128+
129+
var usdObjectRootPath = importedUsdObject.GetComponent<UsdAsset>().m_usdRootPath;
130+
131+
Assert.AreEqual(usdObjectRootPath, "/");
132+
133+
var usdzScene = ImportHelpers.InitForOpen(usdzPath);
134+
var usdzObject = ImportHelpers.ImportSceneAsGameObject(usdzScene, importOptions:
135+
new SceneImportOptions()
136+
{
137+
materialImportMode = MaterialImportMode.ImportPreviewSurface
138+
}
139+
);
140+
141+
Assert.AreEqual(usdzObject.GetComponent<UsdAsset>().m_usdRootPath, usdObjectRootPath);
142+
143+
ExportAssert.Runtime.IsDataStructureKeptInUsdz(
144+
usdzObject,
145+
expectedMaterialsName: TestAssetData.ImportGameObjectName.Material,
146+
expectedRootPrimName: TestAssetData.ImportGameObjectName.RootPrim,
147+
expectedObjectName: TestAssetData.FileName.TexturedOpaque
148+
);
149+
}
113150
}
114151
}

0 commit comments

Comments
 (0)