diff options
author | jada <jada@28c7f869-5b4e-e670-f602-82bfaf57f300> | 2006-02-16 00:17:53 +0000 |
---|---|---|
committer | jada <jada@28c7f869-5b4e-e670-f602-82bfaf57f300> | 2006-02-16 00:17:53 +0000 |
commit | 21f0d6b572a4a632944a12b46e6909ae50d92aba (patch) | |
tree | d8325750bf204586929aa23561bed137afdb3ed4 /src/classes | |
parent | 825c6befcfc363fc14ab406f300686caa623b59a (diff) |
1. Converted all example programs, under objload, glsl_shader and cg_shader,
to use JFrame instead of MainFrame.
2. Created a GUI .form file for each example program.
Diffstat (limited to 'src/classes')
10 files changed, 769 insertions, 513 deletions
diff --git a/src/classes/org/jdesktop/j3d/examples/cg_shader/ObjLoadCg.form b/src/classes/org/jdesktop/j3d/examples/cg_shader/ObjLoadCg.form new file mode 100644 index 0000000..1483b2c --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/cg_shader/ObjLoadCg.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="ObjLoadCg"/> + </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/cg_shader/ObjLoadCg.java b/src/classes/org/jdesktop/j3d/examples/cg_shader/ObjLoadCg.java index 93c89a2..bdb859d 100644 --- a/src/classes/org/jdesktop/j3d/examples/cg_shader/ObjLoadCg.java +++ b/src/classes/org/jdesktop/j3d/examples/cg_shader/ObjLoadCg.java @@ -49,28 +49,31 @@ import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.IncorrectFormatException; import com.sun.j3d.loaders.Scene; import com.sun.j3d.utils.shader.StringIO; -import java.applet.Applet; -import java.awt.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; +import java.net.MalformedURLException; import java.util.Enumeration; import java.io.*; -import com.sun.j3d.utils.behaviors.vp.*; import java.net.URL; -import java.net.MalformedURLException; +import com.sun.j3d.utils.behaviors.vp.*; +import java.io.FileNotFoundException; import org.jdesktop.j3d.examples.Resources; -public class ObjLoadCg extends Applet { +/** + * Simple Java 3D example program to display an .obj object with shader programs. + */ +public class ObjLoadCg 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 @@ -139,7 +142,7 @@ public class ObjLoadCg 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(); @@ -163,46 +166,21 @@ public class ObjLoadCg 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 ObjLoadCg [-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 - - + // Create a Canvas3D using the preferred configuration + Canvas3D canvas3d = new Canvas3D(config); - 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 simple universe with view branch + univ = new SimpleUniverse(canvas3d); + BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); - Canvas3D c = new Canvas3D(config); - add("Center", c); - - // 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(); @@ -213,10 +191,10 @@ public class ObjLoadCg extends Applet { pg.addChild(ambientLightNode); // Set up the directional lights - Color3f light1Color = new Color3f(1.0f, 0.2f, 0.4f); - Vector3f light1Direction = new Vector3f(-1.0f, -1.0f, -1.0f); - Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f); - Vector3f light2Direction = new Vector3f(1.0f, 1.0f, 1.0f); + Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); + Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f); + Color3f light2Color = new Color3f(1.0f, 1.0f, 1.0f); + Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); @@ -235,22 +213,31 @@ public class ObjLoadCg 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); - } - - /* - // Limit the frame rate to 100 Hz - u.getViewer().getView().setMinimumFrameCycleTime(10); - */ + } + + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - u.addBranchGraph(scene); + return canvas3d; } + private void usage() { + System.out.println( + "Usage: java ObjLoadCg [-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 + // Set shader program for all nodes in specified branch graph private void setShaderProgram(BranchGroup g, ShaderProgram shaderProgram) { ShaderAppearance myApp = new ShaderAppearance(); @@ -280,63 +267,99 @@ public class ObjLoadCg extends Applet { } } - // Caled if running as a program - public ObjLoadCg(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]); - } + /** + * Creates new form ObjLoadCg + */ + public ObjLoadCg(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); + } + } } - catch (MalformedURLException e) { - System.err.println(e); - System.exit(1); - } - } - } - } - } - - - - // Running as an applet - public ObjLoadCg() { - } - - public void destroy() { - u.cleanup(); + } + + 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 ObjLoadCg to be run as an application - // as well as an applet - // - public static void main(String[] args) { - new MainFrame(new ObjLoadCg(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("ObjLoadCg"); + 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() { + ObjLoadCg objLoadCg = new ObjLoadCg(args); + objLoadCg.setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/cg_shader/SphereCg.form b/src/classes/org/jdesktop/j3d/examples/cg_shader/SphereCg.form new file mode 100644 index 0000000..ef60e53 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/cg_shader/SphereCg.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="SphereCg"/> + </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/cg_shader/SphereCg.java b/src/classes/org/jdesktop/j3d/examples/cg_shader/SphereCg.java index 2757006..1d7b1b1 100644 --- a/src/classes/org/jdesktop/j3d/examples/cg_shader/SphereCg.java +++ b/src/classes/org/jdesktop/j3d/examples/cg_shader/SphereCg.java @@ -44,23 +44,19 @@ package org.jdesktop.j3d.examples.cg_shader; -import java.applet.Applet; -import java.awt.*; -import java.io.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.Sphere; import com.sun.j3d.utils.shader.StringIO; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; -import java.util.Enumeration; -import java.net.URL; -import java.net.MalformedURLException; +import java.awt.GraphicsConfiguration; +import java.io.*; +import org.jdesktop.j3d.examples.Resources; /** - * Simple CG Shader test program + * Simple Java 3D example program with programmable shader. */ -public class SphereCg extends Applet { +public class SphereCg extends javax.swing.JFrame { // Constants for type of light to use private static final int DIRECTIONAL_LIGHT = 0; @@ -70,10 +66,10 @@ public class SphereCg extends Applet { // Flag indicates type of lights: directional, point, or spot // lights. This flag is set based on command line argument private static int lightType = DIRECTIONAL_LIGHT; + private SimpleUniverse univ = null; + private BranchGroup scene = null; - private SimpleUniverse u = null; - - public BranchGroup createSceneGraph(SimpleUniverse u) { + public BranchGroup createSceneGraph() { Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f); Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f); Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f); @@ -109,15 +105,11 @@ public class SphereCg extends Applet { ShaderAppearance a = new ShaderAppearance(); Material m = new Material(objColor, eColor, objColor, sColor, 100.0f); m.setLightingEnable(true); - Texture t2d = new Texture2D(); - a.setTexture(t2d); - a.setCapability(Appearance.ALLOW_TEXTURE_WRITE); - String vertexProgram = null; String fragmentProgram = null; try { - vertexProgram = StringIO.readFully("./simple_vp.cg"); - fragmentProgram = StringIO.readFully("./simple_fp.cg"); + vertexProgram = StringIO.readFully(Resources.getResource("cg_shader/simple_vp.cg")); + fragmentProgram = StringIO.readFully(Resources.getResource("cg_shader/simple_fp.cg")); } catch (IOException e) { e.printStackTrace(); @@ -163,7 +155,6 @@ public class SphereCg extends Applet { TransformGroup l2Trans = new TransformGroup(t); l2RotTrans.addChild(l2Trans); - /* // Create Geometry for point lights ColoringAttributes caL1 = new ColoringAttributes(); ColoringAttributes caL2 = new ColoringAttributes(); @@ -175,7 +166,6 @@ public class SphereCg extends Applet { appL2.setColoringAttributes(caL2); l1Trans.addChild(new Sphere(0.05f, appL1)); l2Trans.addChild(new Sphere(0.05f, appL2)); - */ // Create lights AmbientLight aLgt = new AmbientLight(alColor); @@ -252,7 +242,7 @@ public class SphereCg extends Applet { // Create a position interpolator and attach it to the view // platform TransformGroup vpTrans = - u.getViewingPlatform().getViewPlatformTransform(); + univ.getViewingPlatform().getViewPlatformTransform(); Transform3D axisOfTranslation = new Transform3D(); Alpha transAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | @@ -274,75 +264,82 @@ public class SphereCg extends Applet { return objRoot; } + + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - public SphereCg() { - } - - public void init() { - setLayout(new BorderLayout()); - GraphicsConfiguration config = - SimpleUniverse.getPreferredConfiguration(); - - Canvas3D c = new Canvas3D(config); - add("Center", c); + // Create a Canvas3D using the preferred configuration + Canvas3D canvas3d = new Canvas3D(config); - u = new SimpleUniverse(c); - BranchGroup scene = createSceneGraph(u); + // Create simple universe with view branch + univ = new SimpleUniverse(canvas3d); + BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); - - /* - // Limit the frame rate to 100 Hz - u.getViewer().getView().setMinimumFrameCycleTime(10); - */ + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); + + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - u.addBranchGraph(scene); + return canvas3d; } - public void destroy() { - u.cleanup(); - } - // - // The following allows SphereCg to be run as an application - // as well as an applet - // - public static void main(String[] args) { - // Parse the Input Arguments - String usage = "Usage: java SphereCg [-point | -spot | -dir]"; - for (int i = 0; i < args.length; i++) { - if (args[i].startsWith("-")) { - if (args[i].equals("-point")) { - /* - System.out.println("Using point lights"); - lightType = POINT_LIGHT; - */ - System.out.println("Point lights not yet implemented, option ignored"); - } - else if (args[i].equals("-spot")) { - /* - System.out.println("Using spot lights"); - lightType = SPOT_LIGHT; - */ - System.out.println("Spot lights not yet implemented, option ignored"); - } - else if (args[i].equals("-dir")) { - System.out.println("Using directional lights"); - lightType = DIRECTIONAL_LIGHT; - } - else { - System.out.println(usage); - System.exit(0); - } + /** + * Creates new form SphereCg + */ + public SphereCg() { + + // 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); } + + // ---------------------------------------------------------------- + + /** 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("SphereCg"); + 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() { + SphereCg sphereCg = new SphereCg(); + sphereCg.setVisible(true); } - else { - System.out.println(usage); - System.exit(0); - } - } - - new MainFrame(new SphereCg(), 700, 700); + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/glsl_shader/ObjLoadGLSL.form b/src/classes/org/jdesktop/j3d/examples/glsl_shader/ObjLoadGLSL.form new file mode 100644 index 0000000..343b6d5 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/glsl_shader/ObjLoadGLSL.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="ObjLoadGLSL"/> + </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/glsl_shader/ObjLoadGLSL.java b/src/classes/org/jdesktop/j3d/examples/glsl_shader/ObjLoadGLSL.java index 9106c0f..baadf8b 100644 --- a/src/classes/org/jdesktop/j3d/examples/glsl_shader/ObjLoadGLSL.java +++ b/src/classes/org/jdesktop/j3d/examples/glsl_shader/ObjLoadGLSL.java @@ -49,20 +49,22 @@ import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.IncorrectFormatException; import com.sun.j3d.loaders.Scene; import com.sun.j3d.utils.shader.StringIO; -import java.applet.Applet; -import java.awt.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; +import java.net.MalformedURLException; import java.util.Enumeration; import java.io.*; -import com.sun.j3d.utils.behaviors.vp.*; import java.net.URL; -import java.net.MalformedURLException; +import com.sun.j3d.utils.behaviors.vp.*; +import java.io.FileNotFoundException; import org.jdesktop.j3d.examples.Resources; -public class ObjLoadGLSL extends Applet { +/** + * Simple Java 3D example program to display an .obj object with shader programs. + */ +public class ObjLoadGLSL extends javax.swing.JFrame { private String shaderName = "polkadot3d"; private boolean spin = false; @@ -70,8 +72,9 @@ public class ObjLoadGLSL extends Applet { 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 @@ -98,21 +101,24 @@ public class ObjLoadGLSL extends Applet { if (!noTriangulate) flags |= ObjectFile.TRIANGULATE; if (!noStripify) flags |= ObjectFile.STRIPIFY; ObjectFile f = new ObjectFile(flags, - (float)(creaseAngle * Math.PI / 180.0)); + (float)(creaseAngle * Math.PI / 180.0)); Scene s = null; try { - s = f.load(filename); + s = f.load(filename); } catch (FileNotFoundException e) { - throw new RuntimeException(e); + System.err.println(e); + System.exit(1); } catch (ParsingErrorException e) { - throw new RuntimeException(e); + System.err.println(e); + System.exit(1); } catch (IncorrectFormatException e) { - throw new RuntimeException(e); + System.err.println(e); + System.exit(1); } - + // Set vertex and fragment shader program for all Shape3D nodes in scene String vertexProgram = null; String fragmentProgram = null; @@ -136,20 +142,20 @@ public class ObjLoadGLSL 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(); - Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, - 0, 0, - 4000, 0, 0, - 0, 0, 0); - - RotationInterpolator rotator = - new RotationInterpolator(rotationAlpha, objTrans, yAxis, - 0.0f, (float) Math.PI*2.0f); - rotator.setSchedulingBounds(bounds); - objTrans.addChild(rotator); + Transform3D yAxis = new Transform3D(); + Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, + 0, 0, + 4000, 0, 0, + 0, 0, 0); + + RotationInterpolator rotator = + new RotationInterpolator(rotationAlpha, objTrans, yAxis, + 0.0f, (float) Math.PI*2.0f); + rotator.setSchedulingBounds(bounds); + objTrans.addChild(rotator); } // Set up the background @@ -160,47 +166,21 @@ public class ObjLoadGLSL extends Applet { return objRoot; } - - private void usage() - { - System.out.println( - "Usage: java ObjLoadGLSL [-s] [-S shaderName] [-n] [-t] [-c degrees] <.obj file>"); - System.out.println(" -s Spin (no user interaction)"); - System.out.println(" -S Set shader name (default is 'simple')"); - 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 = + + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration(); - Canvas3D c = new Canvas3D(config); - add("Center", c); + // Create a Canvas3D using the preferred configuration + Canvas3D canvas3d = new Canvas3D(config); + + // 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(); @@ -211,10 +191,10 @@ public class ObjLoadGLSL extends Applet { pg.addChild(ambientLightNode); // Set up the directional lights - Color3f light1Color = new Color3f(1.0f, 0.2f, 0.4f); - Vector3f light1Direction = new Vector3f(-1.0f, -1.0f, -1.0f); - Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f); - Vector3f light2Direction = new Vector3f(1.0f, 1.0f, 1.0f); + Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f); + Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f); + Color3f light2Color = new Color3f(1.0f, 1.0f, 1.0f); + Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f); DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction); @@ -233,23 +213,32 @@ public class ObjLoadGLSL 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); - /* - // Limit the frame rate to 100 Hz - u.getViewer().getView().setMinimumFrameCycleTime(10); - */ - - u.addBranchGraph(scene); + return canvas3d; } - // Set shader program for all nodes in specified branch graph + private void usage() { + System.out.println("Usage: java ObjLoadGLSL [-s] [-S shaderName] [-n] [-t] [-c degrees] <.obj file>"); + System.out.println(" -s Spin (no user interaction)"); + System.out.println(" -S Set shader name (default is 'simple')"); + 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 + + // Set shader program for all nodes in specified branch graph private void setShaderProgram(BranchGroup g, ShaderProgram shaderProgram) { ShaderAppearance myApp = new ShaderAppearance(); Material mat = new Material(); @@ -275,66 +264,103 @@ public class ObjLoadGLSL extends Applet { } } - // Caled if running as a program - public ObjLoadGLSL(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 if (args[i].equals("-S")) { - if (i < args.length - 1) { - shaderName = args[++i]; - } 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) { - throw new RuntimeException(e); - } - } - } - } - } - - - - // Running as an applet - public ObjLoadGLSL() { - } - - public void destroy() { - u.cleanup(); + /** + * Creates new form ObjLoadGLSL + */ + public ObjLoadGLSL(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 if (args[i].equals("-S")) { + if (i < args.length - 1) { + shaderName = args[++i]; + } 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 ObjLoadGLSL to be run as an application - // as well as an applet - // - public static void main(String[] args) { - new MainFrame(new ObjLoadGLSL(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("ObjLoadGLSL"); + 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() { + ObjLoadGLSL objLoadGLSL = new ObjLoadGLSL(args); + objLoadGLSL.setVisible(true); + } + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } diff --git a/src/classes/org/jdesktop/j3d/examples/glsl_shader/SphereGLSL.form b/src/classes/org/jdesktop/j3d/examples/glsl_shader/SphereGLSL.form new file mode 100644 index 0000000..26e9b32 --- /dev/null +++ b/src/classes/org/jdesktop/j3d/examples/glsl_shader/SphereGLSL.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="SphereGLSL"/> + </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/glsl_shader/SphereGLSL.java b/src/classes/org/jdesktop/j3d/examples/glsl_shader/SphereGLSL.java index d1ac99e..768e38e 100644 --- a/src/classes/org/jdesktop/j3d/examples/glsl_shader/SphereGLSL.java +++ b/src/classes/org/jdesktop/j3d/examples/glsl_shader/SphereGLSL.java @@ -44,21 +44,19 @@ package org.jdesktop.j3d.examples.glsl_shader; -import java.applet.Applet; -import java.awt.*; -import java.io.*; -import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.geometry.Sphere; import com.sun.j3d.utils.shader.StringIO; import com.sun.j3d.utils.universe.*; import javax.media.j3d.*; import javax.vecmath.*; +import java.awt.GraphicsConfiguration; +import java.io.*; import org.jdesktop.j3d.examples.Resources; /** - * Simple GLSL Shader test program + * Simple Java 3D example program with programmable shader. */ -public class SphereGLSL extends Applet { +public class SphereGLSL extends javax.swing.JFrame { // Constants for type of light to use private static final int DIRECTIONAL_LIGHT = 0; @@ -68,10 +66,10 @@ public class SphereGLSL extends Applet { // Flag indicates type of lights: directional, point, or spot // lights. This flag is set based on command line argument private static int lightType = DIRECTIONAL_LIGHT; + private SimpleUniverse univ = null; + private BranchGroup scene = null; - private SimpleUniverse u = null; - - public BranchGroup createSceneGraph(SimpleUniverse u) { + public BranchGroup createSceneGraph() { Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f); Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f); Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f); @@ -243,7 +241,7 @@ public class SphereGLSL extends Applet { // Create a position interpolator and attach it to the view // platform TransformGroup vpTrans = - u.getViewingPlatform().getViewPlatformTransform(); + univ.getViewingPlatform().getViewPlatformTransform(); Transform3D axisOfTranslation = new Transform3D(); Alpha transAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | @@ -265,75 +263,82 @@ public class SphereGLSL extends Applet { return objRoot; } + + private Canvas3D createUniverse() { + // Get the preferred graphics configuration for the default screen + GraphicsConfiguration config = + SimpleUniverse.getPreferredConfiguration(); - public SphereGLSL() { - } - - public void init() { - 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); - - u = new SimpleUniverse(c); - BranchGroup scene = createSceneGraph(u); + // Create simple universe with view branch + univ = new SimpleUniverse(canvas3d); + BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0); + // This will move the ViewPlatform back a bit so the - // objects in the scene can be viewed. - u.getViewingPlatform().setNominalViewingTransform(); - - /* - // Limit the frame rate to 100 Hz - u.getViewer().getView().setMinimumFrameCycleTime(10); - */ + // objects in the scene can be viewed. + univ.getViewingPlatform().setNominalViewingTransform(); + + // Ensure at least 5 msec per frame (i.e., < 200Hz) + univ.getViewer().getView().setMinimumFrameCycleTime(5); - u.addBranchGraph(scene); + return canvas3d; } - public void destroy() { - u.cleanup(); - } - // - // The following allows SphereGLSL to be run as an application - // as well as an applet - // - public static void main(String[] args) { - // Parse the Input Arguments - String usage = "Usage: java SphereGLSL [-point | -spot | -dir]"; - for (int i = 0; i < args.length; i++) { - if (args[i].startsWith("-")) { - if (args[i].equals("-point")) { - /* - System.out.println("Using point lights"); - lightType = POINT_LIGHT; - */ - System.out.println("Point lights not yet implemented, option ignored"); - } - else if (args[i].equals("-spot")) { - /* - System.out.println("Using spot lights"); - lightType = SPOT_LIGHT; - */ - System.out.println("Spot lights not yet implemented, option ignored"); - } - else if (args[i].equals("-dir")) { - System.out.println("Using directional lights"); - lightType = DIRECTIONAL_LIGHT; - } - else { - System.out.println(usage); - System.exit(0); - } + /** + * Creates new form SphereGLSL + */ + public SphereGLSL() { + + // 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); } + + // ---------------------------------------------------------------- + + /** 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("SphereGLSL"); + 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() { + SphereGLSL sphereGLSL = new SphereGLSL(); + sphereGLSL.setVisible(true); } - else { - System.out.println(usage); - System.exit(0); - } - } - - new MainFrame(new SphereGLSL(), 700, 700); + }); } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JPanel drawingPanel; + // End of variables declaration//GEN-END:variables + } 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 + } |