Module imp3d

Class PolygonArray

java.lang.Object
de.grogra.imp3d.VertexArray
de.grogra.imp3d.PolygonArray
All Implemented Interfaces:
Mesh

public class PolygonArray extends VertexArray implements Mesh
This class represents a list of polygons.
Author:
Ole Kniemeyer
  • Field Details

    • uv

      public FloatList uv
      This list contains the uv coordinates. The coordinates are contained contiguously, with two float-values for each vertex.
    • normals

      public ByteList normals
      This list contains the (unnormalized) normal vectors. The components are contained contiguously, with three byte-values for each vertex. Each byte-value c is to be interpreted as a floating-point vector component f in the range [-1, 1] using the formula
      f = (2 c + 1) / 255
    • polygons

      public IntList polygons
      Specifies the polygons. Each polygon is represented by a contiguous sequence of edgeCount indices into the other arrays (however note that if usePolygonNormals is true, normal indices are specified by polygonNormals). The polygons are placed one after another without space inbetween.
    • polygonNormals

      public IntList polygonNormals
      Specifies the normal indices of polygons if usePolygonNormals is true. For each entry in polygons, i.e., a vertex, a corresponding entry has to be present which defines the index into normals.
    • usePolygonNormals

      public boolean usePolygonNormals
      Indicates whether normal indices are specified separately by polygonNormals or just like the other indices by polygons.
    • edgeCount

      public int edgeCount
      Defines the number of edges of the polygons in this list. All polygons have the same number of edges. edgeCount may only be 3 (triangles) or 4 (quadrilaterals).
    • planar

      public boolean planar
      Flag indicating whether the polygons are planar. In the case of triangles, this is always the case. In the case of quadrilaterals, it is guaranteed that each quadrilateral will be planar (all vertices lie on a plane) if planar is true.
    • visibleSides

      public int visibleSides
      Enumeration value indicating the visible polygon sides. If this value is Attributes.VISIBLE_SIDES_FRONT, only front sides (as defined by the counter-clockwise order of vertices) are visible. If this is Attributes.VISIBLE_SIDES_BACK, only back sides are visible. For Attributes.VISIBLE_SIDES_BOTH, both sides are visible.
    • closed

      public boolean closed
      Indicates whether this polygon is a closed surface or not. If it is closed, normal vectors have to point to the exterior.
  • Constructor Details

    • PolygonArray

      public PolygonArray()
  • Method Details

    • freeArrays

      public void freeArrays()
      Overrides:
      freeArrays in class VertexArray
    • copyNormal

      public void copyNormal(int from, int to)
      Copies a vector in the list of normal vectors.
      Parameters:
      from - the source index
      to - the target index
    • setNormal

      public void setNormal(int index, float x, float y, float z)
      Sets a normal vector. The vector is rescaled so that the maximum of the absolute values of its components is one.
      Parameters:
      index - the index of the normal vector (note that the actual index into normals is 3 * index)
      x - the x-component
      y - the y-component
      z - the z-component
    • getNormal

      public void getNormal(float[] out, int index)
      Reads the value of the normal vector at index and places it in out.
      Parameters:
      out - the result will be placed in here
      index - the index of the normal vector (note that the actual index into normals is 3 * index)
    • getPolygonCount

      public int getPolygonCount()
      Description copied from interface: Mesh
      Returns the number of polygons of the mesh.
      Specified by:
      getPolygonCount in interface Mesh
      Returns:
      number of polygons
    • getMaxEdgeCount

      public int getMaxEdgeCount()
      Description copied from interface: Mesh
      Returns the maximum number of edges of a single polygon of the mesh.
      Specified by:
      getMaxEdgeCount in interface Mesh
      Returns:
      maximum number of edges
    • getVertexCount

      public int getVertexCount()
      Description copied from interface: Mesh
      Returns the number of vertices of the mesh.
      Specified by:
      getVertexCount in interface Mesh
      Returns:
      number of vertices
    • getNormalCount

      public int getNormalCount()
      Description copied from interface: Mesh
      Returns the number of normals of the mesh.
      Specified by:
      getNormalCount in interface Mesh
      Returns:
      number of normals
    • isPolygonPlanar

      public boolean isPolygonPlanar(int index)
      Description copied from interface: Mesh
      Returns true iff the polygon number index is planar.
      Specified by:
      isPolygonPlanar in interface Mesh
      Parameters:
      index - polygon number
      Returns:
      is polygon planar?
    • getPolygon

      public int getPolygon(int index, int[] indicesOut, int[] normalsOut)
      Description copied from interface: Mesh
      Writes the vertex indices of polygon index to indicesOut and the normal indices to normalsOut and returns the number of vertices of the polygon. If the mesh is closed (see Mesh.isClosed()), inside and outside are determined by the ordering of the vertices: when seen from the outside, vertices have to be oriented in a counter-clockwise manner. Then also the normal vectors have to point to the outside.
      Specified by:
      getPolygon in interface Mesh
      Parameters:
      index - polygon number
      indicesOut - the vertex indices will be placed in here
      normalsOut - the normal indices will be placed in here
      Returns:
      number of vertex indices of polygon
    • getVertex

      public void getVertex(int index, Tuple3d out)
      Description copied from interface: Mesh
      Gets the spatial vertex coordinates of vertex index.
      Specified by:
      getVertex in interface Mesh
      Parameters:
      index - vertex number
      out - vertex coordinates will be placed in here
    • getNormal

      public void getNormal(int index, Tuple3d out)
      Description copied from interface: Mesh
      Gets the normal vector of normal index. The normal vector is not necessarily normalized.
      Specified by:
      getNormal in interface Mesh
      Parameters:
      index - normal number
      out - normal vector will be placed in here
    • getUV

      public void getUV(int index, Tuple2d out)
      Description copied from interface: Mesh
      Gets the uv coordinates of vertex index.
      Specified by:
      getUV in interface Mesh
      Parameters:
      index - vertex number
      out - uv coordinates will be placed in here
    • isClosed

      public boolean isClosed()
      Description copied from interface: Mesh
      Indicates whether this mesh is a closed surface or not. If it is closed, normal vectors have to point to the exterior.
      Specified by:
      isClosed in interface Mesh
      Returns:
      is surface closed?
    • computeNormals

      public void computeNormals()
      Compute normal vector for every vertex.