diff --git a/code/AssetLib/Collada/ColladaLoader.cpp b/code/AssetLib/Collada/ColladaLoader.cpp index f3750ceab..e1f19a5ed 100644 --- a/code/AssetLib/Collada/ColladaLoader.cpp +++ b/code/AssetLib/Collada/ColladaLoader.cpp @@ -95,6 +95,7 @@ ColladaLoader::ColladaLoader() : noSkeletonMesh(false), removeEmptyBones(false), ignoreUpDirection(false), + ignoreUnitSize(false), useColladaName(false), mNodeNameCounter(0) { // empty @@ -122,6 +123,7 @@ void ColladaLoader::SetupProperties(const Importer *pImp) { noSkeletonMesh = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_NO_SKELETON_MESHES, 0) != 0; removeEmptyBones = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_REMOVE_EMPTY_BONES, true) != 0; ignoreUpDirection = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION, 0) != 0; + ignoreUnitSize = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_IGNORE_UNIT_SIZE, 0) != 0; useColladaName = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_COLLADA_USE_COLLADA_NAMES, 0) != 0; } @@ -170,12 +172,15 @@ void ColladaLoader::InternReadFile(const std::string &pFile, aiScene *pScene, IO // ... then fill the materials with the now adjusted settings FillMaterials(parser, pScene); - // Apply unit-size scale calculation - - pScene->mRootNode->mTransformation *= aiMatrix4x4(parser.mUnitSize, 0, 0, 0, - 0, parser.mUnitSize, 0, 0, - 0, 0, parser.mUnitSize, 0, - 0, 0, 0, 1); + if (!ignoreUnitSize) { + // Apply unit-size scale calculation + pScene->mRootNode->mTransformation *= aiMatrix4x4( + parser.mUnitSize, 0, 0, 0, + 0, parser.mUnitSize, 0, 0, + 0, 0, parser.mUnitSize, 0, + 0, 0, 0, 1); + } + if (!ignoreUpDirection) { // Convert to Y_UP, if different orientation if (parser.mUpDirection == ColladaParser::UP_X) { diff --git a/code/AssetLib/Collada/ColladaLoader.h b/code/AssetLib/Collada/ColladaLoader.h index 870c12a5a..74b5c06b7 100644 --- a/code/AssetLib/Collada/ColladaLoader.h +++ b/code/AssetLib/Collada/ColladaLoader.h @@ -239,6 +239,7 @@ protected: bool noSkeletonMesh; bool removeEmptyBones; bool ignoreUpDirection; + bool ignoreUnitSize; bool useColladaName; /** Used by FindNameForNode() to generate unique node names */ diff --git a/code/AssetLib/glTF2/glTF2Importer.cpp b/code/AssetLib/glTF2/glTF2Importer.cpp index 86fd0ab7e..0fed11cef 100644 --- a/code/AssetLib/glTF2/glTF2Importer.cpp +++ b/code/AssetLib/glTF2/glTF2Importer.cpp @@ -234,7 +234,8 @@ inline void SetMaterialTextureProperty(std::vector &embeddedTexIdxs, Asset SetMaterialTextureProperty(embeddedTexIdxs, r, (glTF2::TextureInfo)prop, mat, texType, texSlot); if (prop.texture && prop.texture->source) { - mat->AddProperty(&prop.strength, 1, AI_MATKEY_GLTF_TEXTURE_STRENGTH(texType, texSlot)); + std::string textureStrengthKey = std::string(_AI_MATKEY_TEXTURE_BASE) + "." + "strength"; + mat->AddProperty(&prop.strength, 1, textureStrengthKey.c_str(), texType, texSlot); } } diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index f7aa847bc..08a79ef19 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -1418,25 +1418,29 @@ if(MSVC AND ASSIMP_INSTALL_PDB) COMPILE_PDB_NAME assimp${LIBRARY_SUFFIX} COMPILE_PDB_NAME_DEBUG assimp${LIBRARY_SUFFIX}${CMAKE_DEBUG_POSTFIX} ) - ENDIF() - IF(CMAKE_GENERATOR MATCHES "^Visual Studio") - install(FILES ${Assimp_BINARY_DIR}/code/Debug/assimp${LIBRARY_SUFFIX}${CMAKE_DEBUG_POSTFIX}.pdb - DESTINATION ${ASSIMP_LIB_INSTALL_DIR} - CONFIGURATIONS Debug - ) - install(FILES ${Assimp_BINARY_DIR}/code/RelWithDebInfo/assimp${LIBRARY_SUFFIX}.pdb - DESTINATION ${ASSIMP_LIB_INSTALL_DIR} - CONFIGURATIONS RelWithDebInfo - ) + IF(GENERATOR_IS_MULTI_CONFIG) + install(FILES ${Assimp_BINARY_DIR}/code/Debug/assimp${LIBRARY_SUFFIX}${CMAKE_DEBUG_POSTFIX}.pdb + DESTINATION ${ASSIMP_LIB_INSTALL_DIR} + CONFIGURATIONS Debug + ) + install(FILES ${Assimp_BINARY_DIR}/code/RelWithDebInfo/assimp${LIBRARY_SUFFIX}.pdb + DESTINATION ${ASSIMP_LIB_INSTALL_DIR} + CONFIGURATIONS RelWithDebInfo + ) + ELSE() + install(FILES ${Assimp_BINARY_DIR}/code/assimp${LIBRARY_SUFFIX}${CMAKE_DEBUG_POSTFIX}.pdb + DESTINATION ${ASSIMP_LIB_INSTALL_DIR} + CONFIGURATIONS Debug + ) + install(FILES ${Assimp_BINARY_DIR}/code/assimp${LIBRARY_SUFFIX}.pdb + DESTINATION ${ASSIMP_LIB_INSTALL_DIR} + CONFIGURATIONS RelWithDebInfo + ) + ENDIF() ELSE() - install(FILES ${Assimp_BINARY_DIR}/code/assimp${LIBRARY_SUFFIX}${CMAKE_DEBUG_POSTFIX}.pdb + install(FILES $ DESTINATION ${ASSIMP_LIB_INSTALL_DIR} - CONFIGURATIONS Debug - ) - install(FILES ${Assimp_BINARY_DIR}/code/assimp${LIBRARY_SUFFIX}.pdb - DESTINATION ${ASSIMP_LIB_INSTALL_DIR} - CONFIGURATIONS RelWithDebInfo ) ENDIF() ENDIF () diff --git a/contrib/openddlparser/CMakeLists.txt b/contrib/openddlparser/CMakeLists.txt index 51f18077c..28f3d5986 100644 --- a/contrib/openddlparser/CMakeLists.txt +++ b/contrib/openddlparser/CMakeLists.txt @@ -15,9 +15,11 @@ option( DDL_STATIC_LIBRARY "Deprecated, use BUILD_SHARED_LIBS instead." # for backwards compatibility use DDL_STATIC_LIBRARY as initial value for cmake variable BUILD_SHARED_LIBS # https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html if ( DDL_STATIC_LIBRARY ) - set ( build_shared_libs_default OFF ) + message("Building shared lib.") + set ( build_shared_libs_default OFF ) else() - set ( build_shared_libs_default ON ) + message("Building static lib.") + set ( build_shared_libs_default ON ) endif() option( DDL_BUILD_SHARED_LIBS "Set to ON to build shared libary of OpenDDL Parser." ${build_shared_libs_default} ) option( COVERALLS "Generate coveralls data" OFF ) @@ -36,6 +38,7 @@ endif() add_definitions( -D_VARIADIC_MAX=10 ) add_definitions( -DGTEST_HAS_PTHREAD=0 ) if ( DDL_DEBUG_OUTPUT ) + message("Enable debug output.") add_definitions( -DDDL_DEBUG_HEADER_NAME) endif() @@ -62,10 +65,12 @@ if (COVERALLS) include(Coveralls) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -fprofile-arcs -ftest-coverage") + message("Enable coveralls.") endif() # Include the doc component. if(DDL_DOCUMENTATION) + message("Generate doxygen documentation.") find_package(Doxygen REQUIRED) CONFIGURE_FILE( doc/openddlparser_doc.in doc/doxygenfile @ONLY ) add_custom_target(doc ALL diff --git a/contrib/openddlparser/README.md b/contrib/openddlparser/README.md index a48ea1be0..78db2a310 100644 --- a/contrib/openddlparser/README.md +++ b/contrib/openddlparser/README.md @@ -5,13 +5,15 @@ The OpenDDL-Parser is a small and easy to use library for OpenDDL-file-format-pa Build status ============ -Linux build status: [![Build Status](https://travis-ci.org/kimkulling/openddl-parser.png)](https://travis-ci.org/kimkulling/openddl-parser) + +Linux build status: [![Build Status](https://travis-ci.com/kimkulling/openddl-parser.svg?branch=master)](https://travis-ci.com/kimkulling/openddl-parser) Current coverity check status: Coverity Scan Build Status Current test coverage:[![Coverage Status](https://coveralls.io/repos/github/kimkulling/openddl-parser/badge.svg?branch=master)](https://coveralls.io/github/kimkulling/openddl-parser?branch=cpp_coveralls) + Get the source code =================== You can get the code from our git repository, which is located at GitHub. You can clone the repository with the following command: @@ -57,11 +59,11 @@ USE_ODDLPARSER_NS; int main( int argc, char *argv[] ) { if( argc < 3 ) { - return 1; + return Error; } char *filename( nullptr ); - if( 0 == strncmp( FileOption, argv[ 1 ], strlen( FileOption ) ) ) { + if( 0 == strncmp( FileOption, argv[1], strlen( FileOption ) ) ) { filename = argv[ 2 ]; } std::cout << "file to import: " << filename << std::endl; @@ -73,24 +75,27 @@ int main( int argc, char *argv[] ) { FILE *fileStream = fopen( filename, "r+" ); if( NULL == filename ) { std::cerr << "Cannot open file " << filename << std::endl; - return 1; + return Error; } // obtain file size: fseek( fileStream, 0, SEEK_END ); - const size_t size( ftell( fileStream ) ); + const size_t size = ftell( fileStream ); rewind( fileStream ); if( size > 0 ) { char *buffer = new char[ size ]; - const size_t readSize( fread( buffer, sizeof( char ), size, fileStream ) ); + const size_t readSize = fread( buffer, sizeof( char ), size, fileStream ); assert( readSize == size ); + + // Set the memory buffer OpenDDLParser theParser; theParser.setBuffer( buffer, size ); - const bool result( theParser.parse() ); - if( !result ) { + if( !theParser.parse() ) { std::cerr << "Error while parsing file " << filename << "." << std::endl; + return Error; } } + return 0; } @@ -106,9 +111,9 @@ theParser.setBuffer( buffer, size ); const bool result( theParser.parse() ); if ( result ) { DDLNode *root = theParser.getRoot(); - DDLNode::DllNodeList childs = root->getChildNodeList(); - for ( size_t i=0; igetChildNodeList(); + for ( size_t i=0; igetProperty(); // to get properties std::string type = child->getType(); // to get the node type Value *values = child->getValue(); // to get the data; diff --git a/contrib/openddlparser/code/OpenDDLExport.cpp b/contrib/openddlparser/code/OpenDDLExport.cpp index 8768ca64f..f8d33c48d 100644 --- a/contrib/openddlparser/code/OpenDDLExport.cpp +++ b/contrib/openddlparser/code/OpenDDLExport.cpp @@ -134,9 +134,10 @@ bool OpenDDLExport::writeToStream(const std::string &statement) { } bool OpenDDLExport::writeNode(DDLNode *node, std::string &statement) { + bool success(true); writeNodeHeader(node, statement); if (node->hasProperties()) { - writeProperties(node, statement); + success = writeProperties(node, statement); } writeLineEnd(statement); @@ -160,7 +161,7 @@ bool OpenDDLExport::writeNode(DDLNode *node, std::string &statement) { writeToStream(statement); - return true; + return success; } bool OpenDDLExport::writeNodeHeader(DDLNode *node, std::string &statement) { diff --git a/contrib/openddlparser/code/OpenDDLParser.cpp b/contrib/openddlparser/code/OpenDDLParser.cpp index fe9d23ab5..3d7dce45e 100644 --- a/contrib/openddlparser/code/OpenDDLParser.cpp +++ b/contrib/openddlparser/code/OpenDDLParser.cpp @@ -30,7 +30,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #ifdef _WIN32 -#include +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# include #endif // _WIN32 BEGIN_ODDLPARSER_NS @@ -71,7 +74,7 @@ const char *getTypeToken(Value::ValueType type) { return Grammar::PrimitiveTypeToken[(size_t)type]; } -static void logInvalidTokenError(char *in, const std::string &exp, OpenDDLParser::logCallback callback) { +static void logInvalidTokenError(const char *in, const std::string &exp, OpenDDLParser::logCallback callback) { if (callback) { std::string full(in); std::string part(full.substr(0, 50)); @@ -338,20 +341,25 @@ char *OpenDDLParser::parseStructure(char *in, char *end) { bool error(false); in = lookForNextToken(in, end); - if (*in == *Grammar::OpenBracketToken) { - // loop over all children ( data and nodes ) - do { - in = parseStructureBody(in, end, error); - if (in == nullptr) { - return nullptr; + if (in != end) { + if (*in == *Grammar::OpenBracketToken) { + // loop over all children ( data and nodes ) + do { + in = parseStructureBody(in, end, error); + if (in == nullptr) { + return nullptr; + } + } while (in != end && + *in != *Grammar::CloseBracketToken); + if (in != end) { + ++in; } - } while (*in != *Grammar::CloseBracketToken); - ++in; - } else { - ++in; - logInvalidTokenError(in, std::string(Grammar::OpenBracketToken), m_logCallback); - error = true; - return nullptr; + } else { + ++in; + logInvalidTokenError(in, std::string(Grammar::OpenBracketToken), m_logCallback); + error = true; + return nullptr; + } } in = lookForNextToken(in, end); @@ -418,8 +426,8 @@ char *OpenDDLParser::parseStructureBody(char *in, char *end, bool &error) { } in = lookForNextToken(in, end); - if (*in != '}') { - logInvalidTokenError(in, std::string(Grammar::CloseBracketToken), m_logCallback); + if (in == end || *in != '}') { + logInvalidTokenError(in == end ? "" : in, std::string(Grammar::CloseBracketToken), m_logCallback); return nullptr; } else { //in++; @@ -455,7 +463,7 @@ DDLNode *OpenDDLParser::top() { return nullptr; } - DDLNode *top(m_stack.back()); + DDLNode *top = m_stack.back(); return top; } @@ -647,12 +655,15 @@ char *OpenDDLParser::parseBooleanLiteral(char *in, char *end, Value **boolean) { in = lookForNextToken(in, end); char *start(in); + + size_t len(0); while (!isSeparator(*in) && in != end) { ++in; + ++len; } - int res = ::strncmp(Grammar::BoolTrue, start, strlen(Grammar::BoolTrue)); + int res = ::strncmp(Grammar::BoolTrue, start, len); if (0 != res) { - res = ::strncmp(Grammar::BoolFalse, start, strlen(Grammar::BoolFalse)); + res = ::strncmp(Grammar::BoolFalse, start, len); if (0 != res) { *boolean = nullptr; return in; @@ -733,7 +744,7 @@ char *OpenDDLParser::parseFloatingLiteral(char *in, char *end, Value **floating, in = lookForNextToken(in, end); char *start(in); - while (!isSeparator(*in) && in != end) { + while (in != end && !isSeparator(*in)) { ++in; } @@ -838,6 +849,13 @@ char *OpenDDLParser::parseHexaLiteral(char *in, char *end, Value **data) { int value(0); while (pos > 0) { int v = hex2Decimal(*start); + if (v < 0) { + while (isEndofLine(*in)) { + ++in; + } + return in; + } + --pos; value = (value << 4) | v; ++start; @@ -901,10 +919,10 @@ char *OpenDDLParser::parseDataList(char *in, char *end, Value::ValueType type, V } in = lookForNextToken(in, end); - if (*in == '{') { + if (in != end && *in == '{') { ++in; Value *current(nullptr), *prev(nullptr); - while ('}' != *in) { + while (in != end && '}' != *in) { current = nullptr; in = lookForNextToken(in, end); if (Value::ValueType::ddl_ref == type) { @@ -962,11 +980,12 @@ char *OpenDDLParser::parseDataList(char *in, char *end, Value::ValueType type, V } in = getNextSeparator(in, end); - if (',' != *in && Grammar::CloseBracketToken[0] != *in && !isSpace(*in)) { + if (in == end || (',' != *in && Grammar::CloseBracketToken[0] != *in && !isSpace(*in))) { break; } } - ++in; + if (in != end) + ++in; } return in; diff --git a/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h b/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h index 6ccc83b88..4b92d1406 100644 --- a/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h +++ b/contrib/openddlparser/include/openddlparser/OpenDDLCommon.h @@ -26,8 +26,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include -#include -#include +#include +#include #ifndef _WIN32 #include #endif diff --git a/contrib/openddlparser/include/openddlparser/OpenDDLParser.h b/contrib/openddlparser/include/openddlparser/OpenDDLParser.h index 3fbb4b6af..735e784e3 100644 --- a/contrib/openddlparser/include/openddlparser/OpenDDLParser.h +++ b/contrib/openddlparser/include/openddlparser/OpenDDLParser.h @@ -40,15 +40,6 @@ struct Identifier; struct Reference; struct Property; -template -inline bool isEmbeddedCommentOpenTag(T *in, T *end) { - if (in == '/' && in + 1 == '*') { - return true; - } - - return false; -} - /// @brief Utility function to search for the next token or the end of the buffer. /// @param in [in] The start position in the buffer. /// @param end [in] The end position in the buffer. diff --git a/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h b/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h index 42ad675f8..62144a01c 100644 --- a/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h +++ b/contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h @@ -54,7 +54,9 @@ inline bool isSeparator(T in) { return false; } -static const unsigned char chartype_table[256] = { +const size_t CharTableSize = 256; + +static const unsigned char chartype_table[CharTableSize] = { 0, 0, 0, @@ -318,6 +320,10 @@ static const unsigned char chartype_table[256] = { template inline bool isNumeric(const T in) { + if (static_cast(in) >= CharTableSize) { + return '\0'; + } + size_t idx = static_cast(in); return idx < sizeof(chartype_table) && (chartype_table[idx] == 1); } @@ -433,7 +439,7 @@ inline bool isEndofLine(const T in) { template inline static T *getNextSeparator(T *in, T *end) { - while (!isSeparator(*in) || in == end) { + while (in != end && !isSeparator(*in)) { ++in; } return in; diff --git a/include/assimp/XmlParser.h b/include/assimp/XmlParser.h index 52a23bd83..4ab42ba2a 100644 --- a/include/assimp/XmlParser.h +++ b/include/assimp/XmlParser.h @@ -302,7 +302,9 @@ bool TXmlParser::parse(IOStream *stream) { stream->Read(&mData[0], 1, len); mDoc = new pugi::xml_document(); - pugi::xml_parse_result parse_result = mDoc->load_string(&mData[0], pugi::parse_full); + // load_string assumes native encoding (aka always utf-8 per build options) + //pugi::xml_parse_result parse_result = mDoc->load_string(&mData[0], pugi::parse_full); + pugi::xml_parse_result parse_result = mDoc->load_buffer(&mData[0], mData.size(), pugi::parse_full); if (parse_result.status == pugi::status_ok) { return true; } diff --git a/include/assimp/config.h.in b/include/assimp/config.h.in index 9e843a20d..97551e602 100644 --- a/include/assimp/config.h.in +++ b/include/assimp/config.h.in @@ -1035,6 +1035,15 @@ enum aiComponent */ #define AI_CONFIG_IMPORT_COLLADA_IGNORE_UP_DIRECTION "IMPORT_COLLADA_IGNORE_UP_DIRECTION" +// --------------------------------------------------------------------------- +/** @brief Specifies whether the Collada loader will ignore the provided unit size. + * + * If this property is set to true, the unit size provided in the file header will + * be ignored and the file will be loaded without scaling the assets. + * Property type: Bool. Default value: false. + */ +#define AI_CONFIG_IMPORT_COLLADA_IGNORE_UNIT_SIZE "IMPORT_COLLADA_IGNORE_UNIT_SIZE" + // --------------------------------------------------------------------------- /** @brief Specifies whether the Collada loader should use Collada names. * diff --git a/include/assimp/material.inl b/include/assimp/material.inl index 744743bc7..b7222f9c7 100644 --- a/include/assimp/material.inl +++ b/include/assimp/material.inl @@ -211,7 +211,8 @@ AI_FORCE_INLINE aiReturn aiMaterial::Get(const char* pKey,unsigned int type, unsigned int idx,aiColor3D& pOut) const { aiColor4D c; const aiReturn ret = aiGetMaterialColor(this,pKey,type,idx,&c); - pOut = aiColor3D(c.r,c.g,c.b); + if (ret == aiReturn_SUCCESS) + pOut = aiColor3D(c.r,c.g,c.b); return ret; } // ---------------------------------------------------------------------------