Paso 3: Importar el objeto en Java
trate de {}
XMLDecoder e = new XMLDecoder (nuevo BufferedInputStream (nuevo FileInputStream("c:/HandShape3D.xml"))); el nombre del archivo aquí
Fred = e.readObject() (Shape3D);
e.Close();
} catch (excepción e) {}
e.printStackTrace();
}
ColoringAttributes a = nuevo ColoringAttributes();
Aspecto ap = nuevo Appearance();
Color3f col = new Color3f (1.0f, 0.0f, 1.0f);
Ca ColoringAttributes = new ColoringAttributes (col, ColoringAttributes.NICEST);
ap.setColoringAttributes(ca);
fred.setAppearance(ap);
obj.addChild(fred);
Inserte este código 3d o utilizar el código completo aquí
Import java.io.*;
Import java.beans.XMLDecoder;
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.applet.Applet;
Import java.awt.BorderLayout;
Import java.awt.Frame;
Import com.sun.j3d.utils.applet.MainFrame;
Import com.sun.j3d.utils.geometry.ColorCube;
Import com.sun.j3d.utils.universe.*;
Import com.sun.j3d.utils.behaviors.mouse.*;
Import javax.media.j3d.*;
Import javax.vecmath.*;
Import java.awt.event.*;
importación de java.util.Enumeration;
pública clase MouseBehaviorApp extiende Applet {}
público BranchGroup createSceneGraph() {
BranchGroup objRoot = nuevo BranchGroup();
TransformGroup objTransform = new TransformGroup();
objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objRoot.addChild(objTransform);
Shape3D fred = null;
trate de {}
XMLDecoder e = new XMLDecoder (nuevo BufferedInputStream (nuevo FileInputStream("c:/HandShape3D.xml")));
Fred = e.readObject() (Shape3D);
e.Close();
} catch (excepción e) {}
e.printStackTrace();
}
ColoringAttributes a = nuevo ColoringAttributes();
Aspecto ap = nuevo Appearance();
Color3f col = new Color3f (1.0f, 0.0f, 1.0f);
Ca ColoringAttributes = new ColoringAttributes (col, ColoringAttributes.NICEST);
ap.setColoringAttributes(ca);
fred.setAppearance(ap);
objTransform.addChild(fred);
MouseRotate myMouseRotate = new MouseRotate();
myMouseRotate.setTransformGroup(objTransform);
myMouseRotate.setSchedulingBounds (nuevo BoundingSphere());
objRoot.addChild(myMouseRotate);
MouseTranslate myMouseTranslate = new MouseTranslate();
myMouseTranslate.setTransformGroup(objTransform);
myMouseTranslate.setSchedulingBounds (nuevo BoundingSphere());
objRoot.addChild(myMouseTranslate);
MouseZoom myMouseZoom = new MouseZoom();
myMouseZoom.setTransformGroup(objTransform);
myMouseZoom.setSchedulingBounds (nuevo BoundingSphere());
objRoot.addChild(myMouseZoom);
objRoot.compile();
volver objRoot;
}
público MouseBehaviorApp() {}
setLayout (new BorderLayout());
Canvas3D canvas3D = nuevo Canvas3D(SimpleUniverse.getPreferredConfiguration());
Añadir ("centro", canvas3D);
Escena de BranchGroup = createSceneGraph();
SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
simpleU.getViewingPlatform().setNominalViewingTransform();
simpleU.addBranchGraph(scene);
}
el principal vacío estático público (String [] args) {}
Marco = nuevo MainFrame (nuevo MouseBehaviorApp(), 256, 256);
}
}
Use esto para un programa completo
tada! usted es hecho!
¿y luego dices "ahora qué"?
No tengo ni idea! Me acabo de enterar Java hace un mes jejeje!