Merge branch 'master' into utf-issue

pull/5279/head
Kim Kulling 2023-11-06 09:56:13 +01:00 committed by GitHub
commit 5f832c9a44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 246 additions and 233 deletions

View File

@ -51,6 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "FBXUtil.h" #include "FBXUtil.h"
#include <assimp/defs.h> #include <assimp/defs.h>
#include <stdint.h> #include <stdint.h>
#include <cstdint>
#include <assimp/Exceptional.h> #include <assimp/Exceptional.h>
#include <assimp/ByteSwapper.h> #include <assimp/ByteSwapper.h>
#include <assimp/DefaultLogger.hpp> #include <assimp/DefaultLogger.hpp>

View File

@ -185,7 +185,7 @@ void IFCImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSy
size_t total = 0; size_t total = 0;
int read = 0; int read = 0;
do { do {
int bufferSize = fileInfo.uncompressed_size < INT16_MAX ? fileInfo.uncompressed_size : INT16_MAX; unsigned bufferSize = fileInfo.uncompressed_size < INT16_MAX ? static_cast<unsigned>(fileInfo.uncompressed_size) : INT16_MAX;
void *buffer = malloc(bufferSize); void *buffer = malloc(bufferSize);
read = unzReadCurrentFile(zip, buffer, bufferSize); read = unzReadCurrentFile(zip, buffer, bufferSize);
if (read > 0) { if (read > 0) {

View File

@ -1372,7 +1372,7 @@ std::vector<IfcVector2> GetContourInPlane2D(const std::shared_ptr<TempMesh>& mes
const std::vector<IfcVector3>& va = mesh->mVerts; const std::vector<IfcVector3>& va = mesh->mVerts;
if(va.size() <= 2) { if(va.size() <= 2) {
std::stringstream msg; std::stringstream msg;
msg << "Skipping: Only " << va.size() << " verticies in opening mesh."; msg << "Skipping: Only " << va.size() << " vertices in opening mesh.";
IFCImporter::LogDebug(msg.str().c_str()); IFCImporter::LogDebug(msg.str().c_str());
ok = false; ok = false;
return contour; return contour;

View File

@ -575,8 +575,8 @@ void SetupMapping(aiMaterial *mat, aiTextureMapping mode, const aiVector3D &axis
m->mSemantic = prop->mSemantic; m->mSemantic = prop->mSemantic;
m->mType = aiPTI_Float; m->mType = aiPTI_Float;
m->mDataLength = 12; m->mDataLength = sizeof(aiVector3D);
m->mData = new char[12]; m->mData = new char[m->mDataLength];
*((aiVector3D *)m->mData) = axis; *((aiVector3D *)m->mData) = axis;
p.push_back(m); p.push_back(m);
} }

View File

@ -57,7 +57,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <cctype> #include <cctype>
#include <memory> #include <memory>
using namespace Assimp; namespace Assimp {
using namespace Assimp::Formatter; using namespace Assimp::Formatter;
static const aiImporterDesc desc = { static const aiImporterDesc desc = {
@ -73,10 +74,6 @@ static const aiImporterDesc desc = {
"x" "x"
}; };
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
XFileImporter::XFileImporter() = default;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Returns whether the class can handle the format of the given file. // Returns whether the class can handle the format of the given file.
bool XFileImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const { bool XFileImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const {
@ -124,8 +121,7 @@ void XFileImporter::InternReadFile( const std::string& pFile, aiScene* pScene, I
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Constructs the return data structure out of the imported data. // Constructs the return data structure out of the imported data.
void XFileImporter::CreateDataRepresentationFromImport( aiScene* pScene, XFile::Scene* pData) void XFileImporter::CreateDataRepresentationFromImport(aiScene *pScene, XFile::Scene *pData) {
{
// Read the global materials first so that meshes referring to them can find them later // Read the global materials first so that meshes referring to them can find them later
ConvertMaterials(pScene, pData->mGlobalMaterials); ConvertMaterials(pScene, pData->mGlobalMaterials);
@ -315,8 +311,8 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec
// collect vertex data for indices of this face // collect vertex data for indices of this face
for (unsigned int d = 0; d < df.mNumIndices; ++d) { for (unsigned int d = 0; d < df.mNumIndices; ++d) {
df.mIndices[d] = newIndex; df.mIndices[d] = newIndex;
const unsigned int newIdx( pf.mIndices[ d ] ); const unsigned int newIdx = pf.mIndices[d];
if ( newIdx > sourceMesh->mPositions.size() ) { if (newIdx >= sourceMesh->mPositions.size()) {
continue; continue;
} }
@ -328,9 +324,11 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec
if (mesh->HasNormals()) { if (mesh->HasNormals()) {
if (sourceMesh->mNormFaces[f].mIndices.size() > d) { if (sourceMesh->mNormFaces[f].mIndices.size() > d) {
const size_t idx(sourceMesh->mNormFaces[f].mIndices[d]); const size_t idx(sourceMesh->mNormFaces[f].mIndices[d]);
if (idx < sourceMesh->mNormals.size()) {
mesh->mNormals[newIndex] = sourceMesh->mNormals[idx]; mesh->mNormals[newIndex] = sourceMesh->mNormals[idx];
} }
} }
}
// texture coord sets // texture coord sets
for (unsigned int e = 0; e < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++e) { for (unsigned int e = 0; e < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++e) {
@ -361,8 +359,11 @@ void XFileImporter::CreateMeshes( aiScene* pScene, aiNode* pNode, const std::vec
// set up a vertex-linear array of the weights for quick searching if a bone influences a vertex // set up a vertex-linear array of the weights for quick searching if a bone influences a vertex
std::vector<ai_real> oldWeights(sourceMesh->mPositions.size(), 0.0); std::vector<ai_real> oldWeights(sourceMesh->mPositions.size(), 0.0);
for (unsigned int d = 0; d < obone.mWeights.size(); ++d) { for (unsigned int d = 0; d < obone.mWeights.size(); ++d) {
const unsigned int boneIdx = obone.mWeights[d].mVertex;
if (boneIdx < obone.mWeights.size()) {
oldWeights[obone.mWeights[d].mVertex] = obone.mWeights[d].mWeight; oldWeights[obone.mWeights[d].mVertex] = obone.mWeights[d].mWeight;
} }
}
// collect all vertex weights that influence a vertex in the new mesh // collect all vertex weights that influence a vertex in the new mesh
std::vector<aiVertexWeight> newWeights; std::vector<aiVertexWeight> newWeights;
@ -451,8 +452,7 @@ void XFileImporter::CreateAnimations( aiScene* pScene, const XFile::Scene* pData
nanim->mChannels[b] = nbone; nanim->mChannels[b] = nbone;
// key-frames are given as combined transformation matrix keys // key-frames are given as combined transformation matrix keys
if( !bone->mTrafoKeys.empty() ) if (!bone->mTrafoKeys.empty()) {
{
nbone->mNumPositionKeys = (unsigned int)bone->mTrafoKeys.size(); nbone->mNumPositionKeys = (unsigned int)bone->mTrafoKeys.size();
nbone->mPositionKeys = new aiVectorKey[nbone->mNumPositionKeys]; nbone->mPositionKeys = new aiVectorKey[nbone->mNumPositionKeys];
nbone->mNumRotationKeys = (unsigned int)bone->mTrafoKeys.size(); nbone->mNumRotationKeys = (unsigned int)bone->mTrafoKeys.size();
@ -538,8 +538,7 @@ void XFileImporter::CreateAnimations( aiScene* pScene, const XFile::Scene* pData
} }
// store all converted animations in the scene // store all converted animations in the scene
if( newAnims.size() > 0) if (newAnims.size() > 0) {
{
pScene->mNumAnimations = (unsigned int)newAnims.size(); pScene->mNumAnimations = (unsigned int)newAnims.size();
pScene->mAnimations = new aiAnimation *[pScene->mNumAnimations]; pScene->mAnimations = new aiAnimation *[pScene->mNumAnimations];
for (unsigned int a = 0; a < newAnims.size(); a++) for (unsigned int a = 0; a < newAnims.size(); a++)
@ -549,8 +548,7 @@ void XFileImporter::CreateAnimations( aiScene* pScene, const XFile::Scene* pData
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Converts all materials in the given array and stores them in the scene's material list. // Converts all materials in the given array and stores them in the scene's material list.
void XFileImporter::ConvertMaterials( aiScene* pScene, std::vector<XFile::Material>& pMaterials) void XFileImporter::ConvertMaterials(aiScene *pScene, std::vector<XFile::Material> &pMaterials) {
{
// count the non-referrer materials in the array // count the non-referrer materials in the array
unsigned int numNewMaterials(0); unsigned int numNewMaterials(0);
for (unsigned int a = 0; a < pMaterials.size(); ++a) { for (unsigned int a = 0; a < pMaterials.size(); ++a) {
@ -599,8 +597,7 @@ void XFileImporter::ConvertMaterials( aiScene* pScene, std::vector<XFile::Materi
// Shading model: hard-coded to PHONG, there is no such information in an XFile // Shading model: hard-coded to PHONG, there is no such information in an XFile
// FIX (aramis): If the specular exponent is 0, use gouraud shading. This is a bugfix // FIX (aramis): If the specular exponent is 0, use gouraud shading. This is a bugfix
// for some models in the SDK (e.g. good old tiny.x) // for some models in the SDK (e.g. good old tiny.x)
int shadeMode = (int)oldMat.mSpecularExponent == 0.0f int shadeMode = (int)oldMat.mSpecularExponent == 0.0f ? aiShadingMode_Gouraud : aiShadingMode_Phong;
? aiShadingMode_Gouraud : aiShadingMode_Phong;
mat->AddProperty<int>(&shadeMode, 1, AI_MATKEY_SHADING_MODEL); mat->AddProperty<int>(&shadeMode, 1, AI_MATKEY_SHADING_MODEL);
// material colours // material colours
@ -611,7 +608,6 @@ void XFileImporter::ConvertMaterials( aiScene* pScene, std::vector<XFile::Materi
mat->AddProperty(&oldMat.mSpecular, 1, AI_MATKEY_COLOR_SPECULAR); mat->AddProperty(&oldMat.mSpecular, 1, AI_MATKEY_COLOR_SPECULAR);
mat->AddProperty(&oldMat.mSpecularExponent, 1, AI_MATKEY_SHININESS); mat->AddProperty(&oldMat.mSpecularExponent, 1, AI_MATKEY_SHININESS);
// texture, if there is one // texture, if there is one
if (1 == oldMat.mTextures.size()) { if (1 == oldMat.mTextures.size()) {
const XFile::TexEntry &otex = oldMat.mTextures.back(); const XFile::TexEntry &otex = oldMat.mTextures.back();
@ -679,4 +675,6 @@ void XFileImporter::ConvertMaterials( aiScene* pScene, std::vector<XFile::Materi
} }
} }
} // namespace Assimp
#endif // !! ASSIMP_BUILD_NO_X_IMPORTER #endif // !! ASSIMP_BUILD_NO_X_IMPORTER

View File

@ -68,7 +68,7 @@ namespace XFile {
*/ */
class XFileImporter : public BaseImporter { class XFileImporter : public BaseImporter {
public: public:
XFileImporter(); XFileImporter() = default;
~XFileImporter() override = default; ~XFileImporter() override = default;
// ------------------------------------------------------------------- // -------------------------------------------------------------------

View File

@ -1380,7 +1380,12 @@ ENDIF()
IF(NOT ASSIMP_HUNTER_ENABLED) IF(NOT ASSIMP_HUNTER_ENABLED)
if (UNZIP_FOUND) if (UNZIP_FOUND)
INCLUDE_DIRECTORIES(${UNZIP_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(${UNZIP_INCLUDE_DIRS})
# TODO if cmake required version has been updated to >3.12.0, collapse this to the second case only
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
TARGET_LINK_LIBRARIES(assimp ${UNZIP_LIBRARIES}) TARGET_LINK_LIBRARIES(assimp ${UNZIP_LIBRARIES})
else()
TARGET_LINK_LIBRARIES(assimp ${UNZIP_LINK_LIBRARIES})
endif()
else () else ()
INCLUDE_DIRECTORIES("../") INCLUDE_DIRECTORIES("../")
endif () endif ()

View File

@ -290,12 +290,6 @@ void PretransformVertices::ComputeAbsoluteTransform(aiNode *pcNode) {
} }
} }
static void normalizeVectorArray(aiVector3D *vectorArrayIn, aiVector3D *vectorArrayOut, size_t numVectors) {
for (size_t i=0; i<numVectors; ++i) {
vectorArrayOut[i] = vectorArrayIn[i].Normalize();
}
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Apply the node transformation to a mesh // Apply the node transformation to a mesh
void PretransformVertices::ApplyTransform(aiMesh *mesh, const aiMatrix4x4 &mat) const { void PretransformVertices::ApplyTransform(aiMesh *mesh, const aiMatrix4x4 &mat) const {
@ -322,8 +316,11 @@ void PretransformVertices::ApplyTransform(aiMesh *mesh, const aiMatrix4x4 &mat)
const aiMatrix3x3 m = aiMatrix3x3(mat).Inverse().Transpose(); const aiMatrix3x3 m = aiMatrix3x3(mat).Inverse().Transpose();
if (mesh->HasNormals()) { if (mesh->HasNormals()) {
normalizeVectorArray(mesh->mNormals, mesh->mNormals, mesh->mNumVertices); for (unsigned int i = 0; i < mesh->mNumVertices; ++i) {
mesh->mNormals[i] = (m * mesh->mNormals[i]).Normalize();
} }
}
if (mesh->HasTangentsAndBitangents()) { if (mesh->HasTangentsAndBitangents()) {
for (unsigned int i = 0; i < mesh->mNumVertices; ++i) { for (unsigned int i = 0; i < mesh->mNumVertices; ++i) {
mesh->mTangents[i] = (m * mesh->mTangents[i]).Normalize(); mesh->mTangents[i] = (m * mesh->mTangents[i]).Normalize();

View File

@ -59,6 +59,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/types.h> #include <assimp/types.h>
#ifdef __cplusplus #ifdef __cplusplus
#include <unordered_set>
extern "C" { extern "C" {
#endif #endif
@ -872,11 +874,15 @@ struct aiMesh {
// DO NOT REMOVE THIS ADDITIONAL CHECK // DO NOT REMOVE THIS ADDITIONAL CHECK
if (mNumBones && mBones) { if (mNumBones && mBones) {
std::unordered_set<const aiBone *> bones;
for (unsigned int a = 0; a < mNumBones; a++) { for (unsigned int a = 0; a < mNumBones; a++) {
if (mBones[a]) { if (mBones[a]) {
delete mBones[a]; bones.insert(mBones[a]);
} }
} }
for (const aiBone *bone: bones) {
delete bone;
}
delete[] mBones; delete[] mBones;
} }

View File

@ -48,6 +48,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class BlendImportAreaLight : public ::testing::Test { class BlendImportAreaLight : public ::testing::Test {
public: public:
BlendImportAreaLight() :
im(nullptr) {}
~BlendImportAreaLight() override = default;
void SetUp() override { void SetUp() override {
im = new Assimp::Importer(); im = new Assimp::Importer();
} }

View File

@ -48,11 +48,14 @@ using namespace ::Assimp;
class BlenderWorkTest : public ::testing::Test { class BlenderWorkTest : public ::testing::Test {
public: public:
virtual void SetUp() { BlenderWorkTest() : im(nullptr) {}
~BlenderWorkTest() override = default;
void SetUp() override {
im = new Assimp::Importer(); im = new Assimp::Importer();
} }
virtual void TearDown() { void TearDown() override {
delete im; delete im;
} }