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.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare generation_baseline JSONL snapshots by relative asset path."""
|
||||
import argparse
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def read(path):
|
||||
rows = [json.loads(line) for line in Path(path).read_text().splitlines()]
|
||||
result = {row["path"]: row for row in rows}
|
||||
if len(rows) != len(result):
|
||||
raise ValueError(f"duplicate paths in {path}")
|
||||
return result
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("before")
|
||||
parser.add_argument("after")
|
||||
args = parser.parse_args()
|
||||
before, after = read(args.before), read(args.after)
|
||||
if before.keys() != after.keys():
|
||||
raise ValueError("sample inventories differ; compare the same corpus root")
|
||||
report = {
|
||||
"samples": len(before),
|
||||
"truncated_before": sum(row["truncated"] for row in before.values()),
|
||||
"truncated_after": sum(row["truncated"] for row in after.values()),
|
||||
"remaining_truncated": [path for path, row in after.items() if row["truncated"]],
|
||||
"new_truncation": [path for path, row in after.items()
|
||||
if row["truncated"] and not before[path]["truncated"]],
|
||||
"geometry_changed": [path for path, row in after.items()
|
||||
if any(row[key] != before[path][key]
|
||||
for key in ("branch_lods", "leaf_lods", "frond_lods"))],
|
||||
"bounds_changed": [path for path, row in after.items()
|
||||
if row["bounds"] != before[path]["bounds"]],
|
||||
}
|
||||
print(json.dumps(report, indent=2, ensure_ascii=False))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,71 @@
|
||||
#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;}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"corpus_root": "AVA2/1. Client DEV/pack_maker",
|
||||
"samples": [
|
||||
{
|
||||
"path": "Tree/ymir work/tree/n2_cinnamonfern_rt_01.spt",
|
||||
"seed": 392987,
|
||||
"sha256": "93ded82028c0f2e97d0403ec045b89bbc1ac859ad8b84a2e1930e0503907b354"
|
||||
},
|
||||
{
|
||||
"path": "Tree/ymir work/tree/wom/ot/treeenglishoakunique01su.spt",
|
||||
"seed": 645082,
|
||||
"sha256": "60c9f3957f8abbf2c38f7b996f5e60e6acdff2693724da86f69968c722a6b3cf"
|
||||
},
|
||||
{
|
||||
"path": "Tree/ymir work/tree/wom/ot/treewhitepinefree.spt",
|
||||
"seed": 777362,
|
||||
"sha256": "e1b2d68db476935cb95e45ba74ae7838d31c9ede6b88d70135365a35c5b383b8"
|
||||
},
|
||||
{
|
||||
"path": "Tree/ymir work/tree/b3_umbrellathorn_rt_flowers4.spt",
|
||||
"seed": 724878,
|
||||
"sha256": "44ec99e53b3158a6619ec7a5cb4110bfb67ff9943224b068a8bc99fa1d92c0d0"
|
||||
}
|
||||
],
|
||||
"synthetic_seeds": [
|
||||
17,
|
||||
18,
|
||||
20
|
||||
],
|
||||
"note": "Fixed source assets and seed-variation fixtures; snapshots are SDK baselines, not original DLL outputs."
|
||||
}
|
||||
Reference in New Issue
Block a user