/// <summary> /// Popu[ file choose dialog and next call sutable import method. /// </summary> public void Import() { var label = LeanLocalization.GetTranslation("Export").Text; var fileNames = StandaloneFileBrowser.OpenFilePanel(label, "", "stl", false); if (fileNames.Length == 0) { return; } if (Path.GetExtension(fileNames[0]).ToLower() == ".stl") { if (fileNames[0].Contains("file:")) { fileNames[0] = fileNames[0].Substring(7); } fileNames[0] = Decode(fileNames[0]); try { var meshes = STLImporter.Import(fileNames[0]); var brick = BrickBuilder.Instansiate(meshes); } catch (Exception e) { Debug.Log(e.Message); Dialog.ShowInfo( LeanLocalization.GetTranslation("ImportFailed").Text, DialogButtonType.ok); } } }
public void ImportBinaryTest() { Mesh[] meshes = STLImporter.Import(string.Format("{0}/Cylinder_BINARY_RH.stl", TEST_MODELS)); Assert.IsTrue(meshes != null); Assert.AreEqual(1, meshes.Length); Assert.AreEqual(240, meshes[0].triangles.Length); Assert.AreEqual(240, meshes[0].vertexCount); }
public void ImportBinaryWithHeadersTest() { Mesh[] meshes = STLImporter.Import(string.Format("{0}/CubedShape_BINARY_H.stl", TEST_MODELS)); Assert.IsTrue(meshes != null); Assert.AreEqual(1, meshes.Length); Assert.AreEqual(204, meshes[0].triangles.Length); Assert.AreEqual(204, meshes[0].vertexCount); }
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); }
private void FileOpen_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == DialogResult.OK) { STLImporter importer = new STLImporter(model); try { importer.Import(openFileDialog1.FileName); SetupScaleAndPosition(); } catch (Exception ex) { MessageBox.Show($"Не могу открыть файл!\n{openFileDialog1.FileName}\n{ex.Message}", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error); model.Clear(); scale = 1f; position = Vector3.Zero; } glControl1.Invalidate(); } }