update assimp lib

This commit is contained in:
marauder2k7 2024-12-09 20:22:47 +00:00
parent 03a348deb7
commit d3f8fee74e
1725 changed files with 196314 additions and 62009 deletions

View file

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -43,7 +43,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @brief Implementation of the OFF importer class
*/
#ifndef ASSIMP_BUILD_NO_OFF_IMPORTER
// internal headers
@ -56,9 +55,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/DefaultLogger.hpp>
#include <assimp/importerdesc.h>
using namespace Assimp;
namespace Assimp {
static const aiImporterDesc desc = {
static constexpr aiImporterDesc desc = {
"OFF Importer",
"",
"",
@ -71,99 +70,92 @@ static const aiImporterDesc desc = {
"off"
};
// ------------------------------------------------------------------------------------------------
// Constructor to be privately used by Importer
OFFImporter::OFFImporter() = default;
// ------------------------------------------------------------------------------------------------
// Destructor, private as well
OFFImporter::~OFFImporter() = default;
// ------------------------------------------------------------------------------------------------
// Returns whether the class can handle the format of the given file.
bool OFFImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool /*checkSig*/) const
{
static const char* tokens[] = { "off" };
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,AI_COUNT_OF(tokens),3);
bool OFFImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /*checkSig*/) const {
static const char *tokens[] = { "off" };
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, AI_COUNT_OF(tokens), 3);
}
// ------------------------------------------------------------------------------------------------
const aiImporterDesc* OFFImporter::GetInfo () const
{
const aiImporterDesc *OFFImporter::GetInfo() const {
return &desc;
}
// skip blank space, lines and comments
static void NextToken(const char **car, const char* end) {
SkipSpacesAndLineEnd(car);
while (*car < end && (**car == '#' || **car == '\n' || **car == '\r')) {
SkipLine(car);
SkipSpacesAndLineEnd(car);
}
static void NextToken(const char **car, const char *end) {
SkipSpacesAndLineEnd(car, end);
while (*car < end && (**car == '#' || **car == '\n' || **car == '\r')) {
SkipLine(car, end);
SkipSpacesAndLineEnd(car, end);
}
}
// ------------------------------------------------------------------------------------------------
// Imports the given file into the given scene structure.
void OFFImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler) {
std::unique_ptr<IOStream> file( pIOHandler->Open( pFile, "rb"));
void OFFImporter::InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler) {
std::unique_ptr<IOStream> file(pIOHandler->Open(pFile, "rb"));
// Check whether we can read from the file
if( file.get() == nullptr) {
throw DeadlyImportError( "Failed to open OFF file ", pFile, ".");
if (file == nullptr) {
throw DeadlyImportError("Failed to open OFF file ", pFile, ".");
}
// allocate storage and copy the contents of the file to a memory buffer
std::vector<char> mBuffer2;
TextFileToBuffer(file.get(),mBuffer2);
const char* buffer = &mBuffer2[0];
TextFileToBuffer(file.get(), mBuffer2);
const char *buffer = &mBuffer2[0];
// Proper OFF header parser. We only implement normal loading for now.
bool hasTexCoord = false, hasNormals = false, hasColors = false;
bool hasHomogenous = false, hasDimension = false;
unsigned int dimensions = 3;
const char* car = buffer;
const char* end = buffer + mBuffer2.size();
const char *car = buffer;
const char *end = buffer + mBuffer2.size();
NextToken(&car, end);
if (car < end - 2 && car[0] == 'S' && car[1] == 'T') {
hasTexCoord = true; car += 2;
hasTexCoord = true;
car += 2;
}
if (car < end - 1 && car[0] == 'C') {
hasColors = true; car++;
hasColors = true;
car++;
}
if (car < end- 1 && car[0] == 'N') {
hasNormals = true; car++;
if (car < end - 1 && car[0] == 'N') {
hasNormals = true;
car++;
}
if (car < end - 1 && car[0] == '4') {
hasHomogenous = true; car++;
hasHomogenous = true;
car++;
}
if (car < end - 1 && car[0] == 'n') {
hasDimension = true; car++;
hasDimension = true;
car++;
}
if (car < end - 3 && car[0] == 'O' && car[1] == 'F' && car[2] == 'F') {
car += 3;
NextToken(&car, end);
NextToken(&car, end);
} else {
// in case there is no OFF header (which is allowed by the
// specification...), then we might have unintentionally read an
// additional dimension from the primitive count fields
dimensions = 3;
hasHomogenous = false;
NextToken(&car, end);
// in case there is no OFF header (which is allowed by the
// specification...), then we might have unintentionally read an
// additional dimension from the primitive count fields
dimensions = 3;
hasHomogenous = false;
NextToken(&car, end);
// at this point the next token should be an integer number
if (car >= end - 1 || *car < '0' || *car > '9') {
throw DeadlyImportError("OFF: Header is invalid");
}
// at this point the next token should be an integer number
if (car >= end - 1 || *car < '0' || *car > '9') {
throw DeadlyImportError("OFF: Header is invalid");
}
}
if (hasDimension) {
dimensions = strtoul10(car, &car);
NextToken(&car, end);
NextToken(&car, end);
}
if (dimensions > 3) {
throw DeadlyImportError
("OFF: Number of vertex coordinates higher than 3 unsupported");
throw DeadlyImportError("OFF: Number of vertex coordinates higher than 3 unsupported");
}
NextToken(&car, end);
@ -171,7 +163,7 @@ void OFFImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
NextToken(&car, end);
const unsigned int numFaces = strtoul10(car, &car);
NextToken(&car, end);
strtoul10(car, &car); // skip edge count
strtoul10(car, &car); // skip edge count
NextToken(&car, end);
if (!numVertices) {
@ -182,13 +174,13 @@ void OFFImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
}
pScene->mNumMeshes = 1;
pScene->mMeshes = new aiMesh*[ pScene->mNumMeshes ];
pScene->mMeshes = new aiMesh *[pScene->mNumMeshes];
aiMesh* mesh = new aiMesh();
aiMesh *mesh = new aiMesh();
pScene->mMeshes[0] = mesh;
mesh->mNumFaces = numFaces;
aiFace* faces = new aiFace[mesh->mNumFaces];
aiFace *faces = new aiFace[mesh->mNumFaces];
mesh->mFaces = faces;
mesh->mNumVertices = numVertices;
@ -203,102 +195,105 @@ void OFFImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
char line[4096];
buffer = car;
const char *sz = car;
const char *lineEnd = &line[4096];
// now read all vertex lines
for (unsigned int i = 0; i < numVertices; ++i) {
if(!GetNextLine(buffer, line)) {
if (!GetNextLine(buffer, line)) {
ASSIMP_LOG_ERROR("OFF: The number of verts in the header is incorrect");
break;
}
aiVector3D& v = mesh->mVertices[i];
aiVector3D &v = mesh->mVertices[i];
sz = line;
// helper array to write a for loop over possible dimension values
ai_real* vec[3] = {&v.x, &v.y, &v.z};
// helper array to write a for loop over possible dimension values
ai_real *vec[3] = { &v.x, &v.y, &v.z };
// stop at dimensions: this allows loading 1D or 2D coordinate vertices
for (unsigned int dim = 0; dim < dimensions; ++dim ) {
SkipSpaces(&sz);
sz = fast_atoreal_move<ai_real>(sz, *vec[dim]);
}
// stop at dimensions: this allows loading 1D or 2D coordinate vertices
for (unsigned int dim = 0; dim < dimensions; ++dim) {
SkipSpaces(&sz, lineEnd);
sz = fast_atoreal_move<ai_real>(sz, *vec[dim]);
}
// if has homogeneous coordinate, divide others by this one
if (hasHomogenous) {
SkipSpaces(&sz);
ai_real w = 1.;
sz = fast_atoreal_move<ai_real>(sz, w);
for (unsigned int dim = 0; dim < dimensions; ++dim ) {
*(vec[dim]) /= w;
}
}
// if has homogeneous coordinate, divide others by this one
if (hasHomogenous) {
SkipSpaces(&sz, lineEnd);
ai_real w = 1.;
sz = fast_atoreal_move<ai_real>(sz, w);
for (unsigned int dim = 0; dim < dimensions; ++dim) {
*(vec[dim]) /= w;
}
}
// read optional normals
if (hasNormals) {
aiVector3D& n = mesh->mNormals[i];
SkipSpaces(&sz);
sz = fast_atoreal_move<ai_real>(sz,(ai_real&)n.x);
SkipSpaces(&sz);
sz = fast_atoreal_move<ai_real>(sz,(ai_real&)n.y);
SkipSpaces(&sz);
fast_atoreal_move<ai_real>(sz,(ai_real&)n.z);
}
// read optional normals
if (hasNormals) {
aiVector3D &n = mesh->mNormals[i];
SkipSpaces(&sz, lineEnd);
sz = fast_atoreal_move<ai_real>(sz, (ai_real &)n.x);
SkipSpaces(&sz, lineEnd);
sz = fast_atoreal_move<ai_real>(sz, (ai_real &)n.y);
SkipSpaces(&sz, lineEnd);
fast_atoreal_move<ai_real>(sz, (ai_real &)n.z);
}
// reading colors is a pain because the specification says it can be
// integers or floats, and any number of them between 1 and 4 included,
// until the next comment or end of line
// in theory should be testing type !
if (hasColors) {
aiColor4D& c = mesh->mColors[0][i];
SkipSpaces(&sz);
sz = fast_atoreal_move<ai_real>(sz,(ai_real&)c.r);
// reading colors is a pain because the specification says it can be
// integers or floats, and any number of them between 1 and 4 included,
// until the next comment or end of line
// in theory should be testing type !
if (hasColors) {
aiColor4D &c = mesh->mColors[0][i];
SkipSpaces(&sz, lineEnd);
sz = fast_atoreal_move<ai_real>(sz, (ai_real &)c.r);
if (*sz != '#' && *sz != '\n' && *sz != '\r') {
SkipSpaces(&sz);
sz = fast_atoreal_move<ai_real>(sz,(ai_real&)c.g);
SkipSpaces(&sz, lineEnd);
sz = fast_atoreal_move<ai_real>(sz, (ai_real &)c.g);
} else {
c.g = 0.;
}
c.g = 0.;
}
if (*sz != '#' && *sz != '\n' && *sz != '\r') {
SkipSpaces(&sz);
sz = fast_atoreal_move<ai_real>(sz,(ai_real&)c.b);
SkipSpaces(&sz, lineEnd);
sz = fast_atoreal_move<ai_real>(sz, (ai_real &)c.b);
} else {
c.b = 0.;
}
c.b = 0.;
}
if (*sz != '#' && *sz != '\n' && *sz != '\r') {
SkipSpaces(&sz);
sz = fast_atoreal_move<ai_real>(sz,(ai_real&)c.a);
SkipSpaces(&sz, lineEnd);
sz = fast_atoreal_move<ai_real>(sz, (ai_real &)c.a);
} else {
c.a = 1.;
}
}
c.a = 1.;
}
}
if (hasTexCoord) {
aiVector3D& t = mesh->mTextureCoords[0][i];
SkipSpaces(&sz);
sz = fast_atoreal_move<ai_real>(sz,(ai_real&)t.x);
SkipSpaces(&sz);
fast_atoreal_move<ai_real>(sz,(ai_real&)t.y);
}
aiVector3D &t = mesh->mTextureCoords[0][i];
SkipSpaces(&sz, lineEnd);
sz = fast_atoreal_move<ai_real>(sz, (ai_real &)t.x);
SkipSpaces(&sz, lineEnd);
fast_atoreal_move<ai_real>(sz, (ai_real &)t.y);
}
}
// load faces with their indices
faces = mesh->mFaces;
for (unsigned int i = 0; i < numFaces; ) {
if(!GetNextLine(buffer,line)) {
for (unsigned int i = 0; i < numFaces;) {
if (!GetNextLine(buffer, line)) {
ASSIMP_LOG_ERROR("OFF: The number of faces in the header is incorrect");
break;
throw DeadlyImportError("OFF: The number of faces in the header is incorrect");
}
unsigned int idx;
sz = line; SkipSpaces(&sz);
idx = strtoul10(sz,&sz);
if(!idx || idx > 9) {
ASSIMP_LOG_ERROR("OFF: Faces with zero indices aren't allowed");
sz = line;
SkipSpaces(&sz, lineEnd);
idx = strtoul10(sz, &sz);
if (!idx || idx > 9) {
ASSIMP_LOG_ERROR("OFF: Faces with zero indices aren't allowed");
--mesh->mNumFaces;
++i;
continue;
}
faces->mNumIndices = idx;
}
faces->mNumIndices = idx;
faces->mIndices = new unsigned int[faces->mNumIndices];
for (unsigned int m = 0; m < faces->mNumIndices;++m) {
SkipSpaces(&sz);
idx = strtoul10(sz,&sz);
for (unsigned int m = 0; m < faces->mNumIndices; ++m) {
SkipSpaces(&sz, lineEnd);
idx = strtoul10(sz, &sz);
if (idx >= numVertices) {
ASSIMP_LOG_ERROR("OFF: Vertex index is out of range");
idx = numVertices - 1;
@ -313,20 +308,22 @@ void OFFImporter::InternReadFile( const std::string& pFile, aiScene* pScene, IOS
pScene->mRootNode = new aiNode();
pScene->mRootNode->mName.Set("<OFFRoot>");
pScene->mRootNode->mNumMeshes = 1;
pScene->mRootNode->mMeshes = new unsigned int [pScene->mRootNode->mNumMeshes];
pScene->mRootNode->mMeshes = new unsigned int[pScene->mRootNode->mNumMeshes];
pScene->mRootNode->mMeshes[0] = 0;
// generate a default material
pScene->mNumMaterials = 1;
pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials];
aiMaterial* pcMat = new aiMaterial();
pScene->mMaterials = new aiMaterial *[pScene->mNumMaterials];
aiMaterial *pcMat = new aiMaterial();
aiColor4D clr( ai_real( 0.6 ), ai_real( 0.6 ), ai_real( 0.6 ), ai_real( 1.0 ) );
pcMat->AddProperty(&clr,1,AI_MATKEY_COLOR_DIFFUSE);
aiColor4D clr(0.6f, 0.6f, 0.6f, 1.0f);
pcMat->AddProperty(&clr, 1, AI_MATKEY_COLOR_DIFFUSE);
pScene->mMaterials[0] = pcMat;
const int twosided = 1;
pcMat->AddProperty(&twosided, 1, AI_MATKEY_TWOSIDED);
}
} // namespace Assimp
#endif // !! ASSIMP_BUILD_NO_OFF_IMPORTER