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 158 159 160 161 162 163 164 165 166 167
| private Texture chercheTexture(String s) {
if ( applet ) {
try {
String adresse = base+s ;
URL u1 = new URL(adresse);
return(new TextureLoader(u1,this).getTexture()) ; }
catch (MalformedURLException e) { return(new Texture2D());} }
else
return(new TextureLoader(s,this).getTexture());
}
public Transform3D Trans_form3D(Vector3d T,Vector3d S,AxisAngle4d r)
{
Transform3D drehung = new Transform3D();
Transform3D drehung2 = new Transform3D();
drehung2.setTranslation(T);
drehung2.setScale(S);
drehung2.setRotation(r);
drehung.mul(drehung2);
return(drehung);
}
public TransformGroup Transform_Group(Transform3D d,String h)
{
TransformGroup objDreh1 = new TransformGroup(d);
Scene scene = null;
if (h.endsWith(".3ds"))
{
Loader3DS loader = new Loader3DS();
loader.setFlags(Loader3DS.LOAD_ALL);
try{
scene = loader.load(h);
}
catch (Exception e)
{
scene = null;
System.err.println(e);
}
if( scene == null )
{System.out.printf("kkkk");
System.exit(1);
}
}
if (h.endsWith(".obj"))
{
ObjectFile file = new ObjectFile(ObjectFile.RESIZE);
try {
scene = file.load(ClassLoader.getSystemResource(h ));
} catch (FileNotFoundException e) {
}
}
BranchGroup rootGroup = null;
if (scene != null && (rootGroup = scene.getSceneGroup()) != null)
objDreh1.addChild(rootGroup);
return(objDreh1);
}
public void platforme(TransformGroup objTrans)
{
Appearance a1 = new Appearance();
Texture t = chercheTexture("texture/textuer03.jpg");
a1.setTexture(t);
Transform3D t3D = new Transform3D();
t3D.setRotation(new AxisAngle4d(1.0,0.0,0.0,Math.PI / 2.0d));//Math.PI/5.0)) ;
objTrans.setTransform(t3D);
Box b=new Box(0.5F,0.5F,0.001F,Box.GENERATE_TEXTURE_COORDS|Box.GENERATE_NORMALS|Box.ENABLE_GEOMETRY_PICKING,a1);
b.setCapability(Geometry.ALLOW_INTERSECT);
PickRotateBehavior behavior1 =new PickRotateBehavior(objRoot, c, largeBounds);
behavior1.setMode(PickTool.GEOMETRY);
objTrans0.addChild(behavior1);
objTrans2.addChild(b);
}
public TransformGroup TFG(BoundingSphere largeBounds,Vector3d T,Vector3d S,AxisAngle4d r,String h)
{ Transform3D drehung2 = Trans_form3D(T,S,r);
TransformGroup objTrans = new TransformGroup();
objTranss.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTranss.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objTranss.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
{ MouseZoom behavior = new MouseZoom(objTranss);
objTranss.addChild(behavior);
behavior.setSchedulingBounds(largeBounds); }
// move platform
{ MouseRotate behavior = new MouseRotate(objTranss);
objTranss.addChild(behavior);
behavior.setSchedulingBounds(largeBounds); }
if (h!="")
objTrans.addChild(Transform_Group(drehung2,h));
return(objTrans);
}
void objets()
{
objTrans2=TFG(largeBounds,T2,S,r,"");
platforme(objTrans2 );
}
public BranchGroup createSceneGraph(SimpleUniverse u) {
largeBounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),100.0);
{ Vector3f ldir = new Vector3f(1.0F,1.0F,-1.0F);
Color3f lcouldl = new Color3f(1.0F,1.0F,1.0F);
DirectionalLight dl = new DirectionalLight(lcouldl,ldir);
dl.setInfluencingBounds(largeBounds);
objRoot.addChild(dl); }
{ Color3f lcoulal = new Color3f(0.3F,0.3F,0.1F);
AmbientLight al = new AmbientLight(lcoulal);
al.setInfluencingBounds(largeBounds);
objRoot.addChild(al); }
objets();
///////////////////////
objTranss.addChild(objTrans2);
objRoot.addChild(objTranss);
///////////////////////////
objRoot.compile();
return objRoot;
}
public void lanceJava3D() {
setLayout(new BorderLayout());
GraphicsConfiguration config;
config = SimpleUniverse.getPreferredConfiguration();
c = new Canvas3D(config);
add("North",c);
u = new SimpleUniverse(c);
BranchGroup scene = createSceneGraph(u);
Vector3f viewTranslation = new Vector3f();
viewTranslation.z = 3;
viewTranslation.x = 0f;
viewTranslation.y = .3f;
Transform3D viewTransform = new Transform3D();
viewTransform.setTranslation(viewTranslation);
rotation.mul(viewTransform);
////////////////////////////////////
c.setSize(300, 300);
Panel panel = new Panel();
panel.setLayout(new BorderLayout());
panel.setSize(500,500);
panel.add(c);
add("Center", panel);
//////////////////////////////////
u.getViewingPlatform().getViewPlatformTransform().setTransform(rotation);
u.addBranchGraph(scene);
//u1.getViewingPlatform().getViewPlatformTransform().setTransform(rotation);
}
public void init() {
if ( applet ) {
URL url = this.getCodeBase();
base = url.toString();
lanceJava3D(); }
}
public platform() {
if ( !applet ) {
lanceJava3D(); }
}
public static void main(String[] args) {
applet = false ;
new MainFrame(new platform(),600,150);
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void actionPerformed(ActionEvent e) {
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
}
} |