These classes are for loading 3D models in 3DS format into Java 3D.
License:
This code is being provided as a service to the Java 3D community.
It may be used and improved royalty free. It may not be modified
and sold. All rights are reserved by the author, John Wright, and
Starfire Research. We are asking for a "donation" of $10 to help
defray the cost of development and distribution.
Minimal usage code snippet (using Inspector3DS):
import com.mnstarfire.loaders3d.Inspector3DS;
...
Inspector3DS loader = new Inspector3DS("model.3ds"); // constructor
loader.parseIt(); // process the file
TransformGroup theModel = loader.getModel(); // get the resulting 3D
model as a Transform Group with Shape3Ds as children
Detailed usage code snippet (using Inspector3DS):
import com.mnstarfire.loaders3d.Inspector3DS;
...
Inspector3DS loader = new Inspector3DS("D:\ThreeD\models\model.3ds");
loader.setLogging(true); // turns on logging to a disk file "log3ds.txt"
loader.setDetail(6); // sets the level of detail to be logged
loader.setTextureLightingOn(); // turns on modulate mode for textures (lighting)
// loader.setTexturePath("D:\MyTextures"); // optional alternative path to find
texture files
loader.parseIt();
TransformGroup theModel = loader.getModel();
or (using Loader3DS):
import com.mnstarfire.loaders3d.Loader3DS;
// setup a file name "fileName"
try {
Loader3DS loader = new Loader3DS();
// optional options to be used
// loader.setLogging(true); // turns on writing a log file
// loader.setDetail(7); // sets level of detail of report log
// loader.setTextureLightingOn(); // turns on texture modulate mode
// loader.setTexturePath("D:\MyTextures"); // optional
alternate path to find texture files
// loader.noTextures(); // if you do not want to load textures
Scene theScene = loader.load(fileName);
}
catch(FileNotFoundException fnf) {
// Couldn't find the file you requested - deal with it!
}
// Use the scene as per Sun's documentation of SceneBase
Minimal usage code snippet (for using via URL):
import com.mnstarfire.loaders3d.Inspector3DS;
...
URL url = new URL("http://www.company.com/models/sample.3ds");
String urlBase = "http://www.company.com/models/";
...
Inspector3DS loader = new Inspector3DS(url); // constructor
loader.setURLBase(urlBase);
loader.parseIt(); // process the file
TransformGroup theModel = loader.getModel(); // get the resulting 3D model as
a Transform Group with Shape3Ds as children
Features:
Download:
Inspector3DS/Loader3DS - version 2.20 - February 11, 2003 - extract this for documentation and a jar file which must be placed in your class path
We recommend that you "install" this jar file to your "jre\lib\ext\" directory (both for the runtime and SDK if you are a developer). This should automatically place it in the classpath and require no special setting of a classpath environment variable.
F.A.Q.
Q) Everything seems to work without errors but I don't see the object I'm importing.
A) This is most often due to one of two issues. Sometimes the viewpoint is "inside" the model (often invisible from the inside out). Also often "invisible" models are created in Max, they look fine in Max because of object coloring but don't have materials associated and thus are never imported.
Many people have written and asked how to move the viewpoint. So here is a code snippet of how to move the view in Java 3D:
| TransformGroup vpTrans = simpleU.getViewingPlatform().getViewPlatformTransform(); Vector3f translate = new Vector3f(); translate.set(0,0,25); // move the view to wherever you want it. Transform3D T3D = new Transform3D(); T3D.setTranslation(translate); vpTrans.setTransform(T3D); |
Q) I want to be able to access the individual Shape3Ds that have been imported. And potentially change their appearance.
A) Sun's "J3D Fly Through" code includes "com.sun.j3d.demos.utils.scenegraph.traverser" which is designed to traverse scene graphs to allow you to do things like changing appearances. Or you can do this yourself with code similar to:
BranchGroup sg = loadedScene.getSceneGroup();
Enumeration en = sg.getAllChildren();
traverse(en);
public void traverse (Enumeration e) {
while(e.hasMoreElements()){
Object o = e.nextElement();
if (o instanceof Shape3D){
// found a Shape3D do what
you want with it
}
if (o instanceof Group) {
Group g = (Group) o;
this.traverse(g.getAllChildren());
}
} // end while
} // end traverse
Q) I want to access 3DS files from inside a Jar archive, how do I do that?
A) Here is example code:
URL url = new java.net.URL("jar:file:/C:/dir/archive.jar!/whatever/model.3ds");
String base = "jar:file:/C:/dir/archive.jar!/whatever/";
Loader3DS loader = new Loader3DS();
loader.setURLBase(base);
Scene scene = loader.load(url);
Inspector3DS/Loader3DS - version 1.30 - January 23, 2001 - extract this for documentation and a jar file which must be placed in your class path (this older version will remain available until the new URL support is proven reliable).
Patti Koenig has created "Fastscript3D", this uses our loader to display 3DS files via an applet:
http://fastscript3d.jpl.nasa.gov/starfire3ds.html