Class PolygonObjParser.Face

  • Enclosing class:
    PolygonObjParser

    public static final class PolygonObjParser.Face
    extends java.lang.Object
    Class representing an OBJ face definition. Faces are defined with the format

    f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 ...

    where the v elements are indices into the model vertices, the vt elements are indices into the model texture coordinates, and the vn elements are indices into the model normal coordinates. Only the vertex indices are required.

    All vertex attribute indices are normalized to be 0-based and positive and all faces are assumed to define geometrically valid convex polygons.

    • Constructor Detail

      • Face

        Face​(java.util.List<PolygonObjParser.VertexAttributes> vertexAttributes)
        Construct a new instance with the given vertex attributes.
        Parameters:
        vertexAttributes - face vertex attributes
    • Method Detail

      • getVertexAttributes

        public java.util.List<PolygonObjParser.VertexAttributes> getVertexAttributes()
        Get the list of vertex attributes for the instance.
        Returns:
        list of vertex attribute
      • getDefinedCompositeNormal

        public Vector3D getDefinedCompositeNormal​(java.util.function.IntFunction<Vector3D> modelNormalFn)
        Get a composite normal for the face by computing the sum of all defined vertex normals and normalizing the result. Null is returned if no vertex normals are defined or the defined normals sum to zero.
        Parameters:
        modelNormalFn - function used to access normals parsed earlier in the model; callers are responsible for storing these values as they are parsed
        Returns:
        composite face normal or null if no composite normal can be determined from the normals defined for the face
      • computeNormalFromVertices

        public Vector3D computeNormalFromVertices​(java.util.function.IntFunction<Vector3D> modelVertexFn)
        Compute a normal for the face using its first three vertices. The vertices will wind in a counter-clockwise direction when viewed looking down the returned normal. Null is returned if the normal could not be determined, which would be the case if the vertices lie in the same line or two or more are equal.
        Parameters:
        modelVertexFn - function used to access model vertices parsed earlier in the content; callers are responsible for storing these values as they are passed
        Returns:
        a face normal computed from the first 3 vertices or null if a normal cannot be determined
      • getVertexAttributesCounterClockwise

        public java.util.List<PolygonObjParser.VertexAttributes> getVertexAttributesCounterClockwise​(Vector3D normal,
                                                                                                     java.util.function.IntFunction<Vector3D> modelVertexFn)
        Get the vertex attributes for the face listed in the order that produces a counter-clockwise winding of vertices when viewed looking down the given normal direction. If normal is null, the original vertex sequence is used.
        Parameters:
        normal - requested face normal; may be null
        modelVertexFn - function used to access model vertices parsed earlier in the content; callers are responsible for storing these values as they are passed
        Returns:
        list of vertex attributes for the face, oriented to correspond with the given face normal
      • getVertices

        public java.util.List<Vector3D> getVertices​(java.util.function.IntFunction<Vector3D> modelVertexFn)
        Get the face vertices in the order defined in the face definition.
        Parameters:
        modelVertexFn - function used to access model vertices parsed earlier in the content; callers are responsible for storing these values as they are passed
        Returns:
        face vertices in their defined ordering
      • getVerticesCounterClockwise

        public java.util.List<Vector3D> getVerticesCounterClockwise​(Vector3D normal,
                                                                    java.util.function.IntFunction<Vector3D> modelVertexFn)
        Get the face vertices in the order that produces a counter-clockwise winding when viewed looking down the given normal.
        Parameters:
        normal - requested face normal
        modelVertexFn - function used to access model vertices parsed earlier in the content; callers are responsible for storing these values as they are passed
        Returns:
        face vertices in the order that produces a counter-clockwise winding when viewed looking down the given normal
        See Also:
        getVertexAttributesCounterClockwise(Vector3D, IntFunction)
      • getVertexIndices

        public int[] getVertexIndices()
        Get the vertex indices for the face.
        Returns:
        vertex indices for the face
      • getTextureIndices

        public int[] getTextureIndices()
        Get the texture indices for the face. The value -1 is used if a texture index is not set.
        Returns:
        texture indices
      • getNormalIndices

        public int[] getNormalIndices()
        Get the normal indices for the face. The value -1 is used if a texture index is not set.
        Returns:
        normal indices
      • getIndices

        private int[] getIndices​(java.util.function.ToIntFunction<PolygonObjParser.VertexAttributes> fn)
        Get indices for the face, using the given function to extract the value from the vertex attributes.
        Parameters:
        fn - function used to extract the required value from each vertex attribute
        Returns:
        extracted indices