Skip to content

Commit 6c2f5f2

Browse files
author
Benoit Hudson
committed
New test for ConvertToModel.
1 parent 827911c commit 6c2f5f2

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

Assets/FbxExporters/Editor/UnitTests/ConvertToModelTest.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace FbxExporters.UnitTests
1010
{
11-
public class ConvertToModelTest
11+
public class ConvertToModelTest : ExporterTestBase
1212
{
1313
public static List<string> ChildNames(Transform a) {
1414
var names = new List<string>();
@@ -122,5 +122,48 @@ public void TestStaticHelpers()
122122
Assert.AreEqual (new Vector3 (1, 2, 3), b1.transform.localPosition);
123123
}
124124
}
125+
126+
[Test]
127+
public void BasicTest()
128+
{
129+
// Get a random directory.
130+
var path = GetRandomFileNamePath(extName: "");
131+
132+
// Create a cube.
133+
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
134+
135+
// Convert it to a prefab.
136+
var cubePrefabInstance = ConvertToModel.CreateInstantiatedModelPrefab(cube,
137+
directoryFullPath: path, keepOriginal: true);
138+
139+
// Make sure it's what we expect.
140+
Assert.IsTrue(cube); // we kept the original
141+
Assert.IsTrue(cubePrefabInstance); // we got the new
142+
Assert.AreEqual("Cube", cubePrefabInstance.name); // it has the right name
143+
Assert.IsFalse(EditorUtility.IsPersistent(cubePrefabInstance));
144+
var cubePrefabAsset = PrefabUtility.GetPrefabParent(cubePrefabInstance);
145+
146+
// it's a different mesh instance, but the same mesh
147+
Assert.AreNotEqual(
148+
cube.GetComponent<MeshFilter>().sharedMesh,
149+
cubePrefabInstance.GetComponent<MeshFilter>().sharedMesh);
150+
Assert.IsTrue(cubePrefabInstance.GetComponent<FbxPrefab>());
151+
152+
// Should be all the same triangles. But it isn't. TODO.
153+
// At least the indices should match in multiplicity.
154+
var cubeMesh = cube.GetComponent<MeshFilter>().sharedMesh;
155+
var cubePrefabMesh = cubePrefabInstance.GetComponent<MeshFilter>().sharedMesh;
156+
//Assert.That(
157+
// cubeMesh.triangles,
158+
// Is.EqualTo(cubePrefabMesh.triangles)
159+
//);
160+
Assert.That(cubeMesh.triangles, Is.EquivalentTo(cubeMesh.triangles));
161+
162+
// Make sure it's where we expect.
163+
var assetRelativePath = AssetDatabase.GetAssetPath(cubePrefabAsset);
164+
var assetFullPath = Path.GetFullPath(Path.Combine(Application.dataPath,
165+
"../" + assetRelativePath));
166+
Assert.AreEqual(Path.GetFullPath(path), Path.GetDirectoryName(assetFullPath));
167+
}
125168
}
126169
}

0 commit comments

Comments
 (0)