From d4a3a5bc06fed666b09a2d3275b64c3dda2b65b8 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Wed, 26 May 2021 03:11:36 +0800 Subject: [PATCH] Weld vertices --- nel/tools/3d/shape2obj/main.cpp | 39 ++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/nel/tools/3d/shape2obj/main.cpp b/nel/tools/3d/shape2obj/main.cpp index fbfc713d4..6268a9aaa 100644 --- a/nel/tools/3d/shape2obj/main.cpp +++ b/nel/tools/3d/shape2obj/main.cpp @@ -591,8 +591,6 @@ bool ProcessMesh(const std::string &filename, IShape *shapeMesh) vector vertexToVSkin; vertexToVSkin.resize(vertexUsed.size()); shadowVertices.reserve(vertexUsed.size()); - // use a map to remove duplicates (because of UV/normal discontinuities before!!) - uint numMerged= 0; for(i=0;i weldedVerticesToId; + vector weldedVertices; + vector shadowToWelded; + weldedVertices.reserve(shadowVertices.size()); + shadowToWelded.resize(shadowVertices.size()); + + for (i = 0; i < shadowVertices.size(); ++i) + { + CVector v = shadowVertices[i].vertex; + map::iterator it = weldedVerticesToId.find(v); + if (it == weldedVerticesToId.end()) + { + weldedVerticesToId[v] = weldedVertices.size(); + shadowToWelded[i] = weldedVertices.size(); + weldedVertices.push_back(v); + } + else + { + shadowToWelded[i] = it->second; + } + } + + for(size_t y = 0; y < weldedVertices.size(); ++y) + { + CVector v = weldedVertices[y]; + ofs << "v " << v.x << " " << v.y << " " << v.z << endl; + } + for(size_t y = 0; y < shadowVertices.size(); ++y) { - CVector v = shadowVertices[y].vertex; CVector vn = shadowVertices[y].normal; CUV vt = shadowVertices[y].uv; - - ofs << "v " << v.x << " " << v.y << " " << v.z << endl; ofs << "vn " << vn.x << " " << vn.y << " " << vn.z << endl; ofs << "vt " << vt.U << " " << (1.0f - vt.V) << endl; } @@ -672,9 +695,9 @@ bool ProcessMesh(const std::string &filename, IShape *shapeMesh) for(size_t pass = 0; pass