Class PolygonObjParser.Face
- java.lang.Object
-
- org.apache.commons.geometry.io.euclidean.threed.obj.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 formatf v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 ...
where the
v
elements are indices into the model vertices, thevt
elements are indices into the model texture coordinates, and thevn
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.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<PolygonObjParser.VertexAttributes>
vertexAttributes
List of vertex attributes for the face.
-
Constructor Summary
Constructors Constructor Description Face(java.util.List<PolygonObjParser.VertexAttributes> vertexAttributes)
Construct a new instance with the given vertex attributes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Vector3D
computeNormalFromVertices(java.util.function.IntFunction<Vector3D> modelVertexFn)
Compute a normal for the face using its first three vertices.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.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.int[]
getNormalIndices()
Get the normal indices for the face.int[]
getTextureIndices()
Get the texture indices for the face.java.util.List<PolygonObjParser.VertexAttributes>
getVertexAttributes()
Get the list of vertex attributes for the instance.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.int[]
getVertexIndices()
Get the vertex indices for the face.java.util.List<Vector3D>
getVertices(java.util.function.IntFunction<Vector3D> modelVertexFn)
Get the face vertices in the order defined in the face definition.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.
-
-
-
Field Detail
-
vertexAttributes
private final java.util.List<PolygonObjParser.VertexAttributes> vertexAttributes
List of vertex attributes for the face.
-
-
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. Ifnormal
is null, the original vertex sequence is used.- Parameters:
normal
- requested face normal; may be nullmodelVertexFn
- 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 normalmodelVertexFn
- 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
-
-