glmodel
Class GL_OBJ_Reader

java.lang.Object
  extended by glmodel.GL_OBJ_Reader

public class GL_OBJ_Reader
extends java.lang.Object

Based on Object3D.java by Jeremy Adams (elias4444) august 2005 Read an OBJ file into ArrayLists which can then be imported into a final mesh class. This class just loads and holds data, and can be used independently of specific 3D model classes. Populates a "faces" Arraylist with all faces in the mesh. Also stores face groups in the "groups" Arraylist (an Arraylist that contains Group objects). jul 2006: add Group class to hold group faces, materialname and groupname jul 2006: read usemtl command and store material names with groups


Field Summary
 float bottompoint
           
 java.util.ArrayList faces
           
 float farpoint
           
 java.lang.String filename
           
 java.lang.String filepath
           
 java.util.ArrayList groups
           
 float leftpoint
           
 GLMaterialLib materialLib
           
 java.lang.String materialLibeName
           
 float nearpoint
           
 java.util.ArrayList normals
           
 float rightpoint
           
 java.util.ArrayList textureCoords
           
 float toppoint
           
 java.util.ArrayList vertices
           
 
Constructor Summary
GL_OBJ_Reader(java.io.InputStream in)
           
GL_OBJ_Reader(java.lang.String objfilename)
           
 
Method Summary
 void calcDimensions()
          Find min/max points of mesh.
 int convertIndex(java.lang.String token, int numVerts)
          Convert a vertex reference number into the correct vertex array index.
 glmodel.GL_OBJ_Reader.Group findGroup(java.lang.String name)
          look for the given groupname in the groups list
 java.util.ArrayList getGroupFaces(int g)
           
 java.lang.String getGroupMaterialName(int g)
           
 java.lang.String getGroupName(int g)
           
 int getGroupTriangleCount(int g)
           
 float getXWidth()
           
 float getYHeight()
           
 float getZDepth()
           
 void loadobject(java.io.BufferedReader br)
          OBJ file format in a nutshell: First part of file lists vertex data: vert coords, texture coords and normals.
 void loadobject(java.io.InputStream in)
           
 void loadobject(java.lang.String objfilename)
           
 int numGroups()
           
 int numpolygons()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vertices

public java.util.ArrayList vertices

normals

public java.util.ArrayList normals

textureCoords

public java.util.ArrayList textureCoords

faces

public java.util.ArrayList faces

groups

public java.util.ArrayList groups

materialLibeName

public java.lang.String materialLibeName

materialLib

public GLMaterialLib materialLib

filepath

public java.lang.String filepath

filename

public java.lang.String filename

leftpoint

public float leftpoint

rightpoint

public float rightpoint

bottompoint

public float bottompoint

toppoint

public float toppoint

farpoint

public float farpoint

nearpoint

public float nearpoint
Constructor Detail

GL_OBJ_Reader

public GL_OBJ_Reader(java.lang.String objfilename)

GL_OBJ_Reader

public GL_OBJ_Reader(java.io.InputStream in)
Method Detail

loadobject

public void loadobject(java.lang.String objfilename)

loadobject

public void loadobject(java.io.InputStream in)

loadobject

public void loadobject(java.io.BufferedReader br)
OBJ file format in a nutshell: First part of file lists vertex data: vert coords, texture coords and normals. These lines start with v, vt and vn respectively. Second part of file lists faces. These lines start with f. Each face is defined as a set of verts, usually three, but may be more. The face definition line contains triplets: three numbers separated by slashes. Each number is an index into the vert, texture coord, or normal list. NOTE: these lists are indexed starting with 1, not 0.


findGroup

public glmodel.GL_OBJ_Reader.Group findGroup(java.lang.String name)
look for the given groupname in the groups list

Parameters:
name -
Returns:
the found Group or null if not found

convertIndex

public int convertIndex(java.lang.String token,
                        int numVerts)
Convert a vertex reference number into the correct vertex array index.
Face definitions in the OBJ file refer to verts, texture coords and normals using a reference number. The reference numbers is the position of the vert in the vertex list, in the order read from the OBJ file. Reference numbers start at 1, and can be negative (to refer back into the vert list starting at the bottom, though this seems to be rare). The same approach applies to texture coords and normals.
This function converts reference numbers to an array index starting at 0, and converts negative reference numbers to 0-N array indexes. It returns -1 if the token is blank, meaning there was no data given (ie. there is no texture coord or normal available).

Parameters:
token - a token from the OBJ file containing a numeric value or blank
Returns:
idx will be 0 - N index into vert array, or -1 if token is blank

calcDimensions

public void calcDimensions()
Find min/max points of mesh.


getXWidth

public float getXWidth()

getYHeight

public float getYHeight()

getZDepth

public float getZDepth()

numpolygons

public int numpolygons()

numGroups

public int numGroups()

getGroupName

public java.lang.String getGroupName(int g)

getGroupFaces

public java.util.ArrayList getGroupFaces(int g)

getGroupMaterialName

public java.lang.String getGroupMaterialName(int g)

getGroupTriangleCount

public int getGroupTriangleCount(int g)