Merge pull request #1828 from JeffH-BMG/patch-2

STL binary Export should write 4-byte floats for vertex and normal co…
pull/1829/head
Kim Kulling 2018-03-10 15:48:32 +01:00 committed by GitHub
commit beaadf55df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -172,12 +172,16 @@ void STLExporter :: WriteMeshBinary(const aiMesh* m)
} }
nor.Normalize(); 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); AI_SWAP4(nx); AI_SWAP4(ny); AI_SWAP4(nz);
mOutput.write((char *)&nx, 4); mOutput.write((char *)&ny, 4); mOutput.write((char *)&nz, 4); mOutput.write((char *)&nx, 4); mOutput.write((char *)&ny, 4); mOutput.write((char *)&nz, 4);
for(unsigned int a = 0; a < f.mNumIndices; ++a) { for(unsigned int a = 0; a < f.mNumIndices; ++a) {
const aiVector3D& v = m->mVertices[f.mIndices[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); AI_SWAP4(vx); AI_SWAP4(vy); AI_SWAP4(vz);
mOutput.write((char *)&vx, 4); mOutput.write((char *)&vy, 4); mOutput.write((char *)&vz, 4); mOutput.write((char *)&vx, 4); mOutput.write((char *)&vy, 4); mOutput.write((char *)&vz, 4);
} }