Class threedee.RenderPolygon
A render polygon is a wrapper around a polygon for internal usage
while rendering.
Defined in: RenderPolygon.js.
Constructor Attributes | Constructor Name and Description |
---|---|
threedee.RenderPolygon(model, polygon, vertices)
Constructs a new render polygon.
|
Method Attributes | Method Name and Description |
---|---|
clip(plane)
Clips this polygon against the specified view plane.
|
|
<static> |
threedee.RenderPolygon.compare(a, b)
Compares two polygons according to their average Z value.
|
Returns the number of used vertices.
|
|
Returns the center of the polygon.
|
|
Returns the polygon material.
|
|
Calculates the normal of the polygon.
|
|
getVertex(index)
Returns the vertex with the specified index.
|
|
init()
Initializes the polygon for the next rendering.
|
|
Checks if currently the backface of the polygon is visible.
|
|
Updates the average Z value.
|
Class Detail
threedee.RenderPolygon(model, polygon, vertices)
Constructs a new render polygon.
- Parameters:
- {!threedee.Model} model
- The original model this polygon is connected to.
- {!threedee.Polygon} polygon
- The original polygon.
- {!Array.} vertices
- The vertices array.
Method Detail
{boolean}
clip(plane)
Clips this polygon against the specified view plane.
- Parameters:
- {threedee.Plane} plane
- The clipping plane
- Returns:
- {boolean} True if polygon was clipped completely away, false if it is still visible (even if clipped)
<static>
{number}
threedee.RenderPolygon.compare(a, b)
Compares two polygons according to their average Z value. This is used
to sort polygons.
- Parameters:
- {!threedee.RenderPolygon} a
- The first polygon to compare
- {!threedee.RenderPolygon} b
- The second polygon to compare
- Returns:
- {number} Lower than 0 if z-value of second polygon is lower then z-value of first polygon. Greater than 0 if the other way around. 0 means z-values are equal
{number}
countVertices()
Returns the number of used vertices.
- Returns:
- {number} The number of used vertices
{!threedee.Vector}
getCenter()
Returns the center of the polygon.
Speed-optimization: The calculated center vector is cached in an instance
scope variable to prevent creation of vector objects on reach frame render.
WARNING: If you want to use the returned center vector for a longer time
(and not only for a single frame) then you should copy the vector because
otherwise the content may change when the polygon changes.
- Returns:
- {!threedee.Vector} The center of the polygon
{threedee.Material}
getMaterial()
Returns the polygon material. If it has a specific material then this one
is returned. Otherwise the global modal material is returned.
- Returns:
- {threedee.Material} The material to be used for this polygon
{?threedee.Vector}
getNormal()
Calculates the normal of the polygon. May return null if polygon has
fewer then three vertices.
Speed-optimization: For calculating the normal we need three additional
vectors. Two of them (V1 and V2) are only temporary and therefore are
shared in static scope. The third one is polygon-specific and
is shared in instance scope. WARNING: If you want to use the returned normal
vector for a longer time (and not only for a single frame) then you should
copy the vector because otherwise the content may change when the polygon
changes.
- Returns:
- {?threedee.Vector} The normal or null if polygon has fewer then three vertices
{!threedee.Vector}
getVertex(index)
Returns the vertex with the specified index.
- Parameters:
- {number} index
- The vertex index
- Returns:
- {!threedee.Vector} The vertex
init()
Initializes the polygon for the next rendering. This simply resets the
vertex indices to the original order and resets the counter of extra
vertices.
{boolean}
isBackface()
Checks if currently the backface of the polygon is visible.
- Returns:
- {boolean} True if backface is visible, false if front-side.
updateAverageZ()
Updates the average Z value.