|
8 | 8 |
|
9 | 9 | namespace FbxExporters.UnitTests
|
10 | 10 | {
|
11 |
| - public class ConvertToModelTest |
| 11 | + public class ConvertToModelTest : ExporterTestBase |
12 | 12 | {
|
13 | 13 | public static List<string> ChildNames(Transform a) {
|
14 | 14 | var names = new List<string>();
|
@@ -122,5 +122,48 @@ public void TestStaticHelpers()
|
122 | 122 | Assert.AreEqual (new Vector3 (1, 2, 3), b1.transform.localPosition);
|
123 | 123 | }
|
124 | 124 | }
|
| 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 | + } |
125 | 168 | }
|
126 | 169 | }
|
0 commit comments