From 89a4cf94957711117e7c64d483bb1fe42d05f7e9 Mon Sep 17 00:00:00 2001 From: JeffH-BMG <37119778+JeffH-BMG@users.noreply.github.com> Date: Wed, 7 Mar 2018 17:26:01 -0500 Subject: [PATCH] Respond to comments Use memcpy() to read normals and vertices, to mitigate alignment issues, per comments. --- code/STLLoader.cpp | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/code/STLLoader.cpp b/code/STLLoader.cpp index 115e5f816..e01162a30 100644 --- a/code/STLLoader.cpp +++ b/code/STLLoader.cpp @@ -451,6 +451,7 @@ bool STLImporter::LoadBinaryFile() typedef aiVector3t aiVector3F; aiVector3F* theVec; + aiVector3F theVec3F; for ( unsigned int i = 0; i < pMesh->mNumFaces; ++i ) { // NOTE: Blender sometimes writes empty normals ... this is not @@ -459,19 +460,32 @@ bool STLImporter::LoadBinaryFile() // There's one normal for the face in the STL; use it three times // for vertex normals theVec = (aiVector3F*) sz; - *vn++ = *theVec; - *vn++ = *theVec; - *vn++ = *theVec++; + ::memcpy( &theVec3F, theVec, sizeof(aiVector3F) ); + vn->x = theVec3F.x; vn->y = theVec3F.y; vn->z = theVec3F.z; + *(vn+1) = *vn; + *(vn+2) = *vn; + ++theVec; + vn += 3; // vertex 1 - *vp++ = *theVec++; + ::memcpy( &theVec3F, theVec, sizeof(aiVector3F) ); + vp->x = theVec3F.x; vp->y = theVec3F.y; vp->z = theVec3F.z; + ++theVec; + ++vp; // vertex 2 - *vp++ = *theVec++; + ::memcpy( &theVec3F, theVec, sizeof(aiVector3F) ); + vp->x = theVec3F.x; vp->y = theVec3F.y; vp->z = theVec3F.z; + ++theVec; + ++vp; // vertex 3 - *vp++ = *theVec; - sz += 4 * sizeof( aiVector3F ); + ::memcpy( &theVec3F, theVec, sizeof(aiVector3F) ); + vp->x = theVec3F.x; vp->y = theVec3F.y; vp->z = theVec3F.z; + ++theVec; + ++vp; + + sz = theVec; uint16_t color = *((uint16_t*)sz); sz += 2;