fix(v1.0.1): VDE-011/012/013 — write_stl return bool, StlTrianglef, module options
VDE-011 (Medium): write_stl / write_stl_ascii return bool - Return false on file open failure, true on success VDE-012 (Low): StlTrianglef for float precision - New StlTrianglef struct with Vector3F/Point3F - to_stl_trianglef() / from_stl_trianglef() conversions VDE-013 (Medium): Per-module build options - VDE_BUILD_CURVES/MESH/BREP/SPATIAL/BOOLEAN/COLLISION/SKETCH/SDF/CAPI - All default ON, parent project can set OFF
This commit is contained in:
@@ -115,8 +115,9 @@ std::vector<StlTriangle> read_stl(const std::string& filepath) {
|
||||
return read_stl_binary(filepath);
|
||||
}
|
||||
|
||||
void write_stl(const std::string& filepath, const std::vector<StlTriangle>& tris) {
|
||||
bool write_stl(const std::string& filepath, const std::vector<StlTriangle>& tris) {
|
||||
std::ofstream file(filepath, std::ios::binary);
|
||||
if (!file) return false;
|
||||
char header[80] = {};
|
||||
file.write(header, 80);
|
||||
uint32_t count = static_cast<uint32_t>(tris.size());
|
||||
@@ -129,10 +130,12 @@ void write_stl(const std::string& filepath, const std::vector<StlTriangle>& tris
|
||||
uint16_t attr = 0;
|
||||
file.write(reinterpret_cast<const char*>(&attr), 2);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void write_stl_ascii(const std::string& filepath, const std::vector<StlTriangle>& tris) {
|
||||
bool write_stl_ascii(const std::string& filepath, const std::vector<StlTriangle>& tris) {
|
||||
std::ofstream file(filepath);
|
||||
if (!file) return false;
|
||||
file.precision(12);
|
||||
file << "solid vde\n";
|
||||
for (const auto& tri : tris) {
|
||||
@@ -146,6 +149,14 @@ void write_stl_ascii(const std::string& filepath, const std::vector<StlTriangle>
|
||||
file << " endfacet\n";
|
||||
}
|
||||
file << "endsolid vde\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
StlTrianglef to_stl_trianglef(const StlTriangle& t) {
|
||||
return {t.normal.cast<float>(), t.v0.cast<float>(), t.v1.cast<float>(), t.v2.cast<float>()};
|
||||
}
|
||||
StlTriangle from_stl_trianglef(const StlTrianglef& t) {
|
||||
return {t.normal.cast<double>(), t.v0.cast<double>(), t.v1.cast<double>(), t.v2.cast<double>()};
|
||||
}
|
||||
|
||||
} // namespace vde::foundation
|
||||
|
||||
Reference in New Issue
Block a user