diff options
Diffstat (limited to 'src/classes/org/jdesktop/j3d/examples/objload')
-rw-r--r-- | src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.form | 36 | ||||
-rw-r--r-- | src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java | 243 |
2 files changed, 170 insertions, 109 deletions
diff --git a/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.form b/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.form new file mode 100644 index 0000000..f8ced41 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.form @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8" ?> + +<Form version="1.0" type="org.netbeans.modules.form.forminfo.JFrameFormInfo"> + <Properties> + <Property name="defaultCloseOperation" type="int" value="3"/> + <Property name="title" type="java.lang.String" value="ObjLoad"/> + </Properties> + <SyntheticProperties> + <SyntheticProperty name="formSizePolicy" type="int" value="1"/> + </SyntheticProperties> + <AuxValues> + <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/> + <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/> + <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/> + <AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/> + </AuxValues> + + <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> + <SubComponents> + <Container class="javax.swing.JPanel" name="drawingPanel"> + <Properties> + <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> + <Dimension value="[700, 700]"/> + </Property> + </Properties> + <Constraints> + <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout" value="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout$BorderConstraintsDescription"> + <BorderConstraints direction="Center"/> + </Constraint> + </Constraints> + + <Layout class="org.netbeans.modules.form.compat2.layouts.DesignBorderLayout"/> + </Container> + </SubComponents> +</Form> diff --git a/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java b/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java index dfe6c13..059747e 100644 --- a/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java +++ b/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java @@ -48,30 +48,30 @@ import com.sun.j3d.loaders.objectfile.ObjectFile; import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.IncorrectFormatException; import com.sun.j3d.loaders.Scene; -import java.applet.Applet; -import com.sun.j3d.utils.applet.MainFrame; + import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; -import java.io.*; -import com.sun.j3d.utils.behaviors.vp.*; -import java.net.URL; +import java.awt.GraphicsConfiguration; import java.net.MalformedURLException; - - - -import java.awt.*; +import java.net.URL; +import com.sun.j3d.utils.behaviors.vp.*; +import java.io.FileNotFoundException; import org.jdesktop.j3d.examples.Resources; -public class ObjLoad extends Applet { +/** + * Simple Java 3D example program to display an .obj object. + */ +public class ObjLoad extends javax.swing.JFrame { private boolean spin = false; private boolean noTriangulate = false; private boolean noStripify = false; private double creaseAngle = 60.0; private URL filename = null; - private SimpleUniverse u; - private BoundingSphere bounds; + + private SimpleUniverse univ = null; + private BranchGroup scene = null; public BranchGroup createSceneGraph() { // Create the root of the branch graph @@ -118,7 +118,7 @@ public class ObjLoad extends Applet { objTrans.addChild(s.getSceneGroup()); - bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); if (spin) { Transform3D yAxis = new Transform3D(); @@ -142,46 +142,21 @@ public class ObjLoad extends Applet { return objRoot; } + + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - private void usage() - { - System.out.println( - "Usage: java ObjLoad [-s] [-n] [-t] [-c degrees] <.obj file>"); - System.out.println(" -s Spin (no user interaction)"); - System.out.println(" -n No triangulation"); - System.out.println(" -t No stripification"); - System.out.println( - " -c Set crease angle for normal generation (default is 60 without"); - System.out.println( - " smoothing group info, otherwise 180 within smoothing groups)"); - System.exit(0); - } // End of usage - - - - public void init() { - if (filename == null) { - // Applet - filename = Resources.getResource("resources/geometry/galleon.obj"); - if (filename == null) { - System.err.println("resources/geometry/galleon.obj not found"); - System.exit(1); - } - } - - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); + // Create a Canvas3D using the preferred configuration + Canvas3D canvas3d = new Canvas3D(config); - Canvas3D c = new Canvas3D(config); - add("Center", c); + // Create simple universe with view branch + univ = new SimpleUniverse(canvas3d); + BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); - // Create a simple scene and attach it to the virtual universe - BranchGroup scene = createSceneGraph(); - u = new SimpleUniverse(c); - // add mouse behaviors to the ViewingPlatform - ViewingPlatform viewingPlatform = u.getViewingPlatform(); + ViewingPlatform viewingPlatform = univ.getViewingPlatform(); PlatformGeometry pg = new PlatformGeometry(); @@ -214,74 +189,124 @@ public class ObjLoad extends Applet { viewingPlatform.setNominalViewingTransform(); if (!spin) { - OrbitBehavior orbit = new OrbitBehavior(c, + OrbitBehavior orbit = new OrbitBehavior(canvas3d, OrbitBehavior.REVERSE_ALL); - BoundingSphere bounds = - new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0); orbit.setSchedulingBounds(bounds); viewingPlatform.setViewPlatformBehavior(orbit); - } - - u.addBranchGraph(scene); - } + } + + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - // Caled if running as a program - public ObjLoad(String[] args) { - if (args.length != 0) { - for (int i = 0 ; i < args.length ; i++) { - if (args[i].startsWith("-")) { - if (args[i].equals("-s")) { - spin = true; - } else if (args[i].equals("-n")) { - noTriangulate = true; - } else if (args[i].equals("-t")) { - noStripify = true; - } else if (args[i].equals("-c")) { - if (i < args.length - 1) { - creaseAngle = (new Double(args[++i])).doubleValue(); - } else usage(); - } else { - usage(); - } - } else { - try { - if ((args[i].indexOf("file:") == 0) || - (args[i].indexOf("http") == 0)) { - filename = new URL(args[i]); - } - else if (args[i].charAt(0) != '/') { - filename = new URL("file:./" + args[i]); - } - else { - filename = new URL("file:" + args[i]); - } - } - catch (MalformedURLException e) { - System.err.println(e); - System.exit(1); - } - } - } - } + return canvas3d; } + private void usage() { + System.out.println( + "Usage: java ObjLoad [-s] [-n] [-t] [-c degrees] <.obj file>"); + System.out.println(" -s Spin (no user interaction)"); + System.out.println(" -n No triangulation"); + System.out.println(" -t No stripification"); + System.out.println( + " -c Set crease angle for normal generation (default is 60 without"); + System.out.println( + " smoothing group info, otherwise 180 within smoothing groups)"); + System.exit(0); + } // End of usage - - // Running as an applet - public ObjLoad() { - } - - public void destroy() { - u.cleanup(); + /** + * Creates new form ObjLoad + */ + public ObjLoad(String args[]) { + if (args.length != 0) { + for (int i = 0 ; i < args.length ; i++) { + if (args[i].startsWith("-")) { + if (args[i].equals("-s")) { + spin = true; + } else if (args[i].equals("-n")) { + noTriangulate = true; + } else if (args[i].equals("-t")) { + noStripify = true; + } else if (args[i].equals("-c")) { + if (i < args.length - 1) { + creaseAngle = (new Double(args[++i])).doubleValue(); + } else usage(); + } else { + usage(); + } + } else { + try { + if ((args[i].indexOf("file:") == 0) || + (args[i].indexOf("http") == 0)) { + filename = new URL(args[i]); + } else if (args[i].charAt(0) != '/') { + filename = new URL("file:./" + args[i]); + } else { + filename = new URL("file:" + args[i]); + } + } catch (MalformedURLException e) { + System.err.println(e); + System.exit(1); + } + } + } + } + + if (filename == null) { + filename = Resources.getResource("resources/geometry/galleon.obj"); + if (filename == null) { + System.err.println("resources/geometry/galleon.obj not found"); + System.exit(1); + } + } + + // Initialize the GUI components + initComponents(); + + // Create Canvas3D and SimpleUniverse; add canvas to drawing panel + Canvas3D c = createUniverse(); + drawingPanel.add(c, java.awt.BorderLayout.CENTER); + + // Create the content branch and add it to the universe + scene = createSceneGraph(); + univ.addBranchGraph(scene); } - - - // - // The following allows ObjLoad to be run as an application - // as well as an applet - // - public static void main(String[] args) { - new MainFrame(new ObjLoad(args), 700, 700); + // ---------------------------------------------------------------- + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents + private void initComponents() { + drawingPanel = new javax.swing.JPanel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setTitle("ObjLoad"); + drawingPanel.setLayout(new java.awt.BorderLayout()); + + drawingPanel.setPreferredSize(new java.awt.Dimension(700, 700)); + getContentPane().add(drawingPanel, java.awt.BorderLayout.CENTER); + + pack(); + }// </editor-fold>//GEN-END:initComponents + + /** + * @param args the command line arguments + */ + public static void main(final String args[]) { + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + ObjLoad objLoad = new ObjLoad(args); + objLoad.setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } |