Support Forum G3D Web Page |
Triangle implementation optimized for ray-triangle intersection.
More...
Public Member Functions | |
Tri (const int i0, const int i1, const int i2, const CPUVertexArray &vertexArray, const shared_ptr< ReferenceCountedObject > &data=shared_ptr< ReferenceCountedObject >(), bool twoSided=false) | |
Assumes that normals are perpendicular to tangents, or that the tangents are zero. More... | |
Tri (const int i0, const int i1, const int i2, const CPUVertexArray &vertexArray, const shared_ptr< ReferenceCountedObject > &data, bool twoSided, bool partialCoverage) | |
Tri () | |
float | area () const |
Surface area. More... | |
template<class T > | |
shared_ptr< T > | data () const |
Extract the data field. More... | |
Vector3 | e1 (const CPUVertexArray &vertexArray) const |
Edge vector v1 - v0. More... | |
Vector3 | e2 (const CPUVertexArray &vertexArray) const |
Edge vector v2 - v0. More... | |
void | getBounds (const CPUVertexArray &vertexArray, AABox &box) const |
Returns a bounding box. More... | |
uint32 | getIndex (int i) const |
uint32 | hashCode () const |
Returns a (relatively) unique integer for this object. More... | |
bool | hasPartialCoverage () const |
True if this triangle has a material with any alpha < 1. More... | |
bool | intersectionAlphaTest (const CPUVertexArray &vertexArray, float u, float v, float threshold) const |
Returns true if the alpha value at intersection coordinates (u, v) is less than or equal to the threshold. More... | |
shared_ptr< Material > | material () const |
Resolve and return the material for this Tri. More... | |
Vector3 | nonUnitNormal (const CPUVertexArray &vertexArray) const |
Face normal. More... | |
Vector3 | normal (const CPUVertexArray &vertexArray) const |
Face normal. More... | |
const Vector3 & | normal (const CPUVertexArray &vertexArray, int i) const |
Vertex normal. More... | |
bool | operator== (const Tri &t) const |
const Vector4 & | packedTangent (const CPUVertexArray &vertexArray, int i) const |
Point3 | position (const CPUVertexArray &vertexArray, int i) const |
Vertex position (must be computed) More... | |
void | sample (float u, float v, int triIndex, const CPUVertexArray &vertexArray, bool backface, shared_ptr< Surfel > &surfel, float du=0, float dv=0, bool twoSided=true) const |
void | setData (const shared_ptr< ReferenceCountedObject > &newData) |
shared_ptr< Surface > | surface () const |
Vector3 | tangent (const CPUVertexArray &vertexArray, int i) const |
Per-vertex unit tangent, for bump mapping. More... | |
Vector3 | tangent2 (const CPUVertexArray &vertexArray, int i) const |
Per-vertex unit tangent = normal x tangent, for bump mapping. More... | |
const Vector2 & | texCoord (const CPUVertexArray &vertexArray, int i) const |
Triangle | toTriangle (const CPUVertexArray &vertexArray) const |
bool | twoSided () const |
True if this triangle should be treated as double-sided. More... | |
const CPUVertexArray::Vertex & | vertex (const CPUVertexArray &vertexArray, int i) const |
Useful for accessing several vertex properties at once (for less pointer indirection) More... | |
Static Public Member Functions | |
static void | setStorage (const Array< Tri > &triArray, ImageStorage newStorage) |
Set the storage on all Materials in the array. More... | |
Public Attributes | |
uint32 | index [3] |
Indices into the CPU Vertex array. More... | |
Friends | |
class | NativeTriTree |
class | UniversalSurfel |
Triangle implementation optimized for ray-triangle intersection.
Single sided and immutable once created.
The size of this class is carefully controlled so that large scenes can be stored efficiently and that cache coherence is maintained during processing. The implementation is currently 32 bytes in a 64-bit build.
G3D::Tri::Tri | ( | const int | i0, |
const int | i1, | ||
const int | i2, | ||
const CPUVertexArray & | vertexArray, | ||
const shared_ptr< ReferenceCountedObject > & | data = shared_ptr< ReferenceCountedObject >() , |
||
bool | twoSided = false |
||
) |
G3D::Tri::Tri | ( | const int | i0, |
const int | i1, | ||
const int | i2, | ||
const CPUVertexArray & | vertexArray, | ||
const shared_ptr< ReferenceCountedObject > & | data, | ||
bool | twoSided, | ||
bool | partialCoverage | ||
) |
|
inline |
|
inline |
Surface area.
|
inline |
Extract the data field.
Mostly useful when using data that is not a Material or Surface.
|
inline |
Edge vector v1 - v0.
Referenced by nonUnitNormal().
|
inline |
Edge vector v2 - v0.
Referenced by nonUnitNormal().
|
inline |
Returns a bounding box.
|
inline |
|
inline |
Returns a (relatively) unique integer for this object.
NOTE: Hashes only on the indices! Think of Tri simply as a set of indices and not an actual triangle.
|
inline |
True if this triangle has a material with any alpha < 1.
bool G3D::Tri::intersectionAlphaTest | ( | const CPUVertexArray & | vertexArray, |
float | u, | ||
float | v, | ||
float | threshold | ||
) | const |
Returns true if the alpha value at intersection coordinates (u, v) is less than or equal to the threshold.
shared_ptr<Material> G3D::Tri::material | ( | ) | const |
Resolve and return the material for this Tri.
Referenced by G3D::UniversalSurfel::UniversalSurfel().
|
inline |
Face normal.
For degenerate triangles, this is zero. For all other triangles it has arbitrary length and is defined by counter-clockwise winding. Calculated every call.
Referenced by normal().
|
inline |
Face normal.
For degenerate triangles, this is zero. For all other triangles it has unit length and is defined by counter-clockwise winding. Calculated every call.
|
inline |
Vertex normal.
|
inline |
|
inline |
|
inline |
Vertex position (must be computed)
Referenced by e1(), e2(), and getBounds().
void G3D::Tri::sample | ( | float | u, |
float | v, | ||
int | triIndex, | ||
const CPUVertexArray & | vertexArray, | ||
bool | backface, | ||
shared_ptr< Surfel > & | surfel, | ||
float | du = 0 , |
||
float | dv = 0 , |
||
bool | twoSided = true |
||
) | const |
|
inline |
|
static |
Set the storage on all Materials in the array.
shared_ptr<Surface> G3D::Tri::surface | ( | ) | const |
|
inline |
Per-vertex unit tangent, for bump mapping.
Tangents are perpendicular to the corresponding vertex normals.
|
inline |
Per-vertex unit tangent = normal x tangent, for bump mapping.
(Erroneously called the "binormal" in some literature)
|
inline |
Triangle G3D::Tri::toTriangle | ( | const CPUVertexArray & | vertexArray | ) | const |
|
inline |
True if this triangle should be treated as double-sided.
|
inline |
Useful for accessing several vertex properties at once (for less pointer indirection)
Referenced by normal(), packedTangent(), tangent(), tangent2(), and texCoord().
|
friend |
|
friend |
uint32 G3D::Tri::index[3] |
Indices into the CPU Vertex array.
Referenced by getIndex(), hashCode(), operator==(), position(), and vertex().