Skip to content

Commit 4d4432e

Browse files
authored
Merge pull request #504 from Unity-Technologies/v3.0.0-preview
V3.0.0 preview
2 parents 79a577f + 3aa7450 commit 4d4432e

File tree

5 files changed

+60
-29
lines changed

5 files changed

+60
-29
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changes in Fbx Exporter
22

3+
## [3.0.2-preview.1] - 2020-03-25
4+
### Fixed
5+
- Blendshapes naming in FBX so that multiple blendshapes all import correctly in Maya. Thank you to @lazlo-bonin for the fix.
6+
- Don't override transforms when creating FBX Linked Prefab, so that the prefab updates properly when the FBX transforms are modified.
7+
- Changed FBX Linked Prefab to keep Unity materials instead of using materials exported to FBX file.
8+
- Fix issue where Maya imports root bone as null object if it doesn't have any descendants that are also bones.
9+
310
## [3.0.1-preview.2] - 2020-01-22
411
### Added
512
- Added option to export geometry when recording with the FBX recorder (in previous version geometry was always exported).

com.unity.formats.fbx/Editor/ConvertToNestedPrefab.cs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ public static GameObject Convert(
412412
// replace hierarchy in the scene
413413
if (!isPrefabAsset && toConvert != null)
414414
{
415-
fbxInstance.transform.parent = toConvert.transform.parent;
415+
// don't worry about keeping the world position in the prefab, as we will fix the transform on the instance root
416+
fbxInstance.transform.SetParent(toConvert.transform.parent, worldPositionStays: false);
416417
fbxInstance.transform.SetSiblingIndex(toConvert.transform.GetSiblingIndex());
417418
}
418419

@@ -863,10 +864,13 @@ internal static void CopyComponents(GameObject to, GameObject from, GameObject r
863864
continue;
864865
}
865866

866-
// ignore MeshFilter, but still ensure scene references are maintained
867-
if (fromComponent is MeshFilter)
867+
// ignore MeshFilter and Transform, but still ensure scene references are maintained.
868+
// Don't need to copy regular transform (except for the root object) as the values should already be correct in the FBX.
869+
// Furthermore, copying transform values may result in overrides in the prefab, which is undesired as if
870+
// the transform is updated in the FBX, it won't be in the prefab.
871+
if (fromComponent is MeshFilter || (fromComponent is Transform && from != root))
868872
{
869-
FixSceneReferences(fromComponent, to.GetComponent<MeshFilter>(), root);
873+
FixSceneReferences(fromComponent, to.GetComponent(fromComponent.GetType()), root);
870874
continue;
871875
}
872876

@@ -930,27 +934,16 @@ internal static void CopyComponents(GameObject to, GameObject from, GameObject r
930934
}
931935

932936
FixSceneReferences(fromComponent, toComponent, root);
933-
934-
// Do not try to copy materials for ParticleSystemRenderer, since it is not in the
935-
// FBX file
936-
if (fromComponent is Renderer && !(fromComponent is ParticleSystemRenderer))
937-
{
938-
var renderer = toComponent as Renderer;
939-
var sharedMaterials = renderer.sharedMaterials;
940-
EditorJsonUtility.FromJsonOverwrite(json, toComponent);
941-
renderer.sharedMaterials = sharedMaterials;
942-
}
943-
// SkinnedMeshRenderer stores both the mesh and materials.
944-
// Make sure these do not get copied over when the SkinnedMeshRenderer is updated.
945-
else if (fromComponent is SkinnedMeshRenderer)
937+
938+
// SkinnedMeshRenderer also stores the mesh.
939+
// Make sure this is not copied over when the SkinnedMeshRenderer is updated,
940+
// as we want to keep the mesh from the FBX not the scene.
941+
if (fromComponent is SkinnedMeshRenderer)
946942
{
947943
var skinnedMesh = toComponent as SkinnedMeshRenderer;
948944
var mesh = skinnedMesh.sharedMesh;
949-
var materials = skinnedMesh.sharedMaterials;
950945
EditorJsonUtility.FromJsonOverwrite(json, toComponent);
951-
var toSkinnedMesh = toComponent as SkinnedMeshRenderer;
952-
toSkinnedMesh.sharedMesh = mesh;
953-
toSkinnedMesh.sharedMaterials = materials;
946+
skinnedMesh.sharedMesh = mesh;
954947
}
955948
else
956949
{

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,14 @@ private bool ExportBlendShapes(MeshInfo mesh, FbxMesh fbxMesh, FbxScene fbxScene
498498
var weight = umesh.GetBlendShapeFrameWeight(bi, fi);
499499
umesh.GetBlendShapeFrameVertices(bi, fi, deltaPoints, deltaNormals, deltaTangents);
500500

501-
var fbxShape = FbxShape.Create(fbxScene, "");
501+
var fbxShapeName = bsName;
502+
503+
if (numFrames > 1)
504+
{
505+
fbxShapeName += "_" + fi;
506+
}
507+
508+
var fbxShape = FbxShape.Create(fbxScene, fbxShapeName);
502509
fbxChannel.AddTargetShape(fbxShape, weight);
503510

504511
// control points
@@ -2842,8 +2849,28 @@ private bool ExportBoneTransform(
28422849
fbxSkeleton.Size.Set (1.0f * UnitScaleFactor);
28432850
fbxNode.SetNodeAttribute (fbxSkeleton);
28442851
}
2845-
var fbxSkeletonType = rootBone != unityBone
2846-
? FbxSkeleton.EType.eLimbNode : FbxSkeleton.EType.eRoot;
2852+
var fbxSkeletonType = FbxSkeleton.EType.eLimbNode;
2853+
2854+
// Only set the rootbone's skeleton type to FbxSkeleton.EType.eRoot
2855+
// if it has at least one child that is also a bone.
2856+
// Otherwise if it is marked as Root but has no bones underneath,
2857+
// Maya will import it as a Null object instead of a bone.
2858+
if (rootBone == unityBone && rootBone.childCount > 0)
2859+
{
2860+
var hasChildBone = false;
2861+
foreach (Transform child in unityBone)
2862+
{
2863+
if (boneDict.ContainsKey(child))
2864+
{
2865+
hasChildBone = true;
2866+
break;
2867+
}
2868+
}
2869+
if (hasChildBone)
2870+
{
2871+
fbxSkeletonType = FbxSkeleton.EType.eRoot;
2872+
}
2873+
}
28472874
fbxSkeleton.SetSkeletonType (fbxSkeletonType);
28482875

28492876
var bindPoses = skinnedMesh.sharedMesh.bindposes;

com.unity.formats.fbx/Tests/FbxTests/ConvertToModelTest.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,17 @@ protected void AssertSameMeshesAndMaterials(GameObject expectedHierarchy, GameOb
107107
{
108108
Assert.That(actualSkinnedMesh);
109109
Assert.That(expectedSkinnedMesh.sharedMesh, Is.EqualTo(actualSkinnedMesh.sharedMesh));
110-
Assert.That(expectedSkinnedMesh.sharedMaterial, Is.EqualTo(actualSkinnedMesh.sharedMaterial));
110+
// material should not equal what is in the FBX, but what was originally in the scene
111+
Assert.That(expectedSkinnedMesh.sharedMaterial, Is.Not.EqualTo(actualSkinnedMesh.sharedMaterial));
111112
}
112113

113114
var expectedRenderer = expectedHierarchy.GetComponent<Renderer>();
114115
var actualRenderer = actualHierarchy.GetComponent<Renderer>();
115116
if (expectedRenderer)
116117
{
117118
Assert.That(actualRenderer);
118-
Assert.That(expectedRenderer.sharedMaterial, Is.EqualTo(actualRenderer.sharedMaterial));
119+
// material should not equal what is in the FBX, but what was originally in the scene
120+
Assert.That(expectedRenderer.sharedMaterial, Is.Not.EqualTo(actualRenderer.sharedMaterial));
119121
}
120122

121123
var expectedTransform = expectedHierarchy.transform;
@@ -433,6 +435,7 @@ public void TestStaticHelpers()
433435
b2.transform.parent = b.transform; // in alpha order
434436
a.AddComponent<BoxCollider> ();
435437
a1.transform.localPosition = new Vector3 (1, 2, 3);
438+
a.transform.localPosition = new Vector3(4, 5, 6);
436439

437440
Assert.AreNotEqual(b.GetComponent<MeshFilter>().sharedMesh, a.GetComponent<MeshFilter>().sharedMesh);
438441
Assert.IsFalse (b.GetComponent<BoxCollider> ());
@@ -441,11 +444,12 @@ public void TestStaticHelpers()
441444

442445
ConvertToNestedPrefab.UpdateFromSourceRecursive (b, a);
443446

444-
// everything except the mesh + materials should change
447+
// everything except the mesh + materials and child transforms should change
445448
Assert.AreNotEqual(b.GetComponent<MeshFilter>().sharedMesh, a.GetComponent<MeshFilter>().sharedMesh);
446449
Assert.IsTrue (b.GetComponent<BoxCollider> ());
447450
Assert.AreEqual ("BB", b.transform.GetChild (1).name);
448-
Assert.AreEqual (a1.transform.localPosition, b1.transform.localPosition);
451+
Assert.AreEqual(a.transform.localPosition, b.transform.localPosition);
452+
Assert.AreNotEqual (a1.transform.localPosition, b1.transform.localPosition);
449453
}
450454

451455
// Test GetFbxAssetOrNull

com.unity.formats.fbx/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.unity.formats.fbx",
33
"displayName": "FBX Exporter",
4-
"version": "3.0.1-preview.2",
4+
"version": "3.0.2-preview.1",
55
"dependencies": {
66
"com.unity.recorder": "2.1.0-preview.1",
77
"com.unity.timeline": "1.0.0",

0 commit comments

Comments
 (0)