From 51e248909fd84a77ecf449cea02e8496c13068e3 Mon Sep 17 00:00:00 2001 From: Sergio Acereda Date: Fri, 11 Mar 2022 22:29:59 +0100 Subject: [PATCH 1/7] Avoid setting metallic/roughness/sheen/clearcoat properties when they are not found on mtl file. --- code/AssetLib/Obj/ObjFileData.h | 21 +++++++++-------- code/AssetLib/Obj/ObjFileImporter.cpp | 15 ++++++++---- code/AssetLib/Obj/ObjFileMtlImporter.cpp | 20 ++++++++++++++-- code/AssetLib/Obj/ObjFileMtlImporter.h | 3 +++ code/CMakeLists.txt | 1 + code/Common/Maybe.h | 29 ++++++++++++++++++++++++ 6 files changed, 72 insertions(+), 17 deletions(-) create mode 100644 code/Common/Maybe.h diff --git a/code/AssetLib/Obj/ObjFileData.h b/code/AssetLib/Obj/ObjFileData.h index 3d504d0bb..456fce862 100644 --- a/code/AssetLib/Obj/ObjFileData.h +++ b/code/AssetLib/Obj/ObjFileData.h @@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef OBJ_FILEDATA_H_INC #define OBJ_FILEDATA_H_INC +#include #include #include #include @@ -183,15 +184,15 @@ struct Material { aiColor3D transparent; //! PBR Roughness - ai_real roughness; + Maybe roughness; //! PBR Metallic - ai_real metallic; + Maybe metallic; //! PBR Metallic - aiColor3D sheen; + Maybe sheen; //! PBR Clearcoat Thickness - ai_real clearcoat_thickness; + Maybe clearcoat_thickness; //! PBR Clearcoat Rougness - ai_real clearcoat_roughness; + Maybe clearcoat_roughness; //! PBR Anisotropy ai_real anisotropy; @@ -206,11 +207,11 @@ struct Material { illumination_model(1), ior(ai_real(1.0)), transparent(ai_real(1.0), ai_real(1.0), ai_real(1.0)), - roughness(ai_real(1.0)), - metallic(ai_real(0.0)), - sheen(ai_real(1.0), ai_real(1.0), ai_real(1.0)), - clearcoat_thickness(ai_real(0.0)), - clearcoat_roughness(ai_real(0.0)), + roughness(), + metallic(), + sheen(), + clearcoat_thickness(), + clearcoat_roughness(), anisotropy(ai_real(0.0)), bump_multiplier(ai_real(1.0)) { std::fill_n(clamp, static_cast(TextureTypeCount), false); diff --git a/code/AssetLib/Obj/ObjFileImporter.cpp b/code/AssetLib/Obj/ObjFileImporter.cpp index 68fdb2172..429c6ea9d 100644 --- a/code/AssetLib/Obj/ObjFileImporter.cpp +++ b/code/AssetLib/Obj/ObjFileImporter.cpp @@ -616,11 +616,16 @@ void ObjFileImporter::createMaterials(const ObjFile::Model *pModel, aiScene *pSc mat->AddProperty(&pCurrentMaterial->shineness, 1, AI_MATKEY_SHININESS); mat->AddProperty(&pCurrentMaterial->alpha, 1, AI_MATKEY_OPACITY); mat->AddProperty(&pCurrentMaterial->transparent, 1, AI_MATKEY_COLOR_TRANSPARENT); - mat->AddProperty(&pCurrentMaterial->roughness, 1, AI_MATKEY_ROUGHNESS_FACTOR); - mat->AddProperty(&pCurrentMaterial->metallic, 1, AI_MATKEY_METALLIC_FACTOR); - mat->AddProperty(&pCurrentMaterial->sheen, 1, AI_MATKEY_SHEEN_COLOR_FACTOR); - mat->AddProperty(&pCurrentMaterial->clearcoat_thickness, 1, AI_MATKEY_CLEARCOAT_FACTOR); - mat->AddProperty(&pCurrentMaterial->clearcoat_roughness, 1, AI_MATKEY_CLEARCOAT_ROUGHNESS_FACTOR); + if (pCurrentMaterial->roughness) + mat->AddProperty(&pCurrentMaterial->roughness.Get(), 1, AI_MATKEY_ROUGHNESS_FACTOR); + if (pCurrentMaterial->metallic) + mat->AddProperty(&pCurrentMaterial->metallic.Get(), 1, AI_MATKEY_METALLIC_FACTOR); + if (pCurrentMaterial->sheen) + mat->AddProperty(&pCurrentMaterial->sheen.Get(), 1, AI_MATKEY_SHEEN_COLOR_FACTOR); + if (pCurrentMaterial->clearcoat_thickness) + mat->AddProperty(&pCurrentMaterial->clearcoat_thickness.Get(), 1, AI_MATKEY_CLEARCOAT_FACTOR); + if (pCurrentMaterial->clearcoat_roughness) + mat->AddProperty(&pCurrentMaterial->clearcoat_roughness.Get(), 1, AI_MATKEY_CLEARCOAT_ROUGHNESS_FACTOR); mat->AddProperty(&pCurrentMaterial->anisotropy, 1, AI_MATKEY_ANISOTROPY_FACTOR); // Adding refraction index diff --git a/code/AssetLib/Obj/ObjFileMtlImporter.cpp b/code/AssetLib/Obj/ObjFileMtlImporter.cpp index 2441c17f2..e760b7b7b 100644 --- a/code/AssetLib/Obj/ObjFileMtlImporter.cpp +++ b/code/AssetLib/Obj/ObjFileMtlImporter.cpp @@ -205,7 +205,7 @@ void ObjFileMtlImporter::load() { break; case 's': ++m_DataIt; - getColorRGBA(&m_pModel->m_pCurrentMaterial->sheen); + getColorRGBA(m_pModel->m_pCurrentMaterial->sheen); break; case 'c': ++m_DataIt; @@ -267,6 +267,12 @@ void ObjFileMtlImporter::getColorRGBA(aiColor3D *pColor) { pColor->b = b; } +void ObjFileMtlImporter::getColorRGBA(Maybe &value) { + aiColor3D v; + getColorRGBA(&v); + value = Maybe(v); +} + // ------------------------------------------------------------------- // Loads the kind of illumination model. void ObjFileMtlImporter::getIlluminationModel(int &illum_model) { @@ -274,6 +280,7 @@ void ObjFileMtlImporter::getIlluminationModel(int &illum_model) { illum_model = atoi(&m_buffer[0]); } + // ------------------------------------------------------------------- // Loads a single float value. void ObjFileMtlImporter::getFloatValue(ai_real &value) { @@ -283,10 +290,19 @@ void ObjFileMtlImporter::getFloatValue(ai_real &value) { value = 0.0f; return; } - + value = (ai_real)fast_atof(&m_buffer[0]); } +void ObjFileMtlImporter::getFloatValue(Maybe &value) { + m_DataIt = CopyNextWord(m_DataIt, m_DataItEnd, &m_buffer[0], BUFFERSIZE); + size_t len = std::strlen(&m_buffer[0]); + if (len) + value = Maybe(fast_atof(&m_buffer[0])); + else + value = Maybe(); +} + // ------------------------------------------------------------------- // Creates a material from loaded data. void ObjFileMtlImporter::createMaterial() { diff --git a/code/AssetLib/Obj/ObjFileMtlImporter.h b/code/AssetLib/Obj/ObjFileMtlImporter.h index cda7415e6..a0ee967ee 100644 --- a/code/AssetLib/Obj/ObjFileMtlImporter.h +++ b/code/AssetLib/Obj/ObjFileMtlImporter.h @@ -40,6 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef OBJFILEMTLIMPORTER_H_INC #define OBJFILEMTLIMPORTER_H_INC +#include #include #include #include @@ -81,10 +82,12 @@ private: void load(); /// Get color data. void getColorRGBA(aiColor3D *pColor); + void getColorRGBA(Maybe &value); /// Get illumination model from loaded data void getIlluminationModel(int &illum_model); /// Gets a float value from data. void getFloatValue(ai_real &value); + void getFloatValue(Maybe &value); /// Creates a new material from loaded data. void createMaterial(); /// Get texture name from loaded data. diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 7a2f8a109..4f88003f5 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -181,6 +181,7 @@ SET( Common_SRCS Common/DefaultIOSystem.cpp Common/ZipArchiveIOSystem.cpp Common/PolyTools.h + Common/Maybe.h Common/Importer.cpp Common/IFF.h Common/SGSpatialSort.cpp diff --git a/code/Common/Maybe.h b/code/Common/Maybe.h new file mode 100644 index 000000000..e99d72058 --- /dev/null +++ b/code/Common/Maybe.h @@ -0,0 +1,29 @@ +#pragma once +#include + +template +struct Maybe { +private: + T _val; + bool _valid; + +public: + Maybe() : + _valid(false) {} + + explicit Maybe(const T &val) : + _valid(true), _val(val) { + } + + operator bool() const { + return _valid; + } + + const T &Get() const { + ai_assert(_valid); + return _val; + } + +private: + Maybe &operator&() = delete; +}; From 26bb601d8f77e234e4cd2f7ee679fa628b8c78c9 Mon Sep 17 00:00:00 2001 From: Sergio Acereda Date: Sat, 12 Mar 2022 08:03:27 +0100 Subject: [PATCH 2/7] Fix includes --- code/AssetLib/Obj/ObjFileData.h | 2 +- code/AssetLib/Obj/ObjFileMtlImporter.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/code/AssetLib/Obj/ObjFileData.h b/code/AssetLib/Obj/ObjFileData.h index 456fce862..0dd13f545 100644 --- a/code/AssetLib/Obj/ObjFileData.h +++ b/code/AssetLib/Obj/ObjFileData.h @@ -43,11 +43,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef OBJ_FILEDATA_H_INC #define OBJ_FILEDATA_H_INC -#include #include #include #include #include +#include "Common/Maybe.h" namespace Assimp { namespace ObjFile { diff --git a/code/AssetLib/Obj/ObjFileMtlImporter.h b/code/AssetLib/Obj/ObjFileMtlImporter.h index a0ee967ee..6e73cf45c 100644 --- a/code/AssetLib/Obj/ObjFileMtlImporter.h +++ b/code/AssetLib/Obj/ObjFileMtlImporter.h @@ -40,10 +40,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef OBJFILEMTLIMPORTER_H_INC #define OBJFILEMTLIMPORTER_H_INC -#include #include #include #include +#include "Common/Maybe.h" struct aiColor3D; struct aiString; From 729ab8ae334293acc9f21fbd04daf0d9bcbc5ab6 Mon Sep 17 00:00:00 2001 From: Sergio Acereda Date: Sat, 12 Mar 2022 08:15:11 +0100 Subject: [PATCH 3/7] Trying to fix reorder error --- code/Common/Maybe.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/Common/Maybe.h b/code/Common/Maybe.h index e99d72058..3eb2e1d97 100644 --- a/code/Common/Maybe.h +++ b/code/Common/Maybe.h @@ -12,7 +12,7 @@ public: _valid(false) {} explicit Maybe(const T &val) : - _valid(true), _val(val) { + _val(val), _valid(true) { } operator bool() const { From 90a24440db656b0ef1b499ac3575d79e034fec9a Mon Sep 17 00:00:00 2001 From: Carlos Martinez Perez Date: Fri, 18 Mar 2022 17:00:57 +0100 Subject: [PATCH 4/7] - Adapted bat file to new NDK and toolchain - Able to build x86, x86_64, armv8, armv7 for android - Automatically detects latest ndk on your system --- scripts/android_crosscompile/.gitignore | 1 + scripts/android_crosscompile/make_android.bat | 82 +++++++++++++++---- 2 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 scripts/android_crosscompile/.gitignore diff --git a/scripts/android_crosscompile/.gitignore b/scripts/android_crosscompile/.gitignore new file mode 100644 index 000000000..6caf68aff --- /dev/null +++ b/scripts/android_crosscompile/.gitignore @@ -0,0 +1 @@ +output \ No newline at end of file diff --git a/scripts/android_crosscompile/make_android.bat b/scripts/android_crosscompile/make_android.bat index a50695e16..945a9f199 100644 --- a/scripts/android_crosscompile/make_android.bat +++ b/scripts/android_crosscompile/make_android.bat @@ -1,28 +1,76 @@ @echo off -set ASSIMP_PATH=D:\projects\asset-importer-lib\assimp -set CMAKE_PATH="C:\Program Files\CMake\bin\cmake.exe" -set ANDROID_NDK_PATH=C:\Users\kimkulling\AppData\Local\Android\Sdk\ndk-bundle -set ANDROID_CMAKE_PATH=contrib\android-cmake +set ANDROID_PLATFORM=21 +set /p ANDROID_PLATFORM="Enter Android platform - Enter to use %ANDROID_PLATFORM%: " -pushd %ASSIMP_PATH% +set ANDROID_ABI=armeabi-v7a +set /p ANDROID_ABI="Enter Android ABI ( armeabi-v7a, arm64-v8a , x86 , x86_64 ) - Enter to use %ANDROID_ABI% : " -rmdir /s /q build -mkdir build -cd build +set COMMON_CXX_FLAGS=-DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fexceptions -frtti -stdlib=libc++ +set COMMON_C_FLAGS=-DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fexceptions -%CMAKE_PATH% .. ^ - -G"MinGW Makefiles" ^ +if %ANDROID_ABI% == armeabi-v7a ( + set CXX_FLAGS="%COMMON_CXX_FLAGS% -march=armv7-a -mthumb --target=armv7-none-linux-androideabi%ANDROID_PLATFORM%" + set C_FLAGS="%COMMON_C_FLAGS% -march=armv7-a -mthumb --target=armv7-none-linux-androideabi%ANDROID_PLATFORM%" +) +if %ANDROID_ABI% == arm64-v8a ( + set CXX_FLAGS="%COMMON_CXX_FLAGS% -march=armv8-a --target=aarch64-none-linux-android%ANDROID_PLATFORM%" + set C_FLAGS="%COMMON_C_FLAGS% -march=armv8-a --target=aarch64-none-linux-android%ANDROID_PLATFORM%" +) +if %ANDROID_ABI% == x86 ( + set CXX_FLAGS="%COMMON_CXX_FLAGS% --target=i686-none-linux-android%ANDROID_PLATFORM%" + set C_FLAGS="%COMMON_C_FLAGS% --target=i686-none-linux-android%ANDROID_PLATFORM%" +) +if %ANDROID_ABI% == x86_64 ( + set CXX_FLAGS="%COMMON_CXX_FLAGS%" + set C_FLAGS="%COMMON_C_FLAGS%" +) + +set CMAKE_PATH="%ProgramFiles%\CMake\bin\cmake.exe" +if exist %CMAKE_PATH% ( + echo Found cmake at %CMAKE_PATH% +) else ( + set /p CMAKE_PATH="Enter cmake.exe path: " +) + +set ANDROID_NDK_PATH="" +FOR /F "tokens=* USEBACKQ" %%F IN (`dir "%LocalAppData%\Android\Sdk\ndk" /b /o:n /a:d`) DO ( + SET ANDROID_NDK_PATH="%LocalAppData%\Android\Sdk\ndk\%%F" +) +if exist %ANDROID_NDK_PATH% ( + echo Found NDK at %ANDROID_NDK_PATH% +) else ( + set /p ANDROID_NDK_PATH="Enter ndk path: " +) + +set BUILD_FOLDER=build +rmdir /s /q %BUILD_FOLDER% +mkdir %BUILD_FOLDER% + +%CMAKE_PATH% ^ + -G"Unix Makefiles" ^ -DCMAKE_BUILD_TYPE=Release ^ - -DCMAKE_TOOLCHAIN_FILE=%ANDROID_CMAKE_PATH%\android.toolchain.cmake ^ + -DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK_PATH%\build\cmake\android.toolchain.cmake ^ -DCMAKE_MAKE_PROGRAM=%ANDROID_NDK_PATH%\prebuilt\windows-x86_64\bin\make.exe ^ -DANDROID_NDK=%ANDROID_NDK_PATH% ^ - -DANDROID_NATIVE_API_LEVEL=android-9 ^ + -DOPERATING_SYSTEM="Android" ^ + -DANDROID_PLATFORM=%ANDROID_PLATFORM% ^ + -DANDROID_ABI=%ANDROID_ABI% ^ -DASSIMP_ANDROID_JNIIOSYSTEM=ON ^ - -DANDROID_ABI=arm64-v8a ^ - -DASSIMP_BUILD_ZLIB=ON ^ - -DASSIMP_BUILD_TESTS=OFF + -DASSIMP_BUILD_TESTS=OFF ^ + -DCMAKE_CXX_FLAGS=%CXX_FLAGS% ^ + -DMAKE_C_FLAGS=%C_FLAGS% ^ + -S "..\.." ^ + -B ".\%BUILD_FOLDER%\" -%CMAKE_PATH% --build . +%CMAKE_PATH% --build ".\%BUILD_FOLDER%\"" -- -j 4" -popd \ No newline at end of file +set OUTPUT_FOLDER=.\output\ +mkdir %OUTPUT_FOLDER% +mkdir "%OUTPUT_FOLDER%\lib\%ANDROID_ABI%" + +copy "%BUILD_FOLDER%\bin\libassimp.so" "%OUTPUT_FOLDER%\lib\%ANDROID_ABI%\" +xcopy %BUILD_FOLDER%\include\assimp\ %OUTPUT_FOLDER%\include\assimp\ /y /s /e +xcopy ..\..\include\assimp\ %OUTPUT_FOLDER%\include\assimp\ /y /s /e + +rmdir /s /q %BUILD_FOLDER% \ No newline at end of file From 537c46a42aecdacf00c2c2db449892c219104cfe Mon Sep 17 00:00:00 2001 From: Jan Krassnigg Date: Wed, 23 Mar 2022 15:45:09 +0100 Subject: [PATCH 5/7] Prevent nullptr access to normals-array in bitangent computation --- code/AssetLib/glTF2/glTF2Importer.cpp | 43 ++++++++++++++------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Importer.cpp b/code/AssetLib/glTF2/glTF2Importer.cpp index e8b8562e6..293d3dea7 100644 --- a/code/AssetLib/glTF2/glTF2Importer.cpp +++ b/code/AssetLib/glTF2/glTF2Importer.cpp @@ -284,7 +284,7 @@ static aiMaterial *ImportMaterial(std::vector &embeddedTexIdxs, Asset &r, M aimat->AddProperty(&alphaMode, AI_MATKEY_GLTF_ALPHAMODE); aimat->AddProperty(&mat.alphaCutoff, 1, AI_MATKEY_GLTF_ALPHACUTOFF); - //pbrSpecularGlossiness + // pbrSpecularGlossiness if (mat.pbrSpecularGlossiness.isPresent) { PbrSpecularGlossiness &pbrSG = mat.pbrSpecularGlossiness.value; @@ -606,7 +606,10 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) { } } if (needTangents) { - if (target.tangent[0]->count != aim->mNumVertices) { + if (!aiAnimMesh.HasNormals()) { + // prevent nullptr access to aiAnimMesh.mNormals below when no normals are available + ASSIMP_LOG_WARN("Bitangents of target ", i, " in mesh \"", mesh.name, "\" can't be computed, because mesh has no normals."); + } else if (target.tangent[0]->count != aim->mNumVertices) { ASSIMP_LOG_WARN("Tangents of target ", i, " in mesh \"", mesh.name, "\" does not match the vertex count"); } else { Tangent *tangent = nullptr; @@ -698,12 +701,12 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) { nFaces = count - 2; facePtr = faces = new aiFace[nFaces]; for (unsigned int i = 0; i < nFaces; ++i) { - //The ordering is to ensure that the triangles are all drawn with the same orientation + // The ordering is to ensure that the triangles are all drawn with the same orientation if ((i + 1) % 2 == 0) { - //For even n, vertices n + 1, n, and n + 2 define triangle n + // For even n, vertices n + 1, n, and n + 2 define triangle n SetFaceAndAdvance3(facePtr, aim->mNumVertices, data.GetUInt(i + 1), data.GetUInt(i), data.GetUInt(i + 2)); } else { - //For odd n, vertices n, n+1, and n+2 define triangle n + // For odd n, vertices n, n+1, and n+2 define triangle n SetFaceAndAdvance3(facePtr, aim->mNumVertices, data.GetUInt(i), data.GetUInt(i + 1), data.GetUInt(i + 2)); } } @@ -776,12 +779,12 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) { nFaces = count - 2; facePtr = faces = new aiFace[nFaces]; for (unsigned int i = 0; i < nFaces; ++i) { - //The ordering is to ensure that the triangles are all drawn with the same orientation + // The ordering is to ensure that the triangles are all drawn with the same orientation if ((i + 1) % 2 == 0) { - //For even n, vertices n + 1, n, and n + 2 define triangle n + // For even n, vertices n + 1, n, and n + 2 define triangle n SetFaceAndAdvance3(facePtr, aim->mNumVertices, i + 1, i, i + 2); } else { - //For odd n, vertices n, n+1, and n+2 define triangle n + // For odd n, vertices n, n+1, and n+2 define triangle n SetFaceAndAdvance3(facePtr, aim->mNumVertices, i, i + 1, i + 2); } } @@ -904,14 +907,14 @@ void glTF2Importer::ImportLights(glTF2::Asset &r) { ail->mAttenuationLinear = 0.0; ail->mAttenuationQuadratic = 0.0; } else { - //in PBR attenuation is calculated using inverse square law which can be expressed - //using assimps equation: 1/(att0 + att1 * d + att2 * d*d) with the following parameters - //this is correct equation for the case when range (see - //https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual) - //is not present. When range is not present it is assumed that it is infinite and so numerator is 1. - //When range is present then numerator might be any value in range [0,1] and then assimps equation - //will not suffice. In this case range is added into metadata in ImportNode function - //and its up to implementation to read it when it wants to + // in PBR attenuation is calculated using inverse square law which can be expressed + // using assimps equation: 1/(att0 + att1 * d + att2 * d*d) with the following parameters + // this is correct equation for the case when range (see + // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual) + // is not present. When range is not present it is assumed that it is infinite and so numerator is 1. + // When range is present then numerator might be any value in range [0,1] and then assimps equation + // will not suffice. In this case range is added into metadata in ImportNode function + // and its up to implementation to read it when it wants to ail->mAttenuationConstant = 0.0; ail->mAttenuationLinear = 0.0; ail->mAttenuationQuadratic = 1.0; @@ -1161,8 +1164,8 @@ aiNode *ImportNode(aiScene *pScene, glTF2::Asset &r, std::vector & if (node.light) { pScene->mLights[node.light.GetIndex()]->mName = ainode->mName; - //range is optional - see https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual - //it is added to meta data of parent node, because there is no other place to put it + // range is optional - see https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual + // it is added to meta data of parent node, because there is no other place to put it if (node.light->range.isPresent) { if (!ainode->mMetaData) { ainode->mMetaData = aiMetadata::Alloc(1); @@ -1556,9 +1559,9 @@ void glTF2Importer::ImportEmbeddedTextures(glTF2::Asset &r) { if (ext) { if (strcmp(ext, "jpeg") == 0) { ext = "jpg"; - } else if (strcmp(ext, "ktx2") == 0) { //basisu: ktx remains + } else if (strcmp(ext, "ktx2") == 0) { // basisu: ktx remains ext = "kx2"; - } else if (strcmp(ext, "basis") == 0) { //basisu + } else if (strcmp(ext, "basis") == 0) { // basisu ext = "bu"; } From 128242e3710c3683160a05d1db0a136d14bca1fc Mon Sep 17 00:00:00 2001 From: Ichiro Date: Mon, 18 Apr 2022 01:28:03 +0900 Subject: [PATCH 6/7] Fix ogre xml serializer --- code/AssetLib/Ogre/OgreXmlSerializer.cpp | 26 ++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/code/AssetLib/Ogre/OgreXmlSerializer.cpp b/code/AssetLib/Ogre/OgreXmlSerializer.cpp index 545107ea3..923cb1ae2 100644 --- a/code/AssetLib/Ogre/OgreXmlSerializer.cpp +++ b/code/AssetLib/Ogre/OgreXmlSerializer.cpp @@ -248,6 +248,7 @@ void OgreXmlSerializer::ReadMesh(MeshXml *mesh) { } else if (currentName == nnBoneAssignments) { ReadBoneAssignments(currentNode, mesh->sharedVertexData); } else if (currentName == nnSkeletonLink) { + mesh->skeletonRef = currentNode.attribute("name").as_string(); } } @@ -488,6 +489,15 @@ bool OgreXmlSerializer::ImportSkeleton(Assimp::IOSystem *pIOHandler, MeshXml *me Skeleton *skeleton = new Skeleton(); OgreXmlSerializer serializer(xmlParser.get()); XmlNode root = xmlParser->getRootNode(); + if (std::string(root.name()) != nnSkeleton) { + printf("\nSkeleton is not a valid root: %s\n", root.name()); + for (auto &a : root.children()) { + if (std::string(a.name()) == nnSkeleton) { + root = a; + break; + } + } + } serializer.ReadSkeleton(root, skeleton); mesh->skeleton = skeleton; return true; @@ -537,7 +547,7 @@ XmlParserPtr OgreXmlSerializer::OpenXmlParser(Assimp::IOSystem *pIOHandler, cons } void OgreXmlSerializer::ReadSkeleton(XmlNode &node, Skeleton *skeleton) { - if (node.name() != nnSkeleton) { + if (std::string(node.name()) != nnSkeleton) { throw DeadlyImportError("Root node is <" + std::string(node.name()) + "> expecting "); } @@ -574,7 +584,7 @@ void OgreXmlSerializer::ReadAnimations(XmlNode &node, Skeleton *skeleton) { anim->name = ReadAttribute(currentNode, "name"); anim->length = ReadAttribute(currentNode, "length"); for (XmlNode ¤tChildNode : currentNode.children()) { - const std::string currentChildName = currentNode.name(); + const std::string currentChildName = currentChildNode.name(); if (currentChildName == nnTracks) { ReadAnimationTracks(currentChildNode, anim); skeleton->animations.push_back(anim); @@ -594,7 +604,7 @@ void OgreXmlSerializer::ReadAnimationTracks(XmlNode &node, Animation *dest) { track.type = VertexAnimationTrack::VAT_TRANSFORM; track.boneName = ReadAttribute(currentNode, "bone"); for (XmlNode ¤tChildNode : currentNode.children()) { - const std::string currentChildName = currentNode.name(); + const std::string currentChildName = currentChildNode.name(); if (currentChildName == nnKeyFrames) { ReadAnimationKeyFrames(currentChildNode, dest, &track); dest->tracks.push_back(track); @@ -614,7 +624,7 @@ void OgreXmlSerializer::ReadAnimationKeyFrames(XmlNode &node, Animation *anim, V if (currentName == nnKeyFrame) { keyframe.timePos = ReadAttribute(currentNode, "time"); for (XmlNode ¤tChildNode : currentNode.children()) { - const std::string currentChildName = currentNode.name(); + const std::string currentChildName = currentChildNode.name(); if (currentChildName == nnTranslate) { keyframe.position.x = ReadAttribute(currentChildNode, anX); keyframe.position.y = ReadAttribute(currentChildNode, anY); @@ -622,7 +632,7 @@ void OgreXmlSerializer::ReadAnimationKeyFrames(XmlNode &node, Animation *anim, V } else if (currentChildName == nnRotate) { float angle = ReadAttribute(currentChildNode, "angle"); for (XmlNode ¤tChildChildNode : currentNode.children()) { - const std::string currentChildChildName = currentNode.name(); + const std::string currentChildChildName = currentChildChildNode.name(); if (currentChildChildName == nnAxis) { aiVector3D axis; axis.x = ReadAttribute(currentChildChildNode, anX); @@ -695,12 +705,12 @@ void OgreXmlSerializer::ReadBones(XmlNode &node, Skeleton *skeleton) { bone->id = ReadAttribute(currentNode, "id"); bone->name = ReadAttribute(currentNode, "name"); for (XmlNode ¤tChildNode : currentNode.children()) { - const std::string currentChildName = currentNode.name(); - if (currentChildName == nnRotation) { + const std::string currentChildName = currentChildNode.name(); + if (currentChildName == nnPosition) { bone->position.x = ReadAttribute(currentChildNode, anX); bone->position.y = ReadAttribute(currentChildNode, anY); bone->position.z = ReadAttribute(currentChildNode, anZ); - } else if (currentChildName == nnScale) { + } else if (currentChildName == nnRotation) { float angle = ReadAttribute(currentChildNode, "angle"); for (XmlNode currentChildChildNode : currentChildNode.children()) { const std::string ¤tChildChildName = currentChildChildNode.name(); From 9ab6ebd36321bc8496acf6b569e180c3f80fab40 Mon Sep 17 00:00:00 2001 From: Ichiro Date: Mon, 18 Apr 2022 04:11:06 +0900 Subject: [PATCH 7/7] Fix foreach --- code/AssetLib/Ogre/OgreXmlSerializer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/code/AssetLib/Ogre/OgreXmlSerializer.cpp b/code/AssetLib/Ogre/OgreXmlSerializer.cpp index 923cb1ae2..f6164c64f 100644 --- a/code/AssetLib/Ogre/OgreXmlSerializer.cpp +++ b/code/AssetLib/Ogre/OgreXmlSerializer.cpp @@ -587,11 +587,11 @@ void OgreXmlSerializer::ReadAnimations(XmlNode &node, Skeleton *skeleton) { const std::string currentChildName = currentChildNode.name(); if (currentChildName == nnTracks) { ReadAnimationTracks(currentChildNode, anim); - skeleton->animations.push_back(anim); } else { throw DeadlyImportError("No found in ", anim->name); } } + skeleton->animations.push_back(anim); } } } @@ -607,11 +607,11 @@ void OgreXmlSerializer::ReadAnimationTracks(XmlNode &node, Animation *dest) { const std::string currentChildName = currentChildNode.name(); if (currentChildName == nnKeyFrames) { ReadAnimationKeyFrames(currentChildNode, dest, &track); - dest->tracks.push_back(track); } else { throw DeadlyImportError("No found in ", dest->name); } } + dest->tracks.push_back(track); } } } @@ -631,7 +631,7 @@ void OgreXmlSerializer::ReadAnimationKeyFrames(XmlNode &node, Animation *anim, V keyframe.position.z = ReadAttribute(currentChildNode, anZ); } else if (currentChildName == nnRotate) { float angle = ReadAttribute(currentChildNode, "angle"); - for (XmlNode ¤tChildChildNode : currentNode.children()) { + for (XmlNode ¤tChildChildNode : currentChildNode.children()) { const std::string currentChildChildName = currentChildChildNode.name(); if (currentChildChildName == nnAxis) { aiVector3D axis;