diff --git a/tools/assimp_cmd/WriteDumb.cpp b/tools/assimp_cmd/WriteDumb.cpp index aa5b321dc..a7b898c93 100644 --- a/tools/assimp_cmd/WriteDumb.cpp +++ b/tools/assimp_cmd/WriteDumb.cpp @@ -108,7 +108,7 @@ inline uint32_t WriteMagic(uint32_t magic) // use template specializations rather than regular overloading to be able to // explicitly select the right 'overload' to leave no doubts on what is called, // retaining the possibility of letting the compiler select. -template uint32_t Write(const T&) {}; +template uint32_t Write(const T&); // ----------------------------------------------------------------------------------- // Serialize an aiString @@ -127,6 +127,11 @@ template <> inline uint32_t Write(const unsigned int& w) { const uint32_t t = (uint32_t)w; + if (w > t) { + // this shouldn't happen, integers in Assimp data structures never exceed 2^32 + printf("loss of data due to 64 -> 32 bit integer conversion"); + } + fwrite(&t,4,1,out); return 4; } @@ -145,6 +150,7 @@ inline uint32_t Write(const uint16_t& w) template <> inline uint32_t Write(const float& f) { + BOOST_STATIC_ASSERT(sizeof(float)==4); fwrite(&f,4,1,out); return 4; } @@ -154,6 +160,7 @@ inline uint32_t Write(const float& f) template <> inline uint32_t Write(const double& f) { + BOOST_STATIC_ASSERT(sizeof(double)==8); fwrite(&f,8,1,out); return 8; } @@ -163,8 +170,44 @@ inline uint32_t Write(const double& f) template <> inline uint32_t Write(const aiVector3D& v) { - fwrite(&v,12,1,out); - return 12; + uint32_t t = Write(v.x); + t += Write(v.y); + t += Write(v.z); + return t; +} + +// ----------------------------------------------------------------------------------- +// Serialize a color value +template <> +inline uint32_t Write(const aiColor4D& v) +{ + uint32_t t = Write(v.r); + t += Write(v.g); + t += Write(v.b); + t += Write(v.a); + return t; +} + +// ----------------------------------------------------------------------------------- +// Serialize a quaternion +template <> +inline uint32_t Write(const aiQuaternion& v) +{ + uint32_t t = Write(v.w); + t += Write(v.x); + t += Write(v.y); + t += Write(v.z); + return 16; +} + + +// ----------------------------------------------------------------------------------- +// Serialize a vertex weight +template <> +inline uint32_t Write(const aiVertexWeight& v) +{ + uint32_t t = Write(v.mVertexId); + return t+Write(v.mWeight); } // -----------------------------------------------------------------------------------