Class Model.Surface

java.lang.Object
edu.cornell.gdiac.graphics.obj.Model.Surface
Enclosing class:
Model

public class Model.Surface extends Object
This class represents a single surface in an OBJ file.

A OBJ surface is a single unit of rendering. A new surface is created any time an OBJ file issues face commands after declaring a new object, group, or material. surfacees doe not have their own ModelView matrix. That is stored in the Model that groups them together.

We currently only support fully specified polygonal surfaces. We do not support any freeform drawing commands, even though those are included in the OBJ specification.

  • Constructor Details

    • Surface

      public Surface(ModelInfo root, ModelInfo.Group info)
      Creates this surface with the given AST.

      This method will build the vertices and mesh information for the surface. However, it will only not create the OpenGL buffer.

      Parameters:
      root - The AST root
      info - The AST for this particular surface
    • Surface

      public Surface(ModelInfo root, ModelInfo.Group info, boolean buffer)
      Creates this surface with the given AST.

      This method will build the vertices and mesh information for the surface. However, it will only create the OpenGL buffer if the parameter buffer is true. This allows us to create meshes off of the main thread (and allocate the buffer once back on the main thread).

      Parameters:
      root - The AST root
      info - The AST for this particular surface
      buffer - Whether to construct the OpenGL buffer
  • Method Details

    • createBuffer

      public boolean createBuffer()
      Returns true if an OpenGL buffer was successfully built for this surface.

      If the surface is already built this method will return true. Otherwise, it will attempt to build the surface and return true on success. This method should only be called on the main thread. It exists to support asset loading off the main thread.

      Returns:
      true if an OpenGL buffer was successfully built for this surface.
    • getIndex

      public int getIndex()
      Returns the smoothing index for this surface.

      As per the OBJ specification, this value is 0 by default.

      Returns:
      the smoothing index for this surface.
    • setIndex

      public void setIndex(int value)
      Sets the smoothing index for this surface.

      As per the OBJ specification, this value is 0 by default.

      Parameters:
      value - The smoothing index for this surface.
    • getObject

      public String getObject()
      Returns the object that this surface is associated with.

      Objects are defined with the o command in OBJ files. This value is the empty string by default.

      Returns:
      the object that this surface is associated with.
    • getObject

      public void getObject(String value)
      Sets the object that this surface is associated with.

      Objects are defined with the o command in OBJ files. This value is the empty string by default.

      Parameters:
      value - The object that this surface is associated with.
    • getTags

      public com.badlogic.gdx.utils.ObjectSet<String> getTags()
      Returns the group tags associated with this surface.

      This tag set is returned by reference. That means modifying this set will modify the associated tags.

      Returns:
      the group tags associated with this surface.
    • hasTag

      public boolean hasTag(String tag)
      Returns true if this surface has the given tag.
      Parameters:
      tag - The tag to query
      Returns:
      true if this surface has the given tag.
    • getMesh

      public ObjMesh getMesh()
      Returns the ObjMesh for storing the drawing data

      ObjMesh objects store the geometry but are independent of any OpenGL buffer. This method is read-only, as it is unsafe to modify the mesh without updating the associated OpenGL buffer.

      Returns:
      the CUGL surface for storing the drawing data
    • getBuffer

      public VertexBuffer getBuffer()
      Returns the vertex buffer storing the drawing data

      Unlike the ObjMesh, the vertex buffer stores the geometry in a format to be used by OpenGL.

      Returns:
      the vertex buffer storing the drawing data
    • getMaterialName

      public String getMaterialName()
      Returns the name of the material associated with this surface.

      If the surface has no material, this will return the empty string.

      Returns:
      the name of the material associated with this surface.
    • setMaterialName

      public void setMaterialName(String name)
      Sets the name of the material associated with this surface.

      If the surface has no material, this will return the empty string.

      Parameters:
      name - The name of the material associated with this surface.
    • getMaterial

      public Material getMaterial()
      Returns the material associated with this surface.

      If the surface has no material, it will drawn using a default white color.

      Returns:
      the material associated with this surface.
    • setMaterial

      public void setMaterial(Material material)
      Sets the material associated with this surface.

      If the surface has no material, it will drawn using a default white color.

      Parameters:
      material - The material associated with this surface.