Skip to content

Commit 7e85c00

Browse files
committed
Merge branch 'master' into Uni-45921-physical-camera
# Conflicts: # Packages/com.unity.formats.fbx/Editor/Integrations.meta # Packages/com.unity.formats.fbx/Editor/Scripts/FbxExporter.cs # Packages/com.unity.formats.fbxsdk/Scripts/FbxPropertyEGateFit.cs.meta
2 parents 69f235a + e06ad24 commit 7e85c00

File tree

16 files changed

+119
-100
lines changed

16 files changed

+119
-100
lines changed

Assets/com.unity.formats.fbx.tests/FbxAnimationTest.cs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,6 @@ public static IEnumerable ContinuousRotationTestCases {
7474
}
7575
}
7676

77-
// test key tangents
78-
public static IEnumerable KeyTangentsTestCases {
79-
get {
80-
yield return new TestCaseData (new float [3] { 0f, 4f, 5f }, new Vector3 [3] { new Vector3 (-100, 100, 0), new Vector3 (0f, 0.0f, 0f), new Vector3 (25f, 0f, 0f) }, new Vector3 [3] { new Vector3 (0, 0, 0), new Vector3 (0f, 0f, 16.9f), new Vector3 (0f, 0f, 0f) }).Returns (6);
81-
}
82-
}
83-
8477
public static IEnumerable SkinnedMeshTestCases {
8578
get {
8679
yield return "Models/DefaultMale/Male_DyingHitFromBack_Blend_T3_Cut01_James.fbx";
@@ -303,33 +296,6 @@ public virtual int Compare(Keyframe a, Keyframe b)
303296
}
304297
}
305298

306-
public class KeyTangentComparer : IComparer<Keyframe>
307-
{
308-
public int CompareKeyTangents(Keyframe a, Keyframe b)
309-
{
310-
bool result = true;
311-
312-
result &= a.time.Equals(b.time);
313-
#if DEBUG_UNITTEST
314-
Debug.Log(string.Format("{2} a.time: {0}, b.time: {1}", a.time, b.time,result));
315-
#endif
316-
// TODO : use AnimationUtility.GetLeftTangentMode
317-
// requires reference to AnimationCurve and keyindex
318-
result &= (a.tangentMode == b.tangentMode);
319-
#if DEBUG_UNITTEST
320-
Debug.Log(string.Format("{2} a.tangentMode={0} b.tangentMode={1}",
321-
((AnimationUtility.TangentMode)a.tangentMode).ToString(),
322-
((AnimationUtility.TangentMode)b.tangentMode).ToString(),result));
323-
#endif
324-
return result ? 0 : 1;
325-
}
326-
327-
public int Compare(Keyframe a, Keyframe b)
328-
{
329-
return CompareKeyTangents(a,b);
330-
}
331-
}
332-
333299
public class AnimTester
334300
{
335301
public FbxAnimationTest.KeyData keyData;
@@ -754,30 +720,6 @@ public int ContinuousRotationAnimTest (RotationCurveType rotCurveType, float []
754720
return tester.DoIt();
755721
}
756722

757-
[Description("Uni-35935 key tangents")]
758-
[Test, TestCaseSource (typeof (AnimationTestDataClass), "KeyTangentsTestCases")]
759-
public int KeyTangentsAnimTest (float [] keyTimesInSeconds, Vector3 [] keyPosValues, Vector3 [] keyRotValues)
760-
{
761-
System.Type componentType = typeof(Transform);
762-
763-
if (keyRotValues == null)
764-
{
765-
keyRotValues = new Vector3[keyPosValues.Length];
766-
}
767-
768-
string[] propertyNames = null;
769-
string testName = componentType.ToString () + "_KeyTangents";
770-
RotationCurveType rotCurveType = RotationCurveType.kEuler;
771-
772-
testName += "_Euler";
773-
propertyNames = AnimationTestDataClass.m_rotationEulerNames.Concat(AnimationTestDataClass.m_translationNames).ToArray();
774-
775-
KeyData keyData = new TransformKeyData { RotationType = rotCurveType, propertyNames = propertyNames, componentType = componentType, keyTimes = keyTimesInSeconds, keyPosValues = keyPosValues, keyEulerValues = keyRotValues };
776-
777-
var tester = new AnimTester {keyData=keyData, testName=testName, path=GetRandomFbxFilePath (), keyComparer=new KeyTangentComparer()};
778-
return tester.DoIt();
779-
}
780-
781723
[Test, TestCaseSource (typeof (AnimationTestDataClass), "ComponentTestCases")]
782724
public int ComponentAnimTest (System.Type componentType)
783725
{

Assets/com.unity.formats.fbx.tests/ModelExporterTest.cs

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using UnityEngine;
1+
//#define DEBUG_UNITTEST
2+
using UnityEngine;
23
using UnityEditor;
34
using UnityEngine.TestTools;
45
using NUnit.Framework;
@@ -10,6 +11,14 @@ namespace FbxExporters.UnitTests
1011
{
1112
public class ModelExporterTest : ExporterTestBase
1213
{
14+
[TearDown]
15+
public override void Term ()
16+
{
17+
#if (!DEBUG_UNITTEST)
18+
base.Term ();
19+
#endif
20+
}
21+
1322
[Test]
1423
public void TestBasics ()
1524
{
@@ -322,7 +331,31 @@ public void TestExporterCallbacks()
322331
}
323332

324333
[Test]
325-
public void TestExportCamera(){
334+
[Ignore("Ignore a camera orthographic test (Uni-48092)")]
335+
public void TestExportCamera2(){
336+
// NOTE: even though the aspect ratio is exported,
337+
// it does not get imported back into Unity.
338+
// Therefore don't modify or check if camera.aspect is the same
339+
// after export.
340+
341+
// create a Unity camera
342+
GameObject cameraObj = new GameObject("TestCamera");
343+
Camera camera = cameraObj.AddComponent<Camera> ();
344+
345+
// test export orthographic camera
346+
camera.orthographic = true;
347+
camera.fieldOfView = 78;
348+
camera.nearClipPlane = 19;
349+
camera.farClipPlane = 500.6f;
350+
351+
var filename = GetRandomFbxFilePath (); // export to a different file
352+
var fbxCamera = ExportCamera (filename, cameraObj);
353+
CompareCameraValues (camera, fbxCamera);
354+
Assert.AreEqual (camera.orthographicSize, fbxCamera.orthographicSize);
355+
}
356+
357+
[Test]
358+
public void TestExportCamera1(){
326359
// NOTE: even though the aspect ratio is exported,
327360
// it does not get imported back into Unity.
328361
// Therefore don't modify or check if camera.aspect is the same
@@ -342,17 +375,6 @@ public void TestExportCamera(){
342375
string filename = GetRandomFbxFilePath();
343376
var fbxCamera = ExportCamera (filename, cameraObj);
344377
CompareCameraValues (camera, fbxCamera);
345-
346-
// test export orthographic camera
347-
camera.orthographic = true;
348-
camera.fieldOfView = 78;
349-
camera.nearClipPlane = 19;
350-
camera.farClipPlane = 500.6f;
351-
352-
filename = GetRandomFbxFilePath (); // export to a different file
353-
fbxCamera = ExportCamera (filename, cameraObj);
354-
CompareCameraValues (camera, fbxCamera);
355-
Assert.AreEqual (camera.orthographicSize, fbxCamera.orthographicSize);
356378
}
357379

358380
/// <summary>

Packages/com.unity.formats.fbx/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
RELEASE NOTES
44

5+
**Version**: 1.5.0-preview
6+
7+
NEW FEATURES
8+
9+
* The roundtrip of assets can now be started from Maya from assets that have not been exported from Unity
10+
* DCC integration plug-in sources have been moved away from the package
11+
* Windows version is now using the FBX SDK version 2018.1.1
12+
* Streamlined public interface for the ModelExporter class
13+
14+
FIXES:
15+
16+
* DCC integration plug-ins now work with packman
17+
518
**Version**: 1.4.0-preview
619

720
NEW FEATURES

Packages/com.unity.formats.fbx/Editor.meta

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

Packages/com.unity.formats.fbx/Editor/Integrations.meta

Lines changed: 0 additions & 8 deletions
This file was deleted.

Packages/com.unity.formats.fbx/Editor/Scripts/ConvertToModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public static GameObject ApplyOrCreatePrefab(GameObject instance,
316316
string prefabFullPath = null)
317317
{
318318
if(PrefabUtility.GetPrefabType(instance) == PrefabType.PrefabInstance) {
319-
return PrefabUtility.ReplacePrefab(instance, PrefabUtility.GetPrefabParent(instance));
319+
return PrefabUtility.ReplacePrefab(instance, PrefabUtility.GetCorrespondingObjectFromSource(instance));
320320
}
321321

322322
// Otherwise, create a new prefab. First choose its filename/path.
@@ -388,7 +388,7 @@ public static GameObject GetFbxAssetOrNull(GameObject go) {
388388
switch(unityPrefabType) {
389389
case PrefabType.ModelPrefabInstance:
390390
if (go.Equals(PrefabUtility.FindPrefabRoot (go))) {
391-
return PrefabUtility.GetPrefabParent(go) as GameObject;
391+
return PrefabUtility.GetCorrespondingObjectFromSource(go) as GameObject;
392392
} else {
393393
return null;
394394
}

Packages/com.unity.formats.fbx/Editor/Scripts/FbxExporter.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,11 +1241,7 @@ protected bool ExportInstance (GameObject unityGo, FbxNode fbxNode, FbxScene fbx
12411241
if (unityPrefabType != PrefabType.PrefabInstance &&
12421242
unityPrefabType != PrefabType.ModelPrefabInstance) return false;
12431243

1244-
#if UNITY_2018_2_OR_NEWER
1245-
Object unityPrefabParent = PrefabUtility.GetCorrespondingObjectFromSource (unityGo);
1246-
#else
1247-
Object unityPrefabParent = PrefabUtility.GetPrefabParent (unityGo);
1248-
#endif
1244+
Object unityPrefabParent = PrefabUtility.GetCorrespondingObjectFromSource(unityGo);
12491245

12501246
if (Verbose)
12511247
Debug.Log (string.Format ("exporting instance {0}({1})", unityGo.name, unityPrefabParent.name));

Packages/com.unity.formats.fbx/Editor/Scripts/FbxPrefabAutoUpdater.cs

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ public static bool OnValidateMenuItem()
257257
bool containsLinkedPrefab = false;
258258
foreach (GameObject selectedObject in selection)
259259
{
260-
GameObject prefab = UnityEditor.PrefabUtility.GetPrefabParent(selectedObject) as GameObject;
260+
GameObject prefab = UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(selectedObject) as GameObject;
261261
if (prefab && prefab.GetComponentInChildren<FbxPrefab>())
262262
{
263263
containsLinkedPrefab = true;
@@ -281,7 +281,7 @@ public static void UpdateLinkedPrefab(GameObject prefabOrInstance)
281281
prefab = prefabOrInstance;
282282
break;
283283
case PrefabType.PrefabInstance:
284-
prefab = PrefabUtility.GetPrefabParent(prefabOrInstance) as GameObject;
284+
prefab = PrefabUtility.GetCorrespondingObjectFromSource(prefabOrInstance) as GameObject;
285285
break;
286286
default:
287287
return;
@@ -1164,6 +1164,17 @@ public HashSet<String> GetNodesToRename()
11641164
return m_nodesToRename;
11651165
}
11661166

1167+
/// <summary>
1168+
/// Get the equivalent transform on the linked prefab for the given fbx transform.
1169+
/// e.g. if there is a transform called Bone1 in the fbx, find the transform called Bone1 in the prefab.
1170+
/// </summary>
1171+
/// <returns>The linked prefab transform that matches the given fbx transform or null if not found</returns>
1172+
private Transform GetMatchingPrefabTransform(Transform fbxTransform, Transform fbxAssetRoot, Transform prefabAssetRoot)
1173+
{
1174+
var transformPath = AnimationUtility.CalculateTransformPath(fbxTransform, fbxAssetRoot);
1175+
return prefabAssetRoot.Find(transformPath);
1176+
}
1177+
11671178
/// <summary>
11681179
/// Then we act -- in a slightly different order:
11691180
/// 1. Create all the new nodes we need to create.
@@ -1355,6 +1366,42 @@ public HashSet<GameObject> ImplementUpdates(FbxPrefab prefabInstance)
13551366
}
13561367
// Now set the values.
13571368
UnityEditor.EditorJsonUtility.FromJsonOverwrite(fbxComponent.jsonValue, prefabComponent);
1369+
1370+
// if the prefab component is a skinned mesh renderer, then make sure to update the bone list so that
1371+
// the bones are in the prefab, and not the fbx
1372+
if (prefabComponent is SkinnedMeshRenderer)
1373+
{
1374+
var skinnedMeshComponent = prefabComponent as SkinnedMeshRenderer;
1375+
var rootBone = skinnedMeshComponent.rootBone;
1376+
var bones = skinnedMeshComponent.bones;
1377+
1378+
var fbxAssetTransform = m_fbxPrefabUtility.GetFbxAsset().transform;
1379+
1380+
var rootPrefabTransform = GetMatchingPrefabTransform(rootBone, fbxAssetTransform, prefabRoot);
1381+
if (rootPrefabTransform == null)
1382+
{
1383+
Debug.LogWarningFormat("FbxPrefabAutoUpdater: Could not find root bone {0} for {1} skinned mesh in linked prefab", rootBone.name, skinnedMeshComponent.name);
1384+
}
1385+
skinnedMeshComponent.rootBone = rootPrefabTransform;
1386+
1387+
var prefabBones = new Transform[bones.Length];
1388+
for (int i = 0; i < bones.Length; i++)
1389+
{
1390+
var bone = bones[i];
1391+
1392+
var prefabTransform = GetMatchingPrefabTransform(bone, fbxAssetTransform, prefabRoot);
1393+
if (prefabTransform == null)
1394+
{
1395+
Debug.LogWarningFormat("FbxPrefabAutoUpdater: Could not find bone {0} for {1} skinned mesh", bone.name, skinnedMeshComponent.name);
1396+
continue;
1397+
}
1398+
1399+
prefabBones[i] = prefabTransform;
1400+
}
1401+
skinnedMeshComponent.bones = prefabBones;
1402+
1403+
continue;
1404+
}
13581405
}
13591406
}
13601407
return updatedNodes;
@@ -1407,7 +1454,7 @@ void CompareAndUpdate()
14071454
m_fbxPrefab.gameObject));
14081455
}
14091456
var fbxPrefabInstance = prefabInstanceRoot.GetComponentsInChildren<FbxPrefab>().FirstOrDefault(
1410-
fbxPrefab => UnityEditor.PrefabUtility.GetPrefabParent(fbxPrefab) == m_fbxPrefab);
1457+
fbxPrefab => UnityEditor.PrefabUtility.GetCorrespondingObjectFromSource(fbxPrefab) == m_fbxPrefab);
14111458
if (!fbxPrefabInstance) {
14121459
throw new System.Exception(string.Format("Internal error: couldn't find the right FbxPrefab after instantiating."));
14131460
}

Packages/com.unity.formats.fbx/Editor/Scripts/ReviewLastSavedModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ public static UnityEditor.EditorWindow GetMainGameView()
300300
private static void SubscribeToEvents ()
301301
{
302302
// ensure we only subscribe once
303-
UnityEditor.EditorApplication.hierarchyWindowChanged -= UpdateLastSavedModel;
304-
UnityEditor.EditorApplication.hierarchyWindowChanged += UpdateLastSavedModel;
303+
UnityEditor.EditorApplication.hierarchyChanged -= UpdateLastSavedModel;
304+
UnityEditor.EditorApplication.hierarchyChanged += UpdateLastSavedModel;
305305
}
306306

307307
private static void UnsubscribeFromEvents ()
@@ -311,7 +311,7 @@ private static void UnsubscribeFromEvents ()
311311
LastModel = null;
312312
LastFilePath = null;
313313

314-
UnityEditor.EditorApplication.hierarchyWindowChanged -= UpdateLastSavedModel;
314+
UnityEditor.EditorApplication.hierarchyChanged -= UpdateLastSavedModel;
315315
}
316316

317317
private static bool AutoUpdateEnabled ()

Packages/com.unity.formats.fbx/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "com.unity.formats.fbx",
33
"displayName" : "FBX Exporter",
4-
"version" : "1.4.0-preview",
5-
"dependencies" : { "com.unity.formats.fbxsdk" : "1.4.0-preview" },
4+
"version" : "1.5.0-preview",
5+
"dependencies" : { "com.unity.formats.fbxsdk" : "1.5.0-preview" },
66
"unity": "2018.1",
77
"description" : "The Unity FBX Exporter package makes it smooth and easy to send geometry and animation from Unity 2017.3 or later to any application that supports FBX and back again with minimal effort.\n\nIn particular, this round-trip workflow enables you to export Unity scenes to FBX, import into Maya, Maya LT, or 3ds Max using an artist-friendly interface, export Unity-ready FBX geometry and animation, and safely merge your changes back into those Assets to continue your work.\n\nThe exporter provides support for GameObject hierarchies, Materials, Textures, Cameras, Lights, Skinned Meshes, and Animation. The Unity FBX importer provides support for hierarchies, Materials, Textures, Stingray Physically Based Shader (PBS), Cameras, Animation and Animated custom properties (when present in the FBX file).\n\nThis package includes a plug-in for Autodesk Maya 2017 or later, Autodesk Maya LT 2017 or later, and 3ds Max 2017 or later.",
88
"keywords" : [ "fbx", "animation", "modeling", "maya", "max" ]

0 commit comments

Comments
 (0)