From 5d3f3281f451f50d4ec7f8ad7c910e66020f354c Mon Sep 17 00:00:00 2001 From: Tomas Maly Date: Tue, 27 Jun 2023 12:40:27 +0200 Subject: [PATCH 01/11] fix incorrect default for material::get with aiColor3D --- include/assimp/material.inl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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; } // --------------------------------------------------------------------------- From 668db327f41afd0c127f096d5cae7c6b64af8325 Mon Sep 17 00:00:00 2001 From: PencilAmazing <16854231+PencilAmazing@users.noreply.github.com> Date: Fri, 7 Jul 2023 13:27:45 -0400 Subject: [PATCH 02/11] Fix misplaced quote --- test/models/IRR/scenegraphAnim.irr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/models/IRR/scenegraphAnim.irr b/test/models/IRR/scenegraphAnim.irr index 1c6fd0ef4..0773f94a5 100644 --- a/test/models/IRR/scenegraphAnim.irr +++ b/test/models/IRR/scenegraphAnim.irr @@ -1,4 +1,4 @@ - + @@ -126,7 +126,7 @@ - + From d6edfad8bb6d69c0c176ba4535128f1d6ce2c8fc Mon Sep 17 00:00:00 2001 From: PencilAmazing <16854231+PencilAmazing@users.noreply.github.com> Date: Wed, 2 Aug 2023 13:52:40 -0400 Subject: [PATCH 03/11] Fix non UTF-8 xml file parsing by passing buffer size manually, as per pugixml documentation --- include/assimp/XmlParser.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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; } From b5032db7418e53d7497589dfe43a4d918f687a6e Mon Sep 17 00:00:00 2001 From: PencilAmazing <16854231+PencilAmazing@users.noreply.github.com> Date: Wed, 2 Aug 2023 13:57:21 -0400 Subject: [PATCH 04/11] Reverse accidental change with test file --- test/models/IRR/scenegraphAnim.irr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/models/IRR/scenegraphAnim.irr b/test/models/IRR/scenegraphAnim.irr index 0773f94a5..2300ea18f 100644 --- a/test/models/IRR/scenegraphAnim.irr +++ b/test/models/IRR/scenegraphAnim.irr @@ -1,4 +1,4 @@ - + From bb1873dd221da14729fab9bb7301c329fc6610bf Mon Sep 17 00:00:00 2001 From: Martin Weber Date: Fri, 4 Aug 2023 09:54:55 +0200 Subject: [PATCH 05/11] Collada: added import property to disable unit size scaling --- code/AssetLib/Collada/ColladaLoader.cpp | 17 +++++++++++------ code/AssetLib/Collada/ColladaLoader.h | 1 + include/assimp/config.h.in | 9 +++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) 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/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. * From 0bfc588c393ad9aeb72bf91bc0918ece98162565 Mon Sep 17 00:00:00 2001 From: Aaron Date: Tue, 15 Aug 2023 18:01:16 +0800 Subject: [PATCH 06/11] Update Triangulate Process [more another case] --- code/Common/PolyTools.h | 19 ++++++++++++++----- code/PostProcessing/TriangulateProcess.cpp | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/code/Common/PolyTools.h b/code/Common/PolyTools.h index a5bd1090b..b53de8579 100644 --- a/code/Common/PolyTools.h +++ b/code/Common/PolyTools.h @@ -64,8 +64,14 @@ inline double GetArea2D(const T& v1, const T& v2, const T& v3) { * The function accepts an unconstrained template parameter for use with * both aiVector3D and aiVector2D, but generally ignores the third coordinate.*/ template -inline bool OnLeftSideOfLine2D(const T& p0, const T& p1,const T& p2) { - return GetArea2D(p0,p2,p1) > 0; +inline int OnLeftSideOfLine2D(const T& p0, const T& p1,const T& p2) { + double area = GetArea2D(p0,p2,p1); + if(std::abs(area) < ai_epsilon) + return 0; + else if(area > 0) + return 1; + else + return -1; } // ------------------------------------------------------------------------------- @@ -75,7 +81,10 @@ inline bool OnLeftSideOfLine2D(const T& p0, const T& p1,const T& p2) { template inline bool PointInTriangle2D(const T& p0, const T& p1,const T& p2, const T& pp) { // pp should be left side of the three triangle side, by ccw arrow - return OnLeftSideOfLine2D(p0, p1, pp) && OnLeftSideOfLine2D(p1, p2, pp) && OnLeftSideOfLine2D(p2, p0, pp); + int c1 = OnLeftSideOfLine2D(p0, p1, pp); + int c2 = OnLeftSideOfLine2D(p1, p2, pp); + int c3 = OnLeftSideOfLine2D(p2, p0, pp); + return (c1 >= 0) && (c2 >= 0) && (c3 >= 0); } @@ -110,7 +119,7 @@ inline bool IsCCW(T* in, size_t npoints) { c = std::sqrt(cc); theta = std::acos((bb + cc - aa) / (2 * b * c)); - if (OnLeftSideOfLine2D(in[i],in[i+2],in[i+1])) { + if (OnLeftSideOfLine2D(in[i],in[i+2],in[i+1]) == 1) { // if (convex(in[i].x, in[i].y, // in[i+1].x, in[i+1].y, // in[i+2].x, in[i+2].y)) { @@ -140,7 +149,7 @@ inline bool IsCCW(T* in, size_t npoints) { //if (convex(in[npoints-2].x, in[npoints-2].y, // in[0].x, in[0].y, // in[1].x, in[1].y)) { - if (OnLeftSideOfLine2D(in[npoints-2],in[1],in[0])) { + if (OnLeftSideOfLine2D(in[npoints-2],in[1],in[0]) == 1) { convex_turn = AI_MATH_PI_F - theta; convex_sum += convex_turn; } else { diff --git a/code/PostProcessing/TriangulateProcess.cpp b/code/PostProcessing/TriangulateProcess.cpp index b4c66b41e..f16de2196 100644 --- a/code/PostProcessing/TriangulateProcess.cpp +++ b/code/PostProcessing/TriangulateProcess.cpp @@ -451,7 +451,7 @@ bool TriangulateProcess::TriangulateMesh( aiMesh* pMesh) { *pnt2 = &temp_verts[next]; // Must be a convex point. Assuming ccw winding, it must be on the right of the line between p-1 and p+1. - if (OnLeftSideOfLine2D(*pnt0,*pnt2,*pnt1)) { + if (OnLeftSideOfLine2D(*pnt0,*pnt2,*pnt1) == 1) { continue; } From 32716002ac55200466cb3a004fa83347235556cc Mon Sep 17 00:00:00 2001 From: zhucan <846422360@qq.com> Date: Mon, 3 Jul 2023 23:27:58 +0800 Subject: [PATCH 07/11] Add DIFFUSE_ROUGHNESS_TEXTURE for gltf2 exporter --- code/AssetLib/glTF2/glTF2Exporter.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index d4568fa31..8777ac4ae 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -870,6 +870,7 @@ void glTF2Exporter::ExportMaterials() { } } + GetMatTex(mat, m->normalTexture, aiTextureType_DIFFUSE_ROUGHNESS); GetMatTex(mat, m->normalTexture, aiTextureType_NORMALS); GetMatTex(mat, m->occlusionTexture, aiTextureType_LIGHTMAP); GetMatTex(mat, m->emissiveTexture, aiTextureType_EMISSIVE); From 3a03fe31b12d482df5c5b0ec587deb93997eae0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E7=81=BF?= Date: Mon, 24 Jul 2023 10:28:01 +0800 Subject: [PATCH 08/11] gltf2 export diffuse roughness --- code/AssetLib/glTF2/glTF2Exporter.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 8777ac4ae..0f2da9e3d 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -836,7 +836,7 @@ void glTF2Exporter::ExportMaterials() { GetMatTex(mat, m->pbrMetallicRoughness.baseColorTexture, aiTextureType_DIFFUSE); } - GetMatTex(mat, m->pbrMetallicRoughness.metallicRoughnessTexture, AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE); + GetMatTex(mat, m->pbrMetallicRoughness.metallicRoughnessTexture, aiTextureType_DIFFUSE_ROUGHNESS); if (GetMatColor(mat, m->pbrMetallicRoughness.baseColorFactor, AI_MATKEY_BASE_COLOR) != AI_SUCCESS) { // if baseColorFactor wasn't defined, then the source is likely not a metallic roughness material. @@ -870,7 +870,6 @@ void glTF2Exporter::ExportMaterials() { } } - GetMatTex(mat, m->normalTexture, aiTextureType_DIFFUSE_ROUGHNESS); GetMatTex(mat, m->normalTexture, aiTextureType_NORMALS); GetMatTex(mat, m->occlusionTexture, aiTextureType_LIGHTMAP); GetMatTex(mat, m->emissiveTexture, aiTextureType_EMISSIVE); From 2b4606c0821f3646a87f34f3fbdb0739ece1e778 Mon Sep 17 00:00:00 2001 From: zhucan <846422360@qq.com> Date: Thu, 27 Jul 2023 23:42:39 +0800 Subject: [PATCH 09/11] add fallback strategy for metallicRoughnessTexture --- code/AssetLib/glTF2/glTF2Exporter.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index 0f2da9e3d..e07ce154d 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -838,6 +838,16 @@ void glTF2Exporter::ExportMaterials() { GetMatTex(mat, m->pbrMetallicRoughness.metallicRoughnessTexture, aiTextureType_DIFFUSE_ROUGHNESS); + if (!m->pbrMetallicRoughness.metallicRoughnessTexture.texture) { + //if there wasn't a aiTextureType_DIFFUSE_ROUGHNESS defined in the source, fallback to aiTextureType_METALNESS + GetMatTex(mat, m->pbrMetallicRoughness.metallicRoughnessTexture, aiTextureType_METALNESS); + } + + if (!m->pbrMetallicRoughness.metallicRoughnessTexture.texture) { + //if there still wasn't a aiTextureType_METALNESS defined in the source, fallback to unknown texture + GetMatTex(mat, m->pbrMetallicRoughness.metallicRoughnessTexture, AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE); + } + if (GetMatColor(mat, m->pbrMetallicRoughness.baseColorFactor, AI_MATKEY_BASE_COLOR) != AI_SUCCESS) { // if baseColorFactor wasn't defined, then the source is likely not a metallic roughness material. //a fallback to any diffuse color should be used instead From 554fa8f5e2cd7b73a2786a7f04c34d4f76263a6a Mon Sep 17 00:00:00 2001 From: zhucan <846422360@qq.com> Date: Thu, 27 Jul 2023 23:43:26 +0800 Subject: [PATCH 10/11] code format --- code/AssetLib/glTF2/glTF2Exporter.cpp | 92 +++++++++++++-------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index e07ce154d..f08a97b6e 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -263,7 +263,7 @@ size_t NZDiff(void *data, void *dataBase, size_t count, unsigned int numCompsIn, for (short idx = 0; bufferData_ptr < bufferData_end; idx += 1, bufferData_ptr += numCompsIn) { bool bNonZero = false; - //for the data, check any component Non Zero + // for the data, check any component Non Zero for (unsigned int j = 0; j < numCompsOut; j++) { double valueData = bufferData_ptr[j]; double valueBase = bufferBase_ptr ? bufferBase_ptr[j] : 0; @@ -273,11 +273,11 @@ size_t NZDiff(void *data, void *dataBase, size_t count, unsigned int numCompsIn, } } - //all zeros, continue + // all zeros, continue if (!bNonZero) continue; - //non zero, store the data + // non zero, store the data for (unsigned int j = 0; j < numCompsOut; j++) { T valueData = bufferData_ptr[j]; T valueBase = bufferBase_ptr ? bufferBase_ptr[j] : 0; @@ -286,14 +286,14 @@ size_t NZDiff(void *data, void *dataBase, size_t count, unsigned int numCompsIn, vNZIdx.push_back(idx); } - //avoid all-0, put 1 item + // avoid all-0, put 1 item if (vNZDiff.size() == 0) { for (unsigned int j = 0; j < numCompsOut; j++) vNZDiff.push_back(0); vNZIdx.push_back(0); } - //process data + // process data outputNZDiff = new T[vNZDiff.size()]; memcpy(outputNZDiff, vNZDiff.data(), vNZDiff.size() * sizeof(T)); @@ -361,7 +361,7 @@ inline Ref ExportDataSparse(Asset &a, std::string &meshName, Refsparse.reset(new Accessor::Sparse); acc->sparse->count = nzCount; - //indices + // indices unsigned int bytesPerIdx = sizeof(unsigned short); size_t indices_offset = buffer->byteLength; size_t indices_padding = indices_offset % bytesPerIdx; @@ -379,7 +379,7 @@ inline Ref ExportDataSparse(Asset &a, std::string &meshName, Refsparse->indicesByteOffset = 0; acc->WriteSparseIndices(nzCount, nzIdx, 1 * bytesPerIdx); - //values + // values size_t values_offset = buffer->byteLength; size_t values_padding = values_offset % bytesPerComp; values_offset += values_padding; @@ -395,9 +395,9 @@ inline Ref ExportDataSparse(Asset &a, std::string &meshName, Refsparse->valuesByteOffset = 0; acc->WriteSparseValues(nzCount, nzDiff, numCompsIn * bytesPerComp); - //clear - delete[](char *) nzDiff; - delete[](char *) nzIdx; + // clear + delete[] (char *)nzDiff; + delete[] (char *)nzIdx; } return acc; } @@ -599,7 +599,7 @@ void glTF2Exporter::GetMatTex(const aiMaterial &mat, Ref &texture, unsi if (curTex != nullptr) { // embedded texture->source->name = curTex->mFilename.C_Str(); - //basisu: embedded ktx2, bu + // basisu: embedded ktx2, bu if (curTex->achFormatHint[0]) { std::string mimeType = "image/"; if (memcmp(curTex->achFormatHint, "jpg", 3) == 0) @@ -619,7 +619,7 @@ void glTF2Exporter::GetMatTex(const aiMaterial &mat, Ref &texture, unsi } // The asset has its own buffer, see Image::SetData - //basisu: "image/ktx2", "image/basis" as is + // basisu: "image/ktx2", "image/basis" as is texture->source->SetData(reinterpret_cast(curTex->pcData), curTex->mWidth, *mAsset); } else { texture->source->uri = path; @@ -629,7 +629,7 @@ void glTF2Exporter::GetMatTex(const aiMaterial &mat, Ref &texture, unsi } } - //basisu + // basisu if (useBasisUniversal) { mAsset->extensionsUsed.KHR_texture_basisu = true; mAsset->extensionsRequired.KHR_texture_basisu = true; @@ -652,7 +652,7 @@ void glTF2Exporter::GetMatTex(const aiMaterial &mat, NormalTextureInfo &prop, ai GetMatTex(mat, texture, prop.texCoord, tt, slot); if (texture) { - //GetMatTexProp(mat, prop.texCoord, "texCoord", tt, slot); + // GetMatTexProp(mat, prop.texCoord, "texCoord", tt, slot); GetMatTexProp(mat, prop.scale, "scale", tt, slot); } } @@ -663,7 +663,7 @@ void glTF2Exporter::GetMatTex(const aiMaterial &mat, OcclusionTextureInfo &prop, GetMatTex(mat, texture, prop.texCoord, tt, slot); if (texture) { - //GetMatTexProp(mat, prop.texCoord, "texCoord", tt, slot); + // GetMatTexProp(mat, prop.texCoord, "texCoord", tt, slot); GetMatTexProp(mat, prop.strength, "strength", tt, slot); } } @@ -832,30 +832,30 @@ void glTF2Exporter::ExportMaterials() { GetMatTex(mat, m->pbrMetallicRoughness.baseColorTexture, aiTextureType_BASE_COLOR); if (!m->pbrMetallicRoughness.baseColorTexture.texture) { - //if there wasn't a baseColorTexture defined in the source, fallback to any diffuse texture + // if there wasn't a baseColorTexture defined in the source, fallback to any diffuse texture GetMatTex(mat, m->pbrMetallicRoughness.baseColorTexture, aiTextureType_DIFFUSE); } GetMatTex(mat, m->pbrMetallicRoughness.metallicRoughnessTexture, aiTextureType_DIFFUSE_ROUGHNESS); if (!m->pbrMetallicRoughness.metallicRoughnessTexture.texture) { - //if there wasn't a aiTextureType_DIFFUSE_ROUGHNESS defined in the source, fallback to aiTextureType_METALNESS + // if there wasn't a aiTextureType_DIFFUSE_ROUGHNESS defined in the source, fallback to aiTextureType_METALNESS GetMatTex(mat, m->pbrMetallicRoughness.metallicRoughnessTexture, aiTextureType_METALNESS); } if (!m->pbrMetallicRoughness.metallicRoughnessTexture.texture) { - //if there still wasn't a aiTextureType_METALNESS defined in the source, fallback to unknown texture + // if there still wasn't a aiTextureType_METALNESS defined in the source, fallback to unknown texture GetMatTex(mat, m->pbrMetallicRoughness.metallicRoughnessTexture, AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE); } if (GetMatColor(mat, m->pbrMetallicRoughness.baseColorFactor, AI_MATKEY_BASE_COLOR) != AI_SUCCESS) { // if baseColorFactor wasn't defined, then the source is likely not a metallic roughness material. - //a fallback to any diffuse color should be used instead + // a fallback to any diffuse color should be used instead GetMatColor(mat, m->pbrMetallicRoughness.baseColorFactor, AI_MATKEY_COLOR_DIFFUSE); } if (mat.Get(AI_MATKEY_METALLIC_FACTOR, m->pbrMetallicRoughness.metallicFactor) != AI_SUCCESS) { - //if metallicFactor wasn't defined, then the source is likely not a PBR file, and the metallicFactor should be 0 + // if metallicFactor wasn't defined, then the source is likely not a PBR file, and the metallicFactor should be 0 m->pbrMetallicRoughness.metallicFactor = 0; } @@ -868,10 +868,10 @@ void glTF2Exporter::ExportMaterials() { if (mat.Get(AI_MATKEY_COLOR_SPECULAR, specularColor) == AI_SUCCESS && mat.Get(AI_MATKEY_SHININESS, shininess) == AI_SUCCESS) { // convert specular color to luminance float specularIntensity = specularColor[0] * 0.2125f + specularColor[1] * 0.7154f + specularColor[2] * 0.0721f; - //normalize shininess (assuming max is 1000) with an inverse exponentional curve + // normalize shininess (assuming max is 1000) with an inverse exponentional curve float normalizedShininess = std::sqrt(shininess / 1000); - //clamp the shininess value between 0 and 1 + // clamp the shininess value between 0 and 1 normalizedShininess = std::min(std::max(normalizedShininess, 0.0f), 1.0f); // low specular intensity values should produce a rough material even if shininess is high. normalizedShininess = normalizedShininess * specularIntensity; @@ -1069,7 +1069,7 @@ void ExportSkin(Asset &mAsset, const aiMesh *aimesh, Ref &meshRef, Ref(jointNamesIndex); } - }else { + } else { vertexJointData[vertexId][jointsPerVertex[vertexId]] = static_cast(jointNamesIndex); vertexWeightData[vertexId][jointsPerVertex[vertexId]] = vertWeight; @@ -1081,7 +1081,7 @@ void ExportSkin(Asset &mAsset, const aiMesh *aimesh, Ref &meshRef, Refprimitives.back(); Ref vertexJointAccessor = ExportData(mAsset, skinRef->id, bufferRef, aimesh->mNumVertices, - vertexJointData, AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT); + vertexJointData, AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT); if (vertexJointAccessor) { size_t offset = vertexJointAccessor->bufferView->byteOffset; size_t bytesLen = vertexJointAccessor->bufferView->byteLength; @@ -1165,7 +1165,7 @@ void glTF2Exporter::ExportMeshes() { /******************* Vertices ********************/ Ref v = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mVertices, AttribType::VEC3, - AttribType::VEC3, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER); + AttribType::VEC3, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER); if (v) { p.attributes.position.push_back(v); } @@ -1179,7 +1179,7 @@ void glTF2Exporter::ExportMeshes() { } Ref n = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mNormals, AttribType::VEC3, - AttribType::VEC3, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER); + AttribType::VEC3, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER); if (n) { p.attributes.normal.push_back(n); } @@ -1201,7 +1201,7 @@ void glTF2Exporter::ExportMeshes() { AttribType::Value type = (aim->mNumUVComponents[i] == 2) ? AttribType::VEC2 : AttribType::VEC3; Ref tc = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mTextureCoords[i], - AttribType::VEC3, type, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER); + AttribType::VEC3, type, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER); if (tc) { p.attributes.texcoord.push_back(tc); } @@ -1211,7 +1211,7 @@ void glTF2Exporter::ExportMeshes() { /*************** Vertex colors ****************/ for (unsigned int indexColorChannel = 0; indexColorChannel < aim->GetNumColorChannels(); ++indexColorChannel) { Ref c = ExportData(*mAsset, meshId, b, aim->mNumVertices, aim->mColors[indexColorChannel], - AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER); + AttribType::VEC4, AttribType::VEC4, ComponentType_FLOAT, BufferViewTarget_ARRAY_BUFFER); if (c) { p.attributes.color.push_back(c); } @@ -1229,7 +1229,7 @@ void glTF2Exporter::ExportMeshes() { } p.indices = ExportData(*mAsset, meshId, b, indices.size(), &indices[0], AttribType::SCALAR, AttribType::SCALAR, - ComponentType_UNSIGNED_INT, BufferViewTarget_ELEMENT_ARRAY_BUFFER); + ComponentType_UNSIGNED_INT, BufferViewTarget_ELEMENT_ARRAY_BUFFER); } switch (aim->mPrimitiveTypes) { @@ -1372,24 +1372,24 @@ void glTF2Exporter::MergeMeshes() { unsigned int nMeshes = static_cast(node->meshes.size()); - //skip if it's 1 or less meshes per node + // skip if it's 1 or less meshes per node if (nMeshes > 1) { Ref firstMesh = node->meshes.at(0); - //loop backwards to allow easy removal of a mesh from a node once it's merged + // loop backwards to allow easy removal of a mesh from a node once it's merged for (unsigned int m = nMeshes - 1; m >= 1; --m) { Ref mesh = node->meshes.at(m); - //append this mesh's primitives to the first mesh's primitives + // append this mesh's primitives to the first mesh's primitives firstMesh->primitives.insert( firstMesh->primitives.end(), mesh->primitives.begin(), mesh->primitives.end()); - //remove the mesh from the list of meshes + // remove the mesh from the list of meshes unsigned int removedIndex = mAsset->meshes.Remove(mesh->id.c_str()); - //find the presence of the removed mesh in other nodes + // find the presence of the removed mesh in other nodes for (unsigned int nn = 0; nn < mAsset->nodes.Size(); ++nn) { Ref curNode = mAsset->nodes.Get(nn); @@ -1408,7 +1408,7 @@ void glTF2Exporter::MergeMeshes() { } } - //since we were looping backwards, reverse the order of merged primitives to their original order + // since we were looping backwards, reverse the order of merged primitives to their original order std::reverse(firstMesh->primitives.begin() + 1, firstMesh->primitives.end()); } } @@ -1440,7 +1440,7 @@ unsigned int glTF2Exporter::ExportNodeHierarchy(const aiNode *n) { return node.GetIndex(); } - /* +/* * Export node and recursively calls ExportNode for all children. * Since these nodes are not the root node, we also export the parent Ref */ @@ -1535,9 +1535,9 @@ inline void ExtractTranslationSampler(Asset &asset, std::string &animId, RefmPositionKeys[i]; // mTime is measured in ticks, but GLTF time is measured in seconds, so convert. times[i] = static_cast(key.mTime / ticksPerSecond); - values[(i * 3) + 0] = (ai_real) key.mValue.x; - values[(i * 3) + 1] = (ai_real) key.mValue.y; - values[(i * 3) + 2] = (ai_real) key.mValue.z; + values[(i * 3) + 0] = (ai_real)key.mValue.x; + values[(i * 3) + 1] = (ai_real)key.mValue.y; + values[(i * 3) + 2] = (ai_real)key.mValue.z; } sampler.input = GetSamplerInputRef(asset, animId, buffer, times); @@ -1554,9 +1554,9 @@ inline void ExtractScaleSampler(Asset &asset, std::string &animId, Ref & const aiVectorKey &key = nodeChannel->mScalingKeys[i]; // mTime is measured in ticks, but GLTF time is measured in seconds, so convert. times[i] = static_cast(key.mTime / ticksPerSecond); - values[(i * 3) + 0] = (ai_real) key.mValue.x; - values[(i * 3) + 1] = (ai_real) key.mValue.y; - values[(i * 3) + 2] = (ai_real) key.mValue.z; + values[(i * 3) + 0] = (ai_real)key.mValue.x; + values[(i * 3) + 1] = (ai_real)key.mValue.y; + values[(i * 3) + 2] = (ai_real)key.mValue.z; } sampler.input = GetSamplerInputRef(asset, animId, buffer, times); @@ -1573,10 +1573,10 @@ inline void ExtractRotationSampler(Asset &asset, std::string &animId, RefmRotationKeys[i]; // mTime is measured in ticks, but GLTF time is measured in seconds, so convert. times[i] = static_cast(key.mTime / ticksPerSecond); - values[(i * 4) + 0] = (ai_real) key.mValue.x; - values[(i * 4) + 1] = (ai_real) key.mValue.y; - values[(i * 4) + 2] = (ai_real) key.mValue.z; - values[(i * 4) + 3] = (ai_real) key.mValue.w; + values[(i * 4) + 0] = (ai_real)key.mValue.x; + values[(i * 4) + 1] = (ai_real)key.mValue.y; + values[(i * 4) + 2] = (ai_real)key.mValue.z; + values[(i * 4) + 3] = (ai_real)key.mValue.w; } sampler.input = GetSamplerInputRef(asset, animId, buffer, times); From d07934bf255b76642dc37a6418e8b8ba91fd6fe7 Mon Sep 17 00:00:00 2001 From: zhucan <846422360@qq.com> Date: Mon, 31 Jul 2023 23:19:11 +0800 Subject: [PATCH 11/11] adjust comment --- code/AssetLib/glTF2/glTF2Exporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/AssetLib/glTF2/glTF2Exporter.cpp b/code/AssetLib/glTF2/glTF2Exporter.cpp index f08a97b6e..d6f778fbe 100644 --- a/code/AssetLib/glTF2/glTF2Exporter.cpp +++ b/code/AssetLib/glTF2/glTF2Exporter.cpp @@ -844,7 +844,7 @@ void glTF2Exporter::ExportMaterials() { } if (!m->pbrMetallicRoughness.metallicRoughnessTexture.texture) { - // if there still wasn't a aiTextureType_METALNESS defined in the source, fallback to unknown texture + // if there still wasn't a aiTextureType_METALNESS defined in the source, fallback to AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE GetMatTex(mat, m->pbrMetallicRoughness.metallicRoughnessTexture, AI_MATKEY_GLTF_PBRMETALLICROUGHNESS_METALLICROUGHNESS_TEXTURE); }