Skip to content

Instantly share code, notes, and snippets.

@sethhall
Created August 9, 2024 15:32
Show Gist options
  • Save sethhall/0a50f824b9d0bca48898b539cf9c18ba to your computer and use it in GitHub Desktop.
Save sethhall/0a50f824b9d0bca48898b539cf9c18ba to your computer and use it in GitHub Desktop.
Binary STL parser in spicy
module STL;
import spicy;
%byte-order = spicy::ByteOrder::Little;
public type File = unit {
header : bytes &size=80;
total_facets : uint32;
facets : Facet[self.total_facets];
};
type Facet = unit {
normal: Point;
vertices: Point[3];
pad: skip bytes &size=2;
};
type Point = unit {
x: real &type=spicy::RealType::IEEE754_Single;
y: real &type=spicy::RealType::IEEE754_Single;
z: real &type=spicy::RealType::IEEE754_Single;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment