1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
| /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
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);
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 = "C:\\Utilisateurs\\imane\\bureau\\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:\\Utilisateurs\\imane\\bureau\\airtable.obj";
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();
}
} |
Partager