43 std::shared_ptr<std::unordered_map<
unsigned int, std::vector<std::weak_ptr<ChunkBuilder>>>>
45 : m_originalMesh(originalMesh), m_vertexUse(vertexUse)
56 std::array<VertexHandle, 3> vertices =
m_originalMesh->getVerticesOfFace(faceHandle);
59 for (
unsigned int i = 0; i < 3; i++)
61 std::weak_ptr<ChunkBuilder> thisBuilderPtr(shared_from_this());
66 m_vertexUse->insert({vertices[i].idx(), std::vector<std::weak_ptr<ChunkBuilder>>()});
68 if (std::find_if(
m_vertexUse->at(vertices[i].idx()).begin(),
70 [&thisBuilderPtr](
const std::weak_ptr<ChunkBuilder>& otherBuilderPtr) {
71 return thisBuilderPtr.lock() == otherBuilderPtr.lock();
75 m_vertexUse->at(vertices[i].idx()).push_back(shared_from_this());
81 for (
unsigned int j = 0; j < 2; j++)
83 m_vertexUse->at(vertices[i].idx())[j].lock()->addDuplicateVertex(vertices[i]);
86 else if (
m_vertexUse->at(vertices[i].idx()).size() > 2)
88 m_vertexUse->at(vertices[i].idx()).back().lock()->addDuplicateVertex(vertices[i]);
115 std::shared_ptr<std::unordered_map<unsigned int, unsigned int>> splitVertices,
116 std::shared_ptr<std::unordered_map<unsigned int, unsigned int>> splitFaces)
const 118 std::unordered_map<unsigned int, unsigned int> vertexIndices;
127 std::vector<std::string> vertexChannelUChar;
128 std::vector<std::string> vertexChannelUInt;
129 std::vector<std::string> vertexChannelFloat;
130 std::vector<std::string> faceChannelUChar;
131 std::vector<std::string> faceChannelUInt;
132 std::vector<std::string> faceChannelFloat;
135 for (
auto elem : *attributedMesh)
137 if(elem.first !=
"vertices" && elem.first !=
"face_indices")
139 if(elem.second.is_type<
unsigned char>())
141 if(elem.second.numElements() == attributedMesh->numVertices())
143 mesh->addEmptyUCharChannel(elem.first,
numVertices(), elem.second.width());
144 vertexChannelUChar.push_back(elem.first);
146 else if(elem.second.numElements() == attributedMesh->numFaces())
148 mesh->addEmptyUCharChannel(elem.first,
numFaces(), elem.second.width());
149 faceChannelUChar.push_back(elem.first);
154 mesh->addUCharChannel(std::make_shared<
158 else if(elem.second.is_type<
unsigned int>())
160 if(elem.second.numElements() == attributedMesh->numVertices())
162 mesh->addEmptyIndexChannel(elem.first,
numVertices(), elem.second.width());
163 vertexChannelUInt.push_back(elem.first);
165 else if(elem.second.numElements() == attributedMesh->numFaces())
167 mesh->addEmptyIndexChannel(elem.first,
numFaces(), elem.second.width());
168 faceChannelUInt.push_back(elem.first);
173 mesh->addIndexChannel(std::make_shared<
177 else if(elem.second.is_type<
float>())
179 if(elem.second.numElements() == attributedMesh->numVertices())
181 mesh->addEmptyFloatChannel(elem.first,
numVertices(), elem.second.width());
182 vertexChannelFloat.push_back(elem.first);
184 else if(elem.second.numElements() == attributedMesh->numFaces())
186 mesh->addEmptyFloatChannel(elem.first,
numFaces(), elem.second.width());
187 faceChannelFloat.push_back(elem.first);
192 mesh->addFloatChannel(std::make_shared<
209 if (vertexIndices.find(vertex.idx()) == vertexIndices.end())
211 unsigned int vertexIndex = vertexIndices.size();
212 vertexIndices[
static_cast<unsigned int>(vertex.idx())] = vertexIndex;
215 for (uint8_t j = 0; j < 3; j++)
217 vertices[vertexIndex * 3 + j] =
m_originalMesh->getVertexPosition(vertex)[j];
221 unsigned int attributedVertexIndex = vertex.idx();
222 if (splitVertices->find(attributedVertexIndex) != splitVertices->end())
224 attributedVertexIndex = splitVertices->at(attributedVertexIndex);
229 for(
const std::string& name : vertexChannelUChar)
232 for(
size_t component = 0; component < tmp.
width(); component++)
236 = attributedMesh->getUCharHandle(attributedVertexIndex, name)[component];
243 for(
const std::string& name : vertexChannelUInt)
246 for(
size_t component = 0; component < tmp.
width(); component++)
249 = attributedMesh->getIndexHandle(attributedVertexIndex, name)[component];
252 for(
const std::string& name : vertexChannelFloat)
256 for(
size_t component = 0; component < tmp.
width(); component++)
259 = attributedMesh->getFloatHandle(attributedVertexIndex, name)[component];
266 for (
unsigned int face = 0; face <
m_faces.size(); face++)
268 for (uint8_t faceVertex = 0; faceVertex < 3; faceVertex++)
270 if (vertexIndices.find(
272 == vertexIndices.end())
274 unsigned int vertexIndex = vertexIndices.size();
275 vertexIndices[
static_cast<unsigned int>(
280 for (uint8_t vertexComponent = 0; vertexComponent < 3; vertexComponent++)
282 vertices[vertexIndex * 3 + vertexComponent]
284 m_faces[face])[faceVertex])[vertexComponent];
288 unsigned int attributedVertexIndex
290 if (splitVertices->find(attributedVertexIndex) != splitVertices->end())
292 attributedVertexIndex = splitVertices->at(attributedVertexIndex);
296 for(
const std::string& name : vertexChannelUChar)
299 for(
size_t component = 0; component < tmp.
width(); component++)
302 = attributedMesh->getUCharHandle(attributedVertexIndex, name)[component];
309 for(
const std::string& name : vertexChannelUInt)
312 for(
size_t component = 0; component < tmp.
width(); component++)
315 = attributedMesh->getIndexHandle(attributedVertexIndex, name)[component];
318 for(
const std::string& name : vertexChannelFloat)
322 for(
size_t component = 0; component < tmp.
width(); component++)
324 mesh->getFloatHandle(vertexIndex, name)[component]
325 = attributedMesh->getFloatHandle(attributedVertexIndex, name)[component];
331 faceIndices[face * 3 + faceVertex] = vertexIndices[
static_cast<unsigned int>(
336 unsigned int attributedFaceIndex =
m_faces[face].idx();
337 if (splitVertices->find(attributedFaceIndex) != splitVertices->end())
339 attributedFaceIndex = splitVertices->at(attributedFaceIndex);
343 for(
const std::string& name : faceChannelUChar)
346 for(
size_t component = 0; component < tmp.
width(); component++)
349 = attributedMesh->getUCharHandle(attributedFaceIndex, name)[component];
356 for(
const std::string& name : faceChannelUInt)
359 for(
size_t component = 0; component < tmp.
width(); component++)
362 = attributedMesh->getIndexHandle(attributedFaceIndex, name)[component];
365 for(
const std::string& name : faceChannelFloat)
369 for(
size_t component = 0; component < tmp.
width(); component++)
371 mesh->getFloatHandle(face, name)[component]
372 = attributedMesh->getFloatHandle(attributedFaceIndex, name)[component];
379 mesh->setFaceIndices(faceIndices,
numFaces());
381 mesh->addAtomic<
unsigned int>(m_duplicateVertices.size(),
"num_duplicates");
std::vector< VertexHandle > m_duplicateVertices
Handle to access vertices of the mesh.
unsigned int numVertices() const
numVertices amount of vertices ot the resulting mesh
std::shared_ptr< std::unordered_map< unsigned int, std::vector< std::weak_ptr< ChunkBuilder > > > > m_vertexUse
std::shared_ptr< MeshBuffer > MeshBufferPtr
const DataPtr dataPtr() const
void addDuplicateVertex(const VertexHandle &index)
addDuplicateVertex marks a vertex as duplicate
boost::shared_array< unsigned int > indexArray
boost::shared_array< float > floatArr
Half-edge data structure implementing the BaseMesh interface.
void addFace(const FaceHandle &index)
assigns a face to the chunk this builder is generating
MeshBufferPtr buildMesh(MeshBufferPtr attributedMesh, std::shared_ptr< std::unordered_map< unsigned int, unsigned int >> splitVertices, std::shared_ptr< std::unordered_map< unsigned int, unsigned int >> splitFaces) const
buildMesh builds a chunk by generating a new mesh buffer
std::shared_ptr< HalfEdgeMesh< BaseVector< float > > > m_originalMesh
std::vector< FaceHandle > m_faces
The MeshBuffer Mesh representation for I/O modules.
unsigned int m_numVertices
ChunkBuilder(std::shared_ptr< HalfEdgeMesh< BaseVector< float >>> originalMesh, std::shared_ptr< std::unordered_map< unsigned int, std::vector< std::weak_ptr< ChunkBuilder >>>> vertexUse)
ChunkBuilder constructs a chun builder that can create individual chunks.
unsigned int numFaces() const
numFaces delivers the number of faces for the chunk
Handle to access faces of the mesh.