Search in sources :

Example 1 with GenericMeshWriter

use of maspack.geometry.io.GenericMeshWriter in project artisynth_core by artisynth.

the class EditorUtils method saveMesh.

public static void saveMesh(MeshBase mesh, AffineTransform3dBase X) {
    Main main = Main.getMain();
    JFrame frame = main.getMainFrame();
    if (mesh == null) {
        showError(frame, "Component does not have a mesh");
        return;
    }
    if (X != null) {
        mesh = mesh.copy();
        mesh.transform(X);
    }
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(main.getModelDirectory());
    int retVal = chooser.showSaveDialog(frame);
    if (retVal == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getSelectedFile();
        try {
            if (mesh instanceof PolygonalMesh) {
                GenericMeshWriter writer = new GenericMeshWriter(file);
                writer.writeMesh(mesh);
                writer.close();
            } else {
                PrintWriter pw = new PrintWriter(new BufferedOutputStream(new FileOutputStream(file)));
                mesh.write(pw, "%.8g");
                pw.close();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            showError(frame, "Error saving file: " + ex.getMessage());
        }
        main.setModelDirectory(chooser.getCurrentDirectory());
    }
}
Also used : GenericMeshWriter(maspack.geometry.io.GenericMeshWriter) Main(artisynth.core.driver.Main) PolygonalMesh(maspack.geometry.PolygonalMesh)

Aggregations

Main (artisynth.core.driver.Main)1 PolygonalMesh (maspack.geometry.PolygonalMesh)1 GenericMeshWriter (maspack.geometry.io.GenericMeshWriter)1