feat: GLTF/GLB export with normals + B-Rep tessellation + pipeline example
CI / Build & Test (push) Failing after 32s
CI / Release Build (push) Failing after 31s

This commit is contained in:
茂之钳
2026-07-24 09:06:12 +00:00
parent b3269b4f09
commit 40440fcc3e
8 changed files with 521 additions and 29 deletions
+2
View File
@@ -0,0 +1,2 @@
add_executable(pipeline_demo main.cpp)
target_link_libraries(pipeline_demo PRIVATE vde)
+68
View File
@@ -0,0 +1,68 @@
#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 <iostream>
#include <cmath>
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;
}