shithub: libstl

ref: d5147306c711858fe4c0380949c36f8358af7f3e
dir: /stl.2.man/

View raw version
.TH STL 2
.SH NAME
readstl,
writestl,
freestl
\- STL parser
.SH SYNOPSIS
.ta 0.7i +0.7i +0.7i +0.7i +0.7i +0.7i +0.7i
.EX
#include <u.h>
#include <libc.h>
#include <stl.h>

enum {
	STLTEXT,
	STLBINARY,
};

typedef struct Stltri Stltri;
typedef struct Stl Stl;

struct Stltri
{
	float	n[3];
	float	v[3][3];
	u16int	attrlen;
	u8int	attrs[];
};

struct Stl
{
	u8int	hdr[80];
	u32int	ntris;
	Stltri	**tris;
};

Stl *readstl(int fd);
usize writestl(int fd, Stl *stl, int fmt);
void freestl(Stl *stl);
.EE
.SH DESCRIPTION
This library provides a parser for both the text (ASCII) and binary
STL file formats.
An
.B Stl
structure contains a set of triangles that make up a single 3D model
or solid.
.PP
.B Readstl
takes an
.I fd
open for reading, and returns an allocated Stl structure filled with
the model it contains.  If the file couldn't be parsed, it will write
the reason to the errstr and return nil.
.PP
.B Freestl
frees an Stl structure created by
.BR readstl .
.PP
The
.B hdr
and
.B attrs
properties of
.B Stl
and
.B Stltri
respectively are not interpreted in any way, and are provided as
blobs; it's up to the user to give them some meaning.
.PP
.B Writestl
takes an
.I fd
open for writing and dumps the
.I stl
structure with the given
.I fmt
(STLTEXT or STLBINARY).  If an error
occurs, it will write the reason to the errstr and return zero.
.SH SOURCE
.B /sys/src/libstl
.SH SEE ALSO
.IR errstr (2)
.br
https://en.wikipedia.org/wiki/STL_(file_format)
.SH BUGS
There's no context about why parsing a binary file went wrong.  In
most cases this means the file is corrupt or malformed, but authors
may appreciate more information about why and where it failed.