Visual Computing Library  devel
Loading...
Searching...
No Matches
mesh_render_data.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_DATA_H
24#define VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_DATA_H
25
26#include <vclib/render/drawable/mesh/mesh_render_info.h>
27#include <vclib/render/drawable/mesh/mesh_render_settings.h>
28
29#include <vclib/algorithms/mesh.h>
30#include <vclib/mesh.h>
31#include <vclib/space/complex.h>
32
33namespace vcl {
34
79template<typename MeshRenderDerived>
81{
82private:
83 using MRI = MeshRenderInfo;
84
85 // Auxiliary data that can be used by the derived class to properly allocate
86 // and fill the buffers
87
88 uint mNumVerts = 0;
89 uint mNumTris = 0;
90 uint mNumEdges = 0;
91 uint nWireframeLines = 0;
92
93 // Vector that tells, for each non-duplicated vertex, which wedges it
94 // belongs to. Each pair is the face index and the vertex index in the face.
95 // It allows to access the wedge texcoords for each non-duplicated vertex
96 std::vector<std::pair<uint, uint>> mVertWedgeMap;
97
98 // The list of vertices that has been duplicated (each element of the list
99 // is the index of the vertex to duplicate)
100 std::list<uint> mVertsToDuplicate;
101
102 // A list that tells, for each duplicated vertex, the list of faces that
103 // must be reassigned to the corresponding duplicated vertex.
104 // Each duplicated vertex has a list of pairs face/vertex index in the face,
105 // that must be/have been reassigned to the duplicated vertex
106 std::list<std::list<std::pair<uint, uint>>> mFacesToReassign;
107
108 // data used to manage the mapping beteween the original polygonal faces
109 // and the triangle faces
110
111 // map that stores the correspondence between the original polygonal faces
112 // and the triangle faces
113 TriPolyIndexBiMap mIndexMap;
114
115 // bitset that tells which buffers must be filled (this value has been set
116 // at construction time). It may differ from the value passed to the update
117 // function, since the user may want to update only a subset of the buffers
118 MRI::BuffersBitSet mBuffersToFill = MRI::BUFFERS_ALL;
119
120protected:
122 {
123 uint startIndex = 0; // start index in the triangle index buffer
124 uint indexCount = 0; // num indices in the triangle index buffer
125 uint vertMaterialId = 0; // material id associated to the vertices
126 uint faceMaterialId = 0; // material id associated to the faces
127 };
128
129 std::vector<TriangleMaterialChunk> mMaterialChunks;
130
131public:
139 void update(
140 const MeshConcept auto& mesh,
141 MRI::BuffersBitSet buffersToUpdate = MRI::BUFFERS_ALL)
142 {
143 using enum MRI::Buffers;
144
145 MRI::BuffersBitSet btu = mBuffersToFill & buffersToUpdate;
146
147 // first thing to do
148 updateAuxiliaryData(mesh, btu);
149
150 // set data for vertices
151 updateVerticesData(mesh, btu);
152
153 // set data for faces
154 updateFacesData(mesh, btu);
155
156 // set data for edges
157 updateEdgesData(mesh, btu);
158
159 // set data for mesh
160 updateMeshData(mesh, btu);
161
162 // set data for textures
163 updateTextureData(mesh, btu);
164 }
165
166protected:
167 MeshRenderData() = default;
168
169 MeshRenderData(MRI::BuffersBitSet buffersToFill) :
170 mBuffersToFill(buffersToFill)
171 {
172 }
173
174 void swap(MeshRenderData& other)
175 {
176 using std::swap;
177 swap(mNumVerts, other.mNumVerts);
178 swap(mNumTris, other.mNumTris);
179 swap(mVertWedgeMap, other.mVertWedgeMap);
180 swap(mVertsToDuplicate, other.mVertsToDuplicate);
181 swap(mFacesToReassign, other.mFacesToReassign);
182 swap(mIndexMap, other.mIndexMap);
183 swap(mBuffersToFill, other.mBuffersToFill);
184 swap(mMaterialChunks, other.mMaterialChunks);
185 }
186
213 uint numVerts() const { return mNumVerts; }
214
241 uint numTris() const { return mNumTris; }
242
265 uint numEdges() const { return mNumEdges; }
266
294 uint numWireframeLines() const { return nWireframeLines; }
295
305 {
306 using enum MeshRenderInfo::Surface;
307
308 if (mrs.isSurface(COLOR_FACE) || mrs.isSurface(COLOR_WEDGE_TEX))
309 return mMaterialChunks[chunkNumber].faceMaterialId;
310 else
311 return mMaterialChunks[chunkNumber].vertMaterialId;
312 }
313
314 // utility functions to fill the buffers
315
325 void fillVertexPositions(const MeshConcept auto& mesh, auto* buffer)
326 {
327 vertexPositionsToBuffer(mesh, buffer);
328 appendDuplicateVertexPositionsToBuffer(mesh, mVertsToDuplicate, buffer);
329 }
330
341 void fillVertexQuadIndices(const MeshConcept auto& mesh, auto* buffer)
342 {
343 vertexQuadIndicesToBuffer(mesh, buffer);
344 }
345
355 void fillVertexNormals(const MeshConcept auto& mesh, auto* buffer)
356 {
357 vertexNormalsToBuffer(mesh, buffer);
358 appendDuplicateVertexNormalsToBuffer(mesh, mVertsToDuplicate, buffer);
359 }
360
371 const MeshConcept auto& mesh,
372 auto* buffer,
374 {
375 vertexColorsToBuffer(mesh, buffer, fmt);
377 mesh, mVertsToDuplicate, buffer, fmt);
378 }
379
389 void fillVertexTexCoords(const MeshConcept auto& mesh, auto* buffer)
390 {
391 vertexTexCoordsToBuffer(mesh, buffer);
392 appendDuplicateVertexTexCoordsToBuffer(mesh, mVertsToDuplicate, buffer);
393 }
394
404 void fillVertexTangents(const MeshConcept auto& mesh, auto* buffer)
405 {
406 vertexTangentsToBuffer(mesh, buffer);
407 appendDuplicateVertexTangentsToBuffer(mesh, mVertsToDuplicate, buffer);
408 }
409
424 void fillWedgeTexCoords(const FaceMeshConcept auto& mesh, auto* buffer)
425 {
427 mesh, mVertWedgeMap, mFacesToReassign, buffer);
428 }
429
439 void fillTriangleIndices(const FaceMeshConcept auto& mesh, auto* buffer)
440 {
441 using MeshType = std::decay_t<decltype(mesh)>;
442 using FaceType = MeshType::FaceType;
443
444 // comparator of faces
445 // ordering first by per-vertex material index (if available),
446 // then by per-face material index (if available)
447 auto faceComp = [&](const FaceType& f1, const FaceType& f2) {
449 if (isPerVertexMaterialIndexAvailable(mesh)) {
450 uint id1 = f1.vertex(0)->materialIndex();
451 uint id2 = f2.vertex(0)->materialIndex();
452 if (id1 != id2) { // do not return true if equal
453 return id1 < id2;
454 }
455 }
456 }
457 if constexpr (HasPerFaceMaterialIndex<MeshType>) {
459 uint id1 = f1.materialIndex();
460 uint id2 = f2.materialIndex();
461 if (id1 != id2) { // do not return true if equal
462 return id1 < id2;
463 }
464 }
465 }
466
467 // if both per-vertex and per-face material indices are equal, sort
468 // by face index to have a stable sorting
469 return f1.index() < f2.index();
470 };
471
472 // get the list of face indices sorted by material ID and
473 // using the face comparator defined above
474 std::vector<uint> faceIndicesSortedByMaterialID =
475 sortFaceIndicesByFunction(mesh, faceComp, true);
476
478 mesh, buffer, mIndexMap, MatrixStorageType::ROW_MAJOR, mNumTris);
480 mesh, mVertsToDuplicate, mFacesToReassign, mIndexMap, buffer);
481
482 // permute the triangulated face vertex indices according to the face
483 // sorting by material ID (the function also edits the index map from
484 // polygonal faces (which still refers to the mesh ones) to the
485 // triangulated faces (which refers to the sorted triangles))
486 permuteTriangulatedFaceVertexIndices(
487 buffer, mIndexMap, faceIndicesSortedByMaterialID);
488
489 fillChuncks(mesh);
490 }
491
501 void fillTriangleNormals(const FaceMeshConcept auto& mesh, auto* buffer)
502 {
504 mesh, buffer, mIndexMap, MatrixStorageType::ROW_MAJOR);
505 }
506
517 const FaceMeshConcept auto& mesh,
518 auto* buffer,
520 {
521 triangulatedFaceColorsToBuffer(mesh, buffer, mIndexMap, fmt);
522 }
523
538 const FaceMeshConcept auto& mesh,
539 auto* buffer)
540 {
542 mesh, buffer, mIndexMap);
543 }
544
554 void fillFaceMaterialIndices(const FaceMeshConcept auto& mesh, auto* buffer)
555 {
556 triangulatedFaceMaterialIndicesToBuffer(mesh, buffer, mIndexMap);
557 }
558
568 void fillEdgeIndices(const EdgeMeshConcept auto& mesh, auto* buffer)
569 {
570 edgeVertexIndicesToBuffer(mesh, buffer);
571 }
572
582 void fillEdgeNormals(const EdgeMeshConcept auto& mesh, auto* buffer)
583 {
584 edgeNormalsToBuffer(mesh, buffer);
585 }
586
597 const EdgeMeshConcept auto& mesh,
598 auto* buffer,
600 {
601 edgeColorsToBuffer(mesh, buffer, fmt);
602 }
603
614 void fillWireframeIndices(const FaceMeshConcept auto& mesh, auto* buffer)
615 {
616 wireframeVertexIndicesToBuffer(mesh, buffer);
617 }
618
619 // functions that must be may implemented by the derived classes to set
620 // the buffers:
621
636
654
672
690
708
731
749
767
785
807
825
843
861
879
897
911 void setTextures(const MeshConcept auto&) {}
912
921 void setMeshUniforms(const MeshConcept auto&) {}
922
923private:
924 MeshRenderDerived& derived()
925 {
926 return static_cast<MeshRenderDerived&>(*this);
927 }
928
929 const MeshRenderDerived& derived() const
930 {
931 return static_cast<const MeshRenderDerived&>(*this);
932 }
933
934 void updateAuxiliaryData(
935 const MeshConcept auto& mesh,
936 MeshRenderInfo::BuffersBitSet btu)
937 {
938 using MeshType = MeshRenderDerived::MeshType;
939 using enum MRI::Buffers;
940
941 if (btu[toUnderlying(VERTICES)] || btu[toUnderlying(WEDGE_TEXCOORDS)] ||
942 btu[toUnderlying(TRIANGLES)]) {
943 mVertWedgeMap.clear();
944 mVertsToDuplicate.clear();
945 mFacesToReassign.clear();
946
947 if constexpr (HasPerFaceWedgeTexCoords<MeshType>) {
948 if (mesh.isPerFaceWedgeTexCoordsEnabled()) {
950 mesh,
951 mVertWedgeMap,
952 mVertsToDuplicate,
953 mFacesToReassign);
954 }
955 }
956
957 mNumVerts = mesh.vertexNumber() + mVertsToDuplicate.size();
958 }
959
960 if constexpr (HasFaces<MeshType>) {
961 if (btu[toUnderlying(TRIANGLES)])
962 mNumTris = countTriangulatedTriangles(mesh);
963 if (btu[toUnderlying(WIREFRAME)])
964 nWireframeLines = countPerFaceVertexReferences(mesh);
965 }
966
967 if constexpr (HasEdges<MeshType>) {
968 if (btu[toUnderlying(EDGES)])
969 mNumEdges = mesh.edgeNumber();
970 }
971 }
972
973 void updateVerticesData(
974 const MeshConcept auto& mesh,
975 MeshRenderInfo::BuffersBitSet btu)
976 {
977 using MeshType = MeshRenderDerived::MeshType;
978 using enum MRI::Buffers;
979
980 if (btu[toUnderlying(VERTICES)]) {
981 // vertex buffer (positions)
982 derived().setVertexPositionsBuffer(mesh);
983 }
984
985 if constexpr (HasPerVertexNormal<MeshType>) {
986 if (isPerVertexNormalAvailable(mesh)) {
987 if (btu[toUnderlying(VERT_NORMALS)]) {
988 // vertex buffer (normals)
989 derived().setVertexNormalsBuffer(mesh);
990 }
991 }
992 }
993
994 if constexpr (HasPerVertexColor<MeshType>) {
995 if (isPerVertexColorAvailable(mesh)) {
996 if (btu[toUnderlying(VERT_COLORS)]) {
997 // vertex buffer (colors)
998 derived().setVertexColorsBuffer(mesh);
999 }
1000 }
1001 }
1002
1003 if constexpr (HasPerVertexTexCoord<MeshType>) {
1004 if (isPerVertexTexCoordAvailable(mesh)) {
1005 if (btu[toUnderlying(VERT_TEXCOORDS)]) {
1006 // vertex buffer (UVs)
1007 derived().setVertexTexCoordsBuffer(mesh);
1008 }
1009 }
1010 }
1011
1012 if constexpr (HasPerVertexTangent<MeshType>) {
1013 if (isPerVertexTangentAvailable(mesh)) {
1014 if (btu[toUnderlying(VERT_TANGENT)]) {
1015 // vertex buffer (tangent)
1016 derived().setVertexTangentsBuffer(mesh);
1017 }
1018 }
1019 }
1020 }
1021
1022 void updateFacesData(
1023 const MeshConcept auto& mesh,
1024 MeshRenderInfo::BuffersBitSet btu)
1025 {
1026 using MeshType = MeshRenderDerived::MeshType;
1027 using enum MRI::Buffers;
1028
1029 if constexpr (HasFaces<MeshType>) {
1030 if (btu[toUnderlying(TRIANGLES)]) {
1031 // triangle index buffer
1032 derived().setTriangleIndicesBuffer(mesh);
1033 }
1034
1035 if constexpr (HasPerFaceWedgeTexCoords<MeshType>) {
1037 if (btu[toUnderlying(WEDGE_TEXCOORDS)]) {
1038 // vertex wedges buffer (duplicated vertices)
1039 derived().setWedgeTexCoordsBuffer(mesh);
1040 }
1041 }
1042 }
1043
1044 if constexpr (HasPerFaceNormal<MeshType>) {
1045 if (isPerFaceNormalAvailable(mesh)) {
1046 if (btu[toUnderlying(TRI_NORMALS)]) {
1047 // triangle normal buffer
1048 derived().setTriangleNormalsBuffer(mesh);
1049 }
1050 }
1051 }
1052
1053 if constexpr (HasPerFaceColor<MeshType>) {
1054 if (isPerFaceColorAvailable(mesh)) {
1055 if (btu[toUnderlying(TRI_COLORS)]) {
1056 // triangle color buffer
1057 derived().setTriangleColorsBuffer(mesh);
1058 }
1059 }
1060 }
1061
1062 // material indices are stored per face (each face has its own
1063 // material index)
1064 if constexpr (HasPerVertexMaterialIndex<MeshType>) {
1065 if (isPerVertexMaterialIndexAvailable(mesh)) {
1066 if (btu[toUnderlying(VERT_TEXCOORDS)]) {
1067 // triangle vertex material indices buffer
1068 derived().setVertexMaterialIndicesBuffer(mesh);
1069 }
1070 }
1071 }
1072
1073 if constexpr (HasPerFaceMaterialIndex<MeshType>) {
1075 if (btu[toUnderlying(WEDGE_TEXCOORDS)]) {
1076 // triangle material indices buffer
1077 derived().setFaceMaterialIndicesBuffer(mesh);
1078 }
1079 }
1080 }
1081
1082 if (btu[toUnderlying(WIREFRAME)]) {
1083 // wireframe index buffer
1084 derived().setWireframeIndicesBuffer(mesh);
1085 }
1086 }
1087 }
1088
1089 void updateEdgesData(
1090 const MeshConcept auto& mesh,
1091 MeshRenderInfo::BuffersBitSet btu)
1092 {
1093 using MeshType = MeshRenderDerived::MeshType;
1094 using enum MRI::Buffers;
1095
1096 if constexpr (HasEdges<MeshType>) {
1097 if (btu[toUnderlying(EDGES)]) {
1098 // edge index buffer
1099 derived().setEdgeIndicesBuffer(mesh);
1100 }
1101
1102 if constexpr (HasPerEdgeNormal<MeshType>) {
1103 if (isPerEdgeNormalAvailable(mesh)) {
1104 if (btu[toUnderlying(EDGE_NORMALS)]) {
1105 // edge normal buffer
1106 derived().setEdgeNormalsBuffer(mesh);
1107 }
1108 }
1109 }
1110
1111 if constexpr (HasPerEdgeColor<MeshType>) {
1112 if (isPerEdgeColorAvailable(mesh)) {
1113 if (btu[toUnderlying(EDGE_COLORS)]) {
1114 // edge color buffer
1115 derived().setEdgeColorsBuffer(mesh);
1116 }
1117 }
1118 }
1119 }
1120 }
1121
1122 void updateMeshData(
1123 const MeshConcept auto& mesh,
1124 MeshRenderInfo::BuffersBitSet btu)
1125 {
1126 using enum MRI::Buffers;
1127
1128 if (btu[toUnderlying(MESH_UNIFORMS)]) {
1129 // mesh uniforms
1130 derived().setMeshUniforms(mesh);
1131 }
1132 }
1133
1134 void updateTextureData(
1135 const MeshConcept auto& mesh,
1136 MeshRenderInfo::BuffersBitSet btu)
1137 {
1138 using MeshType = MeshRenderDerived::MeshType;
1139 using enum MRI::Buffers;
1140
1141 if constexpr (HasMaterials<MeshType>) {
1142 if (btu[toUnderlying(TEXTURES)]) {
1143 // textures
1144 derived().setTextures(mesh);
1145 }
1146 }
1147 }
1148
1149 static void permuteTriangulatedFaceVertexIndices(
1150 auto* buffer,
1151 TriPolyIndexBiMap& indexMap,
1152 const std::vector<uint>& newFaceIndices)
1153 {
1154 // newFaceIndices tells for each face, which is its new position
1155 // we need the inverse mapping: for each new position, which is the old
1156 // face index
1157 std::vector<uint> oldFaceIndices(newFaceIndices.size());
1158 for (uint i = 0; i < newFaceIndices.size(); ++i) {
1159 oldFaceIndices[newFaceIndices[i]] = static_cast<uint>(i);
1160 }
1161
1162 // temporary copy of the buffer
1163 std::vector<uint> bufferCopy(indexMap.triangleNumber() * 3);
1164
1165 // temporary bimbap
1166 TriPolyIndexBiMap indexMapCopy;
1167 indexMapCopy.reserve(
1168 indexMap.triangleNumber(), indexMap.polygonNumber());
1169
1170 uint copiedTriangles = 0;
1171
1172 for (uint i = 0; i < oldFaceIndices.size(); ++i) {
1173 // need to place the k triangles associated to the i-th face
1174 // of oldFaceIndices
1175 uint polyIndex = oldFaceIndices[i];
1176 uint firstTri = indexMap.triangleBegin(polyIndex);
1177 uint nTris = indexMap.triangleNumber(polyIndex);
1178
1179 std::copy(
1180 buffer + firstTri * 3,
1181 buffer + (firstTri + nTris) * 3,
1182 bufferCopy.data() + copiedTriangles * 3);
1183
1184 for (uint t = copiedTriangles; t < copiedTriangles + nTris; ++t) {
1185 indexMapCopy.insert(t, polyIndex);
1186 }
1187
1188 copiedTriangles += nTris;
1189 }
1190
1191 // copy back
1192 std::copy(
1193 bufferCopy.begin(),
1194 bufferCopy.begin() + copiedTriangles * 3,
1195 buffer);
1196 indexMap = std::move(indexMapCopy);
1197 }
1198
1199 void fillChuncks(const FaceMeshConcept auto& mesh)
1200 {
1201 using MeshType = std::decay_t<decltype(mesh)>;
1202
1203 mMaterialChunks.clear();
1204
1205 uint first = 0;
1206 uint n = 0;
1207
1208 uint currentVertMatID = UINT_NULL;
1209 uint currentFaceMatID = UINT_NULL;
1210
1211 for (uint i = 0; i < mIndexMap.triangleNumber(); ++i) {
1212 uint fIndex = mIndexMap.polygon(i);
1213
1214 if constexpr (HasPerVertexMaterialIndex<MeshType>) {
1215 if (isPerVertexMaterialIndexAvailable(mesh)) {
1216 uint mId = mesh.face(fIndex).vertex(0)->materialIndex();
1217 if (mId != currentVertMatID && n != 0) {
1218 if (currentVertMatID != UINT_NULL) {
1219 mMaterialChunks.push_back(
1220 {first, n, currentVertMatID, currentFaceMatID});
1221 first += n;
1222 n = 0;
1223 }
1224 currentVertMatID = mId;
1225 }
1226 }
1227 }
1228 if constexpr (HasPerFaceMaterialIndex<MeshType>) {
1230 uint mId = mesh.face(fIndex).materialIndex();
1231 if (mId != currentFaceMatID && n != 0) {
1232 if (currentFaceMatID != UINT_NULL) {
1233 mMaterialChunks.push_back(
1234 {first, n, currentVertMatID, currentFaceMatID});
1235 first += n;
1236 n = 0;
1237 }
1238 currentFaceMatID = mId;
1239 }
1240 }
1241 }
1242
1243 n++;
1244 }
1245
1246 mMaterialChunks.push_back(
1247 {first, n, currentVertMatID, currentFaceMatID});
1248 }
1249};
1250
1251} // namespace vcl
1252
1253#endif // VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_DATA_H
The BitSet class allows to treat an integral type as an array of booleans of a guaranteed size.
Definition bit_set.h:52
A class representing a box in N-dimensional space.
Definition box.h:46
Format
Color format enumeration.
Definition color.h:77
The MeshRenderData class provides a common interface to automatically update the buffers used to rend...
Definition mesh_render_data.h:81
uint materialIndex(const MeshRenderSettings &mrs, uint chunkNumber) const
Returns the material index for the given triangle chunk, according to the current render settings.
Definition mesh_render_data.h:304
void fillFaceMaterialIndices(const FaceMeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the wedge texture indices of the mesh...
Definition mesh_render_data.h:554
void setTriangleIndicesBuffer(const FaceMeshConcept auto &)
Function that sets the content of triangle indices buffer and sends the data to the GPU.
Definition mesh_render_data.h:748
void setEdgeIndicesBuffer(const EdgeMeshConcept auto &)
Function that sets the content of edge indices buffer and sends the data to the GPU.
Definition mesh_render_data.h:860
uint numWireframeLines() const
Returns the number of wireframe lines that will be used to render the mesh.
Definition mesh_render_data.h:294
void setVertexColorsBuffer(const MeshConcept auto &)
Function that sets the content of vertex colors buffer and sends the data to the GPU.
Definition mesh_render_data.h:671
void setEdgeNormalsBuffer(const EdgeMeshConcept auto &)
Function that sets the content of edge normals buffer and sends the data to the GPU.
Definition mesh_render_data.h:878
void setTextures(const MeshConcept auto &)
Function that sets the textures from the mesh and sends the data to the GPU.
Definition mesh_render_data.h:911
void fillEdgeIndices(const EdgeMeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the edge indices of the mesh.
Definition mesh_render_data.h:568
void setEdgeColorsBuffer(const EdgeMeshConcept auto &)
Function that sets the content of edge colors buffer and sends the data to the GPU.
Definition mesh_render_data.h:896
uint numVerts() const
Returns the number of vertices that will be used to render the mesh.
Definition mesh_render_data.h:213
void fillWireframeIndices(const FaceMeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the wireframe indices of the mesh.
Definition mesh_render_data.h:614
void fillVertexPositions(const MeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the vertex positions of the mesh.
Definition mesh_render_data.h:325
void fillVertexMaterialIndices(const FaceMeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the vertex material indices of the me...
Definition mesh_render_data.h:537
void fillEdgeNormals(const EdgeMeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the edge normals of the mesh.
Definition mesh_render_data.h:582
void fillTriangleColors(const FaceMeshConcept auto &mesh, auto *buffer, Color::Format fmt)
Given the mesh and a pointer to a buffer, fills the buffer with the triangle colors of the mesh (each...
Definition mesh_render_data.h:516
uint numTris() const
Returns the number of triangles that will be used to render the mesh.
Definition mesh_render_data.h:241
void fillEdgeColors(const EdgeMeshConcept auto &mesh, auto *buffer, Color::Format fmt)
Given the mesh and a pointer to a buffer, fills the buffer with the edge colors of the mesh (each col...
Definition mesh_render_data.h:596
void setVertexMaterialIndicesBuffer(const FaceMeshConcept auto &)
Function that sets the content of vertex material indices buffer and sends the data to the GPU.
Definition mesh_render_data.h:806
uint numEdges() const
Returns the number of edges that will be used to render the mesh.
Definition mesh_render_data.h:265
void setVertexTexCoordsBuffer(const MeshConcept auto &)
Function that sets the content of vertex texture coordinates buffer and sends the data to the GPU.
Definition mesh_render_data.h:689
void fillTriangleNormals(const FaceMeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the triangle normals of the mesh.
Definition mesh_render_data.h:501
void update(const MeshConcept auto &mesh, MRI::BuffersBitSet buffersToUpdate=MRI::BUFFERS_ALL)
Update the buffers used to render the mesh.
Definition mesh_render_data.h:139
void fillVertexTexCoords(const MeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the vertex texcoords of the mesh.
Definition mesh_render_data.h:389
void fillVertexQuadIndices(const MeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the vertex quad indices of the mesh (...
Definition mesh_render_data.h:341
void fillVertexTangents(const MeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the vertex tangent of the mesh.
Definition mesh_render_data.h:404
void setTriangleColorsBuffer(const FaceMeshConcept auto &)
Function that sets the content of triangle colors buffer and sends the data to the GPU.
Definition mesh_render_data.h:784
void setVertexNormalsBuffer(const MeshConcept auto &)
Function that sets the content of vertex normals buffer and sends the data to the GPU.
Definition mesh_render_data.h:653
void setVertexPositionsBuffer(const MeshConcept auto &)
Function that sets the content of vertex positions buffer and sends the data to the GPU.
Definition mesh_render_data.h:635
void setVertexTangentsBuffer(const MeshConcept auto &)
Function that sets the content of vertex tangent buffer and sends the data to the GPU.
Definition mesh_render_data.h:707
void fillTriangleIndices(const FaceMeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the triangle indices of the mesh.
Definition mesh_render_data.h:439
void setWireframeIndicesBuffer(const FaceMeshConcept auto &)
Function that sets the content of wireframe indices buffer and sends the data to the GPU.
Definition mesh_render_data.h:842
void fillVertexNormals(const MeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the vertex normals of the mesh.
Definition mesh_render_data.h:355
void fillWedgeTexCoords(const FaceMeshConcept auto &mesh, auto *buffer)
Given the mesh and a pointer to a buffer, fills the buffer with the wedge texcoors of the mesh.
Definition mesh_render_data.h:424
void setMeshUniforms(const MeshConcept auto &)
Function that sets the mesh uniforms from the mesh.
Definition mesh_render_data.h:921
void setWedgeTexCoordsBuffer(const MeshConcept auto &)
Function that sets the content of wedge texture coordinates buffer and sends the data to the GPU.
Definition mesh_render_data.h:730
void fillVertexColors(const MeshConcept auto &mesh, auto *buffer, Color::Format fmt)
Given the mesh and a pointer to a buffer, fills the buffer with the vertex colors of the mesh (each c...
Definition mesh_render_data.h:370
void setTriangleNormalsBuffer(const FaceMeshConcept auto &)
Function that sets the content of triangle normals buffer and sends the data to the GPU.
Definition mesh_render_data.h:766
void setFaceMaterialIndicesBuffer(const FaceMeshConcept auto &)
Function that sets the content of face material indices buffer and sends the data to the GPU.
Definition mesh_render_data.h:824
The MeshRenderInfo class is a collection of rendering settings for a Mesh.
Definition mesh_render_info.h:61
Surface
List of possible settings for the surface primitive.
Definition mesh_render_info.h:148
The MeshRenderSettings class allows an easy management of render settings of a Mesh....
Definition mesh_render_settings.h:70
The TriPolyIndexBiMap class allows to store a bidirectional mapping between a Polygon Mesh and a Tria...
Definition tri_poly_index_bimap.h:50
uint polygon(uint triangleIndex) const
Returns the index of the polygon mapped to the triangle having the index given as input argument.
Definition tri_poly_index_bimap.h:68
uint triangleBegin(uint polygonIndex) const
Returns the smallest index of set of triangles mapped to the polygon having the index given as input ...
Definition tri_poly_index_bimap.h:84
uint polygonNumber() const
Returns the number of polygons stored in the BiMap.
Definition tri_poly_index_bimap.h:195
uint triangleNumber(uint polygonIndex) const
Returns the number of (consecutive index) triangles mapped to a polygon.
Definition tri_poly_index_bimap.h:113
The EdgeMeshConcept is evaluated true if the type T is a Mesh (it satisfies the vcl::MeshConcept) and...
Definition edge_requirements.h:58
The FaceMeshConcept is evaluated true if the type T is a Mesh (it satisfies the vcl::MeshConcept) and...
Definition face_requirements.h:70
Concept that checks if a Mesh has the per Face MaterialIndex component.
Definition face_requirements.h:188
Concept that checks if a Mesh has the per Vertex MaterialIndex component.
Definition vertex_requirements.h:141
A concept that checks whether a class is (inherits from) a Mesh class.
Definition mesh.h:2169
void replaceTriangulatedFaceVertexIndicesByVertexDuplicationToBuffer(const MeshType &mesh, const std::list< uint > &vertsToDuplicate, const std::list< std::list< std::pair< uint, uint > > > &facesToReassign, const TriPolyIndexBiMap &indexMap, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR)
Replace the triangulated face vertex indices in the given buffer with the new indices of the duplicat...
Definition append_replace_to_buffer.h:250
void appendDuplicateVertexPositionsToBuffer(const MeshType &mesh, const std::list< uint > &vertsToDuplicate, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR)
Append the positions of the duplicated vertices to the given buffer.
Definition append_replace_to_buffer.h:102
void wedgeTexCoordsAsDuplicatedVertexTexCoordsToBuffer(const MeshType &mesh, const std::vector< std::pair< vcl::uint, vcl::uint > > &vertWedgeMap, const std::list< std::list< std::pair< vcl::uint, vcl::uint > > > &facesToReassign, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR)
Export wedge texture coordinates to a buffer of the duplicated vertex texture coordinates.
Definition export_buffer.h:1743
void appendDuplicateVertexColorsToBuffer(const MeshType &mesh, const std::list< uint > &vertsToDuplicate, auto *buffer, Color::Representation representation=Color::Representation::INT_0_255, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR)
Append the colors of the duplicated vertices to the given buffer.
Definition append_replace_to_buffer.h:456
void appendDuplicateVertexTangentsToBuffer(const MeshType &mesh, const std::list< uint > &vertsToDuplicate, auto *buffer, bool storeHandednessAsW=true, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR)
Append the tangent of the duplicated vertices to the given buffer.
Definition append_replace_to_buffer.h:719
void appendDuplicateVertexNormalsToBuffer(const MeshType &mesh, const std::list< uint > &vertsToDuplicate, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR)
Append the normals of the duplicated vertices to the given buffer.
Definition append_replace_to_buffer.h:391
void appendDuplicateVertexTexCoordsToBuffer(const MeshType &mesh, const std::list< uint > &vertsToDuplicate, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR)
Append the texture coordinates of the duplicated vertices to the given buffer.
Definition append_replace_to_buffer.h:646
constexpr uint UINT_NULL
The UINT_NULL value represent a null value of uint that is the maximum value that can be represented ...
Definition base.h:48
bool isPerEdgeColorAvailable(const MeshType &m)
Returns true if the Color component is available (enabled) in the Edge element of the input mesh m.
Definition edge_requirements.h:370
bool isPerEdgeNormalAvailable(const MeshType &m)
Returns true if the Normal component is available (enabled) in the Edge element of the input mesh m.
Definition edge_requirements.h:486
void vertexPositionsToBuffer(const MeshType &mesh, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR, uint rowNumber=UINT_NULL)
Export the vertex positions of a mesh to a buffer.
Definition export_buffer.h:74
void edgeVertexIndicesToBuffer(const MeshType &mesh, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR, bool getIndicesAsIfContainerCompact=true, uint rowNumber=UINT_NULL)
Export into a buffer the vertex indices for each edge of a Mesh.
Definition export_buffer.h:456
void wireframeVertexIndicesToBuffer(const MeshType &mesh, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR, bool getIndicesAsIfContainerCompact=true, uint rowNumber=UINT_NULL)
Export into a buffer the vertex indices for each edge that composes the wireframe of the Mesh (i....
Definition export_buffer.h:511
void triangulatedFaceVertexIndicesToBuffer(const MeshType &mesh, auto *buffer, TriPolyIndexBiMap &indexMap=detail::indexMap, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR, uint numTriangles=UINT_NULL, bool getIndicesAsIfContainerCompact=true)
Export into a buffer the vertex indices for each triangle computed by triangulating the faces of a Me...
Definition export_buffer.h:366
void triangulatedFaceMaterialIndicesToBuffer(const MeshType &mesh, auto *buffer, const TriPolyIndexBiMap &indexMap)
Export into a buffer the per triangle material indices of a mesh. Triangles are computed by triangula...
Definition export_buffer.h:1682
void vertexQuadIndicesToBuffer(const MeshType &mesh, auto *buffer)
Export the indices of a quad per vertex to a buffer.
Definition export_buffer.h:111
bool isPerFaceWedgeTexCoordsAvailable(const MeshType &m)
Returns true if the WedgeTexCoords component is available (enabled) in the Face element of the input ...
Definition face_requirements.h:910
bool isPerFaceNormalAvailable(const MeshType &m)
Returns true if the Normal component is available (enabled) in the Face element of the input mesh m.
Definition face_requirements.h:669
bool isPerFaceMaterialIndexAvailable(const MeshType &m)
Returns true if the MaterialIndex component is available (enabled) in the Face element of the input m...
Definition face_requirements.h:608
bool isPerFaceColorAvailable(const MeshType &m)
Returns true if the Color component is available (enabled) in the Face element of the input mesh m.
Definition face_requirements.h:492
uint countVerticesToDuplicateByWedgeTexCoords(const MeshType &mesh, std::vector< std::pair< uint, uint > > &vertWedgeMap=detail::dummyVectorOfPairs, std::list< uint > &vertsToDuplicate=detail::dummyUintList, std::list< std::list< std::pair< uint, uint > > > &facesToReassign=detail::dummyListOfLists)
This function counts the number of vertices that must be duplicated in a mesh to have a unique texcoo...
Definition topology.h:471
uint countPerFaceVertexReferences(const FaceMeshConcept auto &mesh)
Count the number of references to vertices in the mesh faces.
Definition topology.h:182
uint countTriangulatedTriangles(const FaceMeshConcept auto &mesh)
Counts the number of resulting triangles if the input mesh would be triangulated by splitting each fa...
Definition topology.h:240
Definition mesh_render_data.h:122