#include "vde/sdf/sdf_primitives.h" #include "vde/sdf/sdf_operations.h" #include "vde/sdf/sdf_to_mesh.h" #include "vde/brep/modeling.h" #include "vde/mesh/marching_cubes.h" #include "vde/mesh/halfedge_mesh.h" #include "vde/foundation/io_gltf.h" #include #include int main() { // ── Pipeline 1: SDF → Mesh → GLB ── std::cout << "Pipeline 1: SDF → Mesh → GLB\n"; // Build SDF expression: smooth union of sphere and box auto sphere_sdf = [](const vde::core::Point3D& p) { return vde::sdf::sphere(p, 1.5); }; auto combined = [&](double x, double y, double z) -> double { vde::core::Point3D p(x, y, z); double d_sphere = sphere_sdf(p); double d_box = vde::sdf::box(p, vde::core::Point3D(1.0, 1.0, 1.0)); return vde::sdf::op_smooth_union(d_sphere, d_box, 0.3); }; // Marching cubes → MCMesh double iso = 0.0; vde::core::Point3D bmin(-3.0, -3.0, -3.0); vde::core::Point3D bmax(3.0, 3.0, 3.0); int resolution = 64; auto mc_result = vde::mesh::marching_cubes(combined, iso, bmin, bmax, resolution); // Build HalfedgeMesh from marching cubes result vde::mesh::HalfedgeMesh sdf_mesh; sdf_mesh.build_from_triangles(mc_result.vertices, mc_result.triangles); // Export vde::foundation::GltfOptions opt; opt.binary = true; opt.include_normals = true; std::string sdf_out = "output_sdf_shape.glb"; if (vde::foundation::write_gltf(sdf_out, sdf_mesh, opt)) { std::cout << " → " << sdf_out << " written (" << sdf_mesh.num_vertices() << " vertices, " << sdf_mesh.num_faces() << " faces)\n"; } else { std::cerr << " ✗ Failed to write " << sdf_out << "\n"; } // ── Pipeline 2: B-Rep → Tessellate → GLB ── std::cout << "\nPipeline 2: B-Rep → Tessellate → GLB\n"; auto box_b = vde::brep::make_box(2.0, 2.0, 2.0); auto shelled = vde::brep::shell(box_b, -1, 0.15); // closed shell, 0.15 thickness std::string brep_out = "output_brep_shell.glb"; if (vde::foundation::write_brep_gltf(brep_out, shelled, 32)) { std::cout << " → " << brep_out << " written\n"; } else { std::cerr << " ✗ Failed to write " << brep_out << "\n"; } std::cout << "\nDone! Open .glb files in any 3D viewer.\n"; return 0; }