Updated assimp to latest

This commit is contained in:
Areloch 2019-03-05 14:39:38 -06:00
parent 25ce4477ce
commit 161bf7f83b
461 changed files with 34662 additions and 30165 deletions

View file

@ -3,7 +3,8 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2017, assimp team
Copyright (c) 2006-2019, assimp team
All rights reserved.
@ -47,8 +48,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// internal headers
#include "STLLoader.h"
#include "ParsingUtils.h"
#include "fast_atof.h"
#include <assimp/ParsingUtils.h>
#include <assimp/fast_atof.h>
#include <memory>
#include <assimp/IOSystem.hpp>
#include <assimp/scene.h>
@ -89,6 +90,9 @@ static bool IsBinarySTL(const char* buffer, unsigned int fileSize) {
return expectedBinaryFileSize == fileSize;
}
static const size_t BufferSize = 500;
static const char UnicodeBoundary = 127;
// An ascii STL buffer will begin with "solid NAME", where NAME is optional.
// Note: The "solid NAME" check is necessary, but not sufficient, to determine
// if the buffer is ASCII; a binary header could also begin with "solid NAME".
@ -107,10 +111,10 @@ static bool IsAsciiSTL(const char* buffer, unsigned int fileSize) {
bool isASCII( strncmp( buffer, "solid", 5 ) == 0 );
if( isASCII ) {
// A lot of importers are write solid even if the file is binary. So we have to check for ASCII-characters.
if( fileSize >= 500 ) {
if( fileSize >= BufferSize) {
isASCII = true;
for( unsigned int i = 0; i < 500; i++ ) {
if( buffer[ i ] > 127 ) {
for( unsigned int i = 0; i < BufferSize; i++ ) {
if( buffer[ i ] > UnicodeBoundary) {
isASCII = false;
break;
}
@ -178,7 +182,7 @@ void STLImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
std::unique_ptr<IOStream> file( pIOHandler->Open( pFile, "rb"));
// Check whether we can read from the file
if( file.get() == NULL) {
if( file.get() == nullptr) {
throw DeadlyImportError( "Failed to open STL file " + pFile + ".");
}
@ -186,11 +190,11 @@ void STLImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
// allocate storage and copy the contents of the file to a memory buffer
// (terminate it with zero)
std::vector<char> mBuffer2;
TextFileToBuffer(file.get(),mBuffer2);
std::vector<char> buffer2;
TextFileToBuffer(file.get(),buffer2);
this->pScene = pScene;
this->mBuffer = &mBuffer2[0];
this->mBuffer = &buffer2[0];
// the default vertex color is light gray.
clrColorDefault.r = clrColorDefault.g = clrColorDefault.b = clrColorDefault.a = (ai_real) 0.6;
@ -227,6 +231,8 @@ void STLImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
pScene->mNumMaterials = 1;
pScene->mMaterials = new aiMaterial*[1];
pScene->mMaterials[0] = pcMat;
mBuffer = nullptr;
}
// ------------------------------------------------------------------------------------------------
@ -285,14 +291,14 @@ void STLImporter::LoadASCIIFile( aiNode *root ) {
if(!SkipSpacesAndLineEnd(&sz))
{
// seems we're finished although there was no end marker
DefaultLogger::get()->warn("STL: unexpected EOF. \'endsolid\' keyword was expected");
ASSIMP_LOG_WARN("STL: unexpected EOF. \'endsolid\' keyword was expected");
break;
}
// facet normal -0.13 -0.13 -0.98
if (!strncmp(sz,"facet",5) && IsSpaceOrNewLine(*(sz+5)) && *(sz + 5) != '\0') {
if (faceVertexCounter != 3) {
DefaultLogger::get()->warn("STL: A new facet begins but the old is not yet complete");
ASSIMP_LOG_WARN("STL: A new facet begins but the old is not yet complete");
}
faceVertexCounter = 0;
normalBuffer.push_back(aiVector3D());
@ -301,7 +307,7 @@ void STLImporter::LoadASCIIFile( aiNode *root ) {
sz += 6;
SkipSpaces(&sz);
if (strncmp(sz,"normal",6)) {
DefaultLogger::get()->warn("STL: a facet normal vector was expected but not found");
ASSIMP_LOG_WARN("STL: a facet normal vector was expected but not found");
} else {
if (sz[6] == '\0') {
throw DeadlyImportError("STL: unexpected EOF while parsing facet");
@ -318,7 +324,7 @@ void STLImporter::LoadASCIIFile( aiNode *root ) {
}
} else if (!strncmp(sz,"vertex",6) && ::IsSpaceOrNewLine(*(sz+6))) { // vertex 1.50000 1.50000 0.00000
if (faceVertexCounter >= 3) {
DefaultLogger::get()->error("STL: a facet with more than 3 vertices has been found");
ASSIMP_LOG_ERROR("STL: a facet with more than 3 vertices has been found");
++sz;
} else {
if (sz[6] == '\0') {
@ -351,7 +357,7 @@ void STLImporter::LoadASCIIFile( aiNode *root ) {
if (positionBuffer.empty()) {
pMesh->mNumFaces = 0;
throw DeadlyImportError("STL: ASCII file is empty or invalid; no data loaded");
ASSIMP_LOG_WARN("STL: mesh is empty or invalid; no data loaded");
}
if (positionBuffer.size() % 3 != 0) {
pMesh->mNumFaces = 0;
@ -361,14 +367,23 @@ void STLImporter::LoadASCIIFile( aiNode *root ) {
pMesh->mNumFaces = 0;
throw DeadlyImportError("Normal buffer size does not match position buffer size");
}
pMesh->mNumFaces = static_cast<unsigned int>(positionBuffer.size() / 3);
pMesh->mNumVertices = static_cast<unsigned int>(positionBuffer.size());
pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
memcpy(pMesh->mVertices, &positionBuffer[0].x, pMesh->mNumVertices * sizeof(aiVector3D));
positionBuffer.clear();
pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
memcpy(pMesh->mNormals, &normalBuffer[0].x, pMesh->mNumVertices * sizeof(aiVector3D));
normalBuffer.clear();
// only process positionbuffer when filled, else exception when accessing with index operator
// see line 353: only warning is triggered
// see line 373(now): access to empty positionbuffer with index operator forced exception
if (!positionBuffer.empty()) {
pMesh->mNumFaces = static_cast<unsigned int>(positionBuffer.size() / 3);
pMesh->mNumVertices = static_cast<unsigned int>(positionBuffer.size());
pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
memcpy(pMesh->mVertices, &positionBuffer[0].x, pMesh->mNumVertices * sizeof(aiVector3D));
positionBuffer.clear();
}
// also only process normalBuffer when filled, else exception when accessing with index operator
if (!normalBuffer.empty()) {
pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
memcpy(pMesh->mNormals, &normalBuffer[0].x, pMesh->mNumVertices * sizeof(aiVector3D));
normalBuffer.clear();
}
// now copy faces
addFacesToMesh(pMesh);
@ -417,7 +432,7 @@ bool STLImporter::LoadBinaryFile()
// read the default vertex color for facets
bIsMaterialise = true;
DefaultLogger::get()->info("STL: Taking code path for Materialise files");
ASSIMP_LOG_INFO("STL: Taking code path for Materialise files");
const ai_real invByte = (ai_real)1.0 / ( ai_real )255.0;
clrColorDefault.r = (*sz2++) * invByte;
clrColorDefault.g = (*sz2++) * invByte;
@ -444,28 +459,47 @@ bool STLImporter::LoadBinaryFile()
pMesh->mNumVertices = pMesh->mNumFaces*3;
aiVector3D* vp,*vn;
vp = pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
vn = pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
for (unsigned int i = 0; i < pMesh->mNumFaces;++i) {
aiVector3D *vp = pMesh->mVertices = new aiVector3D[pMesh->mNumVertices];
aiVector3D *vn = pMesh->mNormals = new aiVector3D[pMesh->mNumVertices];
typedef aiVector3t<float> aiVector3F;
aiVector3F* theVec;
aiVector3F theVec3F;
for ( unsigned int i = 0; i < pMesh->mNumFaces; ++i ) {
// NOTE: Blender sometimes writes empty normals ... this is not
// our fault ... the RemoveInvalidData helper step should fix that
*vn = *((aiVector3D*)sz);
sz += sizeof(aiVector3D);
// There's one normal for the face in the STL; use it three times
// for vertex normals
theVec = (aiVector3F*) sz;
::memcpy( &theVec3F, theVec, sizeof(aiVector3F) );
vn->x = theVec3F.x; vn->y = theVec3F.y; vn->z = theVec3F.z;
*(vn+1) = *vn;
*(vn+2) = *vn;
++theVec;
vn += 3;
*vp++ = *((aiVector3D*)sz);
sz += sizeof(aiVector3D);
// vertex 1
::memcpy( &theVec3F, theVec, sizeof(aiVector3F) );
vp->x = theVec3F.x; vp->y = theVec3F.y; vp->z = theVec3F.z;
++theVec;
++vp;
*vp++ = *((aiVector3D*)sz);
sz += sizeof(aiVector3D);
// vertex 2
::memcpy( &theVec3F, theVec, sizeof(aiVector3F) );
vp->x = theVec3F.x; vp->y = theVec3F.y; vp->z = theVec3F.z;
++theVec;
++vp;
*vp++ = *((aiVector3D*)sz);
sz += sizeof(aiVector3D);
// vertex 3
::memcpy( &theVec3F, theVec, sizeof(aiVector3F) );
vp->x = theVec3F.x; vp->y = theVec3F.y; vp->z = theVec3F.z;
++theVec;
++vp;
sz = (const unsigned char*) theVec;
uint16_t color = *((uint16_t*)sz);
sz += 2;
@ -480,7 +514,7 @@ bool STLImporter::LoadBinaryFile()
*pMesh->mColors[0]++ = this->clrColorDefault;
pMesh->mColors[0] -= pMesh->mNumVertices;
DefaultLogger::get()->info("STL: Mesh has vertex colors");
ASSIMP_LOG_INFO("STL: Mesh has vertex colors");
}
aiColor4D* clr = &pMesh->mColors[0][i*3];
clr->a = 1.0;
@ -506,11 +540,21 @@ bool STLImporter::LoadBinaryFile()
// now copy faces
addFacesToMesh(pMesh);
aiNode* root = pScene->mRootNode;
// allocate one node
aiNode* node = new aiNode();
node->mParent = root;
root->mNumChildren = 1u;
root->mChildren = new aiNode*[root->mNumChildren];
root->mChildren[0] = node;
// add all created meshes to the single node
pScene->mRootNode->mNumMeshes = pScene->mNumMeshes;
pScene->mRootNode->mMeshes = new unsigned int[pScene->mNumMeshes];
node->mNumMeshes = pScene->mNumMeshes;
node->mMeshes = new unsigned int[pScene->mNumMeshes];
for (unsigned int i = 0; i < pScene->mNumMeshes; i++)
pScene->mRootNode->mMeshes[i] = i;
node->mMeshes[i] = i;
if (bIsMaterialise && !pMesh->mColors[0])
{