How can I use loader

Hi,
I drew the box in 3d max and I want to display it using java 3d
my question are in what format can I export the box and how can I use loader
I tried before and this my tries:
I export the file in .OBJ format

code:

[quote]import com.sun.j3d.loaders.objectfile.ObjectFile;
import com.sun.j3d.loaders.ParsingErrorException;
import com.sun.j3d.loaders.IncorrectFormatException;
import com.sun.j3d.loaders.Scene;
import java.applet.Applet;
import javax.media.j3d.;
import javax.vecmath.
;
import java.io.*;

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.
;
import javax.media.j3d.;
import javax.vecmath.
;

public class ObjLoad extends Applet {

private String filename = “test”;

public BranchGroup createSceneGraph() {
// Create the root of the branch graph
BranchGroup objRoot = new BranchGroup();

ObjectFile f = new ObjectFile();
Scene s = null;
try {
s = f.load(filename);
}
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);
}

objRoot.addChild(s.getSceneGroup());
return objRoot;
}

public ObjLoad() {
setLayout(new BorderLayout());
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();

    Canvas3D canvas3D = new Canvas3D(config);
    add("Center", canvas3D);

    BranchGroup scene = createSceneGraph();

    // SimpleUniverse is a Convenience Utility class
    SimpleUniverse simpleU = new SimpleUniverse(canvas3D);

// This will move the ViewPlatform back a bit so the
// objects in the scene can be viewed.
    simpleU.getViewingPlatform().setNominalViewingTransform();

    simpleU.addBranchGraph(scene);
} // end of HelloJava3Db (constructor)
//  The following allows this to be run as an application
//  as well as an applet

public static void main(String[] args) {
Frame frame = new MainFrame(new ObjLoad(), 256, 256);
} // end of main (method of HelloJava3Db)

} // end of class HelloJava3D
[/quote]
and I have this error in the run time:

java.io.FileNotFoundException: test (The system cannot find the file specified)

----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

It looks like you are trying to load your file as “test”.

To test it I would give the full filepath (“C:\images\test…3ds”) and specify the file type to start with.

You may need to download a loader specific to your file type since Java only supports a few of the major ones. Here is an example of how I used a 3DS Loader I found on the web somewhere (start a googlin’ for one).

Loader3DS myOBJ = new Loader3DS();
Scene myOBJScene = null;

//Attempt to load in the OBJ content using ObjectFile.
try {
myOBJScene = myOBJ.load(“C:\workspace\Java3D\troll.3ds”);
} catch (FileNotFoundException e) {
System.out.println(“Could not open OBJ file…exiting”);
System.exit(1);
}

Thank you darkpegasus ,
I put the full file bath and there was no error , but the box did’nt appear. :-[
I want to use 3DS loader but , I don’t know how . ::slight_smile:
Must I download 3DS loader?! and where I can find it ?
and if you have any complete example please give me.

You’ll have to download a JAR file and put it in your classpath. I don’t remember exactly where I got mine from but if you do a search for “java 3ds loader” you should find plenty of resources to get that particular format (I don’t think you specified exactly which format you were using). If you’re using a standard OBJ class you can use the built in loaders.

Here is all of the code I needed to just load an object and add it to the scene. The commented code can be uncommented to load an OBJ file with the standard Java calls.
// Deleted some imports for brevity
import com.microcrowd.loader.java3d.max3ds.Loader3DS;
import com.sun.j3d.loaders.Scene;
import com.sun.j3d.loaders.objectfile.ObjectFile;
import com.sun.j3d.utils.universe.SimpleUniverse;

public class LoaderExample {

public LoaderExample()

{
SimpleUniverse universe = new SimpleUniverse();
BranchGroup group = constructContentBranch();
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(group);
}

public static void main( String[] args ) {
new LoaderExample();
}

private BranchGroup constructContentBranch() {
//ObjectFile myOBJ = new ObjectFile();
Loader3DS myOBJ = new Loader3DS();
Scene myOBJScene = null;

     //Attempt to load in the OBJ content using ObjectFile.
     try {
    	 myOBJScene = myOBJ.load("C:\\workspace\\Java3D\\troll.3ds");
    	 //myOBJScene = myOBJ.load("C:\\workspace\\Java3D\\troll.obj");
     } catch (FileNotFoundException e) {
       System.out.println("Could not open OBJ file...exiting");
       System.exit(1);
     }
     
     //Construct and return branch group containing our OBJ scene.
     BranchGroup contentBranchGroup = new BranchGroup();
     contentBranchGroup.addChild(transform(myOBJScene.getSceneGroup()));
     return(contentBranchGroup);
   }

}