#include "speedtree/speedtree.h" #include "speedtree/foliage_shaders.h" #include #include #include #include #include #include #include #include using namespace speedtree; void check(bool v,const char* message) { if(!v) throw std::runtime_error(message); } bool close(float a,float b) { return std::abs(a-b)<0.002f; } struct Stream { std::vector data; void u(uint32_t v) { for(int i=0;i<4;++i)data.push_back(uint8_t(v>>(i*8))); } void f(float v) { u(std::bit_cast(v)); } void s(const std::string& s) { u(uint32_t(s.size()));data.insert(data.end(),s.begin(),s.end()); } }; Stream authored(uint32_t seed,float radius,float density=-1,uint32_t levels=2) { Stream b;b.u(1000);b.s("__IdvSpt_02_");b.u(1002); b.u(2005);b.u(seed);b.u(2006);b.f(1000);b.u(2007);b.f(30); b.u(1014);b.u(levels); for(uint32_t level=0;level=0) { b.u(6010);b.f(0.3f);b.u(6011);b.f(1);b.u(6012);b.f(density); } b.u(1017); } b.u(1015);b.u(1003);b.u(1001);return b; } void frondTests() { auto make=[](uint32_t type,bool enabled,float scale) { auto b=authored(17,0.04f); b.u(13000);b.u(13002);b.u(1);b.u(13003);b.u(type); b.u(13004);b.u(3);b.u(13006);b.u(4);b.u(13007);b.data.push_back(enabled); b.u(13005);b.s("BezierSpline 0 0.25 0 { 2 0 0 1 1 0.2 1 1 1 1 0.2 }"); b.u(13008);b.u(1);b.u(14000);b.u(14002);b.s("D:/textures/frond.tga"); b.u(14003);b.f(0.5f);b.u(14004);b.f(scale); b.u(14005);b.f(0);b.u(14006);b.f(0);b.u(14001);b.u(13001); return b; }; for(uint32_t type:{0u,1u}) { auto bytes=make(type,true,1); auto model=SpeedTreeModel::CreateFromMemory(bytes.data.data(),bytes.data.size(),"grass"); check(model && !model->GetFrondMeshes().empty(),"fronds not generated"); check(!model->IsGrassOrShrub(),"filename heuristic suppressed authored fronds"); check(model->GetLeafMesh().vertices.empty(),"frond limbs also generated leaf cards"); const auto& mesh=model->GetFrondMeshes()[0]; check(!mesh.vertices.empty() && mesh.texture=="frond.dds" && mesh.alpha_test && mesh.is_double_sided,"frond material lost"); check(mesh.vertices.size()==size_t(type==0?8*3*5*2:8*5*7),"frond cross-section topology"); WindParameters wind;wind.strength=0;std::vector positions,normals; model->EvaluateCpuTransformedVertices(mesh,positions,normals,0,0,0,0,1,wind); for(size_t i=0;iGetFrondMeshes().empty() && !off->GetLeafMesh().vertices.empty(),"disabled fronds changed tree"); auto wider=make(type,true,2); auto big=SpeedTreeModel::CreateFromMemory(wider.data.data(),wider.data.size()); auto span=[type](const SpeedTreeMesh& m) { float sum=0;for(int axis=0;axis<3;++axis) { float d=m.vertices[0].position[axis]-m.vertices[type==0?1:6].position[axis];sum+=d*d; }return std::sqrt(sum); }; check(close(span(big->GetFrondMeshes()[0]),2*span(mesh)),"frond size scale ignored"); } } void leafTests() { auto bytes=authored(17,0.04f);bytes.data.resize(bytes.data.size()-4); bytes.u(1004);bytes.u(1009);bytes.u(1006);bytes.u(1);bytes.u(1007); bytes.u(4003);bytes.s("D:/trees/leaf.tga"); bytes.u(4004);bytes.f(0.25f);bytes.f(0.75f);bytes.f(0); bytes.u(4005);bytes.f(0.1f);bytes.f(0.2f);bytes.f(0.3f); bytes.u(4006);bytes.f(80);bytes.f(120);bytes.f(0); bytes.u(1008);bytes.u(1010);bytes.u(1005);bytes.u(1001); auto model=SpeedTreeModel::CreateFromMemory(bytes.data.data(),bytes.data.size(),"grass",1000,0); check(model && !model->GetLeafMesh().vertices.empty(),"authored leaves missing"); check(model->GetSptInfo().leaves[0].dimensions[0]==80 && model->GetSptInfo().leaves[0].placement[2]==0.3f,"leaf metadata lost"); const auto& mesh=model->GetLeafMesh(); const auto& vertex=mesh.vertices[0]; check(vertex.authored_leaf_card && close(vertex.leaf_pivot_offset[1],30),"leaf pivot not applied"); check(mesh.vertices.size()==8*4,"terminal path must emit one card per attachment"); check(model->GetTrunkMesh().grids.size()==1 && model->GetGenerationStats().terminal_leaf_calls==8, "terminal leaves incorrectly emitted branch tubes"); WindParameters wind;wind.strength=0;std::vector positions,normals; model->EvaluateCpuTransformedVertices(mesh,positions,normals,0,0,0,0,1,wind); for(size_t i=0;i camera{0,0,4000}; model->EvaluateCpuTransformedVertices(mesh,positions,normals,0,0,0,90,2,wind,&camera); for(size_t i=0;i{1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1}}; model->EvaluateCpuTransformedVertices(mesh,positions,normals,0,0,0,0,1,wind); for(size_t i=0;i<4;++i) { const auto& v=mesh.vertices[i]; float phase=wind.legacy_leaf_phase*model->GetSptInfo().leaf_rocking_frequency+v.leaf_rocking_phase; float angle=180*model->GetSptInfo().leaf_rocking_range*wind.strength*std::sin(phase); auto expected=OrientLeafOffset({v.leaf_pivot_offset[0],v.leaf_pivot_offset[1],v.leaf_pivot_offset[2]},0,0,angle); for(size_t axis=0;axis<3;++axis) check(close(positions[i*3+axis],v.position[axis]-v.leaf_pivot_offset[axis]+expected[axis]),"legacy grouped leaf rocking"); check(v.leaf_rocking_phase==vertex.leaf_rocking_phase,"card corners have different rocking phase"); } auto scaled=SpeedTreeModel::CreateFromMemory(bytes.data.data(),bytes.data.size(),"tree",2000,0); check(close(scaled->GetLeafMesh().vertices[0].leaf_pivot_offset[1],60),"property size ignored for leaf dimensions"); auto dense=authored(17,0.04f,25000,2);dense.data.resize(dense.data.size()-4); dense.data.insert(dense.data.end(),bytes.data.begin()+authored(17,0.04f).data.size()-4,bytes.data.end()); auto full=SpeedTreeModel::CreateFromMemory(dense.data.data(),dense.data.size(),"dense",1000,0); check(full && !full->WasGenerationTruncated() && full->GetLeafMesh().vertices.size()==70000, "terminal cards limited by node/16-bit budget"); check(full->GetGenerationStats().nodes_by_level[0]==1 && full->GetGenerationStats().nodes_by_level[1]==0, "terminal cards counted as branch nodes"); // Regression for umbrella-thorn: active fronds do not turn terminal leaves // into complete branch/frond nodes, even with more cards than the node guard. dense.u(13000);dense.u(13002);dense.u(0);dense.u(13003);dense.u(0); dense.u(13004);dense.u(1);dense.u(13007);dense.data.push_back(1);dense.u(13001); auto flowering=SpeedTreeModel::CreateFromMemory(dense.data.data(),dense.data.size(),"frondFlowers",1000,0); check(flowering && !flowering->WasGenerationTruncated(),"frond terminal leaves hit branch budget"); check(flowering->GetTrunkMesh().vertices.empty() && !flowering->GetFrondMeshes().empty() && flowering->GetFrondMeshes()[0].vertices.size()==10,"frond terminal path emitted extra fronds"); check(flowering->GetLeafMesh().vertices.size()==70000 && flowering->GetGenerationStats().terminal_leaf_calls==17500 && flowering->GetGenerationStats().nodes_by_level[1]==0,"frond lost terminal flowers"); } void lodTests() { auto bytes=authored(17,0.04f); bytes.u(9000);bytes.u(9005);bytes.u(9007);bytes.u(3);bytes.u(9011);bytes.u(3);bytes.u(9006); bytes.u(9009);bytes.f(0.25f);bytes.u(9001); auto model=SpeedTreeModel::CreateFromMemory(bytes.data.data(),bytes.data.size()); check(model && model->GetBranchLodCount()==3 && model->GetLeafLodCount()==3,"independent LOD count"); size_t branches=model->GetTrunkMesh().indices.size(),leaves=model->GetLeafMesh().vertices.size(); for(uint32_t level=1;level<3;++level) { const auto& trunk=model->GetTrunkMesh(level);const auto& leaf=model->GetLeafMesh(level); check(trunk.indices.size()indices) check(indexvertices.size(),"LOD index outside mesh"); for(const auto& grid:trunk.grids) for(uint32_t row=0;rowGetLeafMesh(2).indices==same->GetLeafMesh(2).indices,"LOD selection nondeterministic"); auto frond=authored(17,0.04f);frond.u(13000);frond.u(13007);frond.data.push_back(1); frond.u(13003);frond.u(0);frond.u(13009);frond.u(3);frond.u(13001); model=SpeedTreeModel::CreateFromMemory(frond.data.data(),frond.data.size()); check(model->GetFrondLodCount()==3 && !model->GetFrondMeshes().empty(),"frond LOD missing"); check(model->GetFrondMeshes(2)[0].indices.size()GetFrondMeshes()[0].indices.size(),"frond not reduced"); auto distributed=authored(17,0.04f,10,3); model=SpeedTreeModel::CreateFromMemory(distributed.data.data(),distributed.data.size(),"tree",1000,0); check(model->GetTrunkMesh().grids.size()==36,"authored branch density ignored"); auto grid=model->GetTrunkMesh().grids[1];float y=0; for(uint32_t column=0;column+1GetTrunkMesh().vertices[grid.first+column].position[1]; check(close(y/float(grid.columns-1),700*SampleBranchAttachment(17,0,0.3f,1)),"child seed/attachment interpolation not used"); for(uint32_t child=0;child<20;++child) { float t=SampleBranchAttachment(17,child,0.3f,1); check(t>=0.3f && t<=1,"attachment outside authored range"); if(child==0) check(t>=0.895f && t<=0.965f,"first attachment upper interval"); check(t==SampleBranchAttachment(17,child,0.3f,1),"indexed branch sample unstable"); float azimuth=SampleBranchAzimuth(17+3*(child+1)); check(azimuth>=-kPI && azimuth<=kPI && azimuth==SampleBranchAzimuth(17+3*(child+1)),"branch azimuth bounds/reproducibility"); } } void frameAndSpecialLeafTests() { BranchFrame identity; auto axis=identity.Rotate(kPI/2,0,kPI/2).SdkAxis(2); check(close(axis[0],0)&&close(axis[1],0)&&close(axis[2],1),"source frame axes/rotation order"); auto parent=identity.Rotate(0,0,kPI/2); auto inherited=parent.Rotate(0,0,kPI/2).SdkAxis(2); check(close(inherited[0],0)&&close(inherited[1],-1),"frame not inherited"); auto down=parent.ApplyGravity(1,0).SdkAxis(2); auto up=parent.ApplyGravity(1,1).SdkAxis(2); check(close(down[1],-1)&&close(up[1],1),"gravity rotation direction"); check(identity.ApplyGravity(1,0).basis==identity.basis,"vertical gravity singularity"); BranchFrame frame; for(int i=0;i<1024;++i) frame=frame.Rotate(0,0.003f,-0.005f); for(size_t i=0;i<3;++i) for(size_t j=0;j<3;++j) { float dot=0;for(size_t k=0;k<3;++k)dot+=frame.basis[i][k]*frame.basis[j][k]; check(close(dot,i==j?1:0),"frame lost orthogonality"); } auto perturbTree=[](float variance) { auto bytes=authored(17,0.04f,0,2);Stream extra,marker;marker.u(1017); extra.u(6000);extra.s("BezierSpline 0 0 "+std::to_string(variance)+" { 2 0 1 1 0 0.1 1 1 1 0 0.1 }"); auto end=std::search(bytes.data.begin(),bytes.data.end(),marker.data.begin(),marker.data.end()); check(end!=bytes.data.end(),"perturb fixture missing branch end"); bytes.data.insert(end,extra.data.begin(),extra.data.end()); return SpeedTreeModel::CreateFromMemory(bytes.data.data(),bytes.data.size(),"perturb",1000,0); }; auto straight=perturbTree(0),bent=perturbTree(20),repeat=perturbTree(20); check(straight && bent && repeat,"frame perturb generator failed"); auto endpoint=[](const SpeedTreeMesh& mesh) { const auto grid=mesh.grids.front();std::array center{}; for(uint32_t c=0;c+1GetTrunkMesh()),700),"zero perturb changed centerline length"); check(endpoint(bent->GetTrunkMesh())<699,"perturb sampled but not applied to geometry"); for(size_t i=0;iGetTrunkMesh().vertices.size();++i) for(size_t axis=0;axis<3;++axis) check(bent->GetTrunkMesh().vertices[i].position[axis]==repeat->GetTrunkMesh().vertices[i].position[axis],"frame perturb not deterministic"); auto powered=authored(17,0.04f,10,3); powered.u(16000); for(int level=0;level<3;++level) { powered.u(16002);powered.f(2);powered.u(16003);powered.u(0); for(uint32_t t=16004;t<=16012;++t){powered.u(t);powered.f(0);} } powered.u(16001); auto curvedSpacing=SpeedTreeModel::CreateFromMemory(powered.data.data(),powered.data.size(),"spacing",1000,0); check(curvedSpacing && curvedSpacing->GetSptInfo().branch_levels[0].length_exponent==2,"axial exponent skipped"); const auto& spacing=curvedSpacing->GetTrunkMesh();const auto rootGrid=spacing.grids[0]; float firstY=0;for(uint32_t c=0;c+1WasGenerationTruncated(),"valid zero exponent rejected"); const auto& collapsedMesh=collapsed->GetTrunkMesh(); float collapsedY=0;for(uint32_t c=0;c+1{-1,0,1},std::array{1,0,1},std::array{0.1f,1,1}}) { auto bytes=make(args[0],uint32_t(args[1]),args[2]); auto model=SpeedTreeModel::CreateFromMemory(bytes.data.data(),bytes.data.size(),"special",1000,0); bool special=args[0]<0; check(model && model->GetLeafMesh().vertices.size()==32,"special leaf pool generated wrong count"); check(model->GetGenerationStats().special_leaf_cards==(special?8:0),"special card statistics"); check(model->GetSptInfo().special_leaves.ancestor_depth==uint32_t(args[1]) && model->GetSptInfo().special_leaves.minimum_position==args[0],"special metadata skipped"); for(const auto& v:model->GetLeafMesh().vertices)check(v.diffuse==(special?0xff00ff00:0xff0000ff),"wrong special variant/color selected"); } } void generationRecoveryTests() { // Independent integer/shuffle oracle for the recovered entry draw sequence. // Constant curves still consume variance draws, even when variance is zero. BranchLevel level; for(size_t i:{1u,2u,4u,5u,7u}) { check(BranchSpline::Parse("BezierSpline 0.2 0.2 0.1 { 2 0 1 1 0 0.1 1 1 1 0 0.1 }",level.curves[i]),"entry fixture"); } uint32_t state=20;std::array table{}; auto next=[&]() {state=uint32_t(uint64_t(state)*16807%2147483647);return double(state)/2147483648.0;}; for(auto& x:table)x=float(next()); auto draw=[&](float low,float high) {size_t index=size_t(next()*128);float x=table[index];table[index]=float(next());return low+(high-low)*x;}; LegacyRandom random(20);random.Uniform(0,100);draw(0,100); auto sample=SampleBranchEntry(level,0.4f,1000,random); check(close(sample.length,(0.2f+draw(-0.1f,0.1f))*1000),"entry length draw order"); check(close(sample.azimuth,draw(-180,180)*kPI/180),"entry azimuth draw order"); check(close(sample.angle,(0.2f+draw(-0.1f,0.1f))*kPI/180),"entry angle draw order"); check(close(sample.gravity,0.2f+draw(-0.1f,0.1f)),"entry gravity draw order"); check(close(sample.radius,(0.2f+draw(-0.1f,0.1f))*1000),"entry radius draw order"); check(close(sample.flexibility,0.2f+draw(-0.1f,0.1f)),"entry flexibility draw order"); check(random.Uniform()==draw(0,1),"entry trailing stream differs"); auto missing=level;missing.curves[4]={}; LegacyRandom noLength(20),expected(20);expected.Uniform(-180,180); SampleBranchEntry(missing,0.4f,1000,noLength); for(int i=0;i<4;++i)expected.Uniform(); check(noLength.Uniform()==expected.Uniform(),"absent curve consumed a draw"); BranchSpline perturb; check(BranchSpline::Parse("BezierSpline 100 200 3 { 2 0 0 1 1 0.2 1 1 1 1 0.2 }",perturb),"perturb fixture"); LegacyRandom perturbRandom(8),perturbExpected(8); check(close(perturb.EvaluatePerturbation(0.5f,perturbRandom),perturbExpected.Uniform(-perturb.samples[250]*3,perturb.samples[250]*3)),"perturb uses min/max or interpolation"); auto bytes=authored(17,0.04f,4000,2); auto large=SpeedTreeModel::CreateFromMemory(bytes.data.data(),bytes.data.size(),"large",1000,0); check(large && !large->WasGenerationTruncated(),"ordinary high density clipped"); check(large->GetTrunkMesh().vertices.size()>65535,"32 bit trunk still clipped"); check(large->GetTrunkMesh().grids.size()==2801,"density or node count still capped at 128/256"); for(uint32_t index:large->GetTrunkMesh().indices)check(indexGetTrunkMesh().vertices.size(),"large index out of range"); const auto& stats=large->GetGenerationStats(); check(stats.nodes_by_level[0]==1 && stats.nodes_by_level[1]==2800,"branch hierarchy stats wrong"); auto again=SpeedTreeModel::CreateFromMemory(bytes.data.data(),bytes.data.size(),"large",1000,0); check(large->GetTrunkMesh().indices==again->GetTrunkMesh().indices,"large tree scheduling unstable"); for(size_t i=0;iGetTrunkMesh().vertices.size();++i) for(int axis=0;axis<3;++axis) check(large->GetTrunkMesh().vertices[i].position[axis]==again->GetTrunkMesh().vertices[i].position[axis],"large tree positions unstable"); auto zero=authored(17,0.04f,0,2); std::string constant="0.700000",replacement="0.000000"; auto where=std::search(zero.data.begin(),zero.data.end(),constant.begin(),constant.end()); check(where!=zero.data.end(),"zero fixture length missing"); while(where!=zero.data.end()) { std::copy(replacement.begin(),replacement.end(),where); where=std::search(zero.data.begin(),zero.data.end(),constant.begin(),constant.end()); } zero.u(13000);zero.u(13002);zero.u(0);zero.u(13003);zero.u(0); zero.u(13007);zero.data.push_back(1);zero.u(13001); auto empty=SpeedTreeModel::CreateFromMemory(zero.data.data(),zero.data.size(),"empty",1000,0); check(empty && empty->GetTrunkMesh().vertices.empty(),"empty frond emitted geometry"); for(float x:empty->GetBoundsMin())check(std::isfinite(x),"empty model bounds infinite"); for(float x:empty->GetBoundsMax())check(std::isfinite(x),"empty model bounds infinite"); auto hostile=authored(17,0.04f,1e8f,2); auto bounded=SpeedTreeModel::CreateFromMemory(hostile.data.data(),hostile.data.size(),"bounded",1000,0); check(bounded && bounded->WasGenerationTruncated() && bounded->GetGenerationStats().node_limit && bounded->GetGenerationStats().density_limit,"allocation guard not reported"); size_t nodes=0;for(auto n:bounded->GetGenerationStats().nodes_by_level)nodes+=n; check(nodes==GenerationStats::max_nodes,"node allocation guard exceeded"); } void tests() { BranchSpline spline; check(BranchSpline::Parse("BezierSpline 2 6 0 { 2 0 0 1 1 0.2 1 1 1 1 0.2 }",spline),"spline rejected"); check(close(spline.Evaluate(0),2)&&close(spline.Evaluate(0.5f),3.996f)&&close(spline.Evaluate(1),6),"Bezier evaluation"); check(!BranchSpline::Parse("BezierSpline 0 1 0 { 4294967295 }",spline),"unbounded curve count"); check(BranchSpline::Parse("BezierSpline 1 1 -0.1 { 2 0 1 1 0 0.1 1 1 1 0 0.1 }",spline),"signed authored variance rejected"); LegacyRandom random(1),again(1),different(2); bool differs=false; for(int i=0;i<100;++i) { float v=random.Uniform();check(v>=0&&v<1&&v==again.Uniform(),"seed reproducibility");differs|=v!=different.Uniform(); } check(differs,"seeds ignored"); auto bytes=authored(17,0.04f),other=authored(18,0.04f),thick=authored(17,0.08f); auto a=SpeedTreeModel::CreateFromMemory(bytes.data.data(),bytes.data.size(),"pine"); auto b=SpeedTreeModel::CreateFromMemory(bytes.data.data(),bytes.data.size(),"beech"); auto variant=SpeedTreeModel::CreateFromMemory(other.data.data(),other.data.size()); auto bigger=SpeedTreeModel::CreateFromMemory(thick.data.data(),thick.data.size()); check(a&&b&&variant&&bigger,"authored generator failed"); const auto& mesh=a->GetTrunkMesh(); check(mesh.vertices.size()>100&&mesh.indices.size()>500,"limbs not generated"); check(mesh.vertices.size()==b->GetTrunkMesh().vertices.size(),"name changed authored topology"); for(size_t i=0;iGetTrunkMesh().vertices[i].position[j],"name changed authored shape"); check(a->GetHeight()!=variant->GetHeight(),"seed/size variance ignored"); auto exact=SpeedTreeModel::CreateFromMemory(bytes.data.data(),bytes.data.size(),"tree",1200,0); auto varied=SpeedTreeModel::CreateFromMemory(bytes.data.data(),bytes.data.size(),"tree",1200,50); check(exact->GetHeight()==1200 && varied->GetHeight()!=1200,"property size/variance ignored"); check(std::hypot(mesh.vertices[0].position[0],mesh.vertices[0].position[2])GetTrunkMesh().vertices[0].position[0],bigger->GetTrunkMesh().vertices[0].position[2]),"radius curve ignored"); WindParameters wind;wind.strength=0;wind.time=1.3f; std::vector p,n; a->EvaluateCpuTransformedVertices(a->GetLeafMesh(),p,n,0,0,0,0,1,wind); for(size_t i=0;iGetLeafMesh().vertices[i/3].position[i%3]),"zero wind moved foliage"); // Full matrix weight and inverse-transpose normal against a known affine map. SpeedTreeMesh sample;sample.vertices.resize(1);sample.vertices[0].position[0]=2; sample.vertices[0].position[1]=3;sample.vertices[0].position[2]=4; sample.vertices[0].normal[0]=1;sample.vertices[0].wind_weights[0]=0.5f; std::array matrix{2,0,0,0, 0,1,0,0, 0,0,1,0, 10,0,0,1}; wind.matrices={matrix}; a->EvaluateCpuTransformedVertices(sample,p,n,0,0,0,0,1,wind); check(close(p[0],8)&&close(p[1],3)&&close(p[2],4)&&close(n[0],1),"weighted matrix transform"); sample.vertices[0].normal[1]=1; a->EvaluateCpuTransformedVertices(sample,p,n,0,0,0,0,1,wind); check(close(1.5f*n[0]-n[1],0),"normal not perpendicular to transformed tangent"); sample.vertices[0].wind_weights[0]=0; a->EvaluateCpuTransformedVertices(sample,p,n,0,0,0,0,1,wind); check(close(p[0],2),"zero-weight anchor moved"); wind.matrices.clear();wind.strength=1;wind.time=0.7f; sample.vertices[0].wind_weights[0]=1; sample.vertices[0].position[0]=0;sample.vertices[0].position[2]=0; a->EvaluateCpuTransformedVertices(sample,p,n,0,0,0,0,1,wind); auto upright=p; a->EvaluateCpuTransformedVertices(sample,p,n,0,0,0,90,1,wind); for(int i=0;i<3;++i)check(close(p[i],upright[i]),"instance yaw rotated world wind direction"); sample.vertices[0].position[0]=2;sample.vertices[0].position[2]=4; sample.vertices[0].wind_weights[0]=0; // A complete leaf card uses a rigid local rock followed by one shared matrix weight. wind.matrices.clear();wind.strength=1;wind.gust_strength=0; const auto& leaves=a->GetLeafMesh(); a->EvaluateCpuTransformedVertices(leaves,p,n,0,0,0,0,1,wind); auto distance=[&](const float* x,const float* y) { return std::hypot(std::hypot(x[0]-y[0],x[1]-y[1]),x[2]-y[2]); }; // Blending identity and a rotation induces bounded contraction; card edges // still share one affine transform, so opposite edges remain equal. check(close(distance(p.data(),p.data()+3),distance(p.data()+9,p.data()+6)),"card corners use different rocking angles"); for(size_t i=0;i{}.data()),1),"deformed normal not normalized"); wind.strength=0;wind.matrices.clear(); a->EvaluateCpuTransformedVertices(sample,p,n,10,20,30,90,2,wind); check(close(p[0],18)&&close(p[1],26)&&close(p[2],26),"instance scale/yaw/translation order"); } int main(int argc,char** argv) { try { tests(); frameAndSpecialLeafTests(); generationRecoveryTests(); frondTests(); leafTests(); lodTests(); if(argc==3&&std::string(argv[1])=="--shaders") { std::filesystem::create_directories(argv[2]); std::ofstream(std::filesystem::path(argv[2])/"foliage.vert")<WasGenerationTruncated()) ++truncated; if(!model->GetLeafMesh().vertices.empty() && model->GetLeafMesh().vertices[0].authored_leaf_card) ++authoredLeaves; auto quads=model->BuildBillboardMeshes({1000,2000,4000}); if(!quads.empty()) ++billboards; for(const auto& quad:quads) { check(quad.vertices.size()==4 && quad.indices.size()==6,"invalid corpus billboard topology"); for(const auto& vertex:quad.vertices) { for(float value:vertex.position) check(std::isfinite(value),"non-finite billboard position"); for(float value:vertex.uv) check(std::isfinite(value),"non-finite billboard UV"); } } std::vector meshes{&model->GetTrunkMesh(),&model->GetLeafMesh()}; bool hasFronds=false; for(const auto& mesh:model->GetFrondMeshes()) { meshes.push_back(&mesh);hasFronds|=!mesh.vertices.empty(); } if(hasFronds) ++fronds; for(uint32_t level=1;levelGetBranchLodCount();++level) meshes.push_back(&model->GetTrunkMesh(level)); for(uint32_t level=1;levelGetLeafLodCount();++level) meshes.push_back(&model->GetLeafMesh(level)); for(uint32_t level=1;levelGetFrondLodCount();++level) for(const auto& mesh:model->GetFrondMeshes(level)) meshes.push_back(&mesh); for(const auto* mesh:meshes) { check(mesh->vertices.size()<=GenerationStats::max_vertices,"mesh budget exceeded"); for(const auto& v:mesh->vertices) for(int j=0;j<3;++j) check(std::isfinite(v.position[j])&&std::isfinite(v.normal[j]),"non-finite corpus geometry"); for(uint32_t index:mesh->indices)check(indexvertices.size(),"mesh index out of range"); WindParameters wind;wind.time=2.5f;std::vector p,n; model->EvaluateCpuTransformedVertices(*mesh,p,n,0,0,0,45,1,wind); for(float value:p)check(std::isfinite(value),"non-finite wind deformation"); LegacyWindController controller;controller.Update(2.5f,0.2f); wind.strength=0.2f;wind.matrices=controller.GetMatrices(); wind.legacy_leaf_rocking=true;wind.legacy_leaf_phase=controller.GetLeafPhase(); std::array camera{3000,2000,4000}; model->EvaluateCpuTransformedVertices(*mesh,p,n,100,200,300,45,2,wind,&camera); for(float value:p)check(std::isfinite(value),"non-finite native wind/camera deformation"); for(float value:n)check(std::isfinite(value),"non-finite native wind/camera normal"); } } check(count>0,"empty corpus");std::cout<<"Generated and deformed "<