Collect vertex source nodes
parent
34cc69f003
commit
5fd836bfdd
|
@ -56,10 +56,8 @@ struct ObjectNode {
|
||||||
|
|
||||||
class Object {
|
class Object {
|
||||||
public:
|
public:
|
||||||
//std::vector<ObjectNode> nodes;
|
|
||||||
//std::vector<std::pair<std::pair<Uuid, Uuid>, std::pair<Uuid, Uuid>>> edges;
|
|
||||||
std::vector<Vector3> vertices;
|
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>> triangleAndQuads;
|
||||||
std::vector<std::vector<size_t>> triangles;
|
std::vector<std::vector<size_t>> triangles;
|
||||||
std::unordered_map<Uuid, std::map<std::array<PositionKey, 3>, std::array<Vector2, 3>>> partTriangleUvs;
|
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] } });
|
{ 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);
|
componentCache.noneSeamVertices.insert(vertex);
|
||||||
collectSharedQuadEdges(partCache.vertices, partCache.faces, &componentCache.sharedQuadEdges);
|
collectSharedQuadEdges(partCache.vertices, partCache.faces, &componentCache.sharedQuadEdges);
|
||||||
componentCache.partTriangleUvs.insert({ Uuid(partIdString), partCache.triangleUvs });
|
componentCache.partTriangleUvs.insert({ Uuid(partIdString), partCache.triangleUvs });
|
||||||
for (const auto& it : partCache.objectNodes)
|
for (const auto& it : partCache.sourceNodeMap)
|
||||||
componentCache.objectNodes.push_back(it);
|
componentCache.sourceNodeMap.emplace(it);
|
||||||
for (const auto& it : partCache.objectEdges)
|
|
||||||
componentCache.objectEdges.push_back(it);
|
|
||||||
for (const auto& it : partCache.objectNodeVertices)
|
|
||||||
componentCache.objectNodeVertices.push_back(it);
|
|
||||||
}
|
}
|
||||||
if (!partCache.joined) {
|
if (!partCache.joined) {
|
||||||
if (mesh)
|
if (mesh)
|
||||||
|
@ -963,12 +963,8 @@ std::unique_ptr<MeshState> MeshGenerator::combineComponentChildGroupMesh(const s
|
||||||
componentCache.sharedQuadEdges.insert(it);
|
componentCache.sharedQuadEdges.insert(it);
|
||||||
for (const auto& it : childComponentCache.partTriangleUvs)
|
for (const auto& it : childComponentCache.partTriangleUvs)
|
||||||
componentCache.partTriangleUvs.insert({ it.first, it.second });
|
componentCache.partTriangleUvs.insert({ it.first, it.second });
|
||||||
for (const auto& it : childComponentCache.objectNodes)
|
for (const auto& it : childComponentCache.sourceNodeMap)
|
||||||
componentCache.objectNodes.push_back(it);
|
componentCache.sourceNodeMap.emplace(it);
|
||||||
for (const auto& it : childComponentCache.objectEdges)
|
|
||||||
componentCache.objectEdges.push_back(it);
|
|
||||||
for (const auto& it : childComponentCache.objectNodeVertices)
|
|
||||||
componentCache.objectNodeVertices.push_back(it);
|
|
||||||
|
|
||||||
if (nullptr == subMesh || subMesh->isNull()) {
|
if (nullptr == subMesh || subMesh->isNull()) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -1021,28 +1017,6 @@ void MeshGenerator::setWeldEnabled(bool enabled)
|
||||||
m_weldEnabled = 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)
|
void MeshGenerator::postprocessObject(Object* object)
|
||||||
{
|
{
|
||||||
std::vector<Vector3> combinedFacesNormals;
|
std::vector<Vector3> combinedFacesNormals;
|
||||||
|
@ -1055,22 +1029,7 @@ void MeshGenerator::postprocessObject(Object* object)
|
||||||
|
|
||||||
object->triangleNormals = combinedFacesNormals;
|
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());
|
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;
|
std::vector<std::vector<Vector3>> triangleVertexNormals;
|
||||||
smoothNormal(object->vertices,
|
smoothNormal(object->vertices,
|
||||||
|
@ -1116,11 +1075,6 @@ void MeshGenerator::collectUncombinedComponent(const std::string& componentIdStr
|
||||||
if (nullptr == componentCache.mesh || componentCache.mesh->isNull()) {
|
if (nullptr == componentCache.mesh || componentCache.mesh->isNull()) {
|
||||||
return;
|
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);
|
collectIncombinableMesh(componentCache.mesh.get(), componentCache);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1293,10 +1247,8 @@ void MeshGenerator::generate()
|
||||||
|
|
||||||
const auto& componentCache = m_cacheContext->components[to_string(Uuid())];
|
const auto& componentCache = m_cacheContext->components[to_string(Uuid())];
|
||||||
|
|
||||||
//m_object->nodes = componentCache.objectNodes;
|
m_object->sourceNodeMap = componentCache.sourceNodeMap;
|
||||||
//m_object->edges = componentCache.objectEdges;
|
|
||||||
m_object->partTriangleUvs = componentCache.partTriangleUvs;
|
m_object->partTriangleUvs = componentCache.partTriangleUvs;
|
||||||
m_nodeVertices = componentCache.objectNodeVertices;
|
|
||||||
|
|
||||||
std::vector<Vector3> combinedVertices;
|
std::vector<Vector3> combinedVertices;
|
||||||
std::vector<std::vector<size_t>> combinedFaces;
|
std::vector<std::vector<size_t>> combinedFaces;
|
||||||
|
@ -1325,7 +1277,6 @@ void MeshGenerator::generate()
|
||||||
// Recursively check uncombined components
|
// Recursively check uncombined components
|
||||||
collectUncombinedComponent(to_string(Uuid()));
|
collectUncombinedComponent(to_string(Uuid()));
|
||||||
|
|
||||||
collectErroredParts();
|
|
||||||
postprocessObject(m_object);
|
postprocessObject(m_object);
|
||||||
|
|
||||||
if (needDeleteCacheContext) {
|
if (needDeleteCacheContext) {
|
||||||
|
|
|
@ -44,11 +44,9 @@ public:
|
||||||
|
|
||||||
struct GeneratedPart {
|
struct GeneratedPart {
|
||||||
std::vector<Vector3> vertices;
|
std::vector<Vector3> vertices;
|
||||||
|
std::map<PositionKey, Uuid> sourceNodeMap;
|
||||||
std::vector<std::vector<size_t>> faces;
|
std::vector<std::vector<size_t>> faces;
|
||||||
std::map<std::array<PositionKey, 3>, std::array<Vector2, 3>> triangleUvs;
|
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);
|
Color color = Color(1.0, 1.0, 1.0);
|
||||||
float metalness = 0.0;
|
float metalness = 0.0;
|
||||||
float roughness = 1.0;
|
float roughness = 1.0;
|
||||||
|
@ -59,9 +57,7 @@ public:
|
||||||
vertices.clear();
|
vertices.clear();
|
||||||
faces.clear();
|
faces.clear();
|
||||||
triangleUvs.clear();
|
triangleUvs.clear();
|
||||||
objectNodes.clear();
|
sourceNodeMap.clear();
|
||||||
objectEdges.clear();
|
|
||||||
objectNodeVertices.clear();
|
|
||||||
color = Color(1.0, 1.0, 1.0);
|
color = Color(1.0, 1.0, 1.0);
|
||||||
metalness = 0.0;
|
metalness = 0.0;
|
||||||
roughness = 1.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::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::vector<std::map<std::array<PositionKey, 3>, std::array<Vector2, 3>>> seamTriangleUvs;
|
||||||
std::set<PositionKey> noneSeamVertices;
|
std::set<PositionKey> noneSeamVertices;
|
||||||
std::vector<ObjectNode> objectNodes;
|
std::map<PositionKey, Uuid> sourceNodeMap;
|
||||||
std::vector<std::pair<std::pair<Uuid, Uuid>, std::pair<Uuid, Uuid>>> objectEdges;
|
|
||||||
std::vector<std::pair<Vector3, std::pair<Uuid, Uuid>>> objectNodeVertices;
|
|
||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
mesh.reset();
|
mesh.reset();
|
||||||
|
@ -86,9 +80,7 @@ public:
|
||||||
partTriangleUvs.clear();
|
partTriangleUvs.clear();
|
||||||
seamTriangleUvs.clear();
|
seamTriangleUvs.clear();
|
||||||
noneSeamVertices.clear();
|
noneSeamVertices.clear();
|
||||||
objectNodes.clear();
|
sourceNodeMap.clear();
|
||||||
objectEdges.clear();
|
|
||||||
objectNodeVertices.clear();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -137,7 +129,6 @@ private:
|
||||||
float m_mainProfileMiddleX = 0;
|
float m_mainProfileMiddleX = 0;
|
||||||
float m_sideProfileMiddleX = 0;
|
float m_sideProfileMiddleX = 0;
|
||||||
float m_mainProfileMiddleY = 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_partNodeIds;
|
||||||
std::map<std::string, std::set<std::string>> m_partEdgeIds;
|
std::map<std::string, std::set<std::string>> m_partEdgeIds;
|
||||||
bool m_isSuccessful = false;
|
bool m_isSuccessful = false;
|
||||||
|
@ -172,7 +163,6 @@ private:
|
||||||
void collectUncombinedComponent(const std::string& componentIdString);
|
void collectUncombinedComponent(const std::string& componentIdString);
|
||||||
void cutFaceStringToCutTemplate(const std::string& cutFaceString, std::vector<Vector2>& cutTemplate);
|
void cutFaceStringToCutTemplate(const std::string& cutFaceString, std::vector<Vector2>& cutTemplate);
|
||||||
void postprocessObject(Object* object);
|
void postprocessObject(Object* object);
|
||||||
void collectErroredParts();
|
|
||||||
void preprocessMirror();
|
void preprocessMirror();
|
||||||
std::string reverseUuid(const std::string& uuidString);
|
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);
|
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