de.javagl.utils.obj.impl
Class ObjUtils

java.lang.Object
  extended by de.javagl.utils.obj.impl.ObjUtils

public class ObjUtils
extends Object

This class offers utility methods for handling Objs.


Method Summary
static void assertUniqueTextureCoords(Obj input, ObjTarget output, List<Integer> indexMapping, float epsilon)
          Two faces may reference the same vertex in the OBJ file.
static float[] getFaceTexCoordsOf(Obj obj, int stride)
          Returns an array containing the texture coordinates of the vertices of the faces in the given Obj.
static float[] getVertexCoordsOf(Obj obj)
          Returns all vertex coordinates of the given Obj as an array.
static int[] getVertexIndicesOf(Obj obj)
          Returns the vertex indices of the given Obj as an array.
static void groupToObj(Obj input, ObjGroup inputGroup, ObjTarget output, List<Integer> vertexIndexMapping)
          This method will store the given group of the given Obj in the given output.
static void storeFaceTexCoordsOf(Obj obj, int stride, float[] texCoords, int offset)
          Stores the texture coordinates of the vertices of the faces in the given Obj in the given array.
static void storeVertexCoordsOf(Obj obj, float[] vertexCoords, int offset)
          Stores the vertex coordinates of the given Obj in the given array at the given offset
static void storeVertexIndicesOf(Obj obj, int[] vertexIndices, int offset, int[] faceVertices)
          Stores the vertex indices of the given Obj in the given array at the given offset.
static void triangulate(Obj input, ObjTarget output)
          Triangulates the given input, and stores the result in the given output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

triangulate

public static void triangulate(Obj input,
                               ObjTarget output)
Triangulates the given input, and stores the result in the given output. This method will simply subdivide faces with more than 3 vertices so that all faces in the output will be triangles.


groupToObj

public static void groupToObj(Obj input,
                              ObjGroup inputGroup,
                              ObjTarget output,
                              List<Integer> vertexIndexMapping)
This method will store the given group of the given Obj in the given output. vertexIndexMapping may be null. If it is not null, vertexIndexMapping.get(i) afterwards stores the index that vertex i had in the original Obj

Parameters:
input - The input Obj
inputGroup - The group of the input Obj
output - The output Obj
vertexIndexMapping - The optional index mapping

assertUniqueTextureCoords

public static void assertUniqueTextureCoords(Obj input,
                                             ObjTarget output,
                                             List<Integer> indexMapping,
                                             float epsilon)
Two faces may reference the same vertex in the OBJ file. But different texture coordinates may be assigned to the same vertex in both faces. This method ensures that two vertices with different texture coordinates are actually two different vertices with different indices: The vertex that requires two different texture coordinates will be cloned, and the indices in one face will be updated appropriately. The indexMapping may be null. Otherwise it is assumed that it already contains the index mapping that was obtained by a call to "groupToObj", and this mapping will be updated appropriately.

Parameters:
input - The input obj
output - The output obj
indexMapping - The optional index mapping
epsilon - The epsilon defining when two texture coordinates should be considered as equal

getVertexIndicesOf

public static int[] getVertexIndicesOf(Obj obj)
Returns the vertex indices of the given Obj as an array. Note that the actual is determined by the number of vertices in each face of the Obj. For example, only if the Obj contains only triangles, three consecutive entries in the resulting array will describe the vertex indices of one triangle.

Parameters:
obj - The obj
Returns:
The vertex indices

storeVertexIndicesOf

public static void storeVertexIndicesOf(Obj obj,
                                        int[] vertexIndices,
                                        int offset,
                                        int[] faceVertices)
Stores the vertex indices of the given Obj in the given array at the given offset. The faceVertices array may be null. If it is not null, it will afterwards store the number of vertices for each face (thus, it has to be large enough to hold the number of vertices for each face of the given Obj)

Parameters:
obj - The obj
vertexIndices - The array that will store the vertex indices
offset - The offset in the array
faceVertices - The number of vertices in each face

getVertexCoordsOf

public static float[] getVertexCoordsOf(Obj obj)
Returns all vertex coordinates of the given Obj as an array. Three consecutive entries in the resulting array are the x,y,z coordinates of one vertex

Parameters:
obj - The obj
Returns:
The vertex coordinates

storeVertexCoordsOf

public static void storeVertexCoordsOf(Obj obj,
                                       float[] vertexCoords,
                                       int offset)
Stores the vertex coordinates of the given Obj in the given array at the given offset

Parameters:
obj - The obj
vertexCoords - The array that will store the vertex coordinates
offset - The offset in the array

getFaceTexCoordsOf

public static float[] getFaceTexCoordsOf(Obj obj,
                                         int stride)
Returns an array containing the texture coordinates of the vertices of the faces in the given Obj. Note that this is NOT an array with the texture coordinates of the Obj! Instead, the resulting array will contain texture coordinates for each vertex. Since one vertex may have different texture coordinates in different faces, the resulting texture coordinates may be ambiguous, except when the uniqueness of the texture coordinates has been established using assertUniqueTextureCoords

Parameters:
obj - The obj
stride - The number of elements each texture coordinate consists of

storeFaceTexCoordsOf

public static void storeFaceTexCoordsOf(Obj obj,
                                        int stride,
                                        float[] texCoords,
                                        int offset)
Stores the texture coordinates of the vertices of the faces in the given Obj in the given array. Note that these are NOT the texture coordinates of the Obj! Instead, the array will contain texture coordinates for each vertex. Since one vertex may have different texture coordinates in different faces, the resulting texture coordinates may be ambiguous, except when the uniqueness of the texture coordinates has been established using assertUniqueTextureCoords

Parameters:
obj - The obj
stride - The number of elements each texture coordinate consists of
texCoords - The array that will store the texture coordinates
offset - The offset in the array.