Skip to content

Commit 85d6312

Browse files
committed
fix up Convert to Model unit tests
-remove keepOriginalAfterConvert from export settings -check that only mesh changes with CopyComponents -original hierarchy becomes the prefab, keep original checks are redundant
1 parent bd64a8b commit 85d6312

File tree

2 files changed

+33
-40
lines changed

2 files changed

+33
-40
lines changed

Assets/FbxExporters/Editor/FbxExportSettings.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,6 @@ public static string kDefaultAdskRoot {
210210
public bool mayaCompatibleNames;
211211
public bool centerObjects;
212212

213-
/// <summary>
214-
/// In Convert-to-model, by default we delete the original object.
215-
/// This option lets you override that.
216-
/// </summary>
217-
[HideInInspector]
218-
public bool keepOriginalAfterConvert;
219-
220213
public int selectedMayaApp = 0;
221214

222215
/// <summary>
@@ -243,7 +236,6 @@ protected override void LoadDefaults()
243236
{
244237
mayaCompatibleNames = true;
245238
centerObjects = true;
246-
keepOriginalAfterConvert = false;
247239
convertToModelSavePath = kDefaultSavePath;
248240
mayaOptionPaths = null;
249241
mayaOptionNames = null;

Assets/FbxExporters/Editor/UnitTests/ConvertToModelTest.cs

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -60,41 +60,54 @@ public void TestStaticHelpers()
6060

6161
// Test CopyComponents
6262
{
63-
var a = new GameObject("a");
64-
var b = new GameObject("b");
63+
var a = GameObject.CreatePrimitive (PrimitiveType.Cube);
64+
a.name = "a";
65+
var b = GameObject.CreatePrimitive (PrimitiveType.Sphere);
66+
b.name = "b";
6567
a.AddComponent<BoxCollider>();
6668
a.transform.localPosition += new Vector3(1,2,3);
6769
Assert.IsFalse(b.GetComponent<BoxCollider>());
6870
Assert.AreEqual(Vector3.zero, b.transform.localPosition);
69-
ConvertToModel.CopyComponents(a, b);
70-
Assert.IsTrue(b.GetComponent<BoxCollider>());
71-
Assert.AreEqual(new Vector3(1,2,3), b.transform.localPosition);
71+
Assert.AreNotEqual (a.GetComponent<MeshFilter>().sharedMesh, b.GetComponent<MeshFilter> ().sharedMesh);
72+
ConvertToModel.CopyComponents(b, a);
73+
Assert.IsFalse(b.GetComponent<BoxCollider>());
74+
Assert.AreEqual(Vector3.zero, b.transform.localPosition);
75+
Assert.AreEqual (a.GetComponent<MeshFilter>().sharedMesh, b.GetComponent<MeshFilter> ().sharedMesh);
7276
}
7377

74-
// Test SetupImportedGameObject. Very similar but recursive.
78+
// Test UpdateFromSourceRecursive. Very similar but recursive.
7579
{
76-
var a = new GameObject ("a");
77-
var a1 = new GameObject ("AA");
78-
var a2 = new GameObject ("BB");
80+
var a = GameObject.CreatePrimitive (PrimitiveType.Cube);
81+
a.name = "a";
82+
var a1 = GameObject.CreatePrimitive (PrimitiveType.Cube);
83+
a1.name = "AA";
84+
var a2 = GameObject.CreatePrimitive (PrimitiveType.Cube);
85+
a2.name = "BB";
7986
a2.transform.parent = a.transform;
8087
a1.transform.parent = a.transform; // out of alpha order!
81-
var b = new GameObject ("b");
82-
var b1 = new GameObject ("AA");
83-
var b2 = new GameObject ("BB");
88+
var b = GameObject.CreatePrimitive (PrimitiveType.Sphere);
89+
b.name = "b";
90+
var b1 = GameObject.CreatePrimitive (PrimitiveType.Sphere);
91+
b1.name = "AA";
92+
var b2 = GameObject.CreatePrimitive (PrimitiveType.Sphere);
93+
b2.name = "BB";
8494
b1.transform.parent = b.transform;
8595
b2.transform.parent = b.transform; // in alpha order
8696
a.AddComponent<BoxCollider> ();
8797
a1.transform.localPosition = new Vector3 (1, 2, 3);
8898

99+
Assert.AreNotEqual(b.GetComponent<MeshFilter>().sharedMesh, a.GetComponent<MeshFilter>().sharedMesh);
89100
Assert.IsFalse (b.GetComponent<BoxCollider> ());
90101
Assert.AreEqual ("BB", b.transform.GetChild (1).name);
91102
Assert.AreEqual (Vector3.zero, b1.transform.localPosition);
92103

93-
ConvertToModel.UpdateFromSourceRecursive (a, b);
104+
ConvertToModel.UpdateFromSourceRecursive (b, a);
94105

95-
Assert.IsTrue (b.GetComponent<BoxCollider> ());
96-
Assert.AreEqual ("AA", b.transform.GetChild (1).name);
97-
Assert.AreEqual (new Vector3 (1, 2, 3), b1.transform.localPosition);
106+
// only the mesh + materials should change
107+
Assert.AreEqual(b.GetComponent<MeshFilter>().sharedMesh, a.GetComponent<MeshFilter>().sharedMesh);
108+
Assert.IsFalse (b.GetComponent<BoxCollider> ());
109+
Assert.AreEqual ("BB", b.transform.GetChild (1).name);
110+
Assert.AreEqual (Vector3.zero, b1.transform.localPosition);
98111
}
99112
}
100113

@@ -114,20 +127,18 @@ public void BasicTest()
114127
// Make sure it's what we expect.
115128
Assert.That(cube); // we kept the original
116129
Assert.That(cubePrefabInstance); // we got the new
130+
Assert.AreSame(cube, cubePrefabInstance); // the original and new are the same
117131
Assert.AreEqual("Cube", cubePrefabInstance.name); // it has the right name
118132
Assert.That(!EditorUtility.IsPersistent(cubePrefabInstance));
119133
var cubePrefabAsset = PrefabUtility.GetPrefabParent(cubePrefabInstance);
120134
Assert.That(cubePrefabAsset);
135+
Assert.That (EditorUtility.IsPersistent (cubePrefabAsset));
121136

122-
// it's a different mesh instance, but the same mesh
123-
Assert.AreNotEqual(
124-
cube.GetComponent<MeshFilter>().sharedMesh,
125-
cubePrefabInstance.GetComponent<MeshFilter>().sharedMesh);
126137
Assert.That(cubePrefabInstance.GetComponent<FbxPrefab>());
127138

128139
// Should be all the same triangles. But it isn't. TODO.
129140
// At least the indices should match in multiplicity.
130-
var cubeMesh = cube.GetComponent<MeshFilter>().sharedMesh;
141+
var cubeMesh = GameObject.CreatePrimitive(PrimitiveType.Cube).GetComponent<MeshFilter>().sharedMesh;
131142
var cubePrefabMesh = cubePrefabInstance.GetComponent<MeshFilter>().sharedMesh;
132143
//Assert.That(
133144
// cubeMesh.triangles,
@@ -145,16 +156,7 @@ public void BasicTest()
145156
// Also make sure we deleted.
146157
var cubePrefabInstance2 = ConvertToModel.Convert(cubePrefabInstance,
147158
directoryFullPath: path);
148-
Assert.IsFalse(cubePrefabInstance);
149159
Assert.That(cubePrefabInstance2.GetComponents<FbxPrefab>().Length, Is.EqualTo(1));
150-
151-
// Create another cube, make sure the export settings drive whether we keep the cube or not.
152-
ConvertToModel.Convert(cube, directoryFullPath: path);
153-
if (ConvertToModel.ExportSettings.keepOriginalAfterConvert) {
154-
Assert.IsTrue(cube);
155-
} else {
156-
Assert.IsFalse(cube);
157-
}
158160
}
159161

160162
[Test]
@@ -173,9 +175,8 @@ public void SkinnedMeshTest()
173175
Object.DestroyImmediate(meshRender);
174176
Object.DestroyImmediate(meshFilter);
175177

176-
// Convert it. Make sure it gets deleted, to avoid a useless error about internal consistency.
178+
// Convert it.
177179
var cubeInstance = ConvertToModel.Convert(cube, fbxFullPath: GetRandomFbxFilePath());
178-
if (cube) { Object.DestroyImmediate(cube); }
179180

180181
// Make sure it doesn't have a skinned mesh renderer on it.
181182
// In the future we'll want to assert the opposite!

0 commit comments

Comments
 (0)