Skip to content

Commit

Permalink
Merge pull request #162 from Unity-Technologies/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
judubu authored Apr 2, 2020
2 parents b28f0fe + 7fd4976 commit da2ddb5
Show file tree
Hide file tree
Showing 17 changed files with 241 additions and 38 deletions.
11 changes: 4 additions & 7 deletions TestProject/Packages/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -38,8 +36,7 @@
"com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0"
},
"testables":
[
"testables": [
"com.unity.formats.usd"
]
}
4 changes: 4 additions & 0 deletions package/com.unity.formats.usd/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
34 changes: 25 additions & 9 deletions package/com.unity.formats.usd/Editor/Scripts/Behaviors/UsdMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -198,29 +198,45 @@ 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
// values, which makes setting an arbitrary time safer (because if only default was authored
// 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));

if (Selection.gameObjects.Length > 0) {
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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package/com.unity.formats.usd/Tests/.tests.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"createSeparatePackage": false
"createSeparatePackage": true
}
63 changes: 61 additions & 2 deletions package/com.unity.formats.usd/Tests/Editor/EditorTests.cs
Original file line number Diff line number Diff line change
@@ -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<GameObject>(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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
]
}
8 changes: 8 additions & 0 deletions package/com.unity.formats.usd/Tests/Runtime/Data.meta

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

Binary file not shown.
100 changes: 100 additions & 0 deletions package/com.unity.formats.usd/Tests/Runtime/Data/withCamera.fbx.meta

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.

2 changes: 1 addition & 1 deletion package/com.unity.formats.usd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
},
"unity": "2018.3",
"unityRelease": "4f1",
"version": "1.0.2-preview.1"
"version": "1.0.3-preview.1"
}

0 comments on commit da2ddb5

Please sign in to comment.