Something went wrong. Try again.
Builds CAD models from 3d scan data
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162// mesh.hpp — STL/OBJ loading, per-vertex normals, and spatial region queries.#pragma once#include <cstdint>#include <string>#include <vector>
#include "geom.hpp"
namespace mesh {
struct Mesh { std::vector<geom::Vec3> verts; std::vector<std::array<int, 3>> tris; std::vector<geom::Vec3> vnormals; // per-vertex, area-weighted
// Lazily built by the discovery engine: std::vector<std::vector<int>> adj; // vertex adjacency (1-ring, deduped) std::vector<float> curv; // per-vertex surface variation [0..1/3]
geom::Vec3 bbMin, bbMax;
bool empty() const { return verts.empty() || tris.empty(); } void computeNormals(); void computeBounds(); void buildAdjacency(); // fills adj void computeCurvature(); // fills curv (builds adj if needed) double bboxDiag() const;};
// Load from a file path. Format inferred from extension (.stl / .obj), with a// content sniff fallback. Returns false on failure and fills `err`.bool load(const std::string& path, Mesh& out, std::string& err);
// Load from an in-memory buffer (format hinted by `ext`, e.g. "stl"/"obj").bool loadFromMemory(const std::string& data, const std::string& ext, Mesh& out, std::string& err);
// Load only points from an in-memory buffer — accepts face-less files (raw// scanner point clouds, typically PLY). Faces, if present, are ignored.bool loadPointsFromMemory(const std::string& data, const std::string& ext, std::vector<geom::Vec3>& pts, std::string& err);
// Indices of vertices within `radius` of `center`.std::vector<int> verticesInRadius(const Mesh& m, const geom::Vec3& center, double radius);
// Global winding polarity from the signed volume: +1 if triangle winding (and thus// the vertex normals) faces outward, -1 if the mesh is inside-out, 0 if it is too// open/flat for the volume test to mean anything.int windingOrientation(const Mesh& m);
// Write a binary STL of only the triangles whose centroid lies within [lo,hi] (a crop// box). Returns the number of triangles written (0 => nothing in the box / write fail).int writeSTLRegion(const std::string& path, const Mesh& m, const geom::Vec3& lo, const geom::Vec3& hi);
// Binary STL in memory, for HTTP responses. The indexed overload writes only the// selected triangle ids and preserves their original winding.std::string binarySTL(const Mesh& m);std::string binarySTL(const Mesh& m, const std::vector<int>& triangleIds);
} // namespace mesh