aboutsummaryrefslogtreecommitdiffstats
path: root/src/classes/org/jdesktop/j3d/examples/objload
diff options
context:
space:
mode:
authorkcr <kcr@28c7f869-5b4e-e670-f602-82bfaf57f300>2006-03-07 17:42:45 +0000
committerkcr <kcr@28c7f869-5b4e-e670-f602-82bfaf57f300>2006-03-07 17:42:45 +0000
commitd2f4b6c478a34d0089711a7bb8286bd0d04abbfb (patch)
tree535d86f45afccd54017d7f9a647302d1409d4312 /src/classes/org/jdesktop/j3d/examples/objload
parent19e30a5771eb1ec413e562c0d99b6263978dfba0 (diff)
Merged changes between 1.4.0-beta4 and 1.4.0-fcs into dev-1_5 branch
Diffstat (limited to 'src/classes/org/jdesktop/j3d/examples/objload')
-rw-r--r--src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java245
1 files changed, 135 insertions, 110 deletions
diff --git a/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java b/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java
index dd57983..059747e 100644
--- a/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java
+++ b/src/classes/org/jdesktop/j3d/examples/objload/ObjLoad.java
@@ -48,27 +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 java.awt.*;
-import java.awt.event.*;
-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.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
@@ -115,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();
@@ -139,49 +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
- try {
- URL path = getCodeBase();
- filename = new URL(path.toString() + "./galleon.obj");
- }
- catch (MalformedURLException e) {
- System.err.println(e);
- 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);
- }
+ }
+
+ // Ensure at least 5 msec per frame (i.e., < 200Hz)
+ univ.getViewer().getView().setMinimumFrameCycleTime(5);
- u.addBranchGraph(scene);
+ return canvas3d;
}
- // 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);
- }
- }
- }
- }
- }
-
-
-
- // Running as an applet
- public ObjLoad() {
- }
+ 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 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
+
}