t
Loading...
Searching...
No Matches
t::Geometry Class Reference

The base 3D geometry class. More...

#include <Geometry.hpp>

Inheritance diagram for t::Geometry:
t::Box t::Plane t::UtahTeapot

Public Member Functions

 Geometry (const BufferAttribute< double > &_vertexPositions, const BufferAttribute< double > &_vertexNormals)
 Creates a new 3D geometry with the specified vertex buffer and normal buffer.
 
void setIndices (BufferAttribute< int > _faceIndices)
 Sets the index buffer of this geometry.
 

Public Attributes

BufferAttribute< double > vertexPositions
 The vertex buffer.
 
std::optional< BufferAttribute< int > > faceIndices
 The index buffer, which is optional.
 
BufferAttribute< double > vertexNormals
 The normal buffer.
 
FrontFace frontFace
 The vertex winding order which classifies the front face of a triangle.
 

Detailed Description

The base 3D geometry class.

A 3D geometry defines the shape of a 3D object.

A 3D geometry is defined in terms of triangles (which have 3 vertices each) and contains the following data:

  • Vertex positions (required): the positions of the geometry's vertices, relative to its origin (or center);
  • Vertex normals (required): the normal vectors of the geometry's vertices, which are vectors pointing at the direction the corresponding vertex is facing. Used for lighting calculations;
  • Face indices (optional): the indices of the vertices that make up the triangles. If this data is missing, then it is assumed that every 3 consecutive vertices in the vertex position buffer form a triangle.

Here is an example of creating a simple depth-less triangle geometry.

auto vertexPositions = BufferAttribute<double>({0, 1, 0, -1, 0, 0, 1, 0, 0}, 3);
auto vertexNormals = BufferAttribute<double>({0, 0, 1, 0, 0, 1, 0, 0, 1}, 3);
auto triangleGeometry = Geometry(vertexPositions, vertexNormals);
A class representing attributes, such as vertex positions, face indices, and vertex normals.
Definition BufferAttribute.hpp:27
BufferAttribute< double > vertexNormals
The normal buffer.
Definition Geometry.hpp:54
Geometry(const BufferAttribute< double > &_vertexPositions, const BufferAttribute< double > &_vertexNormals)
Creates a new 3D geometry with the specified vertex buffer and normal buffer.
Definition Geometry.hpp:81
BufferAttribute< double > vertexPositions
The vertex buffer.
Definition Geometry.hpp:40

In the above example, the triangle has 3 vertices at \((0, 1, 0), (-1, 0, 0), (1, 0, 0)\). All 3 vertex normals point towards the positive Z direction on creation.

Constructor & Destructor Documentation

◆ Geometry()

t::Geometry::Geometry ( const BufferAttribute< double > & _vertexPositions,
const BufferAttribute< double > & _vertexNormals )
inline

Creates a new 3D geometry with the specified vertex buffer and normal buffer.

The new geometry will not have an index buffer by default. To set the index buffer, use setIndices.

The new geometry will assume that the vertices for a front-facing triangle appear in counter-clockwise order. See frontFace.

Parameters
_vertexPositionsThe vertex buffer of the new geometry.
_vertexNormalsThe normal buffer of the new geometry.

Member Function Documentation

◆ setIndices()

void t::Geometry::setIndices ( BufferAttribute< int > _faceIndices)
inline

Sets the index buffer of this geometry.

Every 3 consecutive numbers in this buffer are indices of vertices that form a single triangle.

Parameters
_faceIndicesThe new index buffer of this geometry.

Member Data Documentation

◆ faceIndices

std::optional<BufferAttribute<int> > t::Geometry::faceIndices

The index buffer, which is optional.

Every 3 consecutive numbers in this buffer are the indices of the 3 vertices that make up a single triangle.

◆ frontFace

FrontFace t::Geometry::frontFace
Initial value:
=
FrontFace::CounterClockwise

The vertex winding order which classifies the front face of a triangle.

If the verticies of a triangle after having been transformed in the Material#vertexShader are in this order, then the triangle is considered to be front-facing. Used in conjunction with Material#cullMode to determine if a triangle should be drawn or not.

◆ vertexNormals

BufferAttribute<double> t::Geometry::vertexNormals

The normal buffer.

Every 3 consecutive numbers in this buffer are the x, y, and z components of the normal vector of the corresponding vertex.

◆ vertexPositions

BufferAttribute<double> t::Geometry::vertexPositions

The vertex buffer.

Every 3 consecutive numbers in this buffer define the x, y, and z coordinates of a single vertex. The order in which a vertex appears in the buffer defines its index e.g. the first 3 numbers are the position of the vertex at index 0, the next 3 numbers are the position of the vertex at index 1, and so on. If the index buffer is missing, then every 3 consecutive vertices (i.e. 9 consecutive numbers) in this buffer form a triangle.


The documentation for this class was generated from the following file: