Sun's Object File Loader

Last update: 18 Sept 1998
Author: Sun
File Format(s): OBJ (Wavefront)
Availability: One of the Java 3D Utility Libraries that ships with Java 3D. Source code included with the Java 3D SDK in the file java3d-utils-src.jar:,,,,
Notes: Demo program (demo/java3d/ObjLoad) ships with Java 3D. Several example .obj files are also included with Java 3D in demo/java3d/geometry: beethoven.obj, galleon.obj, minimart.obj, and p51_mustang.obj, along with the texture files for minimart:,, gas.rgb,, minimart.mtl,, products.rgb,, thdoor.inta, window.inta.


  java ObjLoad [-s] [-n] [-t] [-c degrees] <.obj file>
    -s Spin (no user interaction)
    -n No triangulation
    -t No stripification
    -c Set crease angle for normal generation (default is 60 without
       smoothing group info, otherwise 180 within smoothing groups)
The Javadoc for "ObjectFile" explains which tags are supported and also can serve as documentation for the file format. Here's a cut & paste:

The ObjectFile class implements the Loader interface for the Wavefront ..obj file format, a standard 3D object file format created for use with Wavefront's Advanced Visualizer (tm) and available for purchase from Viewpoint DataLabs, as well as other 3D model companies. Object Files are text based files supporting both polygonal and free-form geometry (curves and surfaces). The Java 3D .obj file loader supports a subset of the file format, but it is enough to load almost all commonly available Object Files. Free-form geometry is not supported.

The Object File tokens currently supported by this loader are:

v, vn, vt

f (int, int/int, int/int/int)

A polygonal face. The numbers are indexes into the arrays of vertex positions, texture coordinates, and normals respectively. There is no maximum number of vertices that a single polygon may contain. The .obj file specification says that each face must be flat and convex, but if the trIANGULATE flag is sent to the ObjectFile constructor, each face will be triangulated by the Java 3D Triangulator, and therefore may be concave. A number may be omitted if, for example, texture coordinates are not being defined in the model. Numbers are normally positive indexes, but may also be negative. An index of -1 means the last member added to the respective array, -2 is the one before that, and so on.
g name
Faces defined after this token will be added to the named group. These geometry groups are returned as separated Shape3D objects attached to the parent SceneGroup. Each named Shape3D will also be in the Hashtable returned by Scene.getNamedObjects(). It is legal to add faces to a group, switch to another group, and then add more faces to the original group by reissuing the same name with the g token. If faces are added to the model before the g token is seen, the faces are put into the default group called "default."
s int or off
If the vn token is not used in the file to specify vertex normals for the model, this token may be used to put faces into groups for normal calculation ("smoothing groups") in the same manner as the 'g' token is used to group faces geometrically. Faces in the same smoothing group will have their normals calculated as if they are part of the same smooth surface. To do this, we use the Java 3D NormalGenerator utility with the creaseAngle parameter set to PI (180 degrees - smooth shading, no creases) or to whatever the user has set the creaseAngle. Faces in group 0 or 'off' use a creaseAngle of zero, meaning there is no smoothing (the normal of the face is used at all vertices giving the surface a faceted look; there will be a crease, or "Hard Edge," between each face in group zero). There is also an implied hard edge between each smoothing group, where they meet each other.

If neither the vn nor the s token is used in the file, then normals are calculated using the creaseAngle set in the contructor. Normals are calculated on each geometry group separately, meaning there will be a hard edge between each geometry group.

usemtl name
The current (and subsequent) geometry groups (specified with the 'g' token) have applied to them the named material property. The following set of material properties are available by default:
amber amber_trans aqua aqua_filter
archwhite archwhite2 bflesh black
blondhair blue_pure bluegrey bluetint
blugrn blutan bluteal bone
bone1 bone2 brass brnhair
bronze brown brownlips brownskn
brzskin chappie charcoal deepgreen
default dkblue dkblue_pure dkbrown
dkdkgrey dkgreen dkgrey dkorange
dkpurple dkred dkteal emerald
fgreen flaqua flblack flblonde
flblue_pure flbrown fldkblue_purefldkdkgrey
fldkgreen fldkgreen2 fldkgrey fldkolivegreen
fldkpurple fldkred flesh fleshtransparent
flgrey fllime flltbrown flltgrey
flltolivegreenflmintgreen flmustard florange
flpinegreen flpurple flred fltan
flwhite flwhite1 flyellow glass
glassblutint glasstransparentgold green
greenskn grey hair iris
jetflame lavendar lcdgreen lighttan
lighttan2 lighttan3 lighttannew lightyellow
lime lips ltbrown ltgrey
meh metal mintgrn muscle
navy_blue offwhite.warmolivegreen
orange pale_green pale_pink pale_yellow
peach periwinkle pink pinktan
plasma purple red redbrick
redbrown redorange redwood rubber
ruby sand_stone sapphire shadow
ship2 silver skin sky_blue
smoked_glass tan taupe teeth
violet white yellow yellow_green
yellowbrt yelloworng
mtllib filename
Load material properties from the named file. Materials with the same name as the predefined materials above will override the default value. Any directory path information in (filename) is ignored. The .mtl files are assumed to be in the same directory as the .obj file. If they are in a different directory, use Loader.setBasePath() (or Loader.setBaseUrl() ). The format of the material properties files are as follows:
newmtl name
Start the definition of a new named material property.
Ka Ambient color.

Kd Diffuse color.

Ks Specular color.

illum (0, 1, or 2)

0 to disable lighting, 1 for ambient & diffuse only (specular color set to black), 2 for full lighting.
Ns Shininess (clamped to 1.0 - 128.0).

map_Kd filename

Texture map. Supported file types are .gif, .jpg, .xbm, .rgb, .rgba, .int, .inta, .sgi, and .bw.