Visual Computing Library  devel
Loading...
Searching...
No Matches
mesh_render_data.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2026 *
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{
82public:
84 {
85 uint startIndex = 0; // start index in the triangle index buffer
86 uint indexCount = 0; // num indices in the triangle index buffer
87 uint vertMaterialId = 0; // material id associated to the vertices
88 uint faceMaterialId = 0; // material id associated to the faces
89 };
90
91private:
92 using MRI = MeshRenderInfo;
93
94 // Auxiliary data that can be used by the derived class to properly allocate
95 // and fill the buffers
96
97 uint mNumVerts = 0;
98 uint mNumTris = 0;
99 uint mNumEdges = 0;
100 uint nWireframeLines = 0;
101
102 // Vector that tells, for each non-duplicated vertex, which wedges it
103 // belongs to. Each pair is the face index and the vertex index in the face.
104 // It allows to access the wedge texcoords for each non-duplicated vertex
105 std::vector<std::pair<uint, uint>> mVertWedgeMap;
106
107 // The list of vertices that has been duplicated (each element of the list
108 // is the index of the vertex to duplicate)
109 std::list<uint> mVertsToDuplicate;
110
111 // A list that tells, for each duplicated vertex, the list of faces that
112 // must be reassigned to the corresponding duplicated vertex.
113 // Each duplicated vertex has a list of pairs face/vertex index in the face,
114 // that must be/have been reassigned to the duplicated vertex
115 std::list<std::list<std::pair<uint, uint>>> mFacesToReassign;
116
117 // data used to manage the mapping beteween the original polygonal faces
118 // and the triangle faces
119
120 // map that stores the correspondence between the original polygonal faces
121 // and the triangle faces
122 TriPolyIndexBiMap mIndexMap;
123
124 // bitset that tells which buffers must be filled (this value has been set
125 // at construction time). It may differ from the value passed to the update
126 // function, since the user may want to update only a subset of the buffers
127 MRI::BuffersBitSet mBuffersToFill = MRI::BUFFERS_ALL;
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 additional data for mesh
160 updateMeshAdditionalData(mesh, btu);
161
162 // set data for textures
163 updateTextureData(mesh, btu);
164 }
165
174 uint triangleChunksNumber() const { return mMaterialChunks.size(); }
175
184 {
185 return mMaterialChunks[chunkIndex];
186 }
187
197 {
198 using enum MeshRenderInfo::Surface;
199
200 if (mrs.isSurface(COLOR_FACE) || mrs.isSurface(COLOR_WEDGE_TEX))
201 return mMaterialChunks[chunkNumber].faceMaterialId;
202 else
203 return mMaterialChunks[chunkNumber].vertMaterialId;
204 }
205
206protected:
207 MeshRenderData() = default;
208
209 MeshRenderData(MRI::BuffersBitSet buffersToFill) :
210 mBuffersToFill(buffersToFill)
211 {
212 }
213
214 void swap(MeshRenderData& other)
215 {
216 using std::swap;
217 swap(mNumVerts, other.mNumVerts);
218 swap(mNumTris, other.mNumTris);
219 swap(mVertWedgeMap, other.mVertWedgeMap);
220 swap(mVertsToDuplicate, other.mVertsToDuplicate);
221 swap(mFacesToReassign, other.mFacesToReassign);
222 swap(mIndexMap, other.mIndexMap);
223 swap(mBuffersToFill, other.mBuffersToFill);
224 swap(mMaterialChunks, other.mMaterialChunks);
225 }
226
253 uint numVerts() const { return mNumVerts; }
254
281 uint numTris() const { return mNumTris; }
282
305 uint numEdges() const { return mNumEdges; }
306
334 uint numWireframeLines() const { return nWireframeLines; }
335
336 // utility functions to fill the buffers
337
347 void fillVertexPositions(const MeshConcept auto& mesh, auto* buffer)
348 {
349 vertexPositionsToBuffer(mesh, buffer);
350 appendDuplicateVertexPositionsToBuffer(mesh, mVertsToDuplicate, buffer);
351 }
352
363 void fillVertexQuadIndices(const MeshConcept auto& mesh, auto* buffer)
364 {
365 vertexQuadIndicesToBuffer(mesh, buffer);
366 }
367
377 void fillVertexNormals(const MeshConcept auto& mesh, auto* buffer)
378 {
379 vertexNormalsToBuffer(mesh, buffer);
380 appendDuplicateVertexNormalsToBuffer(mesh, mVertsToDuplicate, buffer);
381 }
382
393 const MeshConcept auto& mesh,
394 auto* buffer,
396 {
397 vertexColorsToBuffer(mesh, buffer, fmt);
399 mesh, mVertsToDuplicate, buffer, fmt);
400 }
401
411 void fillVertexTexCoords(const MeshConcept auto& mesh, auto* buffer)
412 {
413 vertexTexCoordsToBuffer(mesh, buffer);
414 appendDuplicateVertexTexCoordsToBuffer(mesh, mVertsToDuplicate, buffer);
415 }
416
426 void fillVertexTangents(const MeshConcept auto& mesh, auto* buffer)
427 {
428 vertexTangentsToBuffer(mesh, buffer);
429 appendDuplicateVertexTangentsToBuffer(mesh, mVertsToDuplicate, buffer);
430 }
431
446 void fillWedgeTexCoords(const FaceMeshConcept auto& mesh, auto* buffer)
447 {
449 mesh, mVertWedgeMap, mFacesToReassign, buffer);
450 }
451
461 void fillTriangleIndices(const FaceMeshConcept auto& mesh, auto* buffer)
462 {
463 using MeshType = std::decay_t<decltype(mesh)>;
464 using FaceType = MeshType::FaceType;
465
466 // comparator of faces
467 // ordering first by per-vertex material index (if available),
468 // then by per-face material index (if available)
469 auto faceComp = [&](const FaceType& f1, const FaceType& f2) {
471 if (isPerVertexMaterialIndexAvailable(mesh)) {
472 uint id1 = f1.vertex(0)->materialIndex();
473 uint id2 = f2.vertex(0)->materialIndex();
474 if (id1 != id2) { // do not return true if equal
475 return id1 < id2;
476 }
477 }
478 }
479 if constexpr (HasPerFaceMaterialIndex<MeshType>) {
481 uint id1 = f1.materialIndex();
482 uint id2 = f2.materialIndex();
483 if (id1 != id2) { // do not return true if equal
484 return id1 < id2;
485 }
486 }
487 }
488
489 // if both per-vertex and per-face material indices are equal, sort
490 // by face index to have a stable sorting
491 return f1.index() < f2.index();
492 };
493
494 // get the list of face indices sorted by material ID and
495 // using the face comparator defined above
496 std::vector<uint> faceIndicesSortedByMaterialID =
497 sortFaceIndicesByFunction(mesh, faceComp, true);
498
500 mesh, buffer, mIndexMap, MatrixStorageType::ROW_MAJOR, mNumTris);
502 mesh, mVertsToDuplicate, mFacesToReassign, mIndexMap, buffer);
503
504 // permute the triangulated face vertex indices according to the face
505 // sorting by material ID (the function also edits the index map from
506 // polygonal faces (which still refers to the mesh ones) to the
507 // triangulated faces (which refers to the sorted triangles))
508 permuteTriangulatedFaceVertexIndices(
509 buffer, mIndexMap, faceIndicesSortedByMaterialID);
510
511 fillChuncks(mesh);
512 }
513
523 void fillTriangleNormals(const FaceMeshConcept auto& mesh, auto* buffer)
524 {
526 mesh, buffer, mIndexMap, MatrixStorageType::ROW_MAJOR);
527 }
528
539 const FaceMeshConcept auto& mesh,
540 auto* buffer,
542 {
543 triangulatedFaceColorsToBuffer(mesh, buffer, mIndexMap, fmt);
544 }
545
560 const FaceMeshConcept auto& mesh,
561 auto* buffer)
562 {
564 mesh, buffer, mIndexMap);
565 }
566
576 void fillFaceMaterialIndices(const FaceMeshConcept auto& mesh, auto* buffer)
577 {
578 triangulatedFaceMaterialIndicesToBuffer(mesh, buffer, mIndexMap);
579 }
580
590 void fillEdgeIndices(const EdgeMeshConcept auto& mesh, auto* buffer)
591 {
592 edgeVertexIndicesToBuffer(mesh, buffer);
593 }
594
604 void fillEdgeNormals(const EdgeMeshConcept auto& mesh, auto* buffer)
605 {
606 edgeNormalsToBuffer(mesh, buffer);
607 }
608
619 const EdgeMeshConcept auto& mesh,
620 auto* buffer,
622 {
623 edgeColorsToBuffer(mesh, buffer, fmt);
624 }
625
636 void fillWireframeIndices(const FaceMeshConcept auto& mesh, auto* buffer)
637 {
638 wireframeVertexIndicesToBuffer(mesh, buffer);
639 }
640
641 // functions that must be may implemented by the derived classes to set
642 // the buffers:
643
658
676
694
712
730
753
771
789
807
829
847
865
883
901
919
933 void setTextures(const MeshConcept auto&) {}
934
944
945private:
946 MeshRenderDerived& derived()
947 {
948 return static_cast<MeshRenderDerived&>(*this);
949 }
950
951 const MeshRenderDerived& derived() const
952 {
953 return static_cast<const MeshRenderDerived&>(*this);
954 }
955
956 void updateAuxiliaryData(
957 const MeshConcept auto& mesh,
958 MeshRenderInfo::BuffersBitSet btu)
959 {
960 using MeshType = MeshRenderDerived::MeshType;
961 using enum MRI::Buffers;
962
963 if (btu[toUnderlying(VERTICES)] || btu[toUnderlying(WEDGE_TEXCOORDS)] ||
964 btu[toUnderlying(TRIANGLES)]) {
965 mVertWedgeMap.clear();
966 mVertsToDuplicate.clear();
967 mFacesToReassign.clear();
968
969 if constexpr (HasPerFaceWedgeTexCoords<MeshType>) {
970 if (mesh.isPerFaceWedgeTexCoordsEnabled()) {
972 mesh,
973 mVertWedgeMap,
974 mVertsToDuplicate,
975 mFacesToReassign);
976 }
977 }
978
979 mNumVerts = mesh.vertexCount() + mVertsToDuplicate.size();
980 }
981
982 if constexpr (HasFaces<MeshType>) {
983 if (btu[toUnderlying(TRIANGLES)])
984 mNumTris = triangulatedFaceCount(mesh);
985 if (btu[toUnderlying(WIREFRAME)])
986 nWireframeLines = faceVertexReferencesCount(mesh);
987 }
988
989 if constexpr (HasEdges<MeshType>) {
990 if (btu[toUnderlying(EDGES)])
991 mNumEdges = mesh.edgeCount();
992 }
993 }
994
995 void updateVerticesData(
996 const MeshConcept auto& mesh,
997 MeshRenderInfo::BuffersBitSet btu)
998 {
999 using MeshType = MeshRenderDerived::MeshType;
1000 using enum MRI::Buffers;
1001
1002 if (btu[toUnderlying(VERTICES)]) {
1003 // vertex buffer (positions)
1004 derived().setVertexPositionsBuffer(mesh);
1005 }
1006
1007 if constexpr (HasPerVertexNormal<MeshType>) {
1008 if (isPerVertexNormalAvailable(mesh)) {
1009 if (btu[toUnderlying(VERT_NORMALS)]) {
1010 // vertex buffer (normals)
1011 derived().setVertexNormalsBuffer(mesh);
1012 }
1013 }
1014 }
1015
1016 if constexpr (HasPerVertexColor<MeshType>) {
1017 if (isPerVertexColorAvailable(mesh)) {
1018 if (btu[toUnderlying(VERT_COLORS)]) {
1019 // vertex buffer (colors)
1020 derived().setVertexColorsBuffer(mesh);
1021 }
1022 }
1023 }
1024
1025 if constexpr (HasPerVertexTexCoord<MeshType>) {
1026 if (isPerVertexTexCoordAvailable(mesh)) {
1027 if (btu[toUnderlying(VERT_TEXCOORDS)]) {
1028 // vertex buffer (UVs)
1029 derived().setVertexTexCoordsBuffer(mesh);
1030 }
1031 }
1032 }
1033
1034 if constexpr (HasPerVertexTangent<MeshType>) {
1035 if (isPerVertexTangentAvailable(mesh)) {
1036 if (btu[toUnderlying(VERT_TANGENT)]) {
1037 // vertex buffer (tangent)
1038 derived().setVertexTangentsBuffer(mesh);
1039 }
1040 }
1041 }
1042 }
1043
1044 void updateFacesData(
1045 const MeshConcept auto& mesh,
1046 MeshRenderInfo::BuffersBitSet btu)
1047 {
1048 using MeshType = MeshRenderDerived::MeshType;
1049 using enum MRI::Buffers;
1050
1051 if constexpr (HasFaces<MeshType>) {
1052 if (btu[toUnderlying(TRIANGLES)]) {
1053 // triangle index buffer
1054 derived().setTriangleIndicesBuffer(mesh);
1055 }
1056
1057 if constexpr (HasPerFaceWedgeTexCoords<MeshType>) {
1059 if (btu[toUnderlying(WEDGE_TEXCOORDS)]) {
1060 // vertex wedges buffer (duplicated vertices)
1061 derived().setWedgeTexCoordsBuffer(mesh);
1062 }
1063 }
1064 }
1065
1066 if constexpr (HasPerFaceNormal<MeshType>) {
1067 if (isPerFaceNormalAvailable(mesh)) {
1068 if (btu[toUnderlying(TRI_NORMALS)]) {
1069 // triangle normal buffer
1070 derived().setTriangleNormalsBuffer(mesh);
1071 }
1072 }
1073 }
1074
1075 if constexpr (HasPerFaceColor<MeshType>) {
1076 if (isPerFaceColorAvailable(mesh)) {
1077 if (btu[toUnderlying(TRI_COLORS)]) {
1078 // triangle color buffer
1079 derived().setTriangleColorsBuffer(mesh);
1080 }
1081 }
1082 }
1083
1084 // material indices are stored per face (each face has its own
1085 // material index)
1086 if constexpr (HasPerVertexMaterialIndex<MeshType>) {
1087 if (isPerVertexMaterialIndexAvailable(mesh)) {
1088 if (btu[toUnderlying(VERT_TEXCOORDS)]) {
1089 // triangle vertex material indices buffer
1090 derived().setVertexMaterialIndicesBuffer(mesh);
1091 }
1092 }
1093 }
1094
1095 if constexpr (HasPerFaceMaterialIndex<MeshType>) {
1097 if (btu[toUnderlying(WEDGE_TEXCOORDS)]) {
1098 // triangle material indices buffer
1099 derived().setFaceMaterialIndicesBuffer(mesh);
1100 }
1101 }
1102 }
1103
1104 if (btu[toUnderlying(WIREFRAME)]) {
1105 // wireframe index buffer
1106 derived().setWireframeIndicesBuffer(mesh);
1107 }
1108 }
1109 }
1110
1111 void updateEdgesData(
1112 const MeshConcept auto& mesh,
1113 MeshRenderInfo::BuffersBitSet btu)
1114 {
1115 using MeshType = MeshRenderDerived::MeshType;
1116 using enum MRI::Buffers;
1117
1118 if constexpr (HasEdges<MeshType>) {
1119 if (btu[toUnderlying(EDGES)]) {
1120 // edge index buffer
1121 derived().setEdgeIndicesBuffer(mesh);
1122 }
1123
1124 if constexpr (HasPerEdgeNormal<MeshType>) {
1125 if (isPerEdgeNormalAvailable(mesh)) {
1126 if (btu[toUnderlying(EDGE_NORMALS)]) {
1127 // edge normal buffer
1128 derived().setEdgeNormalsBuffer(mesh);
1129 }
1130 }
1131 }
1132
1133 if constexpr (HasPerEdgeColor<MeshType>) {
1134 if (isPerEdgeColorAvailable(mesh)) {
1135 if (btu[toUnderlying(EDGE_COLORS)]) {
1136 // edge color buffer
1137 derived().setEdgeColorsBuffer(mesh);
1138 }
1139 }
1140 }
1141 }
1142 }
1143
1144 void updateMeshAdditionalData(
1145 const MeshConcept auto& mesh,
1146 MeshRenderInfo::BuffersBitSet btu)
1147 {
1148 using enum MRI::Buffers;
1149
1150 if (btu[toUnderlying(MESH_ADDITIONAL_DATA)]) {
1151 // mesh additional data
1152 derived().setMeshAdditionalData(mesh);
1153 }
1154 }
1155
1156 void updateTextureData(
1157 const MeshConcept auto& mesh,
1158 MeshRenderInfo::BuffersBitSet btu)
1159 {
1160 using MeshType = MeshRenderDerived::MeshType;
1161 using enum MRI::Buffers;
1162
1163 if constexpr (HasMaterials<MeshType>) {
1164 if (btu[toUnderlying(TEXTURES)]) {
1165 // textures
1166 derived().setTextures(mesh);
1167 }
1168 }
1169 }
1170
1171 static void permuteTriangulatedFaceVertexIndices(
1172 auto* buffer,
1173 TriPolyIndexBiMap& indexMap,
1174 const std::vector<uint>& newFaceIndices)
1175 {
1176 // newFaceIndices tells for each face, which is its new position
1177 // we need the inverse mapping: for each new position, which is the old
1178 // face index
1179 std::vector<uint> oldFaceIndices(newFaceIndices.size());
1180 for (uint i = 0; i < newFaceIndices.size(); ++i) {
1181 oldFaceIndices[newFaceIndices[i]] = static_cast<uint>(i);
1182 }
1183
1184 // temporary copy of the buffer
1185 std::vector<uint> bufferCopy(indexMap.triangleCount() * 3);
1186
1187 // temporary bimbap
1188 TriPolyIndexBiMap indexMapCopy;
1189 indexMapCopy.reserve(indexMap.triangleCount(), indexMap.polygonCount());
1190
1191 uint copiedTriangles = 0;
1192
1193 for (uint i = 0; i < oldFaceIndices.size(); ++i) {
1194 // need to place the k triangles associated to the i-th face
1195 // of oldFaceIndices
1196 uint polyIndex = oldFaceIndices[i];
1197 uint firstTri = indexMap.triangleBegin(polyIndex);
1198 uint nTris = indexMap.triangleCount(polyIndex);
1199
1200 std::copy(
1201 buffer + firstTri * 3,
1202 buffer + (firstTri + nTris) * 3,
1203 bufferCopy.data() + copiedTriangles * 3);
1204
1205 for (uint t = copiedTriangles; t < copiedTriangles + nTris; ++t) {
1206 indexMapCopy.insert(t, polyIndex);
1207 }
1208
1209 copiedTriangles += nTris;
1210 }
1211
1212 // copy back
1213 std::copy(
1214 bufferCopy.begin(),
1215 bufferCopy.begin() + copiedTriangles * 3,
1216 buffer);
1217 indexMap = std::move(indexMapCopy);
1218 }
1219
1220 void fillChuncks(const FaceMeshConcept auto& mesh)
1221 {
1222 using MeshType = std::decay_t<decltype(mesh)>;
1223
1224 mMaterialChunks.clear();
1225
1226 uint first = 0;
1227 uint n = 0;
1228
1229 uint currentVertMatID = UINT_NULL;
1230 uint currentFaceMatID = UINT_NULL;
1231
1232 for (uint i = 0; i < mIndexMap.triangleCount(); ++i) {
1233 uint fIndex = mIndexMap.polygon(i);
1234
1235 if constexpr (HasPerVertexMaterialIndex<MeshType>) {
1236 if (isPerVertexMaterialIndexAvailable(mesh)) {
1237 uint mId = mesh.face(fIndex).vertex(0)->materialIndex();
1238 if (mId != currentVertMatID && n != 0) {
1239 if (currentVertMatID != UINT_NULL) {
1240 mMaterialChunks.push_back(
1241 {first, n, currentVertMatID, currentFaceMatID});
1242 first += n;
1243 n = 0;
1244 }
1245 currentVertMatID = mId;
1246 }
1247 }
1248 }
1249 if constexpr (HasPerFaceMaterialIndex<MeshType>) {
1251 uint mId = mesh.face(fIndex).materialIndex();
1252 if (mId != currentFaceMatID && n != 0) {
1253 if (currentFaceMatID != UINT_NULL) {
1254 mMaterialChunks.push_back(
1255 {first, n, currentVertMatID, currentFaceMatID});
1256 first += n;
1257 n = 0;
1258 }
1259 currentFaceMatID = mId;
1260 }
1261 }
1262 }
1263
1264 n++;
1265 }
1266
1267 mMaterialChunks.push_back(
1268 {first, n, currentVertMatID, currentFaceMatID});
1269 }
1270};
1271
1272} // namespace vcl
1273
1274#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
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:196
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:576
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:770
uint triangleChunksNumber() const
Returns the number of triangle chunks.
Definition mesh_render_data.h:174
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:882
uint numWireframeLines() const
Returns the number of wireframe lines that will be used to render the mesh.
Definition mesh_render_data.h:334
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:693
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:900
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:933
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:590
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:918
uint numVerts() const
Returns the number of vertices that will be used to render the mesh.
Definition mesh_render_data.h:253
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:636
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:347
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:559
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:604
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:538
uint numTris() const
Returns the number of triangles that will be used to render the mesh.
Definition mesh_render_data.h:281
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:618
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:828
uint numEdges() const
Returns the number of edges that will be used to render the mesh.
Definition mesh_render_data.h:305
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:711
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:523
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:411
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:363
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:426
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:806
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:675
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:657
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:729
TriangleMaterialChunk triangleChunk(uint chunkIndex) const
Returns the triangle material chunk at the given index.
Definition mesh_render_data.h:183
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:461
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:864
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:377
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:446
void setMeshAdditionalData(const MeshConcept auto &)
Function that sets the mesh additional data from the mesh.
Definition mesh_render_data.h:943
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:752
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:392
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:788
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:846
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
A class representing a line segment in n-dimensional space. The class is parameterized by a PointConc...
Definition segment.h:41
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 triangleCount(uint polygonIndex) const
Returns the number of (consecutive index) triangles mapped to a polygon.
Definition tri_poly_index_bimap.h:113
uint polygonCount() const
Returns the number of polygons stored in the BiMap.
Definition tri_poly_index_bimap.h:195
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:1740
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:49
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 wireframeVertexIndicesToBuffer(const MeshType &mesh, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR, bool getIndicesAsIfContainerCompact=true, uint numRows=UINT_NULL)
Export into a buffer the vertex indices for each edge that composes the wireframe of the Mesh (i....
Definition export_buffer.h:510
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:365
void edgeVertexIndicesToBuffer(const MeshType &mesh, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR, bool getIndicesAsIfContainerCompact=true, uint numRows=UINT_NULL)
Export into a buffer the vertex indices for each edge of a Mesh.
Definition export_buffer.h:455
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:1679
void vertexPositionsToBuffer(const MeshType &mesh, auto *buffer, MatrixStorageType storage=MatrixStorageType::ROW_MAJOR, uint numRows=UINT_NULL)
Export the vertex positions of a mesh to a buffer.
Definition export_buffer.h:74
void vertexQuadIndicesToBuffer(const MeshType &mesh, auto *buffer)
Export the indices of a quad per vertex to a buffer.
Definition export_buffer.h:110
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 verticesToDuplicateByWedgeTexCoordsCount(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 faceVertexReferencesCount(const FaceMeshConcept auto &mesh)
Count the total number of vertex references in the mesh faces.
Definition topology.h:182
uint triangulatedFaceCount(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:84