Support Forum       G3D Web Page     
Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
G3D::Tri Class Reference


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< Materialmaterial () 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 Vector3normal (const CPUVertexArray &vertexArray, int i) const
 Vertex normal. More...
 
bool operator== (const Tri &t) const
 
const Vector4packedTangent (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< Surfacesurface () 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 Vector2texCoord (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::Vertexvertex (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
 

Detailed Description


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.

See also
G3D::Triangle, G3D::MeshShape, G3D::ArticulatedModel, G3D::Surface, G3D::MeshAlg

Constructor & Destructor Documentation

◆ Tri() [1/3]

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 
)

Assumes that normals are perpendicular to tangents, or that the tangents are zero.

Parameters
dataUsually a Surface or Material, but can be an arbitrary hook

◆ Tri() [2/3]

G3D::Tri::Tri ( const int  i0,
const int  i1,
const int  i2,
const CPUVertexArray vertexArray,
const shared_ptr< ReferenceCountedObject > &  data,
bool  twoSided,
bool  partialCoverage 
)

◆ Tri() [3/3]

G3D::Tri::Tri ( )
inline

Member Function Documentation

◆ area()

float G3D::Tri::area ( ) const
inline

Surface area.

◆ data()

template<class T >
shared_ptr<T> G3D::Tri::data ( ) const
inline


Extract the data field.

Mostly useful when using data that is not a Material or Surface.

See also
surface(), material()

◆ e1()

Vector3 G3D::Tri::e1 ( const CPUVertexArray vertexArray) const
inline

Edge vector v1 - v0.

Referenced by nonUnitNormal().

◆ e2()

Vector3 G3D::Tri::e2 ( const CPUVertexArray vertexArray) const
inline

Edge vector v2 - v0.

Referenced by nonUnitNormal().

◆ getBounds()

void G3D::Tri::getBounds ( const CPUVertexArray vertexArray,
AABox box 
) const
inline

Returns a bounding box.

◆ getIndex()

uint32 G3D::Tri::getIndex ( int  i) const
inline

◆ hashCode()

uint32 G3D::Tri::hashCode ( ) const
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.

◆ hasPartialCoverage()

bool G3D::Tri::hasPartialCoverage ( ) const
inline

True if this triangle has a material with any alpha < 1.

◆ intersectionAlphaTest()

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.

◆ material()

shared_ptr<Material> G3D::Tri::material ( ) const

Resolve and return the material for this Tri.

Referenced by G3D::UniversalSurfel::UniversalSurfel().

◆ nonUnitNormal()

Vector3 G3D::Tri::nonUnitNormal ( const CPUVertexArray vertexArray) const
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().

◆ normal() [1/2]

Vector3 G3D::Tri::normal ( const CPUVertexArray vertexArray) const
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.

◆ normal() [2/2]

const Vector3& G3D::Tri::normal ( const CPUVertexArray vertexArray,
int  i 
) const
inline

Vertex normal.

◆ operator==()

bool G3D::Tri::operator== ( const Tri t) const
inline

◆ packedTangent()

const Vector4& G3D::Tri::packedTangent ( const CPUVertexArray vertexArray,
int  i 
) const
inline

◆ position()

Point3 G3D::Tri::position ( const CPUVertexArray vertexArray,
int  i 
) const
inline

Vertex position (must be computed)

Referenced by e1(), e2(), and getBounds().

◆ sample()

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

◆ setData()

void G3D::Tri::setData ( const shared_ptr< ReferenceCountedObject > &  newData)
inline

◆ setStorage()

static void G3D::Tri::setStorage ( const Array< Tri > &  triArray,
ImageStorage  newStorage 
)
static

Set the storage on all Materials in the array.

◆ surface()

shared_ptr<Surface> G3D::Tri::surface ( ) const

◆ tangent()

Vector3 G3D::Tri::tangent ( const CPUVertexArray vertexArray,
int  i 
) const
inline

Per-vertex unit tangent, for bump mapping.

Tangents are perpendicular to the corresponding vertex normals.

◆ tangent2()

Vector3 G3D::Tri::tangent2 ( const CPUVertexArray vertexArray,
int  i 
) const
inline

Per-vertex unit tangent = normal x tangent, for bump mapping.

(Erroneously called the "binormal" in some literature)

◆ texCoord()

const Vector2& G3D::Tri::texCoord ( const CPUVertexArray vertexArray,
int  i 
) const
inline

◆ toTriangle()

Triangle G3D::Tri::toTriangle ( const CPUVertexArray vertexArray) const

◆ twoSided()

bool G3D::Tri::twoSided ( ) const
inline

True if this triangle should be treated as double-sided.

◆ vertex()

const CPUVertexArray::Vertex& G3D::Tri::vertex ( const CPUVertexArray vertexArray,
int  i 
) const
inline

Useful for accessing several vertex properties at once (for less pointer indirection)

Referenced by normal(), packedTangent(), tangent(), tangent2(), and texCoord().

Friends And Related Function Documentation

◆ NativeTriTree

friend class NativeTriTree
friend

◆ UniversalSurfel

friend class UniversalSurfel
friend

Member Data Documentation

◆ index

uint32 G3D::Tri::index[3]

Indices into the CPU Vertex array.

Referenced by getIndex(), hashCode(), operator==(), position(), and vertex().


documentation generated on Wed Nov 24 2021 08:02:01 using doxygen 1.8.15