Files
metin2-SDK/speedtree/tools/generation_baseline.cpp
T
shenandshen 66992b3024 Implement cross-platform SpeedTree runtime and recovery tests
Add bounded SPT parsing, authored branch frames and foliage generation, independent LOD meshes, billboards, collision metadata, and legacy CPU/shader wind support. Restore seeded sampling and special leaf selection with generation diagnostics and reproducible baseline tools.

Include regression coverage and static recovery documentation describing remaining differences from the original runtime. SDK tests pass (4/4); full corpus and client validation are recorded in the recovery notes.
2026-10-12 18:52:02 -07:00

72 lines
3.9 KiB
C++

#include "speedtree/speedtree.h"
#include <algorithm>
#include <bit>
#include <cmath>
#include <filesystem>
#include <iomanip>
#include <iostream>
#include <stdexcept>
// JSONL snapshots deliberately hash fields, never ABI padding or native structs.
static void word(uint64_t& hash,uint32_t value) {
for(int i=0;i<4;++i) {hash^=(value>>(8*i))&255;hash*=1099511628211ull;}
}
static void mesh(const speedtree::SpeedTreeMesh& m) {
uint64_t hash=14695981039346656037ull,pivots=hash;
for(const auto& v:m.vertices) {
for(float x:v.position) {
if(!std::isfinite(x)) throw std::runtime_error("nonfinite position");
word(hash,std::bit_cast<uint32_t>(x));
}
for(float x:v.normal) word(hash,std::bit_cast<uint32_t>(x));
for(float x:v.uv) word(hash,std::bit_cast<uint32_t>(x));
for(float x:v.leaf_pivot_offset) word(pivots,std::bit_cast<uint32_t>(x));
}
for(auto i:m.indices) {if(i>=m.vertices.size()) throw std::runtime_error("invalid index");word(hash,i);}
std::cout<<"{\"vertices\":"<<m.vertices.size()<<",\"triangles\":"<<m.indices.size()/3
<<",\"grids\":"<<m.grids.size()<<",\"geometry_hash\":"<<std::quoted(std::to_string(hash))
<<",\"pivot_hash\":"<<std::quoted(std::to_string(pivots))<<'}';
}
int main(int argc,char** argv) {
if(argc!=2) {std::cerr<<"usage: generation_baseline SPT_DIRECTORY\n";return 2;}
try {
const std::filesystem::path root=argv[1];std::vector<std::filesystem::path> paths;
for(const auto& f:std::filesystem::recursive_directory_iterator(root))
if(f.path().extension()==".spt") paths.push_back(f.path());
std::sort(paths.begin(),paths.end());
if(paths.empty()) throw std::runtime_error("empty corpus");
std::cout<<std::setprecision(9);
for(const auto& path:paths) {
auto m=speedtree::SpeedTreeModel::CreateFromSpt(path.string());
if(!m) throw std::runtime_error("load failed: "+path.string());
std::cout<<"{\"path\":"<<std::quoted(std::filesystem::relative(path,root).generic_string())
<<",\"seed\":"<<m->GetSptInfo().seed<<",\"levels\":"<<m->GetSptInfo().branch_levels.size()
<<",\"truncated\":"<<(m->WasGenerationTruncated()?"true":"false")
<<",\"metadata_complete\":"<<(m->GetSptInfo().metadata_complete?"true":"false")
<<",\"bounds\":[";
bool comma=false;
for(const auto& bounds:{m->GetBoundsMin(),m->GetBoundsMax()}) for(float x:bounds) {
if(!std::isfinite(x)) throw std::runtime_error("nonfinite bounds: "+path.string());
if(comma) std::cout<<',';comma=true;std::cout<<x;
}
const auto& stats=m->GetGenerationStats();
std::cout<<"],\"nodes_by_level\":[";
for(size_t i=0;i<stats.nodes_by_level.size();++i) {if(i)std::cout<<',';std::cout<<stats.nodes_by_level[i];}
std::cout<<"],\"terminal_leaf_calls\":"<<stats.terminal_leaf_calls
<<",\"special_leaf_cards\":"<<stats.special_leaf_cards
<<",\"limits\":{\"nodes\":"<<stats.node_limit<<",\"vertices\":"<<stats.vertex_limit
<<",\"density\":"<<stats.density_limit<<",\"tessellation\":"<<stats.tessellation_limit
<<"},\"branch_lods\":[";
for(uint32_t l=0;l<m->GetBranchLodCount();++l) {if(l)std::cout<<',';mesh(m->GetTrunkMesh(l));}
std::cout<<"],\"leaf_lods\":[";
for(uint32_t l=0;l<m->GetLeafLodCount();++l) {if(l)std::cout<<',';mesh(m->GetLeafMesh(l));}
std::cout<<"],\"frond_lods\":[";
for(uint32_t l=0;l<m->GetFrondLodCount();++l) {
if(l)std::cout<<',';std::cout<<'[';bool first=true;
for(const auto& f:m->GetFrondMeshes(l)) {if(!first)std::cout<<',';first=false;mesh(f);}std::cout<<']';
}
std::cout<<"]}\n";
}
} catch(const std::exception& e) {std::cerr<<e.what()<<'\n';return 1;}
}