LightsprintSDK 2021.08.08
|
#include <RRMesh.h>
Public Member Functions | |
bool | resizeMesh (unsigned numTriangles, unsigned numVertices, const RRVector< unsigned > *texcoords, bool tangents, bool preserveContents) |
bool | reload (const RRMesh *mesh, bool indexed, const RRVector< unsigned > &texcoords, bool tangents) |
RRMeshArrays () | |
virtual | ~RRMeshArrays () |
virtual unsigned | getNumVertices () const override |
virtual void | getVertex (unsigned v, Vertex &out) const override |
virtual unsigned | getNumTriangles () const override |
virtual void | getTriangle (unsigned t, Triangle &out) const override |
virtual void | getTriangleBody (unsigned i, TriangleBody &out) const override |
virtual void | getTriangleNormals (unsigned t, TriangleNormals &out) const override |
virtual bool | getTriangleMapping (unsigned t, TriangleMapping &out, unsigned channel) const override |
virtual void | getUvChannels (RRVector< unsigned > &out) const override |
virtual void | getAABB (RRVec3 *mini, RRVec3 *maxi, RRVec3 *center) const override |
unsigned | flipFrontBack (unsigned numNormalsThatMustPointBack, bool negativeScale) |
void | buildNormals () |
void | buildTangents (unsigned uvChannel) |
unsigned | manipulateMapping (unsigned sourceChannel, const float *matrix2x3, unsigned destinationChannel) |
Public Member Functions inherited from rr::RRMesh | |
RRMesh () | |
virtual | ~RRMesh () |
virtual unsigned | getNumVertices () const =0 |
virtual void | getVertex (unsigned v, Vertex &out) const =0 |
virtual unsigned | getNumTriangles () const =0 |
virtual void | getTriangle (unsigned t, Triangle &out) const =0 |
virtual void | getTriangleBody (unsigned t, TriangleBody &out) const |
virtual bool | getTrianglePlane (unsigned t, RRVec4 &out) const |
virtual RRReal | getTriangleArea (unsigned t) const |
virtual void | getTriangleNormals (unsigned t, TriangleNormals &out) const |
virtual bool | getTriangleMapping (unsigned t, TriangleMapping &out, unsigned channel) const |
virtual PreImportNumber | getPreImportVertex (unsigned postImportVertex, unsigned postImportTriangle) const |
virtual unsigned | getPostImportVertex (PreImportNumber preImportVertex, PreImportNumber preImportTriangle) const |
virtual PreImportNumber | getPreImportTriangle (unsigned postImportTriangle) const |
virtual unsigned | getPostImportTriangle (PreImportNumber preImportTriangle) const |
unsigned | getNumPreImportVertices () const |
virtual void | getUvChannels (RRVector< unsigned > &out) const |
virtual void | getAABB (RRVec3 *mini, RRVec3 *maxi, RRVec3 *center) const |
virtual RRReal | getAverageVertexDistance () const |
virtual RRReal | getMappingDensity (unsigned channel) const |
virtual RRReal | findGroundLevel () const |
virtual RRHash | getHash () const |
TangentSpaceState | checkNormals () const |
TangentSpaceState | checkTangents () const |
virtual unsigned | checkConsistency (unsigned lightmapTexcoord, const char *meshName, class NumReports *numReports=nullptr) const |
RRMesh * | createTransformed (const RRMatrix3x4Ex *transform) const |
const RRMesh * | createOptimizedVertices (float maxDistanceBetweenVerticesToMerge, float maxRadiansBetweenNormalsToMerge, float maxDistanceBetweenUvsToMerge, const RRVector< unsigned > *texcoords) const |
const RRMesh * | createOptimizedTriangles () const |
const RRMesh * | createAccelerated () const |
RRMesh * | createVertexBufferRuler () const |
class RRMeshArrays * | createArrays (bool indexed, const RRVector< unsigned > &texcoords, bool tangents) const |
Public Member Functions inherited from rr::RRUniformlyAllocated | |
void * | operator new (std::size_t n) |
void * | operator new[] (std::size_t n) |
void | operator delete (void *p, std::size_t n) |
void | operator delete[] (void *p, std::size_t n) |
Static Public Member Functions | |
static RRMeshArrays * | rectangle () |
static RRMeshArrays * | plane () |
static RRMeshArrays * | box () |
static RRMeshArrays * | sphere () |
static RRMeshArrays * | cylinder () |
Static Public Member Functions inherited from rr::RRMesh | |
static RRMesh * | create (unsigned flags, Format vertexFormat, void *vertexBuffer, unsigned vertexCount, unsigned vertexStride) |
static RRMesh * | createIndexed (unsigned flags, Format vertexFormat, void *vertexBuffer, unsigned vertexCount, unsigned vertexStride, Format indexFormat, void *indexBuffer, unsigned indexCount, float vertexStitchMaxDistance=0) |
static const RRMesh * | createMultiMesh (const RRMesh *const *meshes, unsigned numMeshes, bool fast) |
Public Attributes | |
unsigned | numTriangles |
Triangle * | triangle |
unsigned | numVertices |
RRVec3 * | position |
RRVec3 * | normal |
RRVec3 * | tangent |
RRVec3 * | bitangent |
RRVector< RRVec2 * > | texcoord |
unsigned | version |
unsigned | unwrapChannel |
unsigned | unwrapWidth |
unsigned | unwrapHeight |
Additional Inherited Members | |
Public Types inherited from rr::RRMesh | |
enum | { UNDEFINED = UINT_MAX } |
enum | TangentSpaceState { TSS_PERFECT , TSS_NOT_ORTHOGONAL , TSS_DENORMALIZED , TSS_INVALID , TSS_MISSING } |
enum | Format { UINT8 = 0 , UINT16 = 1 , UINT32 = 2 , FLOAT32 = 4 } |
enum | Flags { TRI_LIST = 0 , TRI_STRIP = (1<<0) , OPTIMIZED_VERTICES = (1<<1) , OPTIMIZED_TRIANGLES = (1<<2) } |
typedef RRVec3 | Vertex |
Protected Member Functions inherited from rr::RRUniformlyAllocatedNonCopyable | |
RRUniformlyAllocatedNonCopyable () | |
~RRUniformlyAllocatedNonCopyable () | |
Protected Attributes inherited from rr::RRMesh | |
struct AABBCache * | aabbCache |
Mesh that exposes internal structures for direct read-write access.
You may freely edit data in arrays, however, resizing mesh (changing numVertices, numTriangles) is restricted, it is not allowed if other meshes were derived from this one. Derived meshes are e.g. multiobject or worldspace object, they may depend on original mesh size and crash if it changes.
When do we need it? Lightsprint has two major use cases:
If you need direct read-write access to data in RRMesh, try dynamic_cast<RRMeshArrays*> first, your RRMesh might already be RRMeshArrays. If you don't have RRMeshArrays, create it via RRMesh::createArrays().
rr::RRMeshArrays::RRMeshArrays | ( | ) |
|
virtual |
bool rr::RRMeshArrays::resizeMesh | ( | unsigned | numTriangles, |
unsigned | numVertices, | ||
const RRVector< unsigned > * | texcoords, | ||
bool | tangents, | ||
bool | preserveContents | ||
) |
Memory management.
If you resize often, it's safe to resize once to max size and then change only numTriangles/numVertices.
numTriangles | Number of triangles you wish to have after resize. |
numVertices | Number of vertices you wish to have after resize. |
texcoords | Set of uv channels you wish to have after resize. |
tangents | Whether you wish to have tangents and bitangents after resize. |
preserveContents | Whether you wish to preserve data stored in mesh through resizing process. False = triangle and vertex data are uninitialized after resize. True = all triangle and vertex data existing both before and after resize are preserved, while newly allocated data are left uninitialized. |
bool rr::RRMeshArrays::reload | ( | const RRMesh * | mesh, |
bool | indexed, | ||
const RRVector< unsigned > & | texcoords, | ||
bool | tangents | ||
) |
Overwrites content of this RRMeshArrays, copies data from given RRMesh.
mesh | Data source, mesh data are copied to this. |
indexed | False splits vertices, makes numVertices=3*numTriangles. |
texcoords | Lets you specify what texcoord channels to copy from original mesh. |
tangents | True = tangents will be stored in this mesh. False = tangents will be calculated on the fly in getTriangleNormals(). |
|
overridevirtual |
Returns number of vertices in mesh.
Implements rr::RRMesh.
|
overridevirtual |
Writes position of v-th vertex in mesh to out.
Make sure you provide valid v is in range <0..getNumVertices()-1>. Implementations are allowed to expect valid v, result is undefined for invalid v (possible assert in debug, crash in release).
What exactly is vertex, do boxes have 8 or 24 vertices?
RRMesh, RRCollider and RRObject create no constraints, you are free to use your favorite approach - create box with 8 or 24 or any other number of vertices greater than 8, collisions and illumination will be computed correctly. (24 because each one of 8 vertices is used by 3 sides with different normal)
RRSolver depends on vertex list defined here. If you request vertex buffer with per-vertex illumination, vertex buffer will have getNumVertices() items. So when writing new RRMesh implementations, create vertex list so that vertex buffers with the same size and vertex order are compatible with your renderer.
Implements rr::RRMesh.
|
overridevirtual |
Returns number of triangles in mesh.
Implements rr::RRMesh.
|
overridevirtual |
Writes t-th triangle in mesh to out.
Make sure you provide valid t in range <0..getNumTriangles()-1>. Implementators are allowed to expect valid t (performance reasons, may be called very often), so result is completely undefined for invalid t (possible crash).
Order of vertices in triangle has influence on what side of triangle is front, which is important for lighting. See more details in Front/back side.
Implements rr::RRMesh.
|
overridevirtual |
Writes t-th triangle in mesh to out.
Make sure you provide valid t in range <0..getNumTriangles()-1>. Implementators are allowed to expect valid t, so result is completely undefined for invalid t (possible crash).
There is default implementation, but if you know format of your data well, you may provide faster one.
Speed of this function is important for intersection tests performance.
Reimplemented from rr::RRMesh.
|
overridevirtual |
Writes tangent bases in triangle vertices to out. Normals are part of bases.
Tangent bases are used by global illumination solver and renderer. Normals should point to front side hemisphere, see Front/back side.
Default implementation writes all vertex normals equal to triangle plane normal and constructs appropriate tangent space.
t | Index of triangle. Valid t is in range <0..getNumTriangles()-1>. |
out | Caller provided storage for result. For valid t, requested normals are written to out. For invalid t, out stays unmodified. |
Reimplemented from rr::RRMesh.
|
overridevirtual |
Writes t-th triangle's uv mapping to out.
t | Index of triangle. Valid t is in range <0..getNumTriangles()-1>. |
out | Caller provided storage for result. For valid t, requested mapping is written to out. For invalid t, out stays unmodified. |
channel | Texcoord channel to use, RRMaterial::diffuseReflectance.texcoord for diffuse texture mapping, RRMaterial::lightmap.texcoord for unwrap used by lightmaps etc. Note that for proper lighting, unwrap must have all coordinates in <0..1> range and triangles must not overlap. Unwrap may be imported or automatically generated by RRObjects::buildUnwrap(). |
Reimplemented from rr::RRMesh.
|
overridevirtual |
Fills out with uv channels provided by mesh, in ascending order. Default implementation queries presence of channels 0 to 100, ignores higher channels.
Reimplemented from rr::RRMesh.
|
overridevirtual |
Returns axis aligned bounding box and center of mesh. Fast (cached).
mini | nullptr or pointer to vec3 to be filled with minimum of computed AABB. |
maxi | nullptr or pointer to vec3 to be filled with maximum of computed AABB. |
center | nullptr or pointer to vec3 to be filled with average vertex position. |
Reimplemented from rr::RRMesh.
unsigned rr::RRMeshArrays::flipFrontBack | ( | unsigned | numNormalsThatMustPointBack, |
bool | negativeScale | ||
) |
Flips front/back if at least this number of normals in triangle points to back side. So all triangles are flipped if numNormalsThatMustPointBack==0. Meaning of front and back is inverted when negativeScale.
void rr::RRMeshArrays::buildNormals | ( | ) |
Builds new smooth vertex normals from angles between faces.
void rr::RRMeshArrays::buildTangents | ( | unsigned | uvChannel | ) |
Builds new tangents and bitangents from normals.
uvChannel | If such channel exists, tangents will point in u+ direction, bitangents in v+ direction. When building tangentspace for normal maps, pass uv channel used for mapping normal map. |
unsigned rr::RRMeshArrays::manipulateMapping | ( | unsigned | sourceChannel, |
const float * | matrix2x3, | ||
unsigned | destinationChannel | ||
) |
Manipulates mapping by 2x3 matrix.
sourceChannel | Channel data are taken from. If there is no such channel, function fails. |
matrix2x3 | Matrix to transform data with. As this is the only function working with 2x3 matrix, we pass just pointer to 6 floats instead of creating new class. Uvs are transformed as in uv=RRVec2(u*matrix[0]+v*matrix[1]+matrix[2],u*matrix[3]+v*matrix[4]+matrix[5]); nullptr works as identity, i.e. no transformation. |
destinationChannel | Channel results are saved to. If there is no such channel, it is created. |
|
static |
|
static |
|
static |
|
static |
|
static |
unsigned rr::RRMeshArrays::numTriangles |
Triangle* rr::RRMeshArrays::triangle |
32bit triangle list, may be nullptr only in completely empty mesh.
unsigned rr::RRMeshArrays::numVertices |
RRVec3* rr::RRMeshArrays::position |
May be nullptr only in completely empty mesh.
RRVec3* rr::RRMeshArrays::normal |
May be nullptr only in completely empty mesh.
RRVec3* rr::RRMeshArrays::tangent |
May be nullptr.
RRVec3* rr::RRMeshArrays::bitangent |
May be nullptr.
May contain mix of nullptr and non-nullptr channels, e.g. texcoord[5] array is missing but texcoord[6] array is present.
unsigned rr::RRMeshArrays::version |
Increase version each time you modify arrays, to let renderer know that data in GPU are outdated.
unsigned rr::RRMeshArrays::unwrapChannel |
Uv channel with unwrap, UINT_MAX=unknown or none. It is filled by buildUnwrap(), but it is currently not used, renderer and solver use RRMaterial::lightmap.texcoord instead.
unsigned rr::RRMeshArrays::unwrapWidth |
Optimal texture width when using unwrap from unwrapChannel, 0=unknown or none. It is filled by buildUnwrap().
unsigned rr::RRMeshArrays::unwrapHeight |
Optimal texture height when using unwrap from unwrapChannel, 0=unknown or none. It is filled by buildUnwrap().