mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-10 02:53:51 +00:00
refactor(editor): extract vertex weld into shared cli_weld utility
Three callers were each open-coding the same quantize-and-
bucket pass over vertex positions: --info-mesh-stats,
--info-wob-stats, and --bake-wom-collision. Move the
implementation to cli_weld.{hpp,cpp} as buildWeldMap() and
have each caller pass a flat positions array.
Identical std::map-based exact-equality keying preserved
(unbalanced-hash collisions remain absent). All three call
sites verified to produce byte-identical output:
• info-mesh-stats firepit: 240→80 verts, 0 boundary
• info-wob-stats cube: 8→8 verts, watertight YES
• bake-wom-collision tent: 18→6 verts, 8-tri WOC
About 75 lines of duplication removed; future weld-using
commands now opt in by including one header.
This commit is contained in:
parent
9031bdb620
commit
869124fa96
6 changed files with 107 additions and 76 deletions
39
tools/editor/cli_weld.cpp
Normal file
39
tools/editor/cli_weld.cpp
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#include "cli_weld.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <map>
|
||||
#include <tuple>
|
||||
|
||||
namespace wowee {
|
||||
namespace editor {
|
||||
namespace cli {
|
||||
|
||||
std::vector<uint32_t> buildWeldMap(
|
||||
const std::vector<glm::vec3>& positions,
|
||||
float eps,
|
||||
std::size_t& uniqueOut) {
|
||||
const float invEps = 1.0f / std::max(eps, 1e-9f);
|
||||
using QKey = std::tuple<int64_t, int64_t, int64_t>;
|
||||
std::map<QKey, uint32_t> bucket;
|
||||
std::vector<uint32_t> canon(positions.size());
|
||||
for (std::size_t v = 0; v < positions.size(); ++v) {
|
||||
const auto& p = positions[v];
|
||||
QKey k{static_cast<int64_t>(std::lround(p.x * invEps)),
|
||||
static_cast<int64_t>(std::lround(p.y * invEps)),
|
||||
static_cast<int64_t>(std::lround(p.z * invEps))};
|
||||
auto it = bucket.find(k);
|
||||
if (it == bucket.end()) {
|
||||
bucket.emplace(k, static_cast<uint32_t>(v));
|
||||
canon[v] = static_cast<uint32_t>(v);
|
||||
} else {
|
||||
canon[v] = it->second;
|
||||
}
|
||||
}
|
||||
uniqueOut = bucket.size();
|
||||
return canon;
|
||||
}
|
||||
|
||||
} // namespace cli
|
||||
} // namespace editor
|
||||
} // namespace wowee
|
||||
Loading…
Add table
Add a link
Reference in a new issue