Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[USDU-275] Adds testcase for checking if export keeps the original data structure #339

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<UsdPrimSource>(), "Root Prim GameObject did not contain UsdPrimSource component");
Assert.IsNotNull(materials.GetComponent<UsdPrimSource>(), "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<UsdPrimSource>(), "Root Prim Data GameObject did not contain UsdPrimSource component");
Assert.IsNotNull(materialsData.GetComponent<UsdPrimSource>(), "Materials Data GameObject did not contain UsdPrimSource component");
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions package/com.unity.formats.usd/Tests/Editor/ExportTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UsdAsset>().m_usdRootPath;

var usdzScene = ImportHelpers.InitForOpen(usdzPath);
var usdzObject = ImportHelpers.ImportSceneAsGameObject(usdzScene, importOptions:
new SceneImportOptions()
{
materialImportMode = MaterialImportMode.ImportPreviewSurface
}
);

Assert.AreEqual(usdzObject.GetComponent<UsdAsset>().m_usdRootPath, usdObjectRootPath);

ExportAssert.IsDataStructureKeptInUsdz(
usdzObject,
expectedMaterialsName: TestAssetData.ImportGameObjectName.Material,
expectedRootPrimName: TestAssetData.ImportGameObjectName.RootPrim,
expectedObjectName: TestAssetData.FileName.TexturedOpaque
);
}
}
}