Skip to content

Commit

Permalink
Revert "Fixed some possible bugs for big endian systems."
Browse files Browse the repository at this point in the history
This reverts commit 7fdf6c9.
Compatibility for big endian systems dropped since it requires non-standart endian.h file.
  • Loading branch information
ozy committed May 7, 2019
1 parent a425d3c commit 8a4c517
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 31 deletions.
1 change: 1 addition & 0 deletions include/stl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
typedef struct Triangle{
V3f normal;
V3f points[3];
uint16_t attrByteCount;
}Triangle;

typedef struct STLFile{
Expand Down
35 changes: 4 additions & 31 deletions src/stl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <endian.h>
// Endian.h is platform dependent and unnecessary in modern desktop
// cpus. Will be replaced with a possible macro in the future.


STLFile loadSTL(const char* filename){
STLFile stl;
Expand All @@ -15,42 +13,17 @@ STLFile loadSTL(const char* filename){
}

fread(stl.header, sizeof(stl.header), 1, fd);

fread(&stl.numTriangles, sizeof(stl.numTriangles), 1, fd);
stl.numTriangles = le32toh(stl.numTriangles);

assert(stl.numTriangles<50000); // possibly ascii stl.

stl.triangle = malloc(sizeof(Triangle) * stl.numTriangles);
for (int triangleId = 0; triangleId < stl.numTriangles; triangleId++){
stl.triangle[triangleId] = (Triangle){};
fread(&stl.triangle[triangleId].normal.x, sizeof(float), 1, fd);
stl.triangle[triangleId].normal.x = le32toh(stl.triangle[triangleId].normal.x);

fread(&stl.triangle[triangleId].normal.y, sizeof(float), 1, fd);
stl.triangle[triangleId].normal.y = le32toh(stl.triangle[triangleId].normal.y);

fread(&stl.triangle[triangleId].normal.z, sizeof(float), 1, fd);
stl.triangle[triangleId].normal.z = le32toh(stl.triangle[triangleId].normal.z);

for(int pointId = 0; pointId < 3; pointId++){
fread(&stl.triangle[triangleId].points[pointId].x, sizeof(float), 1, fd);
stl.triangle[triangleId].points[pointId].x = le32toh(stl.triangle[triangleId].points[pointId].x);

fread(&stl.triangle[triangleId].points[pointId].y, sizeof(float), 1, fd);
stl.triangle[triangleId].points[pointId].y = le32toh(stl.triangle[triangleId].points[pointId].y);

fread(&stl.triangle[triangleId].points[pointId].z, sizeof(float), 1, fd);
stl.triangle[triangleId].points[pointId].z = le32toh(stl.triangle[triangleId].points[pointId].z);
}

fread(&stl.triangle[triangleId].normal, sizeof(V3f), 1, fd);
fread(&stl.triangle[triangleId].points, sizeof(V3f), 3, fd);
fread(&stl.triangle[triangleId].attrByteCount, sizeof(uint16_t), 1, fd);
//printf ("%d: Normal: %f, %f, %f Points: %f, %f, %f\n", triangleId, stl.triangle[triangleId].normal.x,stl.triangle[triangleId].normal.y,stl.triangle[triangleId].normal.z, stl.triangle[triangleId].points[0].x,stl.triangle[triangleId].points[0].y,stl.triangle[triangleId].points[0].z);

// Skip attribute data.
uint16_t attrByteCount;
fread(&attrByteCount, sizeof(uint16_t), 1, fd);
attrByteCount = le16toh(attrByteCount);
fseek ( fd , attrByteCount , SEEK_CUR );
}
return stl;
}

0 comments on commit 8a4c517

Please sign in to comment.