Files
ImHex-Patterns/patterns/stl.hexpat
Mrmaxmeier c533017d0b git: Various style fixes everywhere, removing whitespaces (#321)
* repo-wide: trim trailing spaces

Note: This doesn't touch the .tbl files in encodings/ since they include
meaningful trailing spaces (`20= `)

* patterns: clean up duplicate semicolons

* ELF: add header magic check

* glTF: use type::Magic for magic value

* glTF: check that the file size in the header matches

* xgstexture: fix generics syntax for magic value

* JPEG: define hex enum with 0x00 instead of 0X00

* CI: update deprecated actions

---------

Co-authored-by: Nik <werwolv98@gmail.com>
2024-11-24 11:41:26 +01:00

55 lines
1.1 KiB
Rust

#pragma author WerWolv
#pragma description STL 3D Model
#pragma MIME model/stl
#pragma MIME model/x.stl-binary
#pragma MIME model/x.stl-ascii
#pragma MIME application/sla
import std.sys;
import std.mem;
import std.core;
struct Vector3f {
float x, y, z;
} [[static, format("format_vector3f")]];
fn format_vector3f(Vector3f vec) {
return std::format("[ {}, {}, {} ]", vec.x, vec.y, vec.z);
};
struct Triangle {
Vector3f normal;
Vector3f points[3];
u16 flags;
} [[static]];
struct BinarySTLHeader {
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];
}
};
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;