From e635c3a5bf2d17a237b20a8a9af14663fbd490d7 Mon Sep 17 00:00:00 2001 From: Nik Date: Mon, 20 Feb 2023 11:35:15 +0100 Subject: [PATCH] patterns/stl: Added 3D model visualization --- patterns/stl.hexpat | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/patterns/stl.hexpat b/patterns/stl.hexpat index ed2941b..bbc02b9 100644 --- a/patterns/stl.hexpat +++ b/patterns/stl.hexpat @@ -5,34 +5,47 @@ #include #include +#include struct Vector3f { - float x, y, z; + float x, y, z; } [[static, format("format_vector3f")]]; fn format_vector3f(Vector3f vec) { - return std::format("[ {}, {}, {} ]", vec.x, vec.y, vec.z); + return std::format("[ {}, {}, {} ]", vec.x, vec.y, vec.z); }; struct Triangle { - Vector3f normal; - Vector3f points[3]; - u16 flags; + Vector3f normal; + Vector3f points[3]; + u16 flags; } [[static]]; struct BinarySTLHeader { - char caption[]; - padding[80 - sizeof(caption)]; - u32 triangleCount; + char caption[while($[$] != 0x00 && $ - addressof(this) < 80)]; + padding[80 - sizeof(caption)]; + u32 triangleCount; }; -struct STL { - if (std::mem::read_string(0, 6) == "solid ") - std::warning("ASCII STL file!"); - else { - BinarySTLHeader header; - Triangle triangles[header.triangleCount]; - } +struct STL { + if (std::mem::read_string(0, 6) == "solid ") + std::warning("ASCII STL file!"); + else { + BinarySTLHeader header; + Triangle triangles[header.triangleCount]; + } }; -STL stl @ 0x00; \ No newline at end of file +STL stl @ 0x00; + +/* Visualize the 3D Model */ + +struct Vertex { + Vector3f points[3] @ addressof(stl.triangles[std::core::array_index()].points); +}; + +struct Model { + Vertex vertices[stl.header.triangleCount]; +} [[highlight_hidden, sealed, hex::visualize("3d", vertices, null)]]; + +Model model @ 0x00;