BranchGroup scene = createSceneGraph(); simpleU.getViewingPlatform().setNominalViewingTransform(); scene.compile(); simpleU.addBranchGraph(scene);
package testobject; import com.sun.j3d.loaders.IncorrectFormatException; import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.Scene; import com.sun.j3d.loaders.objectfile.ObjectFile; import java.awt.*; import java.awt.event.*; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; // classes Java 3D import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.SimpleUniverse; import javax.media.j3d.*; import java.awt.image.*; import javax.vecmath.*; import java.util.*; import com.sun.j3d.utils.picking.behaviors.*; import com.sun.j3d.utils.picking.*; import java.io.FileNotFoundException; public class Test extends Frame implements MouseListener,MouseMotionListener{ SimpleUniverse SimpleU; static boolean application = false; Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); SimpleUniverse simpleU= new SimpleUniverse(canvas3D); ; private double creaseAngle = 60.0; private String filename; TransformGroup tg = new TransformGroup(); BoundingSphere behaveBounds = new BoundingSphere(); JButton parcourir; Panel pan; public Test(){ super("Test de l'application :p :p" ); BranchGroup scene = createSceneGraph(); simpleU.getViewingPlatform().setNominalViewingTransform(); scene.compile(); simpleU.addBranchGraph(scene); setLayout(new BorderLayout()); Panel framepane=new Panel(); framepane.setBackground(Color.cyan); this.add(framepane); framepane.setLayout(null); this.setSize(500,500); this.setVisible(true); Panel panel=new Panel(); panel.setLayout(new BorderLayout());panel.setBackground(Color.blue); panel.setSize(500,500);panel.setLocation(120,40); pan=new Panel();pan.setLayout(null); pan.setBackground(Color.yellow); JSeparator sep = new JToolBar.Separator(); sep.setBackground(Color.blue); sep.setOpaque(true); panel.add(pan); panel.setLocation(140, 80); pan.add(canvas3D); pan.setSize(300,300);canvas3D.setSize(300,500); canvas3D.setLocation(pan.getLocation()); canvas3D.setBackground(Color.red); framepane.add(panel); //---creation des boutons parcourir=new JButton("Parcourir." );parcourir.addMouseListener(this); parcourir.setSize(100,30);parcourir.setLocation(30,10); framepane.add(parcourir); this.setSize(500,500);this.setVisible(true); } //-------------------------- public BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); try { Scene s = null; ObjectFile f = new ObjectFile (); f.setFlags (ObjectFile.RESIZE | ObjectFile.TRIANGULATE | ObjectFile.STRIPIFY); if (application == false){ java.net.URL airFile = new java.net.URL (getCodeBase(), "airtable.obj"); s = f.load (airFile); tg.addChild (s.getSceneGroup ()); } else { String s1 = "airtable.obj"; s = f.load (s1); tg.addChild (s.getSceneGroup ()); } } catch (java.net.MalformedURLException ex){ } catch (java.io.FileNotFoundException ex){ } BoundingSphere bounds = new BoundingSphere (new Point3d (0.0, 0.0, 0.0), 100.0); Color3f ambientColor = new Color3f (0.5f, 0.5f, 0.5f); AmbientLight ambientLightNode = new AmbientLight (ambientColor); ambientLightNode.setInfluencingBounds (bounds); objRoot.addChild (ambientLightNode); t3d.setTranslation(new Vector3f(0f,0f,-5f)); tg.setTransform(t3d); objRoot.addChild(tg); return objRoot; } public void mouseClicked(MouseEvent e){ if (e.getSource()==parcourir) { JFileChooser fd = new JFileChooser("Répertoire des fichiers:"); fd.setVisible(true); fd.showOpenDialog(null); filename = "C:\\imane\\bureau\\wateringcan.obj"; int dim = ObjectFile.RESIZE; ObjectFile f = new ObjectFile(dim, (float)(creaseAngle * Math.PI / 180.0)); Scene s = null; try { s = f.load (filename); tg.addChild (s.getSceneGroup ()); } catch (FileNotFoundException evt) { evt.printStackTrace(); System.exit(1); } catch (ParsingErrorException evt) { evt.printStackTrace(); System.exit(1); } catch (IncorrectFormatException evt) { evt.printStackTrace(); System.exit(1); } canvas3D.getView().setBackClipDistance(Float.MAX_VALUE); canvas3D.getView().setFrontClipDistance(Float.MAX_VALUE); } } //------------------------------------- public void mouseReleased(MouseEvent e){canvas3D.repaint() ;} public void mouseMoved(MouseEvent e){} public void mousePressed(MouseEvent e) {} // public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mouseDragged(MouseEvent e) { } //-------methode main public static void main(String args[]){ Test myApp=new Test(); } public void mouseEntered(MouseEvent e) { canvas3D.repaint(); } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionpackage testobject; import com.sun.j3d.loaders.IncorrectFormatException; import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.Scene; import com.sun.j3d.loaders.objectfile.ObjectFile; import java.awt.*; import java.awt.event.*; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; // classes Java 3D import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.SimpleUniverse; import javax.media.j3d.*; import java.awt.image.*; import javax.vecmath.*; import java.util.*; import com.sun.j3d.utils.picking.behaviors.*; import com.sun.j3d.utils.picking.*; import java.io.FileNotFoundException; public class Test extends Frame implements MouseListener,MouseMotionListener{ SimpleUniverse SimpleU; static boolean application = false; Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); SimpleUniverse simpleU= new SimpleUniverse(canvas3D); ; private double creaseAngle = 60.0; private String filename; TransformGroup tg = new TransformGroup(); BoundingSphere behaveBounds = new BoundingSphere(); JButton parcourir; Panel pan; public Test(){ super("Test de l'application :p :p" ); BranchGroup scene = createSceneGraph(); simpleU.getViewingPlatform().setNominalViewingTransform(); scene.compile(); simpleU.addBranchGraph(scene); setLayout(new BorderLayout()); Panel framepane=new Panel(); framepane.setBackground(Color.cyan); this.add(framepane); framepane.setLayout(null); this.setSize(500,500); this.setVisible(true); Panel panel=new Panel(); panel.setLayout(new BorderLayout());panel.setBackground(Color.blue); panel.setSize(500,500);panel.setLocation(120,40); pan=new Panel();pan.setLayout(null); pan.setBackground(Color.yellow); JSeparator sep = new JToolBar.Separator(); sep.setBackground(Color.blue); sep.setOpaque(true); panel.add(pan); panel.setLocation(140, 80); pan.add(canvas3D); pan.setSize(300,300);canvas3D.setSize(300,500); canvas3D.setLocation(pan.getLocation()); canvas3D.setBackground(Color.red); framepane.add(panel); //---creation des boutons parcourir=new JButton("Parcourir." );parcourir.addMouseListener(this); parcourir.setSize(100,30);parcourir.setLocation(30,10); framepane.add(parcourir); this.setSize(500,500);this.setVisible(true); } //-------------------------- public BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); TransformGroup tg = new TransformGroup(); Transform3D t3d = new Transform3D(); try { Scene s = null; ObjectFile f = new ObjectFile (); f.setFlags (ObjectFile.RESIZE | ObjectFile.TRIANGULATE | ObjectFile.STRIPIFY); if (application == false){ java.net.URL airFile = new java.net.URL (getCodeBase(), "airtable.obj"); s = f.load (airFile); tg.addChild (s.getSceneGroup ()); } else { String s1 = "airtable.obj"; s = f.load (s1); tg.addChild (s.getSceneGroup ()); } } catch (java.net.MalformedURLException ex){ } catch (java.io.FileNotFoundException ex){ } BoundingSphere bounds = new BoundingSphere (new Point3d (0.0, 0.0, 0.0), 100.0); Color3f ambientColor = new Color3f (0.5f, 0.5f, 0.5f); AmbientLight ambientLightNode = new AmbientLight (ambientColor); ambientLightNode.setInfluencingBounds (bounds); objRoot.addChild (ambientLightNode); t3d.setTranslation(new Vector3f(0f,0f,-5f)); tg.setTransform(t3d); objRoot.addChild(tg); return objRoot; } public void mouseClicked(MouseEvent e){ if (e.getSource()==parcourir) { JFileChooser fd = new JFileChooser("Répertoire des fichiers:"); fd.setVisible(true); fd.showOpenDialog(null); filename = "C:\\imane\\bureau\\wateringcan.obj"; int dim = ObjectFile.RESIZE; ObjectFile f = new ObjectFile(dim, (float)(creaseAngle * Math.PI / 180.0)); Scene s = null; try { s = f.load (filename); tg.addChild (s.getSceneGroup ()); } catch (FileNotFoundException evt) { evt.printStackTrace(); System.exit(1); } catch (ParsingErrorException evt) { evt.printStackTrace(); System.exit(1); } catch (IncorrectFormatException evt) { evt.printStackTrace(); System.exit(1); } canvas3D.getView().setBackClipDistance(Float.MAX_VALUE); canvas3D.getView().setFrontClipDistance(Float.MAX_VALUE); } } //------------------------------------- public void mouseReleased(MouseEvent e){canvas3D.repaint() ;} public void mouseMoved(MouseEvent e){} public void mousePressed(MouseEvent e) {} // public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mouseDragged(MouseEvent e) { } //-------methode main public static void main(String args[]){ Test myApp=new Test(); } public void mouseEntered(MouseEvent e) { canvas3D.repaint(); } }
package testobject; import com.sun.j3d.loaders.IncorrectFormatException; import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.Scene; import com.sun.j3d.loaders.objectfile.ObjectFile; import java.awt.*; import java.awt.event.*; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; // classes Java 3D import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.SimpleUniverse; import javax.media.j3d.*; import java.awt.image.*; import javax.vecmath.*; import java.util.*; import com.sun.j3d.utils.picking.behaviors.*; import com.sun.j3d.utils.picking.*; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; public class Test extends Frame implements MouseListener,MouseMotionListener{ SimpleUniverse SimpleU; static boolean application = false; Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); SimpleUniverse simpleU= new SimpleUniverse(canvas3D); ; private double creaseAngle = 60.0; TransformGroup tg = new TransformGroup(); BoundingSphere behaveBounds = new BoundingSphere(); JButton parcourir; Panel pan; public Test(){ super("Test de l'application :p :p" ); setLayout(new BorderLayout()); Panel framepane=new Panel(); framepane.setBackground(Color.cyan); this.add(framepane); framepane.setLayout(null); this.setSize(500,500); this.setVisible(true); Panel panel=new Panel(); panel.setLayout(new BorderLayout());panel.setBackground(Color.blue); panel.setSize(500,500);panel.setLocation(120,40); pan=new Panel();pan.setLayout(null); pan.setBackground(Color.yellow); JSeparator sep = new JToolBar.Separator(); sep.setBackground(Color.blue); sep.setOpaque(true); panel.add(pan); panel.setLocation(140, 80); pan.add(canvas3D); pan.setSize(300,300);canvas3D.setSize(300,500); canvas3D.setLocation(pan.getLocation()); canvas3D.setBackground(Color.red); framepane.add(panel); //---creation des boutons parcourir=new JButton("Parcourir." );parcourir.addMouseListener(this); parcourir.setSize(100,30);parcourir.setLocation(30,10); framepane.add(parcourir); this.setSize(500,500);this.setVisible(true); } //-------------------------- public BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); TransformGroup tg = new TransformGroup(); try { Scene s = null; ObjectFile f = new ObjectFile (); f.setFlags (ObjectFile.RESIZE); String s1 = "airtable.obj"; s = f.load (s1); tg.addChild (s.getSceneGroup ()); } catch (java.io.FileNotFoundException ex){ } return objRoot; } public void mouseClicked(MouseEvent e){ if (e.getSource()==parcourir) { JFileChooser fd = new JFileChooser("Répertoire des fichiers:"); fd.setVisible(true); fd.showOpenDialog(null); String filename = "C:/imane/bureau/airtable.obj"; try { FileReader file = new FileReader(filename); BufferedReader inputStream = new BufferedReader(file); System.out.println(inputStream.readLine()); } catch (IOException ex) { Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex); } BranchGroup scene = createSceneGraph(); simpleU.getViewingPlatform().setNominalViewingTransform(); scene.compile(); simpleU.addBranchGraph(scene); canvas3D.getView().setBackClipDistance(Float.MAX_VALUE); canvas3D.getView().setFrontClipDistance(Float.MAX_VALUE); } } //------------------------------------- public void mouseReleased(MouseEvent e){canvas3D.repaint() ;} public void mouseMoved(MouseEvent e){} public void mousePressed(MouseEvent e) {} // public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mouseDragged(MouseEvent e) { } //-------methode main public static void main(String args[]){ Test myApp=new Test(); } public void mouseEntered(MouseEvent e) { canvas3D.repaint(); } }
package testobject; import com.sun.j3d.loaders.IncorrectFormatException; import com.sun.j3d.loaders.ParsingErrorException; import com.sun.j3d.loaders.Scene; import com.sun.j3d.loaders.objectfile.ObjectFile; import java.awt.*; import java.awt.event.*; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; // classes Java 3D import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.SimpleUniverse; import javax.media.j3d.*; import java.awt.image.*; import javax.vecmath.*; import java.util.*; import com.sun.j3d.utils.picking.behaviors.*; import com.sun.j3d.utils.picking.*; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; public class Test extends Frame implements MouseListener,MouseMotionListener{ SimpleUniverse SimpleU; static boolean application = false; Canvas3D canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); SimpleUniverse simpleU= new SimpleUniverse(canvas3D); ; private double creaseAngle = 60.0; TransformGroup tg = new TransformGroup(); BoundingSphere behaveBounds = new BoundingSphere(); JButton parcourir; Panel pan; public Test(){ super("Test de l'application :p :p" ); setLayout(new BorderLayout()); Panel framepane=new Panel(); framepane.setBackground(Color.cyan); this.add(framepane); framepane.setLayout(null); this.setSize(500,500); this.setVisible(true); Panel panel=new Panel(); panel.setLayout(new BorderLayout());panel.setBackground(Color.blue); panel.setSize(500,500);panel.setLocation(120,40); pan=new Panel();pan.setLayout(null); pan.setBackground(Color.yellow); JSeparator sep = new JToolBar.Separator(); sep.setBackground(Color.blue); sep.setOpaque(true); panel.add(pan); panel.setLocation(140, 80); pan.add(canvas3D); pan.setSize(300,300);canvas3D.setSize(300,500); canvas3D.setLocation(pan.getLocation()); canvas3D.setBackground(Color.red); framepane.add(panel); //---creation des boutons parcourir=new JButton("Parcourir." );parcourir.addMouseListener(this); parcourir.setSize(100,30);parcourir.setLocation(30,10); framepane.add(parcourir); this.setSize(500,500);this.setVisible(true); } //-------------------------- public BranchGroup createSceneGraph() { BranchGroup objRoot = new BranchGroup(); TransformGroup tg = new TransformGroup(); try { Scene s = null; ObjectFile f = new ObjectFile (); f.setFlags (ObjectFile.RESIZE); String s1 = "airtable.obj"; s = f.load (s1); tg.addChild (s.getSceneGroup ()); } catch (java.io.FileNotFoundException ex){ } return objRoot; } public void mouseClicked(MouseEvent e){ if (e.getSource()==parcourir) { JFileChooser fd = new JFileChooser("Répertoire des fichiers:"); fd.setVisible(true); fd.showOpenDialog(null); String filename = "C:/imane/bureau/airtable.obj"; try { FileReader file = new FileReader(filename); BufferedReader inputStream = new BufferedReader(file); System.out.println(inputStream.readLine()); } catch (IOException ex) { Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex); } BranchGroup scene = createSceneGraph(); simpleU.getViewingPlatform().setNominalViewingTransform(); scene.compile(); simpleU.addBranchGraph(scene); canvas3D.getView().setBackClipDistance(Float.MAX_VALUE); canvas3D.getView().setFrontClipDistance(Float.MAX_VALUE); } } //------------------------------------- public void mouseReleased(MouseEvent e){canvas3D.repaint() ;} public void mouseMoved(MouseEvent e){} public void mousePressed(MouseEvent e) {} // public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mouseDragged(MouseEvent e) { } //-------methode main public static void main(String args[]){ Test myApp=new Test(); } public void mouseEntered(MouseEvent e) { canvas3D.repaint(); } }