1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
package sample3d; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Arrays; import javafx.application.Application; import javafx.stage.FileChooser; import my3d._viewport3d; public class _sample10_io extends _sample10 { public static void main(String... args) { Application.launch(args); } @Override public void init_scene(_viewport3d vp) { super.init_scene(vp); FileChooser pose_chooser = new FileChooser(); pose_chooser.setTitle("テクスチャ"); pose_chooser.getExtensionFilters().add(new FileChooser.ExtensionFilter( "ポーズ(*.txt)", Arrays.asList("*.txt"))); add_app_menu((index) -> { File file; switch (index) { case 0: file = pose_chooser.showOpenDialog(stage); if (file == null) return; try (BufferedReader br = new BufferedReader(new FileReader(file.getPath()))) { open_pose(br); repaint(); } catch (IOException e) { e.printStackTrace(); } break; case 1: file = pose_chooser.showSaveDialog(stage); if (file == null) return; try (BufferedWriter bw = new BufferedWriter(new FileWriter(file.getPath()))) { save_pose(bw); } catch (IOException e) { e.printStackTrace(); } break; case 2: copy_pose(); break; case 3: paste_pose(); break; case 4: reverse_pose(); break; } }, "---", "開く", "保存", "---", "コピー", "貼り付け", "反転" ); } private void open_pose(BufferedReader br) throws IOException { double[] params = new double[3]; String line; String[] a; for (_pose pose : all_pose) { line = br.readLine(); a = line.split(","); for (int i = 0; i < PART_NUM; i++) { for (int j = 0; j < 3; j++) params[j] = Double.parseDouble(a[i * 3 + j]); pose.set_params(i, params); } } } private void save_pose(BufferedWriter bw) throws IOException { double[] params; for (_pose pose : all_pose) { for (int i = 0; i < PART_NUM; i++) { params = pose.get_params(i); for (double param : params) bw.write(Math.round(param) + ","); } bw.newLine(); } } private _pose temp_pose = new _pose(); private void copy_pose() { if (curr_pose == null) return; for (int i = 0; i < PART_NUM; i++) temp_pose.set_params(i, curr_pose.get_params(i)); } private void paste_pose() { if (curr_pose == null) return; for (int i = 0; i < PART_NUM; i++) curr_pose.set_params(i, temp_pose.get_params(i)); repaint(); } private void reverse_pose() { if (curr_pose == null) return; double[] temp = new double[3]; curr_pose.get_params(2, temp); curr_pose.set_params(2, curr_pose.get_params(3)); curr_pose.set_params(3, temp); curr_pose.get_params(4, temp); curr_pose.set_params(4, curr_pose.get_params(5)); curr_pose.set_params(5, temp); repaint(); } }