diff --git a/CMakeLists.txt b/CMakeLists.txt index 79db04762..73a30e9d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -186,7 +186,7 @@ IF( UNIX ) IF( ${OPERATING_SYSTEM} MATCHES "Android") ELSE() IF ( CMAKE_SIZEOF_VOID_P EQUAL 4) # only necessary for 32-bit linux - ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 ) + #ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64 ) ENDIF() ENDIF() diff --git a/code/BlenderDNA.h b/code/BlenderDNA.h index 4c7d0fc26..bac8d78bc 100644 --- a/code/BlenderDNA.h +++ b/code/BlenderDNA.h @@ -92,6 +92,12 @@ struct Error : DeadlyImportError { * descendents. It serves as base class for all data structure fields. */ // ------------------------------------------------------------------------------- struct ElemBase { + ElemBase() + : dna_type(nullptr) + { + // empty + } + virtual ~ElemBase() { // empty } diff --git a/code/BlenderScene.cpp b/code/BlenderScene.cpp index b9068329b..0e1dec7f3 100644 --- a/code/BlenderScene.cpp +++ b/code/BlenderScene.cpp @@ -59,7 +59,9 @@ template <> void Structure :: Convert ( { ReadField(dest.id,"id",db); - ReadField((int&)dest.type,"type",db); + int temp = 0; + ReadField(temp,"type",db); + dest.type = static_cast(temp); ReadFieldArray2(dest.obmat,"obmat",db); ReadFieldArray2(dest.parentinv,"parentinv",db); ReadFieldArray(dest.parsubstr,"parsubstr",db); @@ -100,14 +102,21 @@ template <> void Structure :: Convert ( ) const { - ReadField((short&)dest.mapto,"mapto",db); - ReadField((int&)dest.blendtype,"blendtype",db); + int temp_short = 0; + ReadField(temp_short,"mapto",db); + dest.mapto = static_cast(temp_short); + int temp = 0; + ReadField(temp,"blendtype",db); + dest.blendtype = static_cast(temp); ReadFieldPtr(dest.object,"*object",db); ReadFieldPtr(dest.tex,"*tex",db); ReadFieldArray(dest.uvname,"uvname",db); - ReadField((int&)dest.projx,"projx",db); - ReadField((int&)dest.projy,"projy",db); - ReadField((int&)dest.projz,"projz",db); + ReadField(temp,"projx",db); + dest.projx = static_cast(temp); + ReadField(temp,"projy",db); + dest.projy = static_cast(temp); + ReadField(temp,"projz",db); + dest.projx = static_cast(temp); ReadField(dest.mapping,"mapping",db); ReadFieldArray(dest.ofs,"ofs",db); ReadFieldArray(dest.size,"size",db); @@ -190,7 +199,9 @@ template <> void Structure :: Convert ( { ReadField(dest.id,"id",db); - ReadField((int&)dest.type,"type",db); + int temp = 0; + ReadField(temp,"type",db); + dest.type = static_cast(temp); ReadField(dest.flags,"flags",db); ReadField(dest.colormodel,"colormodel",db); ReadField(dest.totex,"totex",db); @@ -204,7 +215,8 @@ template <> void Structure :: Convert ( ReadField(dest.spotblend,"spotblend",db); ReadField(dest.att1,"att1",db); ReadField(dest.att2,"att2",db); - ReadField((int&)dest.falloff_type,"falloff_type",db); + ReadField(temp,"falloff_type",db); + dest.falloff_type = static_cast(temp); ReadField(dest.sun_brightness,"sun_brightness",db); ReadField(dest.area_size,"area_size",db); ReadField(dest.area_sizey,"area_sizey",db); @@ -693,8 +705,12 @@ template <> void Structure :: Convert ( const FileDatabase& db ) const { - ReadField((short&)dest.imaflag,"imaflag",db); - ReadField((int&)dest.type,"type",db); + short temp_short = 0; + ReadField(temp_short,"imaflag",db); + dest.imaflag = static_cast(temp_short); + int temp = 0; + ReadField(temp,"type",db); + dest.type = static_cast(temp); ReadFieldPtr(dest.ima,"*ima",db); db.reader->IncPtr(size); @@ -708,8 +724,11 @@ template <> void Structure :: Convert ( { ReadField(dest.id,"id",db); - ReadField((int&)dest.type,"type",db); - ReadField((int&)dest.flag,"flag",db); + int temp = 0; + ReadField(temp,"type",db); + dest.type = static_cast(temp); + ReadField(temp,"flag",db); + dest.flag = static_cast(temp); ReadField(dest.lens,"lens",db); ReadField(dest.sensor_x,"sensor_x",db); ReadField(dest.clipsta,"clipsta",db); diff --git a/code/BlenderScene.h b/code/BlenderScene.h index 36094eabd..86ab1f30c 100644 --- a/code/BlenderScene.h +++ b/code/BlenderScene.h @@ -225,6 +225,14 @@ struct TFace : ElemBase { // ------------------------------------------------------------------------------- struct MTFace : ElemBase { + MTFace() + : flag(0) + , mode(0) + , tile(0) + , unwrap(0) + { + } + float uv[4][2] FAIL; char flag; short mode; diff --git a/code/FIReader.cpp b/code/FIReader.cpp index fdf6b8a83..53cff257a 100755 --- a/code/FIReader.cpp +++ b/code/FIReader.cpp @@ -45,13 +45,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef ASSIMP_BUILD_NO_X3D_IMPORTER +#include "FIReader.hpp" +#include "StringUtils.h" + // Workaround for issue #1361 // https://github.com/assimp/assimp/issues/1361 #ifdef __ANDROID__ -#define _GLIBCXX_USE_C99 1 +# define _GLIBCXX_USE_C99 1 #endif -#include "FIReader.hpp" #include "Exceptional.h" #include #include @@ -485,7 +487,9 @@ struct FIFloatDecoder: public FIDecoder { value.reserve(numFloats); for (size_t i = 0; i < numFloats; ++i) { int v = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; - value.push_back(*(float*)&v); + float f; + memcpy(&f, &v, 4); + value.push_back(f); data += 4; } return FIFloatValue::create(std::move(value)); @@ -503,7 +507,9 @@ struct FIDoubleDecoder: public FIDecoder { for (size_t i = 0; i < numDoubles; ++i) { long long b0 = data[0], b1 = data[1], b2 = data[2], b3 = data[3], b4 = data[4], b5 = data[5], b6 = data[6], b7 = data[7]; long long v = (b0 << 56) | (b1 << 48) | (b2 << 40) | (b3 << 32) | (b4 << 24) | (b5 << 16) | (b6 << 8) | b7; - value.push_back(*(double*)&v); + double f; + memcpy(&f, &v, 8); + value.push_back(f); data += 8; } return FIDoubleValue::create(std::move(value)); @@ -685,7 +691,7 @@ public: if (intValue) { return intValue->value.size() == 1 ? intValue->value.front() : 0; } - return stoi(attr->value->toString()); + return atoi(attr->value->toString().c_str()); } virtual int getAttributeValueAsInt(int idx) const /*override*/ { @@ -696,7 +702,7 @@ public: if (intValue) { return intValue->value.size() == 1 ? intValue->value.front() : 0; } - return stoi(attributes[idx].value->toString()); + return atoi(attributes[idx].value->toString().c_str()); } virtual float getAttributeValueAsFloat(const char* name) const /*override*/ { @@ -708,7 +714,7 @@ public: if (floatValue) { return floatValue->value.size() == 1 ? floatValue->value.front() : 0; } - return stof(attr->value->toString()); + return atof(attr->value->toString().c_str()); } virtual float getAttributeValueAsFloat(int idx) const /*override*/ { @@ -719,7 +725,7 @@ public: if (floatValue) { return floatValue->value.size() == 1 ? floatValue->value.front() : 0; } - return stof(attributes[idx].value->toString()); + return atof(attributes[idx].value->toString().c_str()); } virtual const char* getNodeName() const /*override*/ { @@ -984,13 +990,13 @@ private: if (index < 32) { FIDecoder *decoder = defaultDecoder[index]; if (!decoder) { - throw DeadlyImportError("Invalid encoding algorithm index " + std::to_string(index)); + throw DeadlyImportError("Invalid encoding algorithm index " + to_string(index)); } return decoder->decode(dataP, len); } else { if (index - 32 >= vocabulary.encodingAlgorithmTable.size()) { - throw DeadlyImportError("Invalid encoding algorithm index " + std::to_string(index)); + throw DeadlyImportError("Invalid encoding algorithm index " + to_string(index)); } std::string uri = vocabulary.encodingAlgorithmTable[index - 32]; auto it = decoderMap.find(uri); @@ -1014,12 +1020,12 @@ private: alphabet = "0123456789-:TZ "; break; default: - throw DeadlyImportError("Invalid restricted alphabet index " + std::to_string(index)); + throw DeadlyImportError("Invalid restricted alphabet index " + to_string(index)); } } else { if (index - 16 >= vocabulary.restrictedAlphabetTable.size()) { - throw DeadlyImportError("Invalid restricted alphabet index " + std::to_string(index)); + throw DeadlyImportError("Invalid restricted alphabet index " + to_string(index)); } alphabet = vocabulary.restrictedAlphabetTable[index - 16]; } @@ -1027,7 +1033,7 @@ private: utf8::utf8to32(alphabet.begin(), alphabet.end(), back_inserter(alphabetUTF32)); std::string::size_type alphabetLength = alphabetUTF32.size(); if (alphabetLength < 2) { - throw DeadlyImportError("Invalid restricted alphabet length " + std::to_string(alphabetLength)); + throw DeadlyImportError("Invalid restricted alphabet length " + to_string(alphabetLength)); } std::string::size_type bitsPerCharacter = 1; while ((1ull << bitsPerCharacter) <= alphabetLength) { diff --git a/code/FIReader.hpp b/code/FIReader.hpp index 4e9f712a9..5f4e5bb48 100644 --- a/code/FIReader.hpp +++ b/code/FIReader.hpp @@ -46,12 +46,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef INCLUDED_AI_FI_READER_H #define INCLUDED_AI_FI_READER_H +#ifndef ASSIMP_BUILD_NO_X3D_IMPORTER + +//#include #include +#include #include #include -#include #include -#include +//#include +//#include #include namespace Assimp { @@ -176,4 +180,6 @@ FIReader::~FIReader() { }// namespace Assimp +#endif // #ifndef ASSIMP_BUILD_NO_X3D_IMPORTER + #endif // INCLUDED_AI_FI_READER_H diff --git a/code/MDLMaterialLoader.cpp b/code/MDLMaterialLoader.cpp index 91dcb49cc..9086925aa 100644 --- a/code/MDLMaterialLoader.cpp +++ b/code/MDLMaterialLoader.cpp @@ -665,7 +665,9 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7( if (0.0f != pcMatIn->Power) { iShadingMode = (int)aiShadingMode_Phong; - pcMatOut->AddProperty(&pcMatIn->Power,1,AI_MATKEY_SHININESS); + // pcMatIn is packed, we can't form pointers to its members + float power = pcMatIn->Power; + pcMatOut->AddProperty(&power,1,AI_MATKEY_SHININESS); } pcMatOut->AddProperty(&iShadingMode,1,AI_MATKEY_SHADING_MODEL); } diff --git a/code/ValidateDataStructure.cpp b/code/ValidateDataStructure.cpp index f1035e441..c036eac18 100644 --- a/code/ValidateDataStructure.cpp +++ b/code/ValidateDataStructure.cpp @@ -334,28 +334,28 @@ void ValidateDSProcess::Validate( const aiMesh* pMesh) case 1: if (0 == (pMesh->mPrimitiveTypes & aiPrimitiveType_POINT)) { - ReportError("aiMesh::mFaces[%i] is a POINT but aiMesh::mPrimtiveTypes " + ReportError("aiMesh::mFaces[%i] is a POINT but aiMesh::mPrimitiveTypes " "does not report the POINT flag",i); } break; case 2: if (0 == (pMesh->mPrimitiveTypes & aiPrimitiveType_LINE)) { - ReportError("aiMesh::mFaces[%i] is a LINE but aiMesh::mPrimtiveTypes " + ReportError("aiMesh::mFaces[%i] is a LINE but aiMesh::mPrimitiveTypes " "does not report the LINE flag",i); } break; case 3: if (0 == (pMesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE)) { - ReportError("aiMesh::mFaces[%i] is a TRIANGLE but aiMesh::mPrimtiveTypes " + ReportError("aiMesh::mFaces[%i] is a TRIANGLE but aiMesh::mPrimitiveTypes " "does not report the TRIANGLE flag",i); } break; default: if (0 == (pMesh->mPrimitiveTypes & aiPrimitiveType_POLYGON)) { - this->ReportError("aiMesh::mFaces[%i] is a POLYGON but aiMesh::mPrimtiveTypes " + this->ReportError("aiMesh::mFaces[%i] is a POLYGON but aiMesh::mPrimitiveTypes " "does not report the POLYGON flag",i); } break; diff --git a/code/ValidateDataStructure.h b/code/ValidateDataStructure.h index c53207483..084a2b083 100644 --- a/code/ValidateDataStructure.h +++ b/code/ValidateDataStructure.h @@ -91,7 +91,7 @@ protected: // ------------------------------------------------------------------- /** Report a validation warning. This won't throw an exception, - * control will return to the callera. + * control will return to the caller. * @param msg Format string for sprintf().*/ void ReportWarning(const char* msg,...); diff --git a/contrib/Open3DGC/o3dgcBinaryStream.h b/contrib/Open3DGC/o3dgcBinaryStream.h index 19e3df973..b7b7678b7 100644 --- a/contrib/Open3DGC/o3dgcBinaryStream.h +++ b/contrib/Open3DGC/o3dgcBinaryStream.h @@ -231,7 +231,8 @@ namespace o3dgc float ReadFloat32Bin(unsigned long & position) const { unsigned long value = ReadUInt32Bin(position); - float fvalue = *((float *)(&value)); + float fvalue; + memcpy(&fvalue, &value, 4); return fvalue; } unsigned long ReadUInt32Bin(unsigned long & position) const @@ -261,7 +262,8 @@ namespace o3dgc void WriteFloat32ASCII(float value) { - unsigned long uiValue = *((unsigned long *)(&value)); + unsigned long uiValue; + memcpy(&uiValue, &value, 4); WriteUInt32ASCII(uiValue); } void WriteUInt32ASCII(unsigned long position, unsigned long value) @@ -314,7 +316,8 @@ namespace o3dgc float ReadFloat32ASCII(unsigned long & position) const { unsigned long value = ReadUInt32ASCII(position); - float fvalue = *((float *)(&value)); + float fvalue; + memcpy(&fvalue, &value, 4); return fvalue; } unsigned long ReadUInt32ASCII(unsigned long & position) const diff --git a/test/unit/utObjImportExport.cpp b/test/unit/utObjImportExport.cpp index 6361813d0..d9df779ac 100644 --- a/test/unit/utObjImportExport.cpp +++ b/test/unit/utObjImportExport.cpp @@ -294,12 +294,12 @@ TEST_F(utObjImportExport, relative_indices_Test) { const aiScene *scene = myimporter.ReadFileFromMemory(ObjModel.c_str(), ObjModel.size(), aiProcess_ValidateDataStructure); EXPECT_NE(nullptr, scene); - EXPECT_EQ(scene->mNumMeshes, 1); + EXPECT_EQ(scene->mNumMeshes, 1U); const aiMesh *mesh = scene->mMeshes[0]; - EXPECT_EQ(mesh->mNumVertices, 4); - EXPECT_EQ(mesh->mNumFaces, 1); + EXPECT_EQ(mesh->mNumVertices, 4U); + EXPECT_EQ(mesh->mNumFaces, 1U); const aiFace face = mesh->mFaces[0]; - EXPECT_EQ(face.mNumIndices, 4); + EXPECT_EQ(face.mNumIndices, 4U); for (unsigned int i = 0; i < face.mNumIndices; ++i) { EXPECT_EQ(face.mIndices[i], i); @@ -318,12 +318,12 @@ TEST_F(utObjImportExport, homogeneous_coordinates_Test) { const aiScene *scene = myimporter.ReadFileFromMemory(ObjModel.c_str(), ObjModel.size(), aiProcess_ValidateDataStructure); EXPECT_NE(nullptr, scene); - EXPECT_EQ(scene->mNumMeshes, 1); + EXPECT_EQ(scene->mNumMeshes, 1U); const aiMesh *mesh = scene->mMeshes[0]; - EXPECT_EQ(mesh->mNumVertices, 3); - EXPECT_EQ(mesh->mNumFaces, 1); + EXPECT_EQ(mesh->mNumVertices, 3U); + EXPECT_EQ(mesh->mNumFaces, 1U); const aiFace face = mesh->mFaces[0]; - EXPECT_EQ(face.mNumIndices, 3); + EXPECT_EQ(face.mNumIndices, 3U); const aiVector3D vertice = mesh->mVertices[0]; EXPECT_EQ(vertice.x, -1.0f); EXPECT_EQ(vertice.y, 0.0f); diff --git a/tools/assimp_cmd/WriteDumb.cpp b/tools/assimp_cmd/WriteDumb.cpp index 69d4efcc5..e1b104d40 100644 --- a/tools/assimp_cmd/WriteDumb.cpp +++ b/tools/assimp_cmd/WriteDumb.cpp @@ -177,6 +177,17 @@ inline uint32_t Write(const aiVector3D& v) return t; } +// ----------------------------------------------------------------------------------- +// Serialize a color value +template <> +inline uint32_t Write(const aiColor3D& v) +{ + uint32_t t = Write(v.r); + t += Write(v.g); + t += Write(v.b); + return t; +} + // ----------------------------------------------------------------------------------- // Serialize a color value template <> @@ -566,9 +577,9 @@ uint32_t WriteBinaryLight(const aiLight* l) len += Write(l->mAttenuationQuadratic); } - len += Write((const aiVector3D&)l->mColorDiffuse); - len += Write((const aiVector3D&)l->mColorSpecular); - len += Write((const aiVector3D&)l->mColorAmbient); + len += Write(l->mColorDiffuse); + len += Write(l->mColorSpecular); + len += Write(l->mColorAmbient); if (l->mType == aiLightSource_SPOT) { len += Write(l->mAngleInnerCone);