Fri Apr 06, 2007 12:49 pm
http://java.sun.com/products/java-media/3D/download.html
import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import java.awt.GraphicsConfiguration;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.mouse.*;
import com.sun.j3d.loaders.Scene;
import com.sun.j3d.loaders.ParsingErrorException;
import com.sun.j3d.loaders.IncorrectFormatException;
import com.sun.j3d.loaders.objectfile.*;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.net.URL;
public class ObjectLoader extends Applet{
public void init(){
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
canvas3D = new Canvas3D( config );
add("Center", canvas3D);
BranchGroup szene = macheSzene();
szene.compile();
universe = new SimpleUniverse( canvas3D );
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(szene);
}
public BranchGroup macheSzene(){
BranchGroup objWurzel = new BranchGroup();
Transform3D drehung = new Transform3D();
Transform3D drehung2 = new Transform3D();
drehung.rotX(Math.PI / 4.0d);
drehung2.rotY(Math.PI / 5.0d);
drehung.mul(drehung2);
TransformGroup objDreh =
new TransformGroup(drehung);
objDreh.setCapability(17);
objDreh.setCapability(18);
ObjectFile file = new ObjectFile (ObjectFile.RESIZE);
Scene scene = null;
//new URL("jar:"+getCodeBase()+"ObjectLoader.jar!/teapot.obj")
try {
if (getCodeBase()!=null){
try {
System.exit(1);
scene = file.load(ClassLoader.getSystemResource("teapot.obj"));
}
catch (Exception e) {
System.err.println(e);
}
}
else scene = file.load(ClassLoader.getSystemResource("teapot.obj"));
}
catch (FileNotFoundException e) {
System.err.println(e);
System.exit(1);
}
catch (ParsingErrorException e) {
System.err.println(e);
System.exit(1);
}
catch (IncorrectFormatException e) {
System.err.println(e);
System.exit(1);
}
objDreh.addChild(scene.getSceneGroup());
DirectionalLight d_Licht = new DirectionalLight(
new Color3f (0.7f, 1.5f, 0.3f), new Vector3f (1.0f, -10.0f, 1.0f));
d_Licht.setInfluencingBounds (new BoundingSphere (new Point3d(0.0d,0.0d,0.0d), 100.0d));
objDreh.addChild(d_Licht);
BoundingSphere bounds=new BoundingSphere();
MouseRotate spin=new MouseRotate();
spin.setTransformGroup(objDreh);
spin.setSchedulingBounds(bounds);
objWurzel.addChild(spin);
objWurzel.addChild(objDreh);
return objWurzel;
}
public void destroy(){
universe.removeAllLocales();
}
public static void main(String[] args) {
frame = new MainFrame(new ObjectLoader(),500,500);
frame.setTitle("ObjectLoader");
}
private SimpleUniverse universe;
private Canvas3D canvas3D;
private static Frame frame;
}
Wed Jan 23, 2013 3:26 pm
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.