diff --git a/code/AssetLib/AMF/AMFImporter.cpp b/code/AssetLib/AMF/AMFImporter.cpp index 88a38b827..9a9ab94ca 100644 --- a/code/AssetLib/AMF/AMFImporter.cpp +++ b/code/AssetLib/AMF/AMFImporter.cpp @@ -511,7 +511,7 @@ bool AMFImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool p } if (extension.empty() || pCheckSig) { - const char *tokens[] = { "frame; } else { // get the first frame in the group - BE_NCONST MDL::GroupFrame *pcFrames2 = (BE_NCONST MDL::GroupFrame *)pcFrames; - pcFirstFrame = &(pcFrames2->frames[0]); + BE_NCONST MDL::GroupFrame *pcFrames2 = (BE_NCONST MDL::GroupFrame *)szCurrent; + pcFirstFrame = (MDL::SimpleFrame *)( szCurrent + sizeof(MDL::GroupFrame::type) + sizeof(MDL::GroupFrame::numframes) + + sizeof(MDL::GroupFrame::min) + sizeof(MDL::GroupFrame::max) + sizeof(*MDL::GroupFrame::times) * pcFrames2->numframes ); } BE_NCONST MDL::Vertex *pcVertices = (BE_NCONST MDL::Vertex *)((pcFirstFrame->name) + sizeof(pcFirstFrame->name)); VALIDATE_FILE_SIZE((const unsigned char *)(pcVertices + pcHeader->num_verts)); diff --git a/code/AssetLib/MMD/MMDImporter.cpp b/code/AssetLib/MMD/MMDImporter.cpp index 2895c3879..84d320e41 100644 --- a/code/AssetLib/MMD/MMDImporter.cpp +++ b/code/AssetLib/MMD/MMDImporter.cpp @@ -94,8 +94,8 @@ bool MMDImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, return SimpleExtensionCheck(pFile, "pmx"); } else { // Check file Header - static const char *pTokens[] = { "PMX " }; - return BaseImporter::SearchFileHeaderForToken(pIOHandler, pFile, pTokens, 1); + static const char * const pTokens[] = { "PMX " }; + return SearchFileHeaderForToken(pIOHandler, pFile, pTokens, 1); } } diff --git a/code/AssetLib/MS3D/MS3DLoader.cpp b/code/AssetLib/MS3D/MS3DLoader.cpp index e4057a43a..4b0269b7b 100644 --- a/code/AssetLib/MS3D/MS3DLoader.cpp +++ b/code/AssetLib/MS3D/MS3DLoader.cpp @@ -104,7 +104,7 @@ bool MS3DImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool if (!pIOHandler) { return true; } - const char* tokens[] = {"MS3D000000"}; + static const char * const tokens[] = {"MS3D000000"}; return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1); } return false; diff --git a/code/AssetLib/NDO/NDOLoader.cpp b/code/AssetLib/NDO/NDOLoader.cpp index 0abc09dc8..0ccbe8a61 100644 --- a/code/AssetLib/NDO/NDOLoader.cpp +++ b/code/AssetLib/NDO/NDOLoader.cpp @@ -91,7 +91,7 @@ bool NDOImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool return true; if ((checkSig || !extension.length()) && pIOHandler) { - const char* tokens[] = {"nendo"}; + static const char * const tokens[] = {"nendo"}; return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1,5); } return false; diff --git a/code/AssetLib/OFF/OFFLoader.cpp b/code/AssetLib/OFF/OFFLoader.cpp index a40b62e4c..8509d0c4d 100644 --- a/code/AssetLib/OFF/OFFLoader.cpp +++ b/code/AssetLib/OFF/OFFLoader.cpp @@ -92,7 +92,7 @@ bool OFFImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool else if (!extension.length() || checkSig) { if (!pIOHandler)return true; - const char* tokens[] = {"off"}; + static const char * const tokens[] = {"off"}; return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1,3); } return false; diff --git a/code/AssetLib/Obj/ObjFileMtlImporter.cpp b/code/AssetLib/Obj/ObjFileMtlImporter.cpp index 94e57c26b..548401d01 100644 --- a/code/AssetLib/Obj/ObjFileMtlImporter.cpp +++ b/code/AssetLib/Obj/ObjFileMtlImporter.cpp @@ -61,7 +61,8 @@ static const std::string EmissiveTexture1 = "map_emissive"; static const std::string EmissiveTexture2 = "map_Ke"; static const std::string BumpTexture1 = "map_bump"; static const std::string BumpTexture2 = "bump"; -static const std::string NormalTexture = "map_Kn"; +static const std::string NormalTextureV1 = "map_Kn"; +static const std::string NormalTextureV2 = "norm"; static const std::string ReflectionTexture = "refl"; static const std::string DisplacementTexture1 = "map_disp"; static const std::string DisplacementTexture2 = "disp"; @@ -232,6 +233,12 @@ void ObjFileMtlImporter::getIlluminationModel(int &illum_model) { // Loads a single float value. void ObjFileMtlImporter::getFloatValue(ai_real &value) { m_DataIt = CopyNextWord(m_DataIt, m_DataItEnd, &m_buffer[0], BUFFERSIZE); + size_t len = std::strlen(&m_buffer[0]); + if (0 == len) { + value = 0.0f; + return; + } + value = (ai_real)fast_atof(&m_buffer[0]); } @@ -315,7 +322,7 @@ void ObjFileMtlImporter::getTexture() { // Bump texture out = &m_pModel->m_pCurrentMaterial->textureBump; clampIndex = ObjFile::Material::TextureBumpType; - } else if (!ASSIMP_strincmp(pPtr, NormalTexture.c_str(), static_cast(NormalTexture.size()))) { + } else if (!ASSIMP_strincmp(pPtr, NormalTextureV1.c_str(), static_cast(NormalTextureV1.size())) || !ASSIMP_strincmp(pPtr, NormalTextureV2.c_str(), static_cast(NormalTextureV2.size()))) { // Normal map out = &m_pModel->m_pCurrentMaterial->textureNormal; clampIndex = ObjFile::Material::TextureNormalType; diff --git a/code/AssetLib/Obj/ObjFileParser.cpp b/code/AssetLib/Obj/ObjFileParser.cpp index 767805c10..2e998a815 100644 --- a/code/AssetLib/Obj/ObjFileParser.cpp +++ b/code/AssetLib/Obj/ObjFileParser.cpp @@ -47,7 +47,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include #include #include #include @@ -56,7 +55,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { -const std::string ObjFileParser::DEFAULT_MATERIAL = AI_DEFAULT_MATERIAL_NAME; +constexpr char ObjFileParser::DEFAULT_MATERIAL[]; ObjFileParser::ObjFileParser() : m_DataIt(), diff --git a/code/AssetLib/Obj/ObjFileParser.h b/code/AssetLib/Obj/ObjFileParser.h index f3791c549..fbd2f2c89 100644 --- a/code/AssetLib/Obj/ObjFileParser.h +++ b/code/AssetLib/Obj/ObjFileParser.h @@ -42,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define OBJ_FILEPARSER_H_INC #include +#include #include #include #include @@ -140,7 +141,7 @@ private: // because the class contains pointer to allocated memory /// Default material name - static const std::string DEFAULT_MATERIAL; + static constexpr char DEFAULT_MATERIAL[] = AI_DEFAULT_MATERIAL_NAME; //! Iterator to current position in buffer DataArrayIt m_DataIt; //! Iterator to end position of buffer diff --git a/code/AssetLib/Obj/ObjTools.h b/code/AssetLib/Obj/ObjTools.h index 61efb98b2..9e57a1c84 100644 --- a/code/AssetLib/Obj/ObjTools.h +++ b/code/AssetLib/Obj/ObjTools.h @@ -2,7 +2,7 @@ Open Asset Import Library (assimp) ---------------------------------------------------------------------- -Copyright (c) 2006-2020, assimp team +Copyright (c) 2006-2021, assimp team All rights reserved. @@ -51,57 +51,62 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { -/** @brief Returns true, if the last entry of the buffer is reached. - * @param it Iterator of current position. - * @param end Iterator with end of buffer. +/** + * @brief Returns true, if the last entry of the buffer is reached. + * @param[in] it Iterator of current position. + * @param[in] end Iterator with end of buffer. * @return true, if the end of the buffer is reached. */ template inline bool isEndOfBuffer(char_t it, char_t end) { if (it == end) { return true; - } else { - --end; } + --end; + return (it == end); } -/** @brief Returns next word separated by a space - * @param pBuffer Pointer to data buffer - * @param pEnd Pointer to end of buffer +/** + * @brief Returns next word separated by a space + * @param[in] pBuffer Pointer to data buffer + * @param[in] pEnd Pointer to end of buffer * @return Pointer to next space */ template inline Char_T getNextWord(Char_T pBuffer, Char_T pEnd) { while (!isEndOfBuffer(pBuffer, pEnd)) { if (!IsSpaceOrNewLine(*pBuffer) || IsLineEnd(*pBuffer)) { - //if ( *pBuffer != '\\' ) break; } - pBuffer++; + ++pBuffer; } + return pBuffer; } -/** @brief Returns pointer a next token - * @param pBuffer Pointer to data buffer - * @param pEnd Pointer to end of buffer +/** + * @brief Returns pointer a next token + * @param[in] pBuffer Pointer to data buffer + * @param[in] pEnd Pointer to end of buffer * @return Pointer to next token */ template inline Char_T getNextToken(Char_T pBuffer, Char_T pEnd) { while (!isEndOfBuffer(pBuffer, pEnd)) { - if (IsSpaceOrNewLine(*pBuffer)) + if (IsSpaceOrNewLine(*pBuffer)) { break; - pBuffer++; + } + ++pBuffer; } return getNextWord(pBuffer, pEnd); } -/** @brief Skips a line - * @param it Iterator set to current position - * @param end Iterator set to end of scratch buffer for readout - * @param uiLine Current line number in format +/** + * @brief Skips a line + * @param[in] it Iterator set to current position + * @param[in] end Iterator set to end of scratch buffer for readout + * @param[out] uiLine Current line number in format * @return Current-iterator with new position */ template @@ -122,11 +127,12 @@ inline char_t skipLine(char_t it, char_t end, unsigned int &uiLine) { return it; } -/** @brief Get a name from the current line. Preserve space in the middle, +/** + * @brief Get a name from the current line. Preserve space in the middle, * but trim it at the end. - * @param it set to current position - * @param end set to end of scratch buffer for readout - * @param name Separated name + * @param[in] it set to current position + * @param[in] end set to end of scratch buffer for readout + * @param[out] name Separated name * @return Current-iterator with new position */ template @@ -150,15 +156,16 @@ inline char_t getName(char_t it, char_t end, std::string &name) { ++it; } std::string strName(pStart, &(*it)); - if (strName.empty()) - return it; - else + if (!strName.empty()) { name = strName; + } + return it; } -/** @brief Get a name from the current line. Do not preserve space +/** + * @brief Get a name from the current line. Do not preserve space * in the middle, but trim it at the end. * @param it set to current position * @param end set to end of scratch buffer for readout @@ -188,19 +195,19 @@ inline char_t getNameNoSpace(char_t it, char_t end, std::string &name) { ++it; } std::string strName(pStart, &(*it)); - if (strName.empty()) - return it; - else + if (!strName.empty()) { name = strName; - + } + return it; } -/** @brief Get next word from given line - * @param it set to current position - * @param end set to end of scratch buffer for readout - * @param pBuffer Buffer for next word - * @param length Buffer length +/** + * @brief Get next word from given line + * @param[in] it set to current position + * @param[in] end set to end of scratch buffer for readout + * @param[in] pBuffer Buffer for next word + * @param[in] length Buffer length * @return Current-iterator with new position */ template @@ -209,19 +216,21 @@ inline char_t CopyNextWord(char_t it, char_t end, char *pBuffer, size_t length) it = getNextWord(it, end); while (!IsSpaceOrNewLine(*it) && !isEndOfBuffer(it, end)) { pBuffer[index] = *it; - index++; - if (index == length - 1) + ++index; + if (index == length - 1) { break; + } ++it; } pBuffer[index] = '\0'; return it; } -/** @brief Get next float from given line - * @param it set to current position - * @param end set to end of scratch buffer for readout - * @param value Separated float value. +/** + * @brief Get next float from given line + * @param[in] it set to current position + * @param[in] end set to end of scratch buffer for readout + * @param[out] value Separated float value. * @return Current-iterator with new position */ template @@ -234,21 +243,33 @@ inline char_t getFloat(char_t it, char_t end, ai_real &value) { return it; } - +/** + * @brief Will remove white-spaces for a string. + * @param[in] str The string to clean + * @return The trimmed string. + */ template -string_type trim_whitespaces(string_type str) { - while (!str.empty() && IsSpace(str[0])) +inline string_type trim_whitespaces(string_type str) { + while (!str.empty() && IsSpace(str[0])) { str.erase(0); - while (!str.empty() && IsSpace(str[str.length() - 1])) + } + while (!str.empty() && IsSpace(str[str.length() - 1])) { str.erase(str.length() - 1); + } return str; } +/** + * @brief Checks for a line-end. + * @param[in] it Current iterator in string. + * @param[in] end End of the string. + * @return The trimmed string. + */ template bool hasLineEnd(T it, T end) { - bool hasLineEnd(false); + bool hasLineEnd = false; while (!isEndOfBuffer(it, end)) { - it++; + ++it; if (IsLineEnd(it)) { hasLineEnd = true; break; diff --git a/code/AssetLib/Ogre/OgreImporter.cpp b/code/AssetLib/Ogre/OgreImporter.cpp index 09c8a9dbf..5250dbe5e 100644 --- a/code/AssetLib/Ogre/OgreImporter.cpp +++ b/code/AssetLib/Ogre/OgreImporter.cpp @@ -79,7 +79,7 @@ bool OgreImporter::CanRead(const std::string &pFile, Assimp::IOSystem *pIOHandle } if (EndsWith(pFile, ".mesh.xml", false)) { - const char *tokens[] = { "" }; + static const char * const tokens[] = { "" }; return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1); } diff --git a/code/AssetLib/OpenGEX/OpenGEXImporter.cpp b/code/AssetLib/OpenGEX/OpenGEXImporter.cpp index e834f5318..bbf689b60 100644 --- a/code/AssetLib/OpenGEX/OpenGEXImporter.cpp +++ b/code/AssetLib/OpenGEX/OpenGEXImporter.cpp @@ -295,8 +295,8 @@ bool OpenGEXImporter::CanRead(const std::string &file, IOSystem *pIOHandler, boo if (!checkSig) { canRead = SimpleExtensionCheck(file, "ogex"); } else { - static const char *token[] = { "Metric", "GeometryNode", "VertexArray (attrib", "IndexArray" }; - canRead = BaseImporter::SearchFileHeaderForToken(pIOHandler, file, token, 4); + static const char * const token[] = { "Metric", "GeometryNode", "VertexArray (attrib", "IndexArray" }; + canRead = SearchFileHeaderForToken(pIOHandler, file, token, 4); } return canRead; diff --git a/code/AssetLib/Ply/PlyLoader.cpp b/code/AssetLib/Ply/PlyLoader.cpp index 93d48bcbf..b58ef1ef2 100644 --- a/code/AssetLib/Ply/PlyLoader.cpp +++ b/code/AssetLib/Ply/PlyLoader.cpp @@ -111,7 +111,7 @@ bool PLYImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c if (!pIOHandler) { return true; } - static const char *tokens[] = { + static const char * const tokens[] = { "ply" }; return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1); diff --git a/code/AssetLib/Q3D/Q3DLoader.cpp b/code/AssetLib/Q3D/Q3DLoader.cpp index f81026547..fe8541a5d 100644 --- a/code/AssetLib/Q3D/Q3DLoader.cpp +++ b/code/AssetLib/Q3D/Q3DLoader.cpp @@ -92,7 +92,7 @@ bool Q3DImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c else if (!extension.length() || checkSig) { if (!pIOHandler) return true; - const char *tokens[] = { "quick3Do", "quick3Ds" }; + static const char * const tokens[] = { "quick3Do", "quick3Ds" }; return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 2); } return false; diff --git a/code/AssetLib/STL/STLLoader.cpp b/code/AssetLib/STL/STLLoader.cpp index 4f644376d..602e07106 100644 --- a/code/AssetLib/STL/STLLoader.cpp +++ b/code/AssetLib/STL/STLLoader.cpp @@ -151,7 +151,7 @@ bool STLImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c if (!pIOHandler) { return true; } - const char *tokens[] = { "STL", "solid" }; + static const char * const tokens[] = { "STL", "solid" }; return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 2); } diff --git a/code/AssetLib/Terragen/TerragenLoader.cpp b/code/AssetLib/Terragen/TerragenLoader.cpp index 413fbbede..a4d8590d5 100644 --- a/code/AssetLib/Terragen/TerragenLoader.cpp +++ b/code/AssetLib/Terragen/TerragenLoader.cpp @@ -97,7 +97,7 @@ bool TerragenImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, b return true; } - const char *tokens[] = { "terragen" }; + static const char * const tokens[] = { "terragen" }; return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1); } diff --git a/code/AssetLib/XGL/XGLLoader.cpp b/code/AssetLib/XGL/XGLLoader.cpp index cb5da241d..a4d9835c5 100644 --- a/code/AssetLib/XGL/XGLLoader.cpp +++ b/code/AssetLib/XGL/XGLLoader.cpp @@ -116,9 +116,9 @@ bool XGLImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c return true; } - if (extension == "xml" || checkSig) { + if (extension == "xml" || checkSig) { ai_assert(pIOHandler != nullptr); - const char *tokens[] = { "", "", "" }; + static const char * const tokens[] = { "", "", "" }; return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 3); } diff --git a/code/Common/BaseImporter.cpp b/code/Common/BaseImporter.cpp index 0f41e9e65..fa6cac938 100644 --- a/code/Common/BaseImporter.cpp +++ b/code/Common/BaseImporter.cpp @@ -155,7 +155,7 @@ void BaseImporter::GetExtensionList(std::set &extensions) { // ------------------------------------------------------------------------------------------------ /*static*/ bool BaseImporter::SearchFileHeaderForToken(IOSystem *pIOHandler, const std::string &pFile, - const char **tokens, + const char * const *tokens, unsigned int numTokens, unsigned int searchBytes /* = 200 */, bool tokensSol /* false */, diff --git a/code/Common/ImporterRegistry.cpp b/code/Common/ImporterRegistry.cpp index 7500d2610..644acf29c 100644 --- a/code/Common/ImporterRegistry.cpp +++ b/code/Common/ImporterRegistry.cpp @@ -46,6 +46,7 @@ directly (unless you are adding new loaders), instead use the corresponding preprocessor flag to selectively disable formats. */ +#include #include #include #include diff --git a/code/PostProcessing/EmbedTexturesProcess.cpp b/code/PostProcessing/EmbedTexturesProcess.cpp index d7720de98..0c1207cff 100644 --- a/code/PostProcessing/EmbedTexturesProcess.cpp +++ b/code/PostProcessing/EmbedTexturesProcess.cpp @@ -89,7 +89,7 @@ void EmbedTexturesProcess::Execute(aiScene* pScene) { // Indeed embed if (addTexture(pScene, path.data)) { auto embeddedTextureId = pScene->mNumTextures - 1u; - ::ai_snprintf(path.data, 1024, "*%u", embeddedTextureId); + path.length = ::ai_snprintf(path.data, 1024, "*%u", embeddedTextureId); material->AddProperty(&path, AI_MATKEY_TEXTURE(tt, texId)); embeddedTexturesCount++; } diff --git a/include/assimp/BaseImporter.h b/include/assimp/BaseImporter.h index 54b5daac1..656e0f165 100644 --- a/include/assimp/BaseImporter.h +++ b/include/assimp/BaseImporter.h @@ -259,7 +259,7 @@ public: // static utilities static bool SearchFileHeaderForToken( IOSystem *pIOSystem, const std::string &file, - const char **tokens, + const char * const *tokens, unsigned int numTokens, unsigned int searchBytes = 200, bool tokensSol = false,