glmodel
Class GLModel

java.lang.Object
  extended by glmodel.GLModel

public class GLModel
extends java.lang.Object

This class loads and renders a mesh from an OBJ file format. The mesh can have multiple materials, including texture images. Uses GL_Mesh to load a .obj file and GLMaterialLIb to load the .mtl file. It assumes the .obj .mtl and any texture images are present in the same folder. Also has a function, renderTextured() to draw a mesh with no groups or materials. The entire mesh will be drawn as one group of triangles with one texture.


Field Summary
static GLMaterial defaultMtl
           
 int displayListID
           
 GLMaterial[] groupMaterials
           
 GL_Mesh mesh
           
 
Constructor Summary
GLModel(java.lang.String filename)
           
 
Method Summary
 int getDisplayListID()
          return the display list ID created by makeDisplayList()
 GL_Mesh loadMesh(java.lang.String filename)
          read the given .obj file into a GL_Mesh object
 void makeDisplayList()
          Render mesh into a displaylist and store the listID in the flowercenter object.
 void regenerateNormals()
          recalculate normals on the mesh object
 void render()
          Draw the model.
 void render(GL_Mesh m)
          Render a mesh with materials.
 void renderGroup(java.lang.String groupName)
          Draw one group from the mesh.
 void renderMeshNormals()
           
 void renderTextured(int textureHandle)
          This is a simple way to render a mesh with no materials.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultMtl

public static GLMaterial defaultMtl

mesh

public GL_Mesh mesh

displayListID

public int displayListID

groupMaterials

public GLMaterial[] groupMaterials
Constructor Detail

GLModel

public GLModel(java.lang.String filename)
Method Detail

loadMesh

public GL_Mesh loadMesh(java.lang.String filename)
read the given .obj file into a GL_Mesh object

Parameters:
filename - (must end in .obj)
Returns:
the loaded GL_Mesh

makeDisplayList

public void makeDisplayList()
Render mesh into a displaylist and store the listID in the flowercenter object.

Parameters:
PR - PetalRing to draw

getDisplayListID

public int getDisplayListID()
return the display list ID created by makeDisplayList()


regenerateNormals

public void regenerateNormals()
recalculate normals on the mesh object

See Also:
GL_Mesh.regenerateNormals(), GL_Mesh.setSmoothingAngle()

render

public void render()
Draw the model. Calls the displaylist if one is created, or calls renderGroups()


renderGroup

public void renderGroup(java.lang.String groupName)
Draw one group from the mesh. This will activate the correct material for the group (including textures).

Parameters:
groupName - name of group (from obj file)

renderTextured

public void renderTextured(int textureHandle)
This is a simple way to render a mesh with no materials. Draws the mesh with normals and texture coordinates. Loops through all triangles in the mesh object (ignores groups and materials).

Parameters:
o - mesh object to render

render

public void render(GL_Mesh m)
Render a mesh with materials. If no materials exist (none are defined in the mesh, or the materials file was not found), then a default material will be applied and texture 0 will be activated (see GLMaterial.java for the default material settings).


renderMeshNormals

public void renderMeshNormals()