From 0dab5c508e15d72ac9502a7e9f155ab880fa58e2 Mon Sep 17 00:00:00 2001 From: JeffH-BMG <37119778+JeffH-BMG@users.noreply.github.com> Date: Tue, 6 Mar 2018 13:55:32 -0500 Subject: [PATCH] STL binary Export should write 4-byte floats for vertex and normal coordinates The STL binary format uses 4-byte floats. When using double-precision builds of Asset Importer, the STL exporter was writing out 8-byte double values instead.. --- code/STLExporter.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/code/STLExporter.cpp b/code/STLExporter.cpp index 4c7a8a639..3d681f8c7 100644 --- a/code/STLExporter.cpp +++ b/code/STLExporter.cpp @@ -172,12 +172,16 @@ void STLExporter :: WriteMeshBinary(const aiMesh* m) } nor.Normalize(); } - ai_real nx = nor.x, ny = nor.y, nz = nor.z; + // STL binary files use 4-byte floats. This may possibly cause loss of precision + // for clients using 8-byte doubles + float nx = (float) nor.x; + float ny = (float) nor.y; + float nz = (float) nor.z; AI_SWAP4(nx); AI_SWAP4(ny); AI_SWAP4(nz); mOutput.write((char *)&nx, 4); mOutput.write((char *)&ny, 4); mOutput.write((char *)&nz, 4); for(unsigned int a = 0; a < f.mNumIndices; ++a) { const aiVector3D& v = m->mVertices[f.mIndices[a]]; - ai_real vx = v.x, vy = v.y, vz = v.z; + float vx = (float) v.x, vy = (float) v.y, vz = (float) v.z; AI_SWAP4(vx); AI_SWAP4(vy); AI_SWAP4(vz); mOutput.write((char *)&vx, 4); mOutput.write((char *)&vy, 4); mOutput.write((char *)&vz, 4); }