Skip to content
Merged
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
10 changes: 10 additions & 0 deletions package/com.unity.formats.usd/Tests/Editor/BaseFixtureEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
// limitations under the License.

using NUnit.Framework;
using System.IO;
using UnityEditor;
using UnityEditor.SceneManagement;
using USD.NET;

namespace Unity.Formats.USD.Tests
{
Expand All @@ -24,5 +27,12 @@ public void EnsureEmptyScene()
{
m_UnityScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
}

protected Scene OpenUSDGUIDAssetScene(string guid, out string filePath)
{
filePath = Path.GetFullPath(AssetDatabase.GUIDToAssetPath(guid));
var stage = pxr.UsdStage.Open(filePath, pxr.UsdStage.InitialLoadSet.LoadNone);
return Scene.Open(stage);
}
}
}

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

Binary file not shown.

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

Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ public void Setup()
Assume.That(m_usdAsset, Is.Not.Null, "Could not find USDAsset component on root gameobject.");
}

private Scene OpenUSDGUIDAssetScene(string guid, out string filePath)
{
filePath = Path.GetFullPath(AssetDatabase.GUIDToAssetPath(guid));
var stage = pxr.UsdStage.Open(filePath, pxr.UsdStage.InitialLoadSet.LoadNone);
return Scene.Open(stage);
}

[TearDown]
public void TearDown()
{
Expand Down
62 changes: 62 additions & 0 deletions package/com.unity.formats.usd/Tests/Editor/UsdPrefabTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using NUnit.Framework;
using UnityEditor;

namespace Unity.Formats.USD.Tests
{
public class UsdPrefabTests : BaseFixtureEditor
{
const string k_USDZGUID = "a90ff3ebef4a2aa42b559da07e4151f5"; // test-roughness.usdz

static string m_prefabUsdPath;

[TearDown]
public void TearDown()
{
if (!string.IsNullOrEmpty(m_prefabUsdPath))
{
AssetDatabase.DeleteAsset(m_prefabUsdPath);
}
}

protected void ImportAsPrefab(string usdGUID)
{
var scene = OpenUSDGUIDAssetScene(usdGUID, out _);
m_prefabUsdPath = ImportHelpers.ImportAsPrefab(scene);
scene.Close();
}

public class Reload : UsdPrefabTests
{
[TestCase(MaterialImportMode.ImportDisplayColor)]
[TestCase(MaterialImportMode.None)]
[TestCase(MaterialImportMode.ImportPreviewSurface)]
[Ignore("USDU-276")]
public void UsdPrefab_ForceReload_Succeed(MaterialImportMode mode)
{
ImportAsPrefab(k_USDZGUID);

var prefabAsset = AssetDatabase.LoadAssetAtPath<UsdAsset>(m_prefabUsdPath);
prefabAsset.m_materialImportMode = mode;
prefabAsset.Reload(true);

// Assertion is not required as it will fail on unhandled error
}

[Test]
[Ignore("USDU-276")]
public void UsdPrefab_ForceReload_ImportPreviewSurface_DoesNotDirtyScene()
{
var initialRootGameObjects = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects();
ImportAsPrefab(k_USDZGUID);

var prefabAsset = AssetDatabase.LoadAssetAtPath<UsdAsset>(m_prefabUsdPath);
prefabAsset.m_materialImportMode = MaterialImportMode.ImportPreviewSurface;
prefabAsset.Reload(true);

var newRootGameObjects = UnityEngine.SceneManagement.SceneManager.GetActiveScene().GetRootGameObjects();

Assert.AreEqual(initialRootGameObjects, newRootGameObjects, "Prefab Reload does not clean up the scene");
}
}
}
}
11 changes: 11 additions & 0 deletions package/com.unity.formats.usd/Tests/Editor/UsdPrefabTests.cs.meta

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