Use fread() to read binary STL files
This commit is contained in:
parent
85232bb6fd
commit
d0d842e24a
2 changed files with 4 additions and 31 deletions
|
@ -181,5 +181,4 @@ static void stl_read(stl_file *stl, int first_facet, int first);
|
||||||
static void stl_facet_stats(stl_file *stl, stl_facet facet, int first);
|
static void stl_facet_stats(stl_file *stl, stl_facet facet, int first);
|
||||||
extern void stl_reallocate(stl_file *stl);
|
extern void stl_reallocate(stl_file *stl);
|
||||||
static int stl_get_little_int(FILE *fp);
|
static int stl_get_little_int(FILE *fp);
|
||||||
static float stl_get_little_float(FILE *fp);
|
|
||||||
extern void stl_get_size(stl_file *stl);
|
extern void stl_get_size(stl_file *stl);
|
||||||
|
|
|
@ -52,22 +52,6 @@ stl_get_little_int(FILE *fp)
|
||||||
return(value);
|
return(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float
|
|
||||||
stl_get_little_float(FILE *fp)
|
|
||||||
{
|
|
||||||
union
|
|
||||||
{
|
|
||||||
int int_value;
|
|
||||||
float float_value;
|
|
||||||
} value;
|
|
||||||
|
|
||||||
value.int_value = fgetc(fp) & 0xFF;
|
|
||||||
value.int_value |= (fgetc(fp) & 0xFF) << 0x08;
|
|
||||||
value.int_value |= (fgetc(fp) & 0xFF) << 0x10;
|
|
||||||
value.int_value |= (fgetc(fp) & 0xFF) << 0x18;
|
|
||||||
return(value.float_value);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
stl_initialize(stl_file *stl)
|
stl_initialize(stl_file *stl)
|
||||||
|
@ -251,20 +235,10 @@ stl_read(stl_file *stl, int first_facet, int first)
|
||||||
if(stl->stats.type == binary)
|
if(stl->stats.type == binary)
|
||||||
/* Read a single facet from a binary .STL file */
|
/* Read a single facet from a binary .STL file */
|
||||||
{
|
{
|
||||||
facet.normal.x = stl_get_little_float(stl->fp);
|
// we assume little-endian architecture!
|
||||||
facet.normal.y = stl_get_little_float(stl->fp);
|
fread(&facet.normal, sizeof(stl_normal), 1, stl->fp);
|
||||||
facet.normal.z = stl_get_little_float(stl->fp);
|
fread(&facet.vertex, sizeof(stl_vertex), 3, stl->fp);
|
||||||
facet.vertex[0].x = stl_get_little_float(stl->fp);
|
fread(&facet.extra, sizeof(char), 2, stl->fp);
|
||||||
facet.vertex[0].y = stl_get_little_float(stl->fp);
|
|
||||||
facet.vertex[0].z = stl_get_little_float(stl->fp);
|
|
||||||
facet.vertex[1].x = stl_get_little_float(stl->fp);
|
|
||||||
facet.vertex[1].y = stl_get_little_float(stl->fp);
|
|
||||||
facet.vertex[1].z = stl_get_little_float(stl->fp);
|
|
||||||
facet.vertex[2].x = stl_get_little_float(stl->fp);
|
|
||||||
facet.vertex[2].y = stl_get_little_float(stl->fp);
|
|
||||||
facet.vertex[2].z = stl_get_little_float(stl->fp);
|
|
||||||
facet.extra[0] = fgetc(stl->fp);
|
|
||||||
facet.extra[1] = fgetc(stl->fp);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
/* Read a single facet from an ASCII .STL file */
|
/* Read a single facet from an ASCII .STL file */
|
||||||
|
|
Loading…
Reference in a new issue