/// <summary> /// Popup file choose dialog and call suitable export methothod acording to choosed file type. /// </summary> public void Export() { var label = LeanLocalization.GetTranslation("Export").Text; var newFileName = StandaloneFileBrowser.SaveFilePanel(label, "", fileName, "stl"); if (newFileName != "") { STLExporter.Export(newFileName, new GameObject[] { gameObject }, FileType.Binary); } }
public void ExportMultipleTest() { GameObject a = GameObject.CreatePrimitive(PrimitiveType.Cube); GameObject b = GameObject.CreatePrimitive(PrimitiveType.Cube); a.transform.position = Vector3.right; b.transform.position = new Vector3(3f, 5f, 2.4f); b.transform.localRotation = Quaternion.Euler(new Vector3(45f, 45f, 10f)); if (!Directory.Exists(TEMP_FILE_DIR)) { Directory.CreateDirectory(TEMP_FILE_DIR); } string temp_model_path = string.Format("{0}/multiple.stl", TEMP_FILE_DIR); STLExporter.Export(temp_model_path, new GameObject[] { a, b }, FileType.Binary); // Comparing binary files isn't great // Assert.IsTrue(CompareFiles(string.Format("{0}/CompositeCubes_BINARY.stl", TEST_MODELS), temp_model_path)); Mesh[] expected = STLImporter.Import(string.Format("{0}/CompositeCubes_BINARY.stl", TEST_MODELS)); Mesh[] results = STLImporter.Import(temp_model_path); Assert.IsTrue(expected != null); Assert.IsTrue(results != null); Assert.IsTrue(expected.Length == 1); Assert.IsTrue(results.Length == 1); Assert.AreEqual(expected[0].vertexCount, results[0].vertexCount); Assert.AreEqual(expected[0].triangles, results[0].triangles); // Can't use Assert.AreEqual(positions, normals, uvs) because Vec3 comparison is subject to floating point inaccuracy for (int i = 0; i < expected[0].vertexCount; i++) { Assert.Less(Vector3.Distance(expected[0].vertices[i], results[0].vertices[i]), .00001f); Assert.Less(Vector3.Distance(expected[0].normals[i], results[0].normals[i]), .00001f); } GameObject.DestroyImmediate(a); GameObject.DestroyImmediate(b); Directory.Delete(TEMP_FILE_DIR, true); }