changeset 3803:3b3ae57ddd59

3D Viewer App: Added poly mesh choice checkbox
author "Jasper Potts"
date Mon, 03 Jun 2013 18:27:19 -0700
parents 228a62a674e3
children aee1e049522e a62bcf50373d
files apps/experiments/3DViewer/src/main/java/com/javafx/experiments/importers/Importer3D.java apps/experiments/3DViewer/src/main/java/com/javafx/experiments/jfx3dviewer/MainController.java apps/experiments/3DViewer/src/main/java/com/javafx/experiments/jfx3dviewer/main.fxml
diffstat 3 files changed, 32 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/apps/experiments/3DViewer/src/main/java/com/javafx/experiments/importers/Importer3D.java	Mon Jun 03 18:03:58 2013 -0700
+++ b/apps/experiments/3DViewer/src/main/java/com/javafx/experiments/importers/Importer3D.java	Mon Jun 03 18:27:19 2013 -0700
@@ -30,13 +30,25 @@
     }
 
     /**
-     * Load a 3D file.
+     * Load a 3D file, always loaded as TriangleMesh.
      *
      * @param fileUrl The url of the 3D file to load
      * @return The loaded Node which could be a MeshView or a Group
      * @throws IOException if issue loading file
      */
     public static Node load(String fileUrl) throws IOException {
+        return load(fileUrl,false);
+    }
+
+    /**
+     * Load a 3D file.
+     *
+     * @param fileUrl The url of the 3D file to load
+     * @param asPolygonMesh When true load as a PolygonMesh if the loader supports
+     * @return The loaded Node which could be a MeshView or a Group
+     * @throws IOException if issue loading file
+     */
+    public static Node load(String fileUrl, boolean asPolygonMesh) throws IOException {
         // get extension
         final int dot = fileUrl.lastIndexOf('.');
         if (dot <= 0) {
@@ -49,7 +61,7 @@
             case "ase":
                 return loadMaxFile(fileUrl);
             case "obj":
-                return loadObjFile(fileUrl);
+                return loadObjFile(fileUrl, asPolygonMesh);
             case "fxml":
                 Object fxmlRoot = FXMLLoader.load(new URL(fileUrl));
                 if (fxmlRoot instanceof Node) {
@@ -78,12 +90,18 @@
         return new MaxLoader().loadMaxUrl(fileUrl);
     }
 
-    private static Node loadObjFile(String fileUrl) throws IOException {
-//        ObjImporter reader = new ObjImporter(fileUrl);
-        PolyObjImporter reader = new PolyObjImporter(fileUrl);
+    private static Node loadObjFile(String fileUrl, boolean asPolygonMesh) throws IOException {
         Group res = new Group();
-        for (String key : reader.getMeshes()) {
-            res.getChildren().add(reader.buildPolygonMeshView(key));
+        if (asPolygonMesh) {
+            PolyObjImporter reader = new PolyObjImporter(fileUrl);
+            for (String key : reader.getMeshes()) {
+                res.getChildren().add(reader.buildPolygonMeshView(key));
+            }
+        } else {
+            ObjImporter reader = new ObjImporter(fileUrl);
+            for (String key : reader.getMeshes()) {
+                res.getChildren().add(reader.buildMeshView(key));
+            }
         }
         return res;
     }
--- a/apps/experiments/3DViewer/src/main/java/com/javafx/experiments/jfx3dviewer/MainController.java	Mon Jun 03 18:03:58 2013 -0700
+++ b/apps/experiments/3DViewer/src/main/java/com/javafx/experiments/jfx3dviewer/MainController.java	Mon Jun 03 18:27:19 2013 -0700
@@ -49,6 +49,7 @@
 import javafx.scene.Parent;
 import javafx.scene.control.Accordion;
 import javafx.scene.control.Button;
+import javafx.scene.control.CheckBox;
 import javafx.scene.control.Label;
 import javafx.scene.control.SplitPane;
 import javafx.scene.control.ToggleButton;
@@ -72,6 +73,7 @@
     public Label status;
     public SplitPane splitPane;
     public ToggleButton settingsBtn;
+    public CheckBox loadAsPolygonsCheckBox;
     private Accordion settingsPanel;
     private double settingsLastWidth = -1;
     private int nodeCount = 0;
@@ -169,7 +171,7 @@
     private void load(File file) {
         loadedPath = file;
         try {
-            Node content = Importer3D.load(file.toURI().toURL().toString());
+            Node content = Importer3D.load(file.toURI().toURL().toString(),loadAsPolygonsCheckBox.isSelected());
             contentModel.set3dContent(content);
         } catch (IOException e) {
             e.printStackTrace();
--- a/apps/experiments/3DViewer/src/main/java/com/javafx/experiments/jfx3dviewer/main.fxml	Mon Jun 03 18:03:58 2013 -0700
+++ b/apps/experiments/3DViewer/src/main/java/com/javafx/experiments/jfx3dviewer/main.fxml	Mon Jun 03 18:27:19 2013 -0700
@@ -44,8 +44,10 @@
   <ToolBar>
     <items>
       <Button fx:id="openBtn" mnemonicParsing="false" onAction="#open" text="Open..." />
-      <Button mnemonicParsing="false" text="Export..."  onAction="#export" />
-      <Pane maxWidth="1.7976931348623157E308" HBox.hgrow="ALWAYS" prefHeight="-1.0" prefWidth="-1.0" />
+      <Button mnemonicParsing="false" onAction="#export" text="Export..." />
+      <Separator orientation="VERTICAL" prefHeight="-1.0" />
+      <CheckBox fx:id="loadAsPolygonsCheckBox" mnemonicParsing="false" text="Load as Polygons" />
+      <Pane maxWidth="1.7976931348623157E308" prefHeight="-1.0" prefWidth="-1.0" HBox.hgrow="ALWAYS"/>
       <ToggleButton fx:id="settingsBtn" mnemonicParsing="false" onAction="#toggleSettings" text="Settings" />
     </items>
   </ToolBar>