Skip to content

Commit 4645d4a

Browse files
authored
Merge pull request #419 from Unity-Technologies/UNI-48541-fix-Fbx-Exporter-FDG-warnings
Uni 48541 fix Fbx Exporter fdg warnings
2 parents d6b7a54 + c78a351 commit 4645d4a

29 files changed

+1194
-1091
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using System.Reflection;
4+
using UnityEngine;
5+
6+
namespace UnityEditor.Formats.Fbx.Exporter.UnitTests
7+
{
8+
/// <summary>
9+
// This class allows accessing the ConvertToModel methods that this
10+
// unit test needs to validate
11+
/// </summary>
12+
public class ConvertToModelReflection
13+
{
14+
public static GameObject GetOrCreateFbxAsset(GameObject toConvert,
15+
string fbxDirectoryFullPath = null,
16+
string fbxFullPath = null,
17+
ConvertToPrefabSettingsSerialize exportOptions = null)
18+
{
19+
return (GameObject)InvokeStaticMethod("GetOrCreateFbxAsset", new object[] { toConvert, fbxDirectoryFullPath, fbxFullPath, exportOptions });
20+
}
21+
22+
public static void CopyComponents(GameObject to, GameObject from)
23+
{
24+
InvokeStaticMethod("CopyComponents", new object[] { to, from });
25+
}
26+
27+
public static void UpdateFromSourceRecursive(GameObject dest, GameObject source)
28+
{
29+
InvokeStaticMethod("UpdateFromSourceRecursive", new object[] { dest, source });
30+
}
31+
32+
public static Dictionary<string, GameObject> MapNameToSourceRecursive(GameObject dest, GameObject source)
33+
{
34+
return (Dictionary<string, GameObject>)InvokeStaticMethod("MapNameToSourceRecursive", new object[] { dest, source });
35+
}
36+
37+
/////////// Helpers ///////////
38+
private static object InvokeStaticMethod(string methodName, object[] argsToPass)
39+
{
40+
// Use reflection to call the internal ModelExporter.GetGameObject static method
41+
var internalMethod = typeof(ConvertToModel).GetMethod(methodName,
42+
BindingFlags.Static | BindingFlags.NonPublic);
43+
return internalMethod.Invoke(null, argsToPass);
44+
}
45+
}
46+
}

Packages/com.unity.formats.fbx/Runtime/FbxTurnTableBase.cs.meta renamed to Assets/com.unity.formats.fbx.tests/ConvertToModelReflection.cs.meta

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

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@ public void TestStaticHelpers()
6262

6363
// Test on an object in the scene
6464
Assert.That(ConvertToModel.WillExportFbx(a));
65-
var aAsset = ConvertToModel.GetOrCreateFbxAsset(a, fbxFullPath: GetRandomFbxFilePath());
65+
var aAsset = ConvertToModelReflection.GetOrCreateFbxAsset(a, fbxFullPath: GetRandomFbxFilePath());
6666
Assert.AreNotEqual(a, aAsset);
6767
AssertSameHierarchy(a, aAsset, ignoreRootName: true);
6868
Assert.AreEqual(PrefabType.ModelPrefab, PrefabUtility.GetPrefabType(aAsset));
6969

7070
// Test on an fbx asset
7171
Assert.That(!ConvertToModel.WillExportFbx(aAsset));
72-
var aAssetAsset = ConvertToModel.GetOrCreateFbxAsset(aAsset, fbxFullPath: GetRandomFbxFilePath());
72+
var aAssetAsset = ConvertToModelReflection.GetOrCreateFbxAsset(aAsset, fbxFullPath: GetRandomFbxFilePath());
7373
Assert.AreEqual(aAsset, aAssetAsset);
7474

7575
// Test on an fbx instance
7676
var aAssetInstance = PrefabUtility.InstantiatePrefab(aAsset) as GameObject;
7777
Assert.That(!ConvertToModel.WillExportFbx(aAssetInstance));
78-
var aAssetInstanceAsset = ConvertToModel.GetOrCreateFbxAsset(aAssetInstance, fbxFullPath: GetRandomFbxFilePath());
78+
var aAssetInstanceAsset = ConvertToModelReflection.GetOrCreateFbxAsset(aAssetInstance, fbxFullPath: GetRandomFbxFilePath());
7979
Assert.AreEqual(aAsset, aAssetInstanceAsset);
8080
}
8181

@@ -88,7 +88,7 @@ public void TestStaticHelpers()
8888
Assert.AreEqual(a, b);
8989

9090
// Test on an fbx asset
91-
var aFbx = ConvertToModel.GetOrCreateFbxAsset(a, fbxFullPath: GetRandomFbxFilePath());
91+
var aFbx = ConvertToModelReflection.GetOrCreateFbxAsset(a, fbxFullPath: GetRandomFbxFilePath());
9292
var bFbx = ConvertToModel.GetOrCreateInstance(aFbx);
9393
Assert.AreNotEqual(aFbx, bFbx);
9494
Assert.AreEqual(aFbx, PrefabUtility.GetCorrespondingObjectFromSource(bFbx));
@@ -103,7 +103,7 @@ public void TestStaticHelpers()
103103
// Test SetupFbxPrefab
104104
{
105105
var a = CreateHierarchy();
106-
var aFbx = ConvertToModel.GetOrCreateFbxAsset(a, fbxFullPath: GetRandomFbxFilePath());
106+
var aFbx = ConvertToModelReflection.GetOrCreateFbxAsset(a, fbxFullPath: GetRandomFbxFilePath());
107107

108108
// We don't have an FbxPrefab; after setup we do; after a second setup we still only have one.
109109
Assert.AreEqual(0, a.GetComponents<FbxPrefab>().Length);
@@ -166,7 +166,7 @@ public void TestStaticHelpers()
166166
Assert.IsFalse(b.GetComponent<BoxCollider>());
167167
Assert.AreEqual(Vector3.zero, b.transform.localPosition);
168168
Assert.AreNotEqual (a.GetComponent<MeshFilter>().sharedMesh, b.GetComponent<MeshFilter> ().sharedMesh);
169-
ConvertToModel.CopyComponents(b, a);
169+
ConvertToModelReflection.CopyComponents(b, a);
170170
Assert.IsFalse(b.GetComponent<BoxCollider>());
171171
Assert.AreEqual(Vector3.zero, b.transform.localPosition);
172172
Assert.AreEqual (a.GetComponent<MeshFilter>().sharedMesh, b.GetComponent<MeshFilter> ().sharedMesh);
@@ -198,7 +198,7 @@ public void TestStaticHelpers()
198198
Assert.AreEqual ("BB", b.transform.GetChild (1).name);
199199
Assert.AreEqual (Vector3.zero, b1.transform.localPosition);
200200

201-
ConvertToModel.UpdateFromSourceRecursive (b, a);
201+
ConvertToModelReflection.UpdateFromSourceRecursive (b, a);
202202

203203
// only the mesh + materials should change
204204
Assert.AreEqual(b.GetComponent<MeshFilter>().sharedMesh, a.GetComponent<MeshFilter>().sharedMesh);
@@ -391,7 +391,7 @@ public void MapNameToSourceTest()
391391
quad2.transform.parent = cube2.transform;
392392
capsule.transform.SetSiblingIndex(1);
393393

394-
var dictionary = ConvertToModel.MapNameToSourceRecursive(cube, cube2);
394+
var dictionary = ConvertToModelReflection.MapNameToSourceRecursive(cube, cube2);
395395

396396
//We expect these to pass because we've given it an identical game object, as it would have after a normal export.
397397
Assert.AreSame(capsule2, dictionary[capsule.name]);
@@ -407,7 +407,7 @@ public void MapNameToSourceTest()
407407
capsule3.transform.parent = cube3.transform;
408408
sphere3.transform.parent = cube3.transform;
409409

410-
var dictionaryBroken = ConvertToModel.MapNameToSourceRecursive(cube, cube3);
410+
var dictionaryBroken = ConvertToModelReflection.MapNameToSourceRecursive(cube, cube3);
411411

412412
//the dictionary size should be equal to the amount of children + the parent
413413
Assert.True(dictionaryBroken.Count == 4);

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ public void TestGetSetFields ()
166166
var appDataPath = Application.dataPath.Replace (Path.AltDirectorySeparatorChar,
167167
Path.DirectorySeparatorChar);
168168

169-
var defaultAbsolutePath = ExportSettings.GetFbxAbsoluteSavePath ();
169+
var defaultAbsolutePath = ExportSettings.FbxAbsoluteSavePath;
170170
var dataPath = Path.GetFullPath (Path.Combine (appDataPath, ExportSettings.kDefaultSavePath));
171171
Assert.AreEqual (dataPath, defaultAbsolutePath);
172172

173-
var prefabDefaultAbsPath = ExportSettings.GetPrefabAbsoluteSavePath ();
173+
var prefabDefaultAbsPath = ExportSettings.PrefabAbsoluteSavePath;
174174
Assert.AreEqual (dataPath, prefabDefaultAbsPath);
175175

176176
// set; check that the saved value is platform-independent,
@@ -184,8 +184,8 @@ public void TestGetSetFields ()
184184
Assert.That (ExportSettings.GetRelativePrefabSavePaths () [0], Is.EqualTo (string.Format("Assets{0}a{0}b{0}c", forwardSlash)));
185185

186186
var platformPath = Path.Combine ("a", Path.Combine ("b", "c"));
187-
Assert.AreEqual (Path.Combine (appDataPath, platformPath), ExportSettings.GetFbxAbsoluteSavePath ());
188-
Assert.AreEqual (Path.Combine (appDataPath, platformPath), ExportSettings.GetPrefabAbsoluteSavePath ());
187+
Assert.AreEqual (Path.Combine (appDataPath, platformPath), ExportSettings.FbxAbsoluteSavePath);
188+
Assert.AreEqual (Path.Combine (appDataPath, platformPath), ExportSettings.PrefabAbsoluteSavePath);
189189

190190
ExportSettings.AddFbxSavePath ("test");
191191
ExportSettings.AddPrefabSavePath ("test2");
@@ -212,43 +212,43 @@ public void TestFindPreferredProgram ()
212212

213213
ExportSettings.instance.SetDCCOptionNames (testList);
214214

215-
int preferred = ExportSettings.instance.GetPreferredDCCApp ();
215+
int preferred = ExportSettings.instance.PreferredDCCApp;
216216
//While Maya 2017 and 3ds Max 2017 are tied for most recent, Maya 2017 (index 8) should win because we prefer Maya.
217217
Assert.AreEqual (preferred, 8);
218218

219219
ExportSettings.instance.ClearDCCOptionNames ();
220220
//Try running it with an empty list
221-
preferred = ExportSettings.instance.GetPreferredDCCApp ();
221+
preferred = ExportSettings.instance.PreferredDCCApp;
222222

223223
Assert.AreEqual (preferred, -1);
224224

225225
ExportSettings.instance.SetDCCOptionNames (null);
226226
//Try running it with a null list
227-
preferred = ExportSettings.instance.GetPreferredDCCApp ();
227+
preferred = ExportSettings.instance.PreferredDCCApp;
228228

229229
Assert.AreEqual(preferred, -1);
230230

231231
//Testing the results of only having a mayaLT install
232232
ExportSettings.instance.SetDCCOptionNames(new List<string> { ExportSettings.kMayaLtOptionName + "2018" }); //hardcoded because the constant is changed in another branch but not this one at this time
233-
preferred = ExportSettings.instance.GetPreferredDCCApp();
233+
preferred = ExportSettings.instance.PreferredDCCApp;
234234

235235
Assert.AreEqual(preferred, 0);
236236

237237
//Testing the results of only having a maya install
238238
ExportSettings.instance.SetDCCOptionNames(new List<string> { ExportSettings.kMayaOptionName + "2018" });
239-
preferred = ExportSettings.instance.GetPreferredDCCApp();
239+
preferred = ExportSettings.instance.PreferredDCCApp;
240240

241241
Assert.AreEqual(preferred, 0);
242242

243243
//Testing the results of only having a max install
244244
ExportSettings.instance.SetDCCOptionNames(new List<string> { ExportSettings.kMaxOptionName + "2018" });
245-
preferred = ExportSettings.instance.GetPreferredDCCApp();
245+
preferred = ExportSettings.instance.PreferredDCCApp;
246246

247247
Assert.AreEqual(preferred, 0);
248248

249249
//Testing the preference priority
250250
ExportSettings.instance.SetDCCOptionNames(new List<string> { ExportSettings.kMaxOptionName + "2018", ExportSettings.kMayaOptionName + "2018", ExportSettings.kMayaLtOptionName + "2018" });
251-
preferred = ExportSettings.instance.GetPreferredDCCApp();
251+
preferred = ExportSettings.instance.PreferredDCCApp;
252252

253253
Assert.AreEqual(preferred, 1);
254254
}
@@ -485,7 +485,7 @@ private void TestLocations(Dictionary<string,List<string>> data)
485485

486486
if (data.ContainsKey("expected3DApp"))
487487
{
488-
int preferred = ExportSettings.instance.GetPreferredDCCApp ();
488+
int preferred = ExportSettings.instance.PreferredDCCApp;
489489
Assert.AreEqual(preferred, int.Parse(data["expected3DApp"][0]) );
490490
}
491491
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void BasicTest ()
4343
{
4444
var fbxPrefabPath = FbxPrefabAutoUpdater.FindFbxPrefabAssetPath ();
4545
Assert.IsFalse (string.IsNullOrEmpty (fbxPrefabPath));
46-
Assert.IsTrue (fbxPrefabPath.EndsWith (FbxPrefabAutoUpdater.FBX_PREFAB_FILE));
46+
Assert.IsTrue (fbxPrefabPath.EndsWith (FbxPrefabAutoUpdater.FbxPrefabFile));
4747

4848
Assert.IsTrue (FbxPrefabAutoUpdater.IsFbxAsset ("Assets/path/to/foo.fbx"));
4949
Assert.IsFalse (FbxPrefabAutoUpdater.IsFbxAsset ("Assets/path/to/foo.png"));

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ FbxPrefabAutoUpdater.FbxPrefabUtility.FbxRepresentation Rep(GameObject go) {
187187
}
188188

189189
FbxPrefabAutoUpdater.FbxPrefabUtility.FbxRepresentation History(GameObject go) {
190-
return new FbxPrefabAutoUpdater.FbxPrefabUtility(go.GetComponent<FbxPrefab>()).GetFbxHistory();
190+
return new FbxPrefabAutoUpdater.FbxPrefabUtility(go.GetComponent<FbxPrefab>()).FbxHistory;
191191
}
192192

193193
GameObject ModifySourceFbx()
@@ -270,7 +270,7 @@ public void BasicTest() {
270270
AssertAreIdentical(newHistory, History(m_manualPrefab));
271271

272272
// Check some corner cases.
273-
Assert.AreEqual(m_source, manualFbxPrefabUtility.GetFbxAsset());
273+
Assert.AreEqual(m_source, manualFbxPrefabUtility.FbxAsset);
274274

275275
// Illegal to set the source model to something that isn't an
276276
// asset.
@@ -287,7 +287,7 @@ public void BasicTest() {
287287
// hierarchy or anything.
288288
Debug.Log("Testing SetSourceModel to null");
289289
Assert.That( () => manualFbxPrefabUtility.SetSourceModel(null), Throws.Nothing );
290-
Assert.IsNull(manualFbxPrefabUtility.GetFbxAsset());
290+
Assert.IsNull(manualFbxPrefabUtility.FbxAsset);
291291
AssertAreIdentical(newHierarchy, Rep(m_manualPrefab));
292292
AssertAreIdentical(newHistory, History(m_manualPrefab));
293293
Assert.That( () => manualFbxPrefabUtility.SyncPrefab(), Throws.Nothing );
@@ -429,7 +429,7 @@ public void TestTransformAndReparenting()
429429
GetRandomFbxFilePath(), root);
430430
SleepForFileTimestamp();
431431

432-
var destFile = new FbxPrefabAutoUpdater.FbxPrefabUtility (original.GetComponent<FbxPrefab> ()).GetFbxAssetPath ();
432+
var destFile = new FbxPrefabAutoUpdater.FbxPrefabUtility (original.GetComponent<FbxPrefab> ()).FbxAssetPath;
433433
if (System.IO.File.Exists (destFile)) {
434434
System.IO.File.Delete (destFile);
435435
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,20 @@ public void BasicTest() {
4141

4242
Assert.IsTrue (MayaIntegration.IsHeadlessInstall () == 0);
4343

44-
LogNonEmptyString ("module template path", mayaIntegration.GetModuleTemplatePath ());
45-
LogNonEmptyString ("package path", MayaIntegration.GetPackagePath ());
44+
LogNonEmptyString ("module template path", mayaIntegration.ModuleTemplatePath);
45+
LogNonEmptyString ("package path", MayaIntegration.PackagePath);
4646

47-
LogNonEmptyString ("export settings path", mayaIntegration.GetExportSettingsPath ());
48-
LogNonEmptyString ("package version", MayaIntegration.GetPackageVersion ());
47+
LogNonEmptyString ("export settings path", mayaIntegration.ExportSettingsPath);
48+
LogNonEmptyString ("package version", MayaIntegration.PackageVersion);
4949

5050
// check if folder is unzipped at invalid paths
5151
Assert.IsFalse (mayaIntegration.FolderAlreadyUnzippedAtPath (null));
5252
Assert.IsFalse (mayaIntegration.FolderAlreadyUnzippedAtPath (""));
5353
Assert.IsFalse (mayaIntegration.FolderAlreadyUnzippedAtPath ("X:/a/b/a/c"));
5454

5555
// test that the paths don't contain backslashes
56-
Assert.IsFalse (MayaIntegration.GetProjectPath ().Contains ("\\"));
57-
Assert.IsFalse (mayaIntegration.GetExportSettingsPath ().Contains ("\\"));
56+
Assert.IsFalse (MayaIntegration.ProjectPath.Contains ("\\"));
57+
Assert.IsFalse (mayaIntegration.ExportSettingsPath.Contains ("\\"));
5858
}
5959

6060
// test Maya LT integration

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ public void TestBasics() {
2323
var animCurve = new AnimationCurve();
2424

2525
eulerCurve.SetCurve (2, animCurve);
26-
Assert.That (eulerCurve.m_curves [2], Is.EqualTo (animCurve));
26+
Assert.That (eulerCurve.Curves [2], Is.EqualTo (animCurve));
2727

2828
Assert.That(() => eulerCurve.SetCurve (-1, animCurve), Throws.Exception.TypeOf<System.IndexOutOfRangeException>());
2929
Assert.That(() => eulerCurve.SetCurve (3, animCurve), Throws.Exception.TypeOf<System.IndexOutOfRangeException>());
3030

3131
quaternionCurve.SetCurve (3, animCurve);
32-
Assert.That (quaternionCurve.m_curves [3], Is.EqualTo (animCurve));
32+
Assert.That (quaternionCurve.Curves [3], Is.EqualTo (animCurve));
3333

3434
Assert.That(() => quaternionCurve.SetCurve (-5, animCurve), Throws.Exception.TypeOf<System.IndexOutOfRangeException>());
3535
Assert.That(() => quaternionCurve.SetCurve (4, animCurve), Throws.Exception.TypeOf<System.IndexOutOfRangeException>());

0 commit comments

Comments
 (0)