From 8a4c517039cfc67d30946f23b06ad1b19d0b6166 Mon Sep 17 00:00:00 2001 From: Metin Ozyildirim Date: Tue, 7 May 2019 15:02:08 +0000 Subject: [PATCH] Revert "Fixed some possible bugs for big endian systems." This reverts commit 7fdf6c9445dc2d997174eff4fbef8fd58669366c. Compatibility for big endian systems dropped since it requires non-standart endian.h file. --- include/stl.h | 1 + src/stl.c | 35 ++++------------------------------- 2 files changed, 5 insertions(+), 31 deletions(-) diff --git a/include/stl.h b/include/stl.h index be0fbe5..8f8da47 100644 --- a/include/stl.h +++ b/include/stl.h @@ -6,6 +6,7 @@ typedef struct Triangle{ V3f normal; V3f points[3]; + uint16_t attrByteCount; }Triangle; typedef struct STLFile{ diff --git a/src/stl.c b/src/stl.c index 921765c..c34cfc5 100644 --- a/src/stl.c +++ b/src/stl.c @@ -2,9 +2,7 @@ #include #include #include -#include -// 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; @@ -15,7 +13,6 @@ 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); @@ -23,34 +20,10 @@ STLFile loadSTL(const char* filename){ 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; } \ No newline at end of file