Collect vertex source nodes
parent
34cc69f003
commit
5fd836bfdd
|
@ -56,10 +56,8 @@ struct ObjectNode {
|
|||
|
||||
class Object {
|
||||
public:
|
||||
//std::vector<ObjectNode> nodes;
|
||||
//std::vector<std::pair<std::pair<Uuid, Uuid>, std::pair<Uuid, Uuid>>> edges;
|
||||
std::vector<Vector3> vertices;
|
||||
std::vector<std::pair<Uuid, Uuid>> vertexSourceNodes;
|
||||
std::map<PositionKey, Uuid> sourceNodeMap;
|
||||
std::vector<std::vector<size_t>> triangleAndQuads;
|
||||
std::vector<std::vector<size_t>> triangles;
|
||||
std::unordered_map<Uuid, std::map<std::array<PositionKey, 3>, std::array<Vector2, 3>>> partTriangleUvs;
|
||||
|
|
|
@ -682,6 +682,10 @@ std::unique_ptr<MeshState> MeshGenerator::combinePartMesh(const std::string& par
|
|||
{ uv[2], uv[3], uv[0] } });
|
||||
}
|
||||
}
|
||||
const auto& vertexSources = tubeMeshBuilder->generatedVertexSources();
|
||||
for (size_t i = 0; i < vertexSources.size(); ++i) {
|
||||
partCache.sourceNodeMap.emplace(std::make_pair(PositionKey(partCache.vertices[i]), vertexSources[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -824,12 +828,8 @@ std::unique_ptr<MeshState> MeshGenerator::combineComponentMesh(const std::string
|
|||
componentCache.noneSeamVertices.insert(vertex);
|
||||
collectSharedQuadEdges(partCache.vertices, partCache.faces, &componentCache.sharedQuadEdges);
|
||||
componentCache.partTriangleUvs.insert({ Uuid(partIdString), partCache.triangleUvs });
|
||||
for (const auto& it : partCache.objectNodes)
|
||||
componentCache.objectNodes.push_back(it);
|
||||
for (const auto& it : partCache.objectEdges)
|
||||
componentCache.objectEdges.push_back(it);
|
||||
for (const auto& it : partCache.objectNodeVertices)
|
||||
componentCache.objectNodeVertices.push_back(it);
|
||||
for (const auto& it : partCache.sourceNodeMap)
|
||||
componentCache.sourceNodeMap.emplace(it);
|
||||
}
|
||||
if (!partCache.joined) {
|
||||
if (mesh)
|
||||
|
@ -963,12 +963,8 @@ std::unique_ptr<MeshState> MeshGenerator::combineComponentChildGroupMesh(const s
|
|||
componentCache.sharedQuadEdges.insert(it);
|
||||
for (const auto& it : childComponentCache.partTriangleUvs)
|
||||
componentCache.partTriangleUvs.insert({ it.first, it.second });
|
||||
for (const auto& it : childComponentCache.objectNodes)
|
||||
componentCache.objectNodes.push_back(it);
|
||||
for (const auto& it : childComponentCache.objectEdges)
|
||||
componentCache.objectEdges.push_back(it);
|
||||
for (const auto& it : childComponentCache.objectNodeVertices)
|
||||
componentCache.objectNodeVertices.push_back(it);
|
||||
for (const auto& it : childComponentCache.sourceNodeMap)
|
||||
componentCache.sourceNodeMap.emplace(it);
|
||||
|
||||
if (nullptr == subMesh || subMesh->isNull()) {
|
||||
continue;
|
||||
|
@ -1021,28 +1017,6 @@ void MeshGenerator::setWeldEnabled(bool enabled)
|
|||
m_weldEnabled = enabled;
|
||||
}
|
||||
|
||||
void MeshGenerator::collectErroredParts()
|
||||
{
|
||||
for (const auto& it : m_cacheContext->parts) {
|
||||
if (!it.second.isSuccessful) {
|
||||
if (!it.second.joined)
|
||||
continue;
|
||||
|
||||
auto updateVertexIndices = [=](std::vector<std::vector<size_t>>& faces, size_t vertexStartIndex) {
|
||||
for (auto& it : faces) {
|
||||
for (auto& subIt : it)
|
||||
subIt += vertexStartIndex;
|
||||
}
|
||||
};
|
||||
|
||||
auto errorTriangleAndQuads = it.second.faces;
|
||||
updateVertexIndices(errorTriangleAndQuads, m_object->vertices.size());
|
||||
m_object->vertices.insert(m_object->vertices.end(), it.second.vertices.begin(), it.second.vertices.end());
|
||||
m_object->triangleAndQuads.insert(m_object->triangleAndQuads.end(), errorTriangleAndQuads.begin(), errorTriangleAndQuads.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MeshGenerator::postprocessObject(Object* object)
|
||||
{
|
||||
std::vector<Vector3> combinedFacesNormals;
|
||||
|
@ -1055,22 +1029,7 @@ void MeshGenerator::postprocessObject(Object* object)
|
|||
|
||||
object->triangleNormals = combinedFacesNormals;
|
||||
|
||||
//std::vector<std::pair<Uuid, Uuid>> sourceNodes;
|
||||
//resolveTriangleSourceNode(*object, m_nodeVertices, sourceNodes, &object->vertexSourceNodes);
|
||||
//object->setTriangleSourceNodes(sourceNodes);
|
||||
|
||||
//std::map<std::pair<Uuid, Uuid>, Color> sourceNodeToColorMap;
|
||||
//for (const auto& node : object->nodes)
|
||||
// sourceNodeToColorMap.insert({ { node.partId, node.nodeId }, node.color });
|
||||
|
||||
object->triangleColors.resize(object->triangles.size(), Color::createWhite());
|
||||
//const std::vector<std::pair<Uuid, Uuid>>* triangleSourceNodes = object->triangleSourceNodes();
|
||||
//if (nullptr != triangleSourceNodes) {
|
||||
//for (size_t triangleIndex = 0; triangleIndex < object->triangles.size(); triangleIndex++) {
|
||||
//const auto& source = (*triangleSourceNodes)[triangleIndex];
|
||||
//object->triangleColors[triangleIndex] = sourceNodeToColorMap[source];
|
||||
//}
|
||||
//}
|
||||
|
||||
std::vector<std::vector<Vector3>> triangleVertexNormals;
|
||||
smoothNormal(object->vertices,
|
||||
|
@ -1116,11 +1075,6 @@ void MeshGenerator::collectUncombinedComponent(const std::string& componentIdStr
|
|||
if (nullptr == componentCache.mesh || componentCache.mesh->isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//m_object->nodes.insert(m_object->nodes.end(), componentCache.objectNodes.begin(), componentCache.objectNodes.end());
|
||||
//m_object->edges.insert(m_object->edges.end(), componentCache.objectEdges.begin(), componentCache.objectEdges.end());
|
||||
m_nodeVertices.insert(m_nodeVertices.end(), componentCache.objectNodeVertices.begin(), componentCache.objectNodeVertices.end());
|
||||
|
||||
collectIncombinableMesh(componentCache.mesh.get(), componentCache);
|
||||
return;
|
||||
}
|
||||
|
@ -1293,10 +1247,8 @@ void MeshGenerator::generate()
|
|||
|
||||
const auto& componentCache = m_cacheContext->components[to_string(Uuid())];
|
||||
|
||||
//m_object->nodes = componentCache.objectNodes;
|
||||
//m_object->edges = componentCache.objectEdges;
|
||||
m_object->sourceNodeMap = componentCache.sourceNodeMap;
|
||||
m_object->partTriangleUvs = componentCache.partTriangleUvs;
|
||||
m_nodeVertices = componentCache.objectNodeVertices;
|
||||
|
||||
std::vector<Vector3> combinedVertices;
|
||||
std::vector<std::vector<size_t>> combinedFaces;
|
||||
|
@ -1325,7 +1277,6 @@ void MeshGenerator::generate()
|
|||
// Recursively check uncombined components
|
||||
collectUncombinedComponent(to_string(Uuid()));
|
||||
|
||||
collectErroredParts();
|
||||
postprocessObject(m_object);
|
||||
|
||||
if (needDeleteCacheContext) {
|
||||
|
|
|
@ -44,11 +44,9 @@ public:
|
|||
|
||||
struct GeneratedPart {
|
||||
std::vector<Vector3> vertices;
|
||||
std::map<PositionKey, Uuid> sourceNodeMap;
|
||||
std::vector<std::vector<size_t>> faces;
|
||||
std::map<std::array<PositionKey, 3>, std::array<Vector2, 3>> triangleUvs;
|
||||
std::vector<ObjectNode> objectNodes;
|
||||
std::vector<std::pair<std::pair<Uuid, Uuid>, std::pair<Uuid, Uuid>>> objectEdges;
|
||||
std::vector<std::pair<Vector3, std::pair<Uuid, Uuid>>> objectNodeVertices;
|
||||
Color color = Color(1.0, 1.0, 1.0);
|
||||
float metalness = 0.0;
|
||||
float roughness = 1.0;
|
||||
|
@ -59,9 +57,7 @@ public:
|
|||
vertices.clear();
|
||||
faces.clear();
|
||||
triangleUvs.clear();
|
||||
objectNodes.clear();
|
||||
objectEdges.clear();
|
||||
objectNodeVertices.clear();
|
||||
sourceNodeMap.clear();
|
||||
color = Color(1.0, 1.0, 1.0);
|
||||
metalness = 0.0;
|
||||
roughness = 1.0;
|
||||
|
@ -76,9 +72,7 @@ public:
|
|||
std::unordered_map<Uuid, std::map<std::array<PositionKey, 3>, std::array<Vector2, 3>>> partTriangleUvs;
|
||||
std::vector<std::map<std::array<PositionKey, 3>, std::array<Vector2, 3>>> seamTriangleUvs;
|
||||
std::set<PositionKey> noneSeamVertices;
|
||||
std::vector<ObjectNode> objectNodes;
|
||||
std::vector<std::pair<std::pair<Uuid, Uuid>, std::pair<Uuid, Uuid>>> objectEdges;
|
||||
std::vector<std::pair<Vector3, std::pair<Uuid, Uuid>>> objectNodeVertices;
|
||||
std::map<PositionKey, Uuid> sourceNodeMap;
|
||||
void reset()
|
||||
{
|
||||
mesh.reset();
|
||||
|
@ -86,9 +80,7 @@ public:
|
|||
partTriangleUvs.clear();
|
||||
seamTriangleUvs.clear();
|
||||
noneSeamVertices.clear();
|
||||
objectNodes.clear();
|
||||
objectEdges.clear();
|
||||
objectNodeVertices.clear();
|
||||
sourceNodeMap.clear();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -137,7 +129,6 @@ private:
|
|||
float m_mainProfileMiddleX = 0;
|
||||
float m_sideProfileMiddleX = 0;
|
||||
float m_mainProfileMiddleY = 0;
|
||||
std::vector<std::pair<Vector3, std::pair<Uuid, Uuid>>> m_nodeVertices;
|
||||
std::map<std::string, std::set<std::string>> m_partNodeIds;
|
||||
std::map<std::string, std::set<std::string>> m_partEdgeIds;
|
||||
bool m_isSuccessful = false;
|
||||
|
@ -172,7 +163,6 @@ private:
|
|||
void collectUncombinedComponent(const std::string& componentIdString);
|
||||
void cutFaceStringToCutTemplate(const std::string& cutFaceString, std::vector<Vector2>& cutTemplate);
|
||||
void postprocessObject(Object* object);
|
||||
void collectErroredParts();
|
||||
void preprocessMirror();
|
||||
std::string reverseUuid(const std::string& uuidString);
|
||||
void recoverQuads(const std::vector<Vector3>& vertices, const std::vector<std::vector<size_t>>& triangles, const std::set<std::pair<PositionKey, PositionKey>>& sharedQuadEdges, std::vector<std::vector<size_t>>& triangleAndQuads);
|
||||
|
|
Loading…
Reference in New Issue