From ff8a924ffbde41c2cc8054fc030aacaed92b4eac Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Wed, 22 Jan 2020 09:09:39 -0500 Subject: [PATCH 01/19] [HL1 MDL] Removed downscale for textures with dimensions greater than 256. --- code/MDL/HalfLife/HL1MDLLoader.cpp | 60 ++++++------------------------ 1 file changed, 11 insertions(+), 49 deletions(-) diff --git a/code/MDL/HalfLife/HL1MDLLoader.cpp b/code/MDL/HalfLife/HL1MDLLoader.cpp index 90a1479a3..eff5b80b7 100644 --- a/code/MDL/HalfLife/HL1MDLLoader.cpp +++ b/code/MDL/HalfLife/HL1MDLLoader.cpp @@ -316,36 +316,14 @@ void HL1MDLLoader::load_sequence_groups_files() { } // ------------------------------------------------------------------------------------------------ -/** @brief Read an MDL texture. -* -* @note This method is taken from HL1 source code. -* source: file: studio_utils.c -* function(s): UploadTexture -*/ +// Read an MDL texture. void HL1MDLLoader::read_texture(const Texture_HL1 *ptexture, uint8_t *data, uint8_t *pal, aiTexture *pResult, aiColor3D &last_palette_color) { - int outwidth, outheight; - int i, j; - int row1[256], row2[256], col1[256], col2[256]; - unsigned char *pix1, *pix2, *pix3, *pix4; - - // convert texture to power of 2 - for (outwidth = 1; outwidth < ptexture->width; outwidth <<= 1) - ; - - if (outwidth > 256) - outwidth = 256; - - for (outheight = 1; outheight < ptexture->height; outheight <<= 1) - ; - - if (outheight > 256) - outheight = 256; pResult->mFilename = ptexture->name; - pResult->mWidth = outwidth; - pResult->mHeight = outheight; + pResult->mWidth = static_cast(ptexture->width); + pResult->mHeight = static_cast(ptexture->height); pResult->achFormatHint[0] = 'b'; pResult->achFormatHint[1] = 'g'; pResult->achFormatHint[2] = 'r'; @@ -356,31 +334,15 @@ void HL1MDLLoader::read_texture(const Texture_HL1 *ptexture, pResult->achFormatHint[7] = '8'; pResult->achFormatHint[8] = '\0'; - aiTexel *out = pResult->pcData = new aiTexel[outwidth * outheight]; + const size_t num_pixels = pResult->mWidth * pResult->mHeight; + aiTexel *out = pResult->pcData = new aiTexel[num_pixels]; - for (i = 0; i < outwidth; i++) { - col1[i] = (int)((i + 0.25) * (ptexture->width / (float)outwidth)); - col2[i] = (int)((i + 0.75) * (ptexture->width / (float)outwidth)); - } - - for (i = 0; i < outheight; i++) { - row1[i] = (int)((i + 0.25) * (ptexture->height / (float)outheight)) * ptexture->width; - row2[i] = (int)((i + 0.75) * (ptexture->height / (float)outheight)) * ptexture->width; - } - - // scale down and convert to 32bit RGB - for (i = 0; i < outheight; i++) { - for (j = 0; j < outwidth; j++, out++) { - pix1 = &pal[data[row1[i] + col1[j]] * 3]; - pix2 = &pal[data[row1[i] + col2[j]] * 3]; - pix3 = &pal[data[row2[i] + col1[j]] * 3]; - pix4 = &pal[data[row2[i] + col2[j]] * 3]; - - out->r = (pix1[0] + pix2[0] + pix3[0] + pix4[0]) >> 2; - out->g = (pix1[1] + pix2[1] + pix3[1] + pix4[1]) >> 2; - out->b = (pix1[2] + pix2[2] + pix3[2] + pix4[2]) >> 2; - out->a = 0xFF; - } + // Convert indexed 8 bit to 32 bit RGBA. + for (size_t i = 0; i < num_pixels; ++i, ++out) { + out->r = pal[data[i] * 3]; + out->g = pal[data[i] * 3 + 1]; + out->b = pal[data[i] * 3 + 2]; + out->a = 255; } // Get the last palette color. From 194d31002d62aca910687bfda5bc9301203c948b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc?= Date: Wed, 29 Jan 2020 14:04:41 +0100 Subject: [PATCH 02/19] Import/export of embedded texture names for the glTF/glTF2 format --- code/glTF/glTFExporter.cpp | 2 ++ code/glTF/glTFImporter.cpp | 1 + code/glTF2/glTF2Exporter.cpp | 2 ++ code/glTF2/glTF2Importer.cpp | 1 + 4 files changed, 6 insertions(+) diff --git a/code/glTF/glTFExporter.cpp b/code/glTF/glTFExporter.cpp index 3caea7de9..4ebe53c00 100644 --- a/code/glTF/glTFExporter.cpp +++ b/code/glTF/glTFExporter.cpp @@ -352,6 +352,8 @@ void glTFExporter::GetMatColorOrTex(const aiMaterial* mat, glTF::TexProperty& pr if (path[0] == '*') { // embedded aiTexture* tex = mScene->mTextures[atoi(&path[1])]; + + prop.texture->source->name = tex->mFilename.C_Str(); uint8_t* data = reinterpret_cast(tex->pcData); prop.texture->source->SetData(data, tex->mWidth, *mAsset); diff --git a/code/glTF/glTFImporter.cpp b/code/glTF/glTFImporter.cpp index 45c0e42a9..bba48dc30 100644 --- a/code/glTF/glTFImporter.cpp +++ b/code/glTF/glTFImporter.cpp @@ -680,6 +680,7 @@ void glTFImporter::ImportEmbeddedTextures(glTF::Asset& r) size_t length = img.GetDataLength(); void* data = img.StealData(); + tex->mFilename = img.name; tex->mWidth = static_cast(length); tex->mHeight = 0; tex->pcData = reinterpret_cast(data); diff --git a/code/glTF2/glTF2Exporter.cpp b/code/glTF2/glTF2Exporter.cpp index 7a7d581cb..b240a5ea9 100644 --- a/code/glTF2/glTF2Exporter.cpp +++ b/code/glTF2/glTF2Exporter.cpp @@ -351,6 +351,8 @@ void glTF2Exporter::GetMatTex(const aiMaterial* mat, Ref& texture, aiTe if (path[0] == '*') { // embedded aiTexture* tex = mScene->mTextures[atoi(&path[1])]; + + texture->source->name = tex->mFilename.C_Str(); // The asset has its own buffer, see Image::SetData texture->source->SetData(reinterpret_cast (tex->pcData), tex->mWidth, *mAsset); diff --git a/code/glTF2/glTF2Importer.cpp b/code/glTF2/glTF2Importer.cpp index e5052d4d6..af98076a7 100644 --- a/code/glTF2/glTF2Importer.cpp +++ b/code/glTF2/glTF2Importer.cpp @@ -1248,6 +1248,7 @@ void glTF2Importer::ImportEmbeddedTextures(glTF2::Asset &r) { size_t length = img.GetDataLength(); void *data = img.StealData(); + tex->mFilename = img.name; tex->mWidth = static_cast(length); tex->mHeight = 0; tex->pcData = reinterpret_cast(data); From 0d672efa905412ecc5beda33dad2124bd8890480 Mon Sep 17 00:00:00 2001 From: Max Vollmer Date: Wed, 29 Jan 2020 15:04:26 +0000 Subject: [PATCH 03/19] Check input token length before copy --- code/FBX/FBXParser.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/code/FBX/FBXParser.cpp b/code/FBX/FBXParser.cpp index 215ff7484..5486fdcc6 100644 --- a/code/FBX/FBXParser.cpp +++ b/code/FBX/FBXParser.cpp @@ -367,9 +367,12 @@ float ParseTokenAsFloat(const Token& t, const char*& err_out) // first - next in the fbx token stream comes ',', // which fast_atof could interpret as decimal point. #define MAX_FLOAT_LENGTH 31 - char temp[MAX_FLOAT_LENGTH + 1]; const size_t length = static_cast(t.end()-t.begin()); - std::copy(t.begin(),t.end(),temp); + if (length > MAX_FLOAT_LENGTH) + return 0.f; + + char temp[MAX_FLOAT_LENGTH + 1]; + std::copy(t.begin(), t.end(), temp); temp[std::min(static_cast(MAX_FLOAT_LENGTH),length)] = '\0'; return fast_atof(temp); From 398a8f757e401bfac5569940e56f82659c7f9e74 Mon Sep 17 00:00:00 2001 From: bzt Date: Wed, 29 Jan 2020 22:08:34 +0100 Subject: [PATCH 04/19] Additional checks on invalid input --- code/M3D/M3DImporter.cpp | 46 +++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/code/M3D/M3DImporter.cpp b/code/M3D/M3DImporter.cpp index a77e75a27..b0759542b 100644 --- a/code/M3D/M3DImporter.cpp +++ b/code/M3D/M3DImporter.cpp @@ -225,7 +225,7 @@ void M3DImporter::InternReadFile(const std::string &file, aiScene *pScene, IOSys // ------------------------------------------------------------------------------------------------ // convert materials. properties are converted using a static table in M3DMaterials.h -void M3DImporter::importMaterials(const M3DWrapper &m3d_wrap) { +void M3DImporter::importMaterials(const M3DWrapper &m3d) { unsigned int i, j, k, l, n; m3dm_t *m; aiString name = aiString(AI_DEFAULT_MATERIAL_NAME); @@ -233,9 +233,9 @@ void M3DImporter::importMaterials(const M3DWrapper &m3d_wrap) { ai_real f; ai_assert(mScene != nullptr); - ai_assert(m3d_wrap); + ai_assert(m3d); - mScene->mNumMaterials = m3d_wrap->nummaterial + 1; + mScene->mNumMaterials = m3d->nummaterial + 1; mScene->mMaterials = new aiMaterial *[mScene->mNumMaterials]; ASSIMP_LOG_DEBUG_F("M3D: importMaterials ", mScene->mNumMaterials); @@ -248,8 +248,11 @@ void M3DImporter::importMaterials(const M3DWrapper &m3d_wrap) { mat->AddProperty(&c, 1, AI_MATKEY_COLOR_DIFFUSE); mScene->mMaterials[0] = mat; - for (i = 0; i < m3d_wrap->nummaterial; i++) { - m = &m3d_wrap->material[i]; + if (!m3d->nummaterial || !m3d->material) + return; + + for (i = 0; i < m3d->nummaterial; i++) { + m = &m3d->material[i]; aiMaterial *mat = new aiMaterial; name.Set(std::string(m->name)); mat->AddProperty(&name, AI_MATKEY_NAME); @@ -294,9 +297,9 @@ void M3DImporter::importMaterials(const M3DWrapper &m3d_wrap) { // texture map properties if (m->prop[j].type >= 128 && aiTxProps[k].pKey && // extra check, should never happen, do we have the refered texture? - m->prop[j].value.textureid < m3d_wrap->numtexture && - m3d_wrap->texture[m->prop[j].value.textureid].name) { - name.Set(std::string(std::string(m3d_wrap->texture[m->prop[j].value.textureid].name) + ".png")); + m->prop[j].value.textureid < m3d->numtexture && + m3d->texture[m->prop[j].value.textureid].name) { + name.Set(std::string(std::string(m3d->texture[m->prop[j].value.textureid].name) + ".png")); mat->AddProperty(&name, aiTxProps[k].pKey, aiTxProps[k].type, aiTxProps[k].index); n = 0; mat->AddProperty(&n, 1, _AI_MATKEY_UVWSRC_BASE, aiProps[k].type, aiProps[k].index); @@ -319,7 +322,7 @@ void M3DImporter::importTextures(const M3DWrapper &m3d) { mScene->mNumTextures = m3d->numtexture; ASSIMP_LOG_DEBUG_F("M3D: importTextures ", mScene->mNumTextures); - if (!m3d->numtexture) + if (!m3d->numtexture || !m3d->texture) return; mScene->mTextures = new aiTexture *[m3d->numtexture]; @@ -387,6 +390,9 @@ void M3DImporter::importMeshes(const M3DWrapper &m3d) { ASSIMP_LOG_DEBUG_F("M3D: importMeshes ", m3d->numface); + if (!m3d->numface || !m3d->face || !m3d->numvertex || !m3d->vertex) + return; + for (i = 0; i < m3d->numface; i++) { // we must switch mesh if material changes if (lastMat != m3d->face[i].materialid) { @@ -420,6 +426,7 @@ void M3DImporter::importMeshes(const M3DWrapper &m3d) { k = static_cast(vertices->size()); pFace->mIndices[j] = k; l = m3d->face[i].vertex[j]; + if(l >= m3d->numvertex) continue; pos.x = m3d->vertex[l].x; pos.y = m3d->vertex[l].y; pos.z = m3d->vertex[l].z; @@ -432,14 +439,14 @@ void M3DImporter::importMeshes(const M3DWrapper &m3d) { vertexids->push_back(l); } l = m3d->face[i].texcoord[j]; - if (l != M3D_UNDEF) { + if (l != M3D_UNDEF && l < m3d->numtmap) { uv.x = m3d->tmap[l].u; uv.y = m3d->tmap[l].v; uv.z = 0.0; texcoords->push_back(uv); } l = m3d->face[i].normal[j]; - if (l != M3D_UNDEF) { + if (l != M3D_UNDEF && l < m3d->numvertex) { norm.x = m3d->vertex[l].x; norm.y = m3d->vertex[l].y; norm.z = m3d->vertex[l].z; @@ -487,6 +494,9 @@ void M3DImporter::importBones(const M3DWrapper &m3d, unsigned int parentid, aiNo ASSIMP_LOG_DEBUG_F("M3D: importBones ", m3d->numbone, " parentid ", (int)parentid); + if (!m3d->numbone || !m3d->bone) + return; + for (n = 0, i = parentid + 1; i < m3d->numbone; i++) if (m3d->bone[i].parent == parentid) n++; pParent->mChildren = new aiNode *[n]; @@ -521,7 +531,7 @@ void M3DImporter::importAnimations(const M3DWrapper &m3d) { ASSIMP_LOG_DEBUG_F("M3D: importAnimations ", mScene->mNumAnimations); - if (!m3d->numaction || !m3d->numbone) + if (!m3d->numaction || !m3d->action || !m3d->numbone || !m3d->bone || !m3d->vertex) return; mScene->mAnimations = new aiAnimation *[m3d->numaction]; @@ -552,6 +562,7 @@ void M3DImporter::importAnimations(const M3DWrapper &m3d) { ori = a->frame[j].transform[k].ori; } } + if(pos >= m3d->numvertex || ori >= m3d->numvertex) continue; m3dv_t *v = &m3d->vertex[pos]; m3dv_t *q = &m3d->vertex[ori]; pAnim->mChannels[l]->mPositionKeys[j].mTime = t; @@ -587,6 +598,8 @@ void M3DImporter::convertPose(const M3DWrapper &m3d, aiMatrix4x4 *m, unsigned in ai_assert(m3d); ai_assert(posid != M3D_UNDEF && posid < m3d->numvertex); ai_assert(orientid != M3D_UNDEF && orientid < m3d->numvertex); + if (!m3d->numvertex || !m3d->vertex) + return; m3dv_t *p = &m3d->vertex[posid]; m3dv_t *q = &m3d->vertex[orientid]; @@ -701,7 +714,7 @@ void M3DImporter::populateMesh(const M3DWrapper &m3d, aiMesh *pMesh, std::vector // vertex but assimp uses lists of local vertex id/weight pairs per local bone list pMesh->mNumBones = m3d->numbone; /* we need aiBone with mOffsetMatrix for bones without weights as well */ - if (pMesh->mNumBones) { + if (pMesh->mNumBones && m3d->numbone && m3d->bone) { pMesh->mBones = new aiBone *[pMesh->mNumBones]; for (unsigned int i = 0; i < m3d->numbone; i++) { aiNode *pNode; @@ -715,10 +728,11 @@ void M3DImporter::populateMesh(const M3DWrapper &m3d, aiMesh *pMesh, std::vector } else pMesh->mBones[i]->mOffsetMatrix = aiMatrix4x4(); } - if (vertexids->size()) { + if (vertexids->size() && m3d->numvertex && m3d->vertex && m3d->numskin && m3d->skin) { unsigned int i, j; // first count how many vertices we have per bone for (i = 0; i < vertexids->size(); i++) { + if(vertexids->at(i) >= m3d->numvertex) continue; unsigned int s = m3d->vertex[vertexids->at(i)].skinid; if (s != M3D_UNDEF && s != M3D_INDEXMAX) { for (unsigned int k = 0; k < M3D_NUMBONE && m3d->skin[s].weight[k] > 0.0; k++) { @@ -742,9 +756,11 @@ void M3DImporter::populateMesh(const M3DWrapper &m3d, aiMesh *pMesh, std::vector } // fill up with data for (i = 0; i < vertexids->size(); i++) { + if(vertexids->at(i) >= m3d->numvertex) continue; unsigned int s = m3d->vertex[vertexids->at(i)].skinid; - if (s != M3D_UNDEF && s != M3D_INDEXMAX) { + if (s != M3D_UNDEF && s != M3D_INDEXMAX && s < m3d->numskin) { for (unsigned int k = 0; k < M3D_NUMBONE && m3d->skin[s].weight[k] > 0.0; k++) { + if(m3d->skin[s].boneid[k] >= m3d->numbone) continue; aiString name = aiString(std::string(m3d->bone[m3d->skin[s].boneid[k]].name)); for (j = 0; j < pMesh->mNumBones; j++) { if (pMesh->mBones[j]->mName == name) { From 605336832ff0aa6fc8a2b9cde1e1a944dc9e9dc3 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 30 Jan 2020 09:47:39 +0100 Subject: [PATCH 05/19] Update M3DImporter.cpp Add missing brackets --- code/M3D/M3DImporter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/M3D/M3DImporter.cpp b/code/M3D/M3DImporter.cpp index 4373672a4..1a5d1866d 100644 --- a/code/M3D/M3DImporter.cpp +++ b/code/M3D/M3DImporter.cpp @@ -248,8 +248,9 @@ void M3DImporter::importMaterials(const M3DWrapper &m3d) { mat->AddProperty(&c, 1, AI_MATKEY_COLOR_DIFFUSE); mScene->mMaterials[0] = mat; - if (!m3d->nummaterial || !m3d->material) + if (!m3d->nummaterial || !m3d->material) { return; + } for (i = 0; i < m3d->nummaterial; i++) { m = &m3d->material[i]; From a2ef0b5bd5e2695d65f29f46cad84eecec1800e1 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 30 Jan 2020 10:00:43 +0100 Subject: [PATCH 06/19] Update M3DImporter.cpp Fix some review finding: - Add missing brackets to make code more readable - fix scope of variables --- code/M3D/M3DImporter.cpp | 135 ++++++++++++++++++++++----------------- 1 file changed, 75 insertions(+), 60 deletions(-) diff --git a/code/M3D/M3DImporter.cpp b/code/M3D/M3DImporter.cpp index 1a5d1866d..20b9b9e44 100644 --- a/code/M3D/M3DImporter.cpp +++ b/code/M3D/M3DImporter.cpp @@ -109,7 +109,9 @@ using namespace std; // ------------------------------------------------------------------------------------------------ // Default constructor M3DImporter::M3DImporter() : - mScene(nullptr) {} + mScene(nullptr) { + // empty +} // ------------------------------------------------------------------------------------------------ // Returns true, if file is a binary or ASCII Model 3D file. @@ -126,14 +128,8 @@ bool M3DImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c if (!pIOHandler) { return true; } - /* - * don't use CheckMagicToken because that checks with swapped bytes too, leading to false - * positives. This magic is not uint32_t, but char[4], so memcmp is the best way - const char* tokens[] = {"3DMO", "3dmo"}; - return CheckMagicToken(pIOHandler,pFile,tokens,2,0,4); - */ - std::unique_ptr pStream(pIOHandler->Open(pFile, "rb")); + std::unique_ptr pStream(pIOHandler->Open(pFile, "rb")); unsigned char data[4]; if (4 != pStream->Read(data, 1, 4)) { return false; @@ -144,7 +140,8 @@ bool M3DImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c #endif ; } - return false; + + return false; } // ------------------------------------------------------------------------------------------------ @@ -257,43 +254,46 @@ void M3DImporter::importMaterials(const M3DWrapper &m3d) { aiMaterial *mat = new aiMaterial; name.Set(std::string(m->name)); mat->AddProperty(&name, AI_MATKEY_NAME); - for (j = 0; j < m->numprop; j++) { + for (j = 0; j < m->numprop; ++j) { // look up property type // 0 - 127 scalar values, // 128 - 255 the same properties but for texture maps k = 256; - for (l = 0; l < sizeof(m3d_propertytypes) / sizeof(m3d_propertytypes[0]); l++) + for (l = 0; l < sizeof(m3d_propertytypes) / sizeof(m3d_propertytypes[0]); ++l) { if (m->prop[j].type == m3d_propertytypes[l].id || m->prop[j].type == m3d_propertytypes[l].id + 128) { k = l; break; } - // should never happen, but be safe than sorry - if (k == 256) continue; + // should never happen, but be safe than sorry + if (k == 256) { + continue; + } - // scalar properties - if (m->prop[j].type < 128 && aiProps[k].pKey) { - switch (m3d_propertytypes[k].format) { - case m3dpf_color: - c = mkColor(m->prop[j].value.color); - mat->AddProperty(&c, 1, aiProps[k].pKey, aiProps[k].type, aiProps[k].index); - break; - case m3dpf_float: - f = m->prop[j].value.fnum; - mat->AddProperty(&f, 1, aiProps[k].pKey, aiProps[k].type, aiProps[k].index); - break; - default: - n = m->prop[j].value.num; - if (m->prop[j].type == m3dp_il) { - switch (n) { - case 0: n = aiShadingMode_NoShading; break; - case 2: n = aiShadingMode_Phong; break; - default: n = aiShadingMode_Gouraud; break; - } - } - mat->AddProperty(&n, 1, aiProps[k].pKey, aiProps[k].type, aiProps[k].index); - break; - } + // scalar properties + if (m->prop[j].type < 128 && aiProps[k].pKey) { + switch (m3d_propertytypes[k].format) { + case m3dpf_color: + c = mkColor(m->prop[j].value.color); + mat->AddProperty(&c, 1, aiProps[k].pKey, aiProps[k].type, aiProps[k].index); + break; + case m3dpf_float: + f = m->prop[j].value.fnum; + mat->AddProperty(&f, 1, aiProps[k].pKey, aiProps[k].type, aiProps[k].index); + break; + default: + n = m->prop[j].value.num; + if (m->prop[j].type == m3dp_il) { + switch (n) { + case 0: n = aiShadingMode_NoShading; break; + case 2: n = aiShadingMode_Phong; break; + default: n = aiShadingMode_Gouraud; break; + } + } + mat->AddProperty(&n, 1, aiProps[k].pKey, aiProps[k].type, aiProps[k].index); + break; + } + } } // texture map properties if (m->prop[j].type >= 128 && aiTxProps[k].pKey && @@ -314,7 +314,11 @@ void M3DImporter::importMaterials(const M3DWrapper &m3d) { // import textures, this is the simplest of all void M3DImporter::importTextures(const M3DWrapper &m3d) { unsigned int i; - const char *formatHint[] = { "rgba0800", "rgba0808", "rgba8880", "rgba8888" }; + static const char *formatHint[] = { + "rgba0800", + "rgba0808", + "rgba8880", + "rgba8888" }; m3dtx_t *t; ai_assert(mScene != nullptr); @@ -323,8 +327,9 @@ void M3DImporter::importTextures(const M3DWrapper &m3d) { mScene->mNumTextures = m3d->numtexture; ASSIMP_LOG_DEBUG_F("M3D: importTextures ", mScene->mNumTextures); - if (!m3d->numtexture || !m3d->texture) + if (!m3d->numtexture || !m3d->texture) { return; + } mScene->mTextures = new aiTexture *[m3d->numtexture]; for (i = 0; i < m3d->numtexture; i++) { @@ -391,8 +396,9 @@ void M3DImporter::importMeshes(const M3DWrapper &m3d) { ASSIMP_LOG_DEBUG_F("M3D: importMeshes ", m3d->numface); - if (!m3d->numface || !m3d->face || !m3d->numvertex || !m3d->vertex) + if (!m3d->numface || !m3d->face || !m3d->numvertex || !m3d->vertex) { return; + } for (i = 0; i < m3d->numface; i++) { // we must switch mesh if material changes @@ -476,12 +482,12 @@ void M3DImporter::importMeshes(const M3DWrapper &m3d) { } delete meshes; - if (faces) delete faces; - if (vertices) delete vertices; - if (normals) delete normals; - if (texcoords) delete texcoords; - if (colors) delete colors; - if (vertexids) delete vertexids; + delete faces; + delete vertices; + delete normals; + delete texcoords; + delete colors; + delete vertexids; } // ------------------------------------------------------------------------------------------------ @@ -495,11 +501,15 @@ void M3DImporter::importBones(const M3DWrapper &m3d, unsigned int parentid, aiNo ASSIMP_LOG_DEBUG_F("M3D: importBones ", m3d->numbone, " parentid ", (int)parentid); - if (!m3d->numbone || !m3d->bone) + if (!m3d->numbone || !m3d->bone) { return; + } - for (n = 0, i = parentid + 1; i < m3d->numbone; i++) - if (m3d->bone[i].parent == parentid) n++; + for (n = 0, i = parentid + 1; i < m3d->numbone; i++) { + if (m3d->bone[i].parent == parentid) { + n++; + } + } pParent->mChildren = new aiNode *[n]; for (i = parentid + 1; i < m3d->numbone; i++) { @@ -532,8 +542,9 @@ void M3DImporter::importAnimations(const M3DWrapper &m3d) { ASSIMP_LOG_DEBUG_F("M3D: importAnimations ", mScene->mNumAnimations); - if (!m3d->numaction || !m3d->action || !m3d->numbone || !m3d->bone || !m3d->vertex) + if (!m3d->numaction || !m3d->action || !m3d->numbone || !m3d->bone || !m3d->vertex) { return; + } mScene->mAnimations = new aiAnimation *[m3d->numaction]; for (i = 0; i < m3d->numaction; i++) { @@ -643,16 +654,17 @@ void M3DImporter::convertPose(const M3DWrapper &m3d, aiMatrix4x4 *m, unsigned in // ------------------------------------------------------------------------------------------------ // find a node by name aiNode *M3DImporter::findNode(aiNode *pNode, aiString name) { - unsigned int i; - ai_assert(pNode != nullptr); ai_assert(mScene != nullptr); - if (pNode->mName == name) + if (pNode->mName == name) { return pNode; - for (i = 0; i < pNode->mNumChildren; i++) { + } + for ( unsigned int i = 0; i < pNode->mNumChildren; i++) { aiNode *pChild = findNode(pNode->mChildren[i], name); - if (pChild) return pChild; + if (pChild) { + return pChild; + } } return nullptr; } @@ -714,7 +726,8 @@ void M3DImporter::populateMesh(const M3DWrapper &m3d, aiMesh *pMesh, std::vector // this is complicated, because M3D stores a list of bone id / weight pairs per // vertex but assimp uses lists of local vertex id/weight pairs per local bone list pMesh->mNumBones = m3d->numbone; - /* we need aiBone with mOffsetMatrix for bones without weights as well */ + + // we need aiBone with mOffsetMatrix for bones without weights as well if (pMesh->mNumBones && m3d->numbone && m3d->bone) { pMesh->mBones = new aiBone *[pMesh->mNumBones]; for (unsigned int i = 0; i < m3d->numbone; i++) { @@ -730,15 +743,16 @@ void M3DImporter::populateMesh(const M3DWrapper &m3d, aiMesh *pMesh, std::vector pMesh->mBones[i]->mOffsetMatrix = aiMatrix4x4(); } if (vertexids->size() && m3d->numvertex && m3d->vertex && m3d->numskin && m3d->skin) { - unsigned int i, j; // first count how many vertices we have per bone - for (i = 0; i < vertexids->size(); i++) { - if(vertexids->at(i) >= m3d->numvertex) continue; + for (unsigned int i = 0; i < vertexids->size(); i++) { + if (vertexids->at(i) >= m3d->numvertex) { + continue; + } unsigned int s = m3d->vertex[vertexids->at(i)].skinid; if (s != M3D_UNDEF && s != M3D_INDEXMAX) { for (unsigned int k = 0; k < M3D_NUMBONE && m3d->skin[s].weight[k] > 0.0; k++) { aiString name = aiString(std::string(m3d->bone[m3d->skin[s].boneid[k]].name)); - for (j = 0; j < pMesh->mNumBones; j++) { + for (unsigned int j = 0; j < pMesh->mNumBones; j++) { if (pMesh->mBones[j]->mName == name) { pMesh->mBones[j]->mNumWeights++; break; @@ -747,7 +761,8 @@ void M3DImporter::populateMesh(const M3DWrapper &m3d, aiMesh *pMesh, std::vector } } } - // allocate mWeights + + // allocate mWeights for (j = 0; j < pMesh->mNumBones; j++) { aiBone *pBone = pMesh->mBones[j]; if (pBone->mNumWeights) { From 2c1c1d846e4584990e2397f195fb3225ec6a8668 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Thu, 30 Jan 2020 16:40:34 -0500 Subject: [PATCH 07/19] Renamed WriteDumb.cpp to WriteDump.cpp This includes as well changes to places referencing WriteDumb.cpp. --- code/Common/assbin_chunks.h | 2 +- tools/assimp_cmd/CMakeLists.txt | 2 +- tools/assimp_cmd/Main.h | 2 +- tools/assimp_cmd/{WriteDumb.cpp => WriteDump.cpp} | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename tools/assimp_cmd/{WriteDumb.cpp => WriteDump.cpp} (99%) diff --git a/code/Common/assbin_chunks.h b/code/Common/assbin_chunks.h index 15e4af5e7..822df5198 100644 --- a/code/Common/assbin_chunks.h +++ b/code/Common/assbin_chunks.h @@ -37,7 +37,7 @@ The ASSBIN file format is composed of chunks to represent the hierarchical aiSce This makes the format extensible and allows backward-compatibility with future data structure versions. The <root>/code/assbin_chunks.h header contains some magic constants for use by stand-alone ASSBIN loaders. Also, Assimp's own file writer can be found -in <root>/tools/assimp_cmd/WriteDumb.cpp (yes, the 'b' is no typo ...). +in <root>/tools/assimp_cmd/WriteDump.cpp (yes, the 'b' is no typo ...). @verbatim diff --git a/tools/assimp_cmd/CMakeLists.txt b/tools/assimp_cmd/CMakeLists.txt index ef7b7f054..fcf36c356 100644 --- a/tools/assimp_cmd/CMakeLists.txt +++ b/tools/assimp_cmd/CMakeLists.txt @@ -54,7 +54,7 @@ ADD_EXECUTABLE( assimp_cmd Main.cpp Main.h resource.h - WriteDumb.cpp + WriteDump.cpp Info.cpp Export.cpp ) diff --git a/tools/assimp_cmd/Main.h b/tools/assimp_cmd/Main.h index 7a6ac942d..ecc65345d 100644 --- a/tools/assimp_cmd/Main.h +++ b/tools/assimp_cmd/Main.h @@ -168,7 +168,7 @@ bool ExportModel(const aiScene* pOut, // ------------------------------------------------------------------------------ /** assimp_dump utility - * @param params Command line parameters to 'assimp dumb' + * @param params Command line parameters to 'assimp dump' * @param Number of params * @return An #AssimpCmdError value.*/ int Assimp_Dump ( diff --git a/tools/assimp_cmd/WriteDumb.cpp b/tools/assimp_cmd/WriteDump.cpp similarity index 99% rename from tools/assimp_cmd/WriteDumb.cpp rename to tools/assimp_cmd/WriteDump.cpp index 0403f3966..67d1a0e76 100644 --- a/tools/assimp_cmd/WriteDumb.cpp +++ b/tools/assimp_cmd/WriteDump.cpp @@ -41,7 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------- */ -/** @file WriteTextDumb.cpp +/** @file WriteDump.cpp * @brief Implementation of the 'assimp dump' utility */ From e434c63c31d474c506b7cb573762aa7ac307e37a Mon Sep 17 00:00:00 2001 From: bzt Date: Fri, 31 Jan 2020 14:20:23 +0100 Subject: [PATCH 08/19] Fixed what kimkulling broke --- code/M3D/M3DImporter.cpp | 137 ++++++++++++++++++++------------------- 1 file changed, 70 insertions(+), 67 deletions(-) diff --git a/code/M3D/M3DImporter.cpp b/code/M3D/M3DImporter.cpp index 20b9b9e44..1c6cea766 100644 --- a/code/M3D/M3DImporter.cpp +++ b/code/M3D/M3DImporter.cpp @@ -110,8 +110,8 @@ using namespace std; // Default constructor M3DImporter::M3DImporter() : mScene(nullptr) { - // empty -} + // empty + } // ------------------------------------------------------------------------------------------------ // Returns true, if file is a binary or ASCII Model 3D file. @@ -128,8 +128,14 @@ bool M3DImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c if (!pIOHandler) { return true; } + /* + * don't use CheckMagicToken because that checks with swapped bytes too, leading to false + * positives. This magic is not uint32_t, but char[4], so memcmp is the best way - std::unique_ptr pStream(pIOHandler->Open(pFile, "rb")); + const char* tokens[] = {"3DMO", "3dmo"}; + return CheckMagicToken(pIOHandler,pFile,tokens,2,0,4); + */ + std::unique_ptr pStream(pIOHandler->Open(pFile, "rb")); unsigned char data[4]; if (4 != pStream->Read(data, 1, 4)) { return false; @@ -140,8 +146,7 @@ bool M3DImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool c #endif ; } - - return false; + return false; } // ------------------------------------------------------------------------------------------------ @@ -247,53 +252,50 @@ void M3DImporter::importMaterials(const M3DWrapper &m3d) { if (!m3d->nummaterial || !m3d->material) { return; - } + } for (i = 0; i < m3d->nummaterial; i++) { m = &m3d->material[i]; aiMaterial *mat = new aiMaterial; name.Set(std::string(m->name)); mat->AddProperty(&name, AI_MATKEY_NAME); - for (j = 0; j < m->numprop; ++j) { + for (j = 0; j < m->numprop; j++) { // look up property type // 0 - 127 scalar values, // 128 - 255 the same properties but for texture maps k = 256; - for (l = 0; l < sizeof(m3d_propertytypes) / sizeof(m3d_propertytypes[0]); ++l) { + for (l = 0; l < sizeof(m3d_propertytypes) / sizeof(m3d_propertytypes[0]); l++) if (m->prop[j].type == m3d_propertytypes[l].id || m->prop[j].type == m3d_propertytypes[l].id + 128) { k = l; break; } - // should never happen, but be safe than sorry - if (k == 256) { - continue; - } + // should never happen, but be safe than sorry + if (k == 256) continue; - // scalar properties - if (m->prop[j].type < 128 && aiProps[k].pKey) { - switch (m3d_propertytypes[k].format) { - case m3dpf_color: - c = mkColor(m->prop[j].value.color); - mat->AddProperty(&c, 1, aiProps[k].pKey, aiProps[k].type, aiProps[k].index); - break; - case m3dpf_float: - f = m->prop[j].value.fnum; - mat->AddProperty(&f, 1, aiProps[k].pKey, aiProps[k].type, aiProps[k].index); - break; - default: - n = m->prop[j].value.num; - if (m->prop[j].type == m3dp_il) { - switch (n) { - case 0: n = aiShadingMode_NoShading; break; - case 2: n = aiShadingMode_Phong; break; - default: n = aiShadingMode_Gouraud; break; - } - } - mat->AddProperty(&n, 1, aiProps[k].pKey, aiProps[k].type, aiProps[k].index); - break; - } - } + // scalar properties + if (m->prop[j].type < 128 && aiProps[k].pKey) { + switch (m3d_propertytypes[k].format) { + case m3dpf_color: + c = mkColor(m->prop[j].value.color); + mat->AddProperty(&c, 1, aiProps[k].pKey, aiProps[k].type, aiProps[k].index); + break; + case m3dpf_float: + f = m->prop[j].value.fnum; + mat->AddProperty(&f, 1, aiProps[k].pKey, aiProps[k].type, aiProps[k].index); + break; + default: + n = m->prop[j].value.num; + if (m->prop[j].type == m3dp_il) { + switch (n) { + case 0: n = aiShadingMode_NoShading; break; + case 2: n = aiShadingMode_Phong; break; + default: n = aiShadingMode_Gouraud; break; + } + } + mat->AddProperty(&n, 1, aiProps[k].pKey, aiProps[k].type, aiProps[k].index); + break; + } } // texture map properties if (m->prop[j].type >= 128 && aiTxProps[k].pKey && @@ -314,11 +316,12 @@ void M3DImporter::importMaterials(const M3DWrapper &m3d) { // import textures, this is the simplest of all void M3DImporter::importTextures(const M3DWrapper &m3d) { unsigned int i; - static const char *formatHint[] = { - "rgba0800", - "rgba0808", - "rgba8880", - "rgba8888" }; + const char *formatHint[] = { + "rgba0800", + "rgba0808", + "rgba8880", + "rgba8888" + }; m3dtx_t *t; ai_assert(mScene != nullptr); @@ -329,7 +332,7 @@ void M3DImporter::importTextures(const M3DWrapper &m3d) { if (!m3d->numtexture || !m3d->texture) { return; - } + } mScene->mTextures = new aiTexture *[m3d->numtexture]; for (i = 0; i < m3d->numtexture; i++) { @@ -398,7 +401,7 @@ void M3DImporter::importMeshes(const M3DWrapper &m3d) { if (!m3d->numface || !m3d->face || !m3d->numvertex || !m3d->vertex) { return; - } + } for (i = 0; i < m3d->numface; i++) { // we must switch mesh if material changes @@ -482,12 +485,12 @@ void M3DImporter::importMeshes(const M3DWrapper &m3d) { } delete meshes; - delete faces; - delete vertices; - delete normals; - delete texcoords; - delete colors; - delete vertexids; + if (faces) delete faces; + if (vertices) delete vertices; + if (normals) delete normals; + if (texcoords) delete texcoords; + if (colors) delete colors; + if (vertexids) delete vertexids; } // ------------------------------------------------------------------------------------------------ @@ -503,13 +506,13 @@ void M3DImporter::importBones(const M3DWrapper &m3d, unsigned int parentid, aiNo if (!m3d->numbone || !m3d->bone) { return; - } + } for (n = 0, i = parentid + 1; i < m3d->numbone; i++) { if (m3d->bone[i].parent == parentid) { - n++; - } - } + n++; + } + } pParent->mChildren = new aiNode *[n]; for (i = parentid + 1; i < m3d->numbone; i++) { @@ -544,7 +547,7 @@ void M3DImporter::importAnimations(const M3DWrapper &m3d) { if (!m3d->numaction || !m3d->action || !m3d->numbone || !m3d->bone || !m3d->vertex) { return; - } + } mScene->mAnimations = new aiAnimation *[m3d->numaction]; for (i = 0; i < m3d->numaction; i++) { @@ -659,12 +662,13 @@ aiNode *M3DImporter::findNode(aiNode *pNode, aiString name) { if (pNode->mName == name) { return pNode; - } - for ( unsigned int i = 0; i < pNode->mNumChildren; i++) { + } + + for (unsigned int i = 0; i < pNode->mNumChildren; i++) { aiNode *pChild = findNode(pNode->mChildren[i], name); if (pChild) { - return pChild; - } + return pChild; + } } return nullptr; } @@ -726,8 +730,7 @@ void M3DImporter::populateMesh(const M3DWrapper &m3d, aiMesh *pMesh, std::vector // this is complicated, because M3D stores a list of bone id / weight pairs per // vertex but assimp uses lists of local vertex id/weight pairs per local bone list pMesh->mNumBones = m3d->numbone; - - // we need aiBone with mOffsetMatrix for bones without weights as well + // we need aiBone with mOffsetMatrix for bones without weights as well if (pMesh->mNumBones && m3d->numbone && m3d->bone) { pMesh->mBones = new aiBone *[pMesh->mNumBones]; for (unsigned int i = 0; i < m3d->numbone; i++) { @@ -743,16 +746,17 @@ void M3DImporter::populateMesh(const M3DWrapper &m3d, aiMesh *pMesh, std::vector pMesh->mBones[i]->mOffsetMatrix = aiMatrix4x4(); } if (vertexids->size() && m3d->numvertex && m3d->vertex && m3d->numskin && m3d->skin) { + unsigned int i, j; // first count how many vertices we have per bone - for (unsigned int i = 0; i < vertexids->size(); i++) { - if (vertexids->at(i) >= m3d->numvertex) { - continue; - } + for (i = 0; i < vertexids->size(); i++) { + if(vertexids->at(i) >= m3d->numvertex) { + continue; + } unsigned int s = m3d->vertex[vertexids->at(i)].skinid; if (s != M3D_UNDEF && s != M3D_INDEXMAX) { for (unsigned int k = 0; k < M3D_NUMBONE && m3d->skin[s].weight[k] > 0.0; k++) { aiString name = aiString(std::string(m3d->bone[m3d->skin[s].boneid[k]].name)); - for (unsigned int j = 0; j < pMesh->mNumBones; j++) { + for (j = 0; j < pMesh->mNumBones; j++) { if (pMesh->mBones[j]->mName == name) { pMesh->mBones[j]->mNumWeights++; break; @@ -761,8 +765,7 @@ void M3DImporter::populateMesh(const M3DWrapper &m3d, aiMesh *pMesh, std::vector } } } - - // allocate mWeights + // allocate mWeights for (j = 0; j < pMesh->mNumBones; j++) { aiBone *pBone = pMesh->mBones[j]; if (pBone->mNumWeights) { From 0af44fb3e8597b812db47f69e59a31cfb640620a Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 31 Jan 2020 19:06:56 +0100 Subject: [PATCH 09/19] Update glTFExporter.cpp Replacing tabs by spaces. --- code/glTF/glTFExporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/glTF/glTFExporter.cpp b/code/glTF/glTFExporter.cpp index 4ebe53c00..072234891 100644 --- a/code/glTF/glTFExporter.cpp +++ b/code/glTF/glTFExporter.cpp @@ -353,7 +353,7 @@ void glTFExporter::GetMatColorOrTex(const aiMaterial* mat, glTF::TexProperty& pr if (path[0] == '*') { // embedded aiTexture* tex = mScene->mTextures[atoi(&path[1])]; - prop.texture->source->name = tex->mFilename.C_Str(); + prop.texture->source->name = tex->mFilename.C_Str(); uint8_t* data = reinterpret_cast(tex->pcData); prop.texture->source->SetData(data, tex->mWidth, *mAsset); From 187b74355bd7ee18b02da9c84d44e6dc186b0c9e Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 31 Jan 2020 19:08:04 +0100 Subject: [PATCH 10/19] Update glTFImporter.cpp Replace tabs by spaces. --- code/glTF/glTFImporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/glTF/glTFImporter.cpp b/code/glTF/glTFImporter.cpp index bba48dc30..16addc977 100644 --- a/code/glTF/glTFImporter.cpp +++ b/code/glTF/glTFImporter.cpp @@ -680,7 +680,7 @@ void glTFImporter::ImportEmbeddedTextures(glTF::Asset& r) size_t length = img.GetDataLength(); void* data = img.StealData(); - tex->mFilename = img.name; + tex->mFilename = img.name; tex->mWidth = static_cast(length); tex->mHeight = 0; tex->pcData = reinterpret_cast(data); From 026900088433e46ee5e35162e062d733c547a121 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 31 Jan 2020 19:11:36 +0100 Subject: [PATCH 11/19] Update glTF2Exporter.cpp Replacing tabs by spaces. --- code/glTF2/glTF2Exporter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/glTF2/glTF2Exporter.cpp b/code/glTF2/glTF2Exporter.cpp index b240a5ea9..1bfee4491 100644 --- a/code/glTF2/glTF2Exporter.cpp +++ b/code/glTF2/glTF2Exporter.cpp @@ -352,7 +352,7 @@ void glTF2Exporter::GetMatTex(const aiMaterial* mat, Ref& texture, aiTe if (path[0] == '*') { // embedded aiTexture* tex = mScene->mTextures[atoi(&path[1])]; - texture->source->name = tex->mFilename.C_Str(); + texture->source->name = tex->mFilename.C_Str(); // The asset has its own buffer, see Image::SetData texture->source->SetData(reinterpret_cast (tex->pcData), tex->mWidth, *mAsset); From d6567e606e6acb472f2b64f700834f8fc1ef41ff Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Fri, 31 Jan 2020 18:14:26 -0500 Subject: [PATCH 12/19] Fixed wrong changes applied during merge. --- code/MDL/HalfLife/HL1MDLLoader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/MDL/HalfLife/HL1MDLLoader.cpp b/code/MDL/HalfLife/HL1MDLLoader.cpp index 6d5f283af..c18528e59 100644 --- a/code/MDL/HalfLife/HL1MDLLoader.cpp +++ b/code/MDL/HalfLife/HL1MDLLoader.cpp @@ -345,8 +345,8 @@ void HL1MDLLoader::read_texture(const Texture_HL1 *ptexture, uint8_t *data, uint8_t *pal, aiTexture *pResult, aiColor3D &last_palette_color) { pResult->mFilename = ptexture->name; - pResult->mWidth = outwidth; - pResult->mHeight = outheight; + pResult->mWidth = static_cast(ptexture->width); + pResult->mHeight = static_cast(ptexture->height); pResult->achFormatHint[0] = 'r'; pResult->achFormatHint[1] = 'g'; pResult->achFormatHint[2] = 'b'; From 29603128f434e23cb93398955fe9fe22e101ed6e Mon Sep 17 00:00:00 2001 From: Frooxius Date: Thu, 6 Feb 2020 10:28:38 +0100 Subject: [PATCH 13/19] Fixed invalid armature node population when there's mesh on a node with the same name as the bone --- code/PostProcessing/ArmaturePopulate.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/PostProcessing/ArmaturePopulate.cpp b/code/PostProcessing/ArmaturePopulate.cpp index c339bebe0..1514e14f2 100644 --- a/code/PostProcessing/ArmaturePopulate.cpp +++ b/code/PostProcessing/ArmaturePopulate.cpp @@ -150,7 +150,8 @@ void ArmaturePopulate::BuildNodeList(const aiNode *current_node, aiNode *child = current_node->mChildren[nodeId]; ai_assert(child); - nodes.push_back(child); + if (child->mNumMeshes == 0) + nodes.push_back(child); BuildNodeList(child, nodes); } From 8c09cd2ef3d72ba150b7a8faf67ea7fcd913984b Mon Sep 17 00:00:00 2001 From: Marc-Antoine Lortie Date: Thu, 6 Feb 2020 13:19:01 -0500 Subject: [PATCH 14/19] Fixed TextureTypeToString defined multiple times. - Moved TextureTypeToString to it's own file. - Added new file to CMakeLists.txt. - Added 6 missing values in TextureTypeToString. - Added 6 missing aiTextureType enum values in assimp_cmd/Info.cpp. --- code/CMakeLists.txt | 1 + code/Common/material.cpp | 97 +++++++++++++++++++++++++++ code/PostProcessing/ProcessHelper.cpp | 40 ----------- code/PostProcessing/ProcessHelper.h | 6 -- include/assimp/material.h | 4 ++ tools/assimp_cmd/Info.cpp | 6 ++ tools/assimp_cmd/WriteDump.cpp | 38 ----------- 7 files changed, 108 insertions(+), 84 deletions(-) create mode 100644 code/Common/material.cpp diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 5278509e8..91f099c02 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -198,6 +198,7 @@ SET( Common_SRCS Common/CreateAnimMesh.cpp Common/simd.h Common/simd.cpp + Common/material.cpp ) SOURCE_GROUP(Common FILES ${Common_SRCS}) diff --git a/code/Common/material.cpp b/code/Common/material.cpp new file mode 100644 index 000000000..f4a29dacf --- /dev/null +++ b/code/Common/material.cpp @@ -0,0 +1,97 @@ +/* +Open Asset Import Library (assimp) +---------------------------------------------------------------------- + +Copyright (c) 2006-2020, assimp team + + +All rights reserved. + +Redistribution and use of this software in source and binary forms, +with or without modification, are permitted provided that the +following conditions are met: + +* Redistributions of source code must retain the above + copyright notice, this list of conditions and the + following disclaimer. + +* Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the + following disclaimer in the documentation and/or other + materials provided with the distribution. + +* Neither the name of the assimp team, nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior + written permission of the assimp team. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +---------------------------------------------------------------------- +*/ + +/// @file material.cpp +/** Implement common material related functions. */ + +#include +#include + +// ------------------------------------------------------------------------------- +const char* TextureTypeToString(aiTextureType in) +{ + switch (in) + { + case aiTextureType_NONE: + return "n/a"; + case aiTextureType_DIFFUSE: + return "Diffuse"; + case aiTextureType_SPECULAR: + return "Specular"; + case aiTextureType_AMBIENT: + return "Ambient"; + case aiTextureType_EMISSIVE: + return "Emissive"; + case aiTextureType_OPACITY: + return "Opacity"; + case aiTextureType_NORMALS: + return "Normals"; + case aiTextureType_HEIGHT: + return "Height"; + case aiTextureType_SHININESS: + return "Shininess"; + case aiTextureType_DISPLACEMENT: + return "Displacement"; + case aiTextureType_LIGHTMAP: + return "Lightmap"; + case aiTextureType_REFLECTION: + return "Reflection"; + case aiTextureType_BASE_COLOR: + return "BaseColor"; + case aiTextureType_NORMAL_CAMERA: + return "NormalCamera"; + case aiTextureType_EMISSION_COLOR: + return "EmissionColor"; + case aiTextureType_METALNESS: + return "Metalness"; + case aiTextureType_DIFFUSE_ROUGHNESS: + return "DiffuseRoughness"; + case aiTextureType_AMBIENT_OCCLUSION: + return "AmbientOcclusion"; + case aiTextureType_UNKNOWN: + return "Unknown"; + default: + break; + } + ai_assert(false); + return "BUG"; +} diff --git a/code/PostProcessing/ProcessHelper.cpp b/code/PostProcessing/ProcessHelper.cpp index 41444afd8..123986438 100644 --- a/code/PostProcessing/ProcessHelper.cpp +++ b/code/PostProcessing/ProcessHelper.cpp @@ -230,46 +230,6 @@ VertexWeightTable* ComputeVertexBoneWeightTable(const aiMesh* pMesh) return avPerVertexWeights; } - -// ------------------------------------------------------------------------------- -const char* TextureTypeToString(aiTextureType in) -{ - switch (in) - { - case aiTextureType_NONE: - return "n/a"; - case aiTextureType_DIFFUSE: - return "Diffuse"; - case aiTextureType_SPECULAR: - return "Specular"; - case aiTextureType_AMBIENT: - return "Ambient"; - case aiTextureType_EMISSIVE: - return "Emissive"; - case aiTextureType_OPACITY: - return "Opacity"; - case aiTextureType_NORMALS: - return "Normals"; - case aiTextureType_HEIGHT: - return "Height"; - case aiTextureType_SHININESS: - return "Shininess"; - case aiTextureType_DISPLACEMENT: - return "Displacement"; - case aiTextureType_LIGHTMAP: - return "Lightmap"; - case aiTextureType_REFLECTION: - return "Reflection"; - case aiTextureType_UNKNOWN: - return "Unknown"; - default: - break; - } - - ai_assert(false); - return "BUG"; -} - // ------------------------------------------------------------------------------- const char* MappingTypeToString(aiTextureMapping in) { diff --git a/code/PostProcessing/ProcessHelper.h b/code/PostProcessing/ProcessHelper.h index 7ff3a9c5f..5762fbb35 100644 --- a/code/PostProcessing/ProcessHelper.h +++ b/code/PostProcessing/ProcessHelper.h @@ -316,12 +316,6 @@ typedef std::vector VertexWeightTable; // Compute a per-vertex bone weight table VertexWeightTable* ComputeVertexBoneWeightTable(const aiMesh* pMesh); - -// ------------------------------------------------------------------------------- -// Get a string for a given aiTextureType -const char* TextureTypeToString(aiTextureType in); - - // ------------------------------------------------------------------------------- // Get a string for a given aiTextureMapping const char* MappingTypeToString(aiTextureMapping in); diff --git a/include/assimp/material.h b/include/assimp/material.h index 6c864e3d4..75695e50b 100644 --- a/include/assimp/material.h +++ b/include/assimp/material.h @@ -312,6 +312,10 @@ enum aiTextureType #define AI_TEXTURE_TYPE_MAX aiTextureType_UNKNOWN +// ------------------------------------------------------------------------------- +// Get a string for a given aiTextureType +ASSIMP_API const char* TextureTypeToString(enum aiTextureType in); + // --------------------------------------------------------------------------- /** @brief Defines all shading models supported by the library * diff --git a/tools/assimp_cmd/Info.cpp b/tools/assimp_cmd/Info.cpp index 1594235f9..52b9edb92 100644 --- a/tools/assimp_cmd/Info.cpp +++ b/tools/assimp_cmd/Info.cpp @@ -444,6 +444,12 @@ int Assimp_Info (const char* const* params, unsigned int num) { aiTextureType_DISPLACEMENT, aiTextureType_LIGHTMAP, aiTextureType_REFLECTION, + aiTextureType_BASE_COLOR, + aiTextureType_NORMAL_CAMERA, + aiTextureType_EMISSION_COLOR, + aiTextureType_METALNESS, + aiTextureType_DIFFUSE_ROUGHNESS, + aiTextureType_AMBIENT_OCCLUSION, aiTextureType_UNKNOWN }; for(unsigned int type = 0; type < sizeof(types)/sizeof(types[0]); ++type) { diff --git a/tools/assimp_cmd/WriteDump.cpp b/tools/assimp_cmd/WriteDump.cpp index 67d1a0e76..86542ed2e 100644 --- a/tools/assimp_cmd/WriteDump.cpp +++ b/tools/assimp_cmd/WriteDump.cpp @@ -69,44 +69,6 @@ const char* AICMD_MSG_DUMP_HELP = FILE* out = NULL; bool shortened = false; -// ------------------------------------------------------------------------------- -const char* TextureTypeToString(aiTextureType in) -{ - switch (in) - { - case aiTextureType_NONE: - return "n/a"; - case aiTextureType_DIFFUSE: - return "Diffuse"; - case aiTextureType_SPECULAR: - return "Specular"; - case aiTextureType_AMBIENT: - return "Ambient"; - case aiTextureType_EMISSIVE: - return "Emissive"; - case aiTextureType_OPACITY: - return "Opacity"; - case aiTextureType_NORMALS: - return "Normals"; - case aiTextureType_HEIGHT: - return "Height"; - case aiTextureType_SHININESS: - return "Shininess"; - case aiTextureType_DISPLACEMENT: - return "Displacement"; - case aiTextureType_LIGHTMAP: - return "Lightmap"; - case aiTextureType_REFLECTION: - return "Reflection"; - case aiTextureType_UNKNOWN: - return "Unknown"; - default: - break; - } - ai_assert(false); - return "BUG"; -} - // ----------------------------------------------------------------------------------- int Assimp_Dump (const char* const* params, unsigned int num) { From d3a70c73c445c01b03495fe2d0c8513bf16e5fb7 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Fri, 7 Feb 2020 10:58:56 +0100 Subject: [PATCH 15/19] Update FUNDING.yml Add paypal sponsoring --- .github/FUNDING.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index e750822ab..a932e5377 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,2 +1,2 @@ patreon: assimp -ko_fi: kimkulling +Paypal: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4JRJVPXC4QJM4 From 8fd053315ce535fca5f103c13c2d1800d4a092ab Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 9 Feb 2020 11:14:42 +0100 Subject: [PATCH 16/19] Update ArmaturePopulate.cpp - Introduce tabs width of 4. - Add missing brackets - Use c++ comment blocks --- code/PostProcessing/ArmaturePopulate.cpp | 283 +++++++++++------------ 1 file changed, 138 insertions(+), 145 deletions(-) diff --git a/code/PostProcessing/ArmaturePopulate.cpp b/code/PostProcessing/ArmaturePopulate.cpp index 1514e14f2..31c99ae94 100644 --- a/code/PostProcessing/ArmaturePopulate.cpp +++ b/code/PostProcessing/ArmaturePopulate.cpp @@ -4,7 +4,6 @@ Open Asset Import Library (assimp) Copyright (c) 2006-2020, assimp team - All rights reserved. Redistribution and use of this software in source and binary forms, @@ -36,7 +35,6 @@ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - ---------------------------------------------------------------------- */ #include "ArmaturePopulate.h" @@ -50,220 +48,215 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. namespace Assimp { /// The default class constructor. -ArmaturePopulate::ArmaturePopulate() : BaseProcess() -{} +ArmaturePopulate::ArmaturePopulate() : + BaseProcess() { + // do nothing +} /// The class destructor. -ArmaturePopulate::~ArmaturePopulate() -{} +ArmaturePopulate::~ArmaturePopulate() { + // do nothing +} bool ArmaturePopulate::IsActive(unsigned int pFlags) const { - return (pFlags & aiProcess_PopulateArmatureData) != 0; + return (pFlags & aiProcess_PopulateArmatureData) != 0; } void ArmaturePopulate::SetupProperties(const Importer *pImp) { - // do nothing + // do nothing } void ArmaturePopulate::Execute(aiScene *out) { - // Now convert all bone positions to the correct mOffsetMatrix - std::vector bones; - std::vector nodes; - std::map bone_stack; - BuildBoneList(out->mRootNode, out->mRootNode, out, bones); - BuildNodeList(out->mRootNode, nodes); + // Now convert all bone positions to the correct mOffsetMatrix + std::vector bones; + std::vector nodes; + std::map bone_stack; + BuildBoneList(out->mRootNode, out->mRootNode, out, bones); + BuildNodeList(out->mRootNode, nodes); - BuildBoneStack(out->mRootNode, out->mRootNode, out, bones, bone_stack, nodes); + BuildBoneStack(out->mRootNode, out->mRootNode, out, bones, bone_stack, nodes); - ASSIMP_LOG_DEBUG_F("Bone stack size: ", bone_stack.size()); + ASSIMP_LOG_DEBUG_F("Bone stack size: ", bone_stack.size()); - for (std::pair kvp : bone_stack) { - aiBone *bone = kvp.first; - aiNode *bone_node = kvp.second; - ASSIMP_LOG_DEBUG_F("active node lookup: ", bone->mName.C_Str()); - // lcl transform grab - done in generate_nodes :) + for (std::pair kvp : bone_stack) { + aiBone *bone = kvp.first; + aiNode *bone_node = kvp.second; + ASSIMP_LOG_DEBUG_F("active node lookup: ", bone->mName.C_Str()); + // lcl transform grab - done in generate_nodes :) - // bone->mOffsetMatrix = bone_node->mTransformation; - aiNode *armature = GetArmatureRoot(bone_node, bones); + // bone->mOffsetMatrix = bone_node->mTransformation; + aiNode *armature = GetArmatureRoot(bone_node, bones); - ai_assert(armature); + ai_assert(armature); - // set up bone armature id - bone->mArmature = armature; + // set up bone armature id + bone->mArmature = armature; - // set this bone node to be referenced properly - ai_assert(bone_node); - bone->mNode = bone_node; - } + // set this bone node to be referenced properly + ai_assert(bone_node); + bone->mNode = bone_node; + } } -/* Reprocess all nodes to calculate bone transforms properly based on the REAL - * mOffsetMatrix not the local. */ -/* Before this would use mesh transforms which is wrong for bone transforms */ -/* Before this would work for simple character skeletons but not complex meshes - * with multiple origins */ -/* Source: sketch fab log cutter fbx */ +// Reprocess all nodes to calculate bone transforms properly based on the REAL +// mOffsetMatrix not the local. +// Before this would use mesh transforms which is wrong for bone transforms +// Before this would work for simple character skeletons but not complex meshes +// with multiple origins +// Source: sketch fab log cutter fbx void ArmaturePopulate::BuildBoneList(aiNode *current_node, const aiNode *root_node, const aiScene *scene, std::vector &bones) { - ai_assert(scene); - for (unsigned int nodeId = 0; nodeId < current_node->mNumChildren; ++nodeId) { - aiNode *child = current_node->mChildren[nodeId]; - ai_assert(child); + ai_assert(scene); + for (unsigned int nodeId = 0; nodeId < current_node->mNumChildren; ++nodeId) { + aiNode *child = current_node->mChildren[nodeId]; + ai_assert(child); - // check for bones - for (unsigned int meshId = 0; meshId < child->mNumMeshes; ++meshId) { - ai_assert(child->mMeshes); - unsigned int mesh_index = child->mMeshes[meshId]; - aiMesh *mesh = scene->mMeshes[mesh_index]; - ai_assert(mesh); + // check for bones + for (unsigned int meshId = 0; meshId < child->mNumMeshes; ++meshId) { + ai_assert(child->mMeshes); + unsigned int mesh_index = child->mMeshes[meshId]; + aiMesh *mesh = scene->mMeshes[mesh_index]; + ai_assert(mesh); - for (unsigned int boneId = 0; boneId < mesh->mNumBones; ++boneId) { - aiBone *bone = mesh->mBones[boneId]; - ai_assert(bone); + for (unsigned int boneId = 0; boneId < mesh->mNumBones; ++boneId) { + aiBone *bone = mesh->mBones[boneId]; + ai_assert(bone); - // duplicate meshes exist with the same bones sometimes :) - // so this must be detected - if (std::find(bones.begin(), bones.end(), bone) == bones.end()) { - // add the element once - bones.push_back(bone); + // duplicate mehes exist with the same bones sometimes :) + // so this must be detected + if (std::find(bones.begin(), bones.end(), bone) == bones.end()) { + // add the element once + bones.push_back(bone); + } + } + + // find mesh and get bones + // then do recursive lookup for bones in root node hierarchy } - } - // find mesh and get bones - // then do recursive lookup for bones in root node hierarchy + BuildBoneList(child, root_node, scene, bones); } - - BuildBoneList(child, root_node, scene, bones); - } } -/* Prepare flat node list which can be used for non recursive lookups later */ +// Prepare flat node list which can be used for non recursive lookups later void ArmaturePopulate::BuildNodeList(const aiNode *current_node, std::vector &nodes) { - ai_assert(current_node); + ai_assert(current_node); - for (unsigned int nodeId = 0; nodeId < current_node->mNumChildren; ++nodeId) { - aiNode *child = current_node->mChildren[nodeId]; - ai_assert(child); + for (unsigned int nodeId = 0; nodeId < current_node->mNumChildren; ++nodeId) { + aiNode *child = current_node->mChildren[nodeId]; + ai_assert(child); - if (child->mNumMeshes == 0) - nodes.push_back(child); + if (child->mNumMeshes == 0) { + nodes.push_back(child); + } - BuildNodeList(child, nodes); + BuildNodeList(child, nodes); } } -/* A bone stack allows us to have multiple armatures, with the same bone names - * A bone stack allows us also to retrieve bones true transform even with - * duplicate names :) - */ +// A bone stack allows us to have multiple armatures, with the same bone names +// A bone stack allows us also to retrieve bones true transform even with +// duplicate names :) void ArmaturePopulate::BuildBoneStack(aiNode *current_node, const aiNode *root_node, const aiScene *scene, const std::vector &bones, std::map &bone_stack, - std::vector &node_stack) { - ai_assert(scene); - ai_assert(root_node); - ai_assert(!node_stack.empty()); + std::vector &node_stack) { + ai_assert(scene); + ai_assert(root_node); + ai_assert(!node_stack.empty()); - for (aiBone *bone : bones) { - ai_assert(bone); - aiNode *node = GetNodeFromStack(bone->mName, node_stack); - if (node == nullptr) { - node_stack.clear(); - BuildNodeList(root_node, node_stack); - ASSIMP_LOG_DEBUG_F("Resetting bone stack: nullptr element ", bone->mName.C_Str()); + for (aiBone *bone : bones) { + ai_assert(bone); + aiNode *node = GetNodeFromStack(bone->mName, node_stack); + if (node == nullptr) { + node_stack.clear(); + BuildNodeList(root_node, node_stack); + ASSIMP_LOG_DEBUG_F("Resetting bone stack: nullptr element ", bone->mName.C_Str()); - node = GetNodeFromStack(bone->mName, node_stack); + node = GetNodeFromStack(bone->mName, node_stack); - if (!node) { - ASSIMP_LOG_ERROR("serious import issue node for bone was not detected"); - continue; - } + if (!node) { + ASSIMP_LOG_ERROR("serious import issue node for bone was not detected"); + continue; + } + } + + ASSIMP_LOG_DEBUG_F("Successfully added bone[", bone->mName.C_Str(), "] to stack and bone node is: ", node->mName.C_Str()); + + bone_stack.insert(std::pair(bone, node)); } - - ASSIMP_LOG_DEBUG_F("Successfully added bone[", bone->mName.C_Str(), "] to stack and bone node is: ", node->mName.C_Str()); - - bone_stack.insert(std::pair(bone, node)); - } } - -/* Returns the armature root node */ -/* This is required to be detected for a bone initially, it will recurse up - * until it cannot find another bone and return the node No known failure - * points. (yet) - */ +// Returns the armature root node +// This is required to be detected for a bone initially, it will recurse up +// until it cannot find another bone and return the node No known failure +// points. (yet) aiNode *ArmaturePopulate::GetArmatureRoot(aiNode *bone_node, std::vector &bone_list) { - while (bone_node) { - if (!IsBoneNode(bone_node->mName, bone_list)) { - ASSIMP_LOG_DEBUG_F("GetArmatureRoot() Found valid armature: ", bone_node->mName.C_Str()); - return bone_node; + while (bone_node) { + if (!IsBoneNode(bone_node->mName, bone_list)) { + ASSIMP_LOG_DEBUG_F("GetArmatureRoot() Found valid armature: ", bone_node->mName.C_Str()); + return bone_node; + } + + bone_node = bone_node->mParent; } - bone_node = bone_node->mParent; - } - - ASSIMP_LOG_ERROR("GetArmatureRoot() can't find armature!"); - - return nullptr; + ASSIMP_LOG_ERROR("GetArmatureRoot() can't find armature!"); + + return nullptr; } - - -/* Simple IsBoneNode check if this could be a bone */ +// Simple IsBoneNode check if this could be a bone bool ArmaturePopulate::IsBoneNode(const aiString &bone_name, std::vector &bones) { - for (aiBone *bone : bones) { - if (bone->mName == bone_name) { - return true; + for (aiBone *bone : bones) { + if (bone->mName == bone_name) { + return true; + } } - } - return false; + return false; } -/* Pop this node by name from the stack if found */ -/* Used in multiple armature situations with duplicate node / bone names */ -/* Known flaw: cannot have nodes with bone names, will be fixed in later release - */ -/* (serious to be fixed) Known flaw: nodes which have more than one bone could - * be prematurely dropped from stack */ +// Pop this node by name from the stack if found +// Used in multiple armature situations with duplicate node / bone names +// Known flaw: cannot have nodes with bone names, will be fixed in later release +// (serious to be fixed) Known flaw: nodes which have more than one bone could +// be prematurely dropped from stack aiNode *ArmaturePopulate::GetNodeFromStack(const aiString &node_name, std::vector &nodes) { - std::vector::iterator iter; - aiNode *found = nullptr; - for (iter = nodes.begin(); iter < nodes.end(); ++iter) { - aiNode *element = *iter; - ai_assert(element); - // node valid and node name matches - if (element->mName == node_name) { - found = element; - break; + std::vector::iterator iter; + aiNode *found = nullptr; + for (iter = nodes.begin(); iter < nodes.end(); ++iter) { + aiNode *element = *iter; + ai_assert(element); + // node valid and node name matches + if (element->mName == node_name) { + found = element; + break; + } } - } - if (found != nullptr) { - ASSIMP_LOG_INFO_F("Removed node from stack: ", found->mName.C_Str()); - // now pop the element from the node list - nodes.erase(iter); + if (found != nullptr) { + ASSIMP_LOG_INFO_F("Removed node from stack: ", found->mName.C_Str()); + // now pop the element from the node list + nodes.erase(iter); - return found; - } + return found; + } - // unique names can cause this problem - ASSIMP_LOG_ERROR("[Serious] GetNodeFromStack() can't find node from stack!"); + // unique names can cause this problem + ASSIMP_LOG_ERROR("[Serious] GetNodeFromStack() can't find node from stack!"); - return nullptr; + return nullptr; } - - - } // Namespace Assimp From ca08cbcb0cfb3e966480fdaaf603cb8c8d367819 Mon Sep 17 00:00:00 2001 From: iamAdrianIusca Date: Sun, 9 Feb 2020 20:31:06 +0200 Subject: [PATCH 17/19] - don't include HunterGate.cmake if you don't enable HUNTER package manager - don't check for DirectX if you don't build the assimp tools or samples --- CMakeLists.txt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd3f1b802..38ebf3480 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,13 +41,13 @@ CMAKE_MINIMUM_REQUIRED( VERSION 3.0 ) # Toggles the use of the hunter package manager option(HUNTER_ENABLED "Enable Hunter package manager support" OFF) -include("cmake/HunterGate.cmake") -HunterGate( +IF(HUNTER_ENABLED) + include("cmake/HunterGate.cmake") + HunterGate( URL "https://github.com/ruslo/hunter/archive/v0.23.176.tar.gz" SHA1 "2e9ae973d028660b735ac4c6142725ca36a0048a" -) + ) -IF(HUNTER_ENABLED) add_definitions(-DASSIMP_USE_HUNTER) ENDIF(HUNTER_ENABLED) @@ -437,7 +437,9 @@ ELSE(HUNTER_ENABLED) DESTINATION "${ASSIMP_LIB_INSTALL_DIR}/cmake/assimp-${ASSIMP_VERSION_MAJOR}.${ASSIMP_VERSION_MINOR}" COMPONENT ${LIBASSIMP-DEV_COMPONENT}) ENDIF(HUNTER_ENABLED) -FIND_PACKAGE( DirectX ) +if (ASSIMP_BUILD_SAMPLES OR ASSIMP_BUILD_SAMPLES) + FIND_PACKAGE(DirectX) +endif(ASSIMP_BUILD_SAMPLES OR ASSIMP_BUILD_SAMPLES) IF( BUILD_DOCS ) ADD_SUBDIRECTORY(doc) From 58990d4e3ff84906b459164c211ce379fe63751c Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Mon, 10 Feb 2020 23:59:52 +0100 Subject: [PATCH 18/19] Update FBXParser.cpp add missing brackets. --- code/FBX/FBXParser.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/FBX/FBXParser.cpp b/code/FBX/FBXParser.cpp index 5486fdcc6..aef59d60c 100644 --- a/code/FBX/FBXParser.cpp +++ b/code/FBX/FBXParser.cpp @@ -368,8 +368,9 @@ float ParseTokenAsFloat(const Token& t, const char*& err_out) // which fast_atof could interpret as decimal point. #define MAX_FLOAT_LENGTH 31 const size_t length = static_cast(t.end()-t.begin()); - if (length > MAX_FLOAT_LENGTH) + if (length > MAX_FLOAT_LENGTH) { return 0.f; + } char temp[MAX_FLOAT_LENGTH + 1]; std::copy(t.begin(), t.end(), temp); From 47fc3f262751c1f15e0912358dedc33abe8cd5ca Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 12 Feb 2020 14:54:00 +0100 Subject: [PATCH 19/19] Update M3DImporter.cpp Fix a memoryleak. --- code/M3D/M3DImporter.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/code/M3D/M3DImporter.cpp b/code/M3D/M3DImporter.cpp index 1c6cea766..9aee14f75 100644 --- a/code/M3D/M3DImporter.cpp +++ b/code/M3D/M3DImporter.cpp @@ -383,7 +383,13 @@ void M3DImporter::importTextures(const M3DWrapper &m3d) { // individually. In assimp there're per mesh vertex and UV lists, and they must be // indexed simultaneously. void M3DImporter::importMeshes(const M3DWrapper &m3d) { - unsigned int i, j, k, l, numpoly = 3, lastMat = M3D_INDEXMAX; + ASSIMP_LOG_DEBUG_F("M3D: importMeshes ", m3d->numface); + + if (!m3d->numface || !m3d->face || !m3d->numvertex || !m3d->vertex) { + return; + } + + unsigned int i, j, k, l, numpoly = 3, lastMat = M3D_INDEXMAX; std::vector *meshes = new std::vector(); std::vector *faces = nullptr; std::vector *vertices = nullptr; @@ -397,11 +403,6 @@ void M3DImporter::importMeshes(const M3DWrapper &m3d) { ai_assert(m3d); ai_assert(mScene->mRootNode != nullptr); - ASSIMP_LOG_DEBUG_F("M3D: importMeshes ", m3d->numface); - - if (!m3d->numface || !m3d->face || !m3d->numvertex || !m3d->vertex) { - return; - } for (i = 0; i < m3d->numface; i++) { // we must switch mesh if material changes