#include "Json.h" #include "StandaloneCoreScheduler.h" #include "StandaloneSnapshotAdapter.h" #include "VoxelForgeCore/VoxelForgeCore.h" #include #include #include #include #include #include #include namespace { constexpr double CoreVoxelsPerMeter = 4.0; constexpr std::int64_t QPerCoreVoxel = VoxelForgeCore::WorldAssemblySubvoxelsPerVoxel; std::int64_t ToQ(double Meters) { return static_cast(std::llround(Meters*CoreVoxelsPerMeter*QPerCoreVoxel)); } void PrintLegacyBoundarySealTerms(const VoxelForgeCore::FloatingIslandManifestV1& Manifest, double X, double Y, double Z) { using namespace VoxelForgeCore; const auto Xq=ToQ(X),Yq=ToQ(Y),Zq=ToQ(Z); const FloatingIslandFieldV1 field(Manifest.recipe,Manifest.plan); const std::int64_t fieldQ=field.densitySubvoxels(Xq,Yq,Zq); const std::int64_t bottom=Manifest.recipe.layoutMinimumZSubvoxels; const std::int64_t top=Manifest.recipe.layoutMaximumZSubvoxels; const std::int64_t seal=Manifest.recipe.boundarySealSubvoxels; std::int64_t bridged=fieldQ; bool applied=false; if(Zq>=bottom&&Zq(1,Zq-bottom));applied=true;} if(Zq<=top&&Zq>top-seal) {bridged=std::min(bridged,-std::max(1,top-Zq));applied=true;} std::printf("[PreFixIslandTerms] xyz_m=%.3f,%.3f,%.3f native_field_q=%lld " "legacy_solid_seal_delta_q=%lld legacy_seal_active=%d pre_fix_wrapper_q=%lld\n", X,Y,Z,static_cast(fieldQ), static_cast(bridged-fieldQ),applied?1:0,static_cast(bridged)); for(const auto& island:Manifest.plan.islands) { const bool inBounds=Xq>=island.influenceMinimumSubvoxels[0] &&Xq<=island.influenceMaximumSubvoxels[0] &&Yq>=island.influenceMinimumSubvoxels[1] &&Yq<=island.influenceMaximumSubvoxels[1] &&Zq>=island.influenceMinimumSubvoxels[2] &&Zq<=island.influenceMaximumSubvoxels[2]; std::printf("[IslandGroup] ordinal=%u center_m=%.3f,%.3f,%.3f " "bounds_contains_sample=%d\n", island.ordinal,island.centerSubvoxels[0]/1024.0,island.centerSubvoxels[1]/1024.0, island.centerSubvoxels[2]/1024.0,inBounds?1:0); } for(const auto& edge:Manifest.plan.clusterEdges) { bool inBounds=true; const std::int64_t q[3]={Xq,Yq,Zq}; for(std::size_t axis=0;axis<3;++axis) inBounds=inBounds&&q[axis]>=edge.influenceMinimumSubvoxels[axis] &&q[axis]<=edge.influenceMaximumSubvoxels[axis]; std::printf("[IslandConnector] id=%016llx bounds_contains_sample=%d\n", static_cast(edge.stableId),inBounds?1:0); } } } void PrintDensityLine(VoxelForgeCore::World& World,const char* Label, double X,double Y,double ZMinimum,double ZMaximum,double Step) { using namespace VoxelForgeCore; std::printf("[DensityLine] label=%s xy_m=(%.6f,%.6f) z_m=%.2f..%.2f step_m=%.2f\n", Label,X,Y,ZMinimum,ZMaximum,Step); for(double Z=ZMinimum;Z<=ZMaximum+1.0e-9;Z+=Step) { const Vec3d Point{X*CoreVoxelsPerMeter,Y*CoreVoxelsPerMeter, Z*CoreVoxelsPerMeter}; const double Density=World.densityAt(Point); const double Unclamped=World.unclampedDensityAt(Point); const DetailFieldSample Detail=World.detailSampleAt(Point); std::printf("[DensitySample] label=%s xyz_m=%.3f,%.3f,%.3f density_core_vox=%.9f " "density_cm=%.3f unclamped_core_vox=%.9f cave_influence=%.6f " "floor_influence=%.6f detail_displacement=%.6f sign=%s\n",Label,X,Y,Z, Density,Density*25.0,Unclamped,Detail.caveInfluence,Detail.floorInfluence, Detail.displacement,Density<0.0?"solid":"air"); } } int main(int argc,char** argv) { if(argc!=2) { std::fprintf(stderr,"usage: %s owner-world-with-world-assembly.json\n",argv[0]); return 2; } VFJson::Value root; std::string error; if(!VFJson::Load(argv[1],root,error)) {std::fprintf(stderr,"owner JSON parse failed: %s\n",error.c_str());return 2;} auto snapshot=VoxelForgeCore::MakeStandaloneSnapshotFromParsedJson(root,0,3,8,false,false,error); if(!snapshot) {std::fprintf(stderr,"snapshot resolve failed: %s\n",error.c_str());return 2;} const auto* assembly=snapshot.worldAssembly(); if(!assembly||assembly->floatingIslands.empty()) {std::fprintf(stderr,"FloatingIslands manifest missing\n");return 2;} VoxelForgeCore::World world(std::move(snapshot)); VoxelForgeCore::ShapeBuildRequest request; request.minVoxel={-96,-512,-288}; request.maxVoxel={96,96,64}; request.clipMinVoxel=request.minVoxel; request.clipMaxVoxel=request.maxVoxel; request.workerLimit=12; request.includeFarWorld=false; FStandaloneCoreScheduler scheduler; if(!world.compile(request,scheduler,error)) {std::fprintf(stderr,"shape compile failed: %s\n",error.c_str());return 2;} constexpr double FlatX=-11.612443923950195; constexpr double FlatY=-118.22123718261719; constexpr double IslandX=-6.3; constexpr double IslandY=-19.057; constexpr double RingX=-4.889; constexpr double RingY=-16.008; std::printf("[DensityRoute] flat_square_xy_m=(%.6f,%.6f) island_ground_xy_m=(%.6f,%.6f) " "compiled=%d core_voxel_size_m=0.25 owner_to_core_chunk_voxels=16\n", FlatX,FlatY,IslandX,IslandY,world.isCompiled()?1:0); PrintDensityLine(world,"flat-square",FlatX,FlatY,2.5,9.0,0.25); PrintDensityLine(world,"fi-sw-boundary",FlatX,FlatY,-62.0,-58.0,0.25); PrintDensityLine(world,"island-center",IslandX,IslandY,-39.0,-20.0,0.5); PrintDensityLine(world,"lod0-lod1-ring-edge",RingX,RingY,-62.0,-20.0,1.0); const auto& island=assembly->floatingIslands.front().manifest; for(double z:{2.75,2.99,3.00,3.01,3.25,3.49,3.50,3.51,3.75,3.99,4.00,4.01,7.75,8.00,8.25}) PrintLegacyBoundarySealTerms(island,FlatX,FlatY,z); for(double z:{-35.0,-30.0,-25.0}) PrintLegacyBoundarySealTerms(island,IslandX,IslandY,z); for(double z:{-60.0,-35.0,-28.0,-25.0}) PrintLegacyBoundarySealTerms(island,RingX,RingY,z); return 0; }