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,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* @brief Implementation of assert handling logic.
*/
#include "AssertHandler.h"
#include <assimp/AssertHandler.h>
#include <iostream>
#include <cstdlib>

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.
@ -233,8 +233,13 @@ const aiScene *aiImportFileFromMemoryWithProperties(
unsigned int pFlags,
const char *pHint,
const aiPropertyStore *props) {
ai_assert(nullptr != pBuffer);
ai_assert(0 != pLength);
if (pBuffer == nullptr) {
return nullptr;
}
if (pLength == 0u) {
return nullptr;
}
const aiScene *scene = nullptr;
ASSIMP_BEGIN_EXCEPTION_REGION();
@ -354,20 +359,25 @@ void CallbackToLogRedirector(const char *msg, char *dt) {
s->write(msg);
}
static LogStream *DefaultStream = nullptr;
// ------------------------------------------------------------------------------------------------
ASSIMP_API aiLogStream aiGetPredefinedLogStream(aiDefaultLogStream pStream, const char *file) {
aiLogStream sout;
ASSIMP_BEGIN_EXCEPTION_REGION();
LogStream *stream = LogStream::createDefaultStream(pStream, file);
if (!stream) {
if (DefaultStream == nullptr) {
DefaultStream = LogStream::createDefaultStream(pStream, file);
}
if (!DefaultStream) {
sout.callback = nullptr;
sout.user = nullptr;
} else {
sout.callback = &CallbackToLogRedirector;
sout.user = (char *)stream;
sout.user = (char *)DefaultStream;
}
gPredefinedStreams.push_back(stream);
gPredefinedStreams.push_back(DefaultStream);
ASSIMP_END_EXCEPTION_REGION(aiLogStream);
return sout;
}
@ -507,6 +517,11 @@ void aiGetMemoryRequirements(const C_STRUCT aiScene *pIn,
ASSIMP_END_EXCEPTION_REGION(void);
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API const C_STRUCT aiTexture *aiGetEmbeddedTexture(const C_STRUCT aiScene *pIn, const char *filename) {
return pIn->GetEmbeddedTexture(filename);
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API aiPropertyStore *aiCreatePropertyStore(void) {
return reinterpret_cast<aiPropertyStore *>(new PropertyMap());
@ -738,14 +753,14 @@ ASSIMP_API void aiVector2DivideByVector(
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API float aiVector2Length(
ASSIMP_API ai_real aiVector2Length(
const C_STRUCT aiVector2D *v) {
ai_assert(nullptr != v);
return v->Length();
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API float aiVector2SquareLength(
ASSIMP_API ai_real aiVector2SquareLength(
const C_STRUCT aiVector2D *v) {
ai_assert(nullptr != v);
return v->SquareLength();
@ -759,7 +774,7 @@ ASSIMP_API void aiVector2Negate(
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API float aiVector2DotProduct(
ASSIMP_API ai_real aiVector2DotProduct(
const C_STRUCT aiVector2D *a,
const C_STRUCT aiVector2D *b) {
ai_assert(nullptr != a);
@ -854,14 +869,14 @@ ASSIMP_API void aiVector3DivideByVector(
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API float aiVector3Length(
ASSIMP_API ai_real aiVector3Length(
const C_STRUCT aiVector3D *v) {
ai_assert(nullptr != v);
return v->Length();
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API float aiVector3SquareLength(
ASSIMP_API ai_real aiVector3SquareLength(
const C_STRUCT aiVector3D *v) {
ai_assert(nullptr != v);
return v->SquareLength();
@ -875,7 +890,7 @@ ASSIMP_API void aiVector3Negate(
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API float aiVector3DotProduct(
ASSIMP_API ai_real aiVector3DotProduct(
const C_STRUCT aiVector3D *a,
const C_STRUCT aiVector3D *b) {
ai_assert(nullptr != a);
@ -961,7 +976,7 @@ ASSIMP_API void aiMatrix3Inverse(C_STRUCT aiMatrix3x3 *mat) {
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API float aiMatrix3Determinant(const C_STRUCT aiMatrix3x3 *mat) {
ASSIMP_API ai_real aiMatrix3Determinant(const C_STRUCT aiMatrix3x3 *mat) {
ai_assert(nullptr != mat);
return mat->Determinant();
}
@ -1061,7 +1076,7 @@ ASSIMP_API void aiMatrix4Inverse(C_STRUCT aiMatrix4x4 *mat) {
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API float aiMatrix4Determinant(const C_STRUCT aiMatrix4x4 *mat) {
ASSIMP_API ai_real aiMatrix4Determinant(const C_STRUCT aiMatrix4x4 *mat) {
ai_assert(nullptr != mat);
return mat->Determinant();
}
@ -1131,7 +1146,7 @@ ASSIMP_API void aiMatrix4RotationX(
ASSIMP_API void aiMatrix4RotationY(
C_STRUCT aiMatrix4x4 *mat,
const float angle) {
ai_assert(NULL != mat);
ai_assert(nullptr != mat);
aiMatrix4x4::RotationY(angle, *mat);
}
@ -1263,7 +1278,6 @@ ASSIMP_API void aiQuaternionInterpolate(
aiQuaternion::Interpolate(*dst, *start, *end, factor);
}
// stb_image is a lightweight image loader. It is shared by:
// - M3D import
// - PBRT export
@ -1273,20 +1287,22 @@ ASSIMP_API void aiQuaternionInterpolate(
#define ASSIMP_HAS_PBRT_EXPORT (!ASSIMP_BUILD_NO_EXPORT && !ASSIMP_BUILD_NO_PBRT_EXPORTER)
#define ASSIMP_HAS_M3D ((!ASSIMP_BUILD_NO_EXPORT && !ASSIMP_BUILD_NO_M3D_EXPORTER) || !ASSIMP_BUILD_NO_M3D_IMPORTER)
#ifndef STB_USE_HUNTER
#if ASSIMP_HAS_PBRT_EXPORT
# define ASSIMP_NEEDS_STB_IMAGE 1
#define ASSIMP_NEEDS_STB_IMAGE 1
#elif ASSIMP_HAS_M3D
# define ASSIMP_NEEDS_STB_IMAGE 1
# define STBI_ONLY_PNG
#define ASSIMP_NEEDS_STB_IMAGE 1
#define STBI_ONLY_PNG
#endif
#endif
// Ensure all symbols are linked correctly
#if ASSIMP_NEEDS_STB_IMAGE
// Share stb_image's PNG loader with other importers/exporters instead of bringing our own copy.
# define STBI_ONLY_PNG
# ifdef ASSIMP_USE_STB_IMAGE_STATIC
# define STB_IMAGE_STATIC
# endif
# define STB_IMAGE_IMPLEMENTATION
# include "Common/StbCommon.h"
// Share stb_image's PNG loader with other importers/exporters instead of bringing our own copy.
#define STBI_ONLY_PNG
#ifdef ASSIMP_USE_STB_IMAGE_STATIC
#define STB_IMAGE_STATIC
#endif
#define STB_IMAGE_IMPLEMENTATION
#include "Common/StbCommon.h"
#endif

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.

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.
@ -59,6 +59,31 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <memory>
#include <sstream>
namespace {
// Checks whether the passed string is a gcs version.
bool IsGcsVersion(const std::string &s) {
if (s.empty()) return false;
return std::all_of(s.cbegin(), s.cend(), [](const char c) {
// gcs only permits numeric characters.
return std::isdigit(static_cast<int>(c));
});
}
// Removes a possible version hash from a filename, as found for example in
// gcs uris (e.g. `gs://bucket/model.glb#1234`), see also
// https://github.com/GoogleCloudPlatform/gsutil/blob/c80f329bc3c4011236c78ce8910988773b2606cb/gslib/storage_url.py#L39.
std::string StripVersionHash(const std::string &filename) {
const std::string::size_type pos = filename.find_last_of('#');
// Only strip if the hash is behind a possible file extension and the part
// behind the hash is a version string.
if (pos != std::string::npos && pos > filename.find_last_of('.') &&
IsGcsVersion(filename.substr(pos + 1))) {
return filename.substr(0, pos);
}
return filename;
}
} // namespace
using namespace Assimp;
// ------------------------------------------------------------------------------------------------
@ -68,10 +93,6 @@ BaseImporter::BaseImporter() AI_NO_EXCEPT
// empty
}
// ------------------------------------------------------------------------------------------------
// Destructor, private as well
BaseImporter::~BaseImporter() = default;
void BaseImporter::UpdateImporterScale(Importer *pImp) {
ai_assert(pImp != nullptr);
ai_assert(importerScale != 0.0);
@ -158,7 +179,7 @@ void BaseImporter::GetExtensionList(std::set<std::string> &extensions) {
std::size_t numTokens,
unsigned int searchBytes /* = 200 */,
bool tokensSol /* false */,
bool noAlphaBeforeTokens /* false */) {
bool noGraphBeforeTokens /* false */) {
ai_assert(nullptr != tokens);
ai_assert(0 != numTokens);
ai_assert(0 != searchBytes);
@ -207,8 +228,9 @@ void BaseImporter::GetExtensionList(std::set<std::string> &extensions) {
continue;
}
// We need to make sure that we didn't accidentally identify the end of another token as our token,
// e.g. in a previous version the "gltf " present in some gltf files was detected as "f "
if (noAlphaBeforeTokens && (r != buffer && isalpha(static_cast<unsigned char>(r[-1])))) {
// e.g. in a previous version the "gltf " present in some gltf files was detected as "f ", or a
// Blender-exported glb file containing "Khronos glTF Blender I/O " was detected as "o "
if (noGraphBeforeTokens && (r != buffer && isgraph(static_cast<unsigned char>(r[-1])))) {
continue;
}
// We got a match, either we don't care where it is, or it happens to
@ -228,34 +250,40 @@ void BaseImporter::GetExtensionList(std::set<std::string> &extensions) {
/*static*/ bool BaseImporter::SimpleExtensionCheck(const std::string &pFile,
const char *ext0,
const char *ext1,
const char *ext2) {
std::string::size_type pos = pFile.find_last_of('.');
// no file extension - can't read
if (pos == std::string::npos) {
return false;
const char *ext2,
const char *ext3) {
std::set<std::string> extensions;
for (const char* ext : {ext0, ext1, ext2, ext3}) {
if (ext == nullptr) continue;
extensions.emplace(ext);
}
return HasExtension(pFile, extensions);
}
const char *ext_real = &pFile[pos + 1];
if (!ASSIMP_stricmp(ext_real, ext0)) {
return true;
// ------------------------------------------------------------------------------------------------
// Check for file extension
/*static*/ bool BaseImporter::HasExtension(const std::string &pFile, const std::set<std::string> &extensions) {
const std::string file = StripVersionHash(pFile);
// CAUTION: Do not just search for the extension!
// GetExtension() returns the part after the *last* dot, but some extensions
// have dots inside them, e.g. ogre.mesh.xml. Compare the entire end of the
// string.
for (const std::string& ext : extensions) {
// Yay for C++<20 not having std::string::ends_with()
const std::string dotExt = "." + ext;
if (dotExt.length() > file.length()) continue;
// Possible optimization: Fetch the lowercase filename!
if (0 == ASSIMP_stricmp(file.c_str() + file.length() - dotExt.length(), dotExt.c_str())) {
return true;
}
}
// check for other, optional, file extensions
if (ext1 && !ASSIMP_stricmp(ext_real, ext1)) {
return true;
}
if (ext2 && !ASSIMP_stricmp(ext_real, ext2)) {
return true;
}
return false;
}
// ------------------------------------------------------------------------------------------------
// Get file extension from path
std::string BaseImporter::GetExtension(const std::string &file) {
std::string BaseImporter::GetExtension(const std::string &pFile) {
const std::string file = StripVersionHash(pFile);
std::string::size_type pos = file.find_last_of('.');
// no file extension at all
@ -281,12 +309,7 @@ std::string BaseImporter::GetExtension(const std::string &file) {
if (!pIOHandler) {
return false;
}
union {
const char *magic;
const uint16_t *magic_u16;
const uint32_t *magic_u32;
};
magic = reinterpret_cast<const char *>(_magic);
const char *magic = reinterpret_cast<const char *>(_magic);
std::unique_ptr<IOStream> pStream(pIOHandler->Open(pFile));
if (pStream) {
@ -308,15 +331,15 @@ std::string BaseImporter::GetExtension(const std::string &file) {
// that's just for convenience, the chance that we cause conflicts
// is quite low and it can save some lines and prevent nasty bugs
if (2 == size) {
uint16_t rev = *magic_u16;
ByteSwap::Swap(&rev);
if (data_u16[0] == *magic_u16 || data_u16[0] == rev) {
uint16_t magic_u16;
memcpy(&magic_u16, magic, 2);
if (data_u16[0] == magic_u16 || data_u16[0] == ByteSwap::Swapped(magic_u16)) {
return true;
}
} else if (4 == size) {
uint32_t rev = *magic_u32;
ByteSwap::Swap(&rev);
if (data_u32[0] == *magic_u32 || data_u32[0] == rev) {
uint32_t magic_u32;
memcpy(&magic_u32, magic, 4);
if (data_u32[0] == magic_u32 || data_u32[0] == ByteSwap::Swapped(magic_u32)) {
return true;
}
} else {
@ -331,11 +354,7 @@ std::string BaseImporter::GetExtension(const std::string &file) {
return false;
}
#ifdef ASSIMP_USE_HUNTER
#include <utf8.h>
#else
#include "../contrib/utf8cpp/source/utf8.h"
#endif
#include "utf8.h"
// ------------------------------------------------------------------------------------------------
// Convert to UTF8 data

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.
@ -57,10 +57,6 @@ BaseProcess::BaseProcess() AI_NO_EXCEPT
// empty
}
// ------------------------------------------------------------------------------------------------
// Destructor, private as well
BaseProcess::~BaseProcess() = default;
// ------------------------------------------------------------------------------------------------
void BaseProcess::ExecuteOnScene(Importer *pImp) {
ai_assert( nullptr != pImp );

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -179,11 +179,11 @@ class ASSIMP_API BaseProcess {
friend class Importer;
public:
/** @brief onstructor to be privately used by Importer */
/** @brief Constructor to be privately used by Importer */
BaseProcess() AI_NO_EXCEPT;
/** @brief Destructor, private as well */
virtual ~BaseProcess();
/** @brief Destructor */
virtual ~BaseProcess() = default;
// -------------------------------------------------------------------
/**

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.
@ -148,8 +148,10 @@ void Bitmap::WriteData(aiTexture *texture, IOStream *file) {
file->Write(pixel, mBytesPerPixel, 1);
}
file->Write(padding_data, padding, 1);
// When padding is 0, passing it as an argument will cause an assertion failure in DefaultIOStream::Write.
if (padding) {
file->Write(padding_data, padding, 1);
}
}
}

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -66,6 +66,10 @@ Compression::Compression() :
Compression::~Compression() {
ai_assert(mImpl != nullptr);
if (mImpl->mOpen) {
close();
}
delete mImpl;
}
@ -124,7 +128,7 @@ static int getFlushMode(Compression::FlushMode flush) {
return z_flush;
}
constexpr size_t MYBLOCK = 32786;
static constexpr size_t MYBLOCK = 32786;
size_t Compression::decompress(const void *data, size_t in, std::vector<char> &uncompressed) {
ai_assert(mImpl != nullptr);

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -41,11 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
#include <zlib.h>
#else
#include "../contrib/zlib/zlib.h"
#endif
#include "zlib.h"
#include <vector>
#include <cstddef> // size_t

View file

@ -4,7 +4,7 @@ Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (C) 2016 The Qt Company Ltd.
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.

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.

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.
@ -93,18 +93,24 @@ static std::string WideToUtf8(const wchar_t *in) {
// ------------------------------------------------------------------------------------------------
// Tests for the existence of a file at the given path.
bool DefaultIOSystem::Exists(const char *pFile) const {
if (pFile == nullptr) {
return false;
}
#ifdef _WIN32
struct __stat64 filestat;
if (_wstat64(Utf8ToWide(pFile).c_str(), &filestat) != 0) {
return false;
}
#else
FILE *file = ::fopen(pFile, "rb");
if (!file) {
struct stat statbuf;
if (stat(pFile, &statbuf) != 0) {
return false;
}
// test for a regular file
if (!S_ISREG(statbuf.st_mode)) {
return false;
}
::fclose(file);
#endif
return true;
@ -116,6 +122,7 @@ IOStream *DefaultIOSystem::Open(const char *strFile, const char *strMode) {
ai_assert(strFile != nullptr);
ai_assert(strMode != nullptr);
FILE *file;
#ifdef _WIN32
std::wstring name = Utf8ToWide(strFile);
if (name.empty()) {
@ -126,6 +133,7 @@ IOStream *DefaultIOSystem::Open(const char *strFile, const char *strMode) {
#else
file = ::fopen(strFile, strMode);
#endif
if (!file) {
return nullptr;
}

View file

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
@ -221,13 +221,11 @@ void DefaultLogger::set(Logger *logger) {
#endif
if (nullptr == logger) {
logger = &s_pNullLogger;
m_pLogger = &s_pNullLogger;
}
if (nullptr != m_pLogger && !isNullLogger()) {
delete m_pLogger;
else {
m_pLogger = logger;
}
DefaultLogger::m_pLogger = logger;
}
// ----------------------------------------------------------------------------------
@ -320,9 +318,13 @@ bool DefaultLogger::attachStream(LogStream *pStream, unsigned int severity) {
}
if (0 == severity) {
severity = Logger::Info | Logger::Err | Logger::Warn | Logger::Debugging;
severity = SeverityAll;
}
#ifndef ASSIMP_BUILD_SINGLETHREADED
std::lock_guard<std::mutex> lock(m_arrayMutex);
#endif
for (StreamIt it = m_StreamArray.begin();
it != m_StreamArray.end();
++it) {
@ -348,6 +350,10 @@ bool DefaultLogger::detachStream(LogStream *pStream, unsigned int severity) {
severity = SeverityAll;
}
#ifndef ASSIMP_BUILD_SINGLETHREADED
std::lock_guard<std::mutex> lock(m_arrayMutex);
#endif
bool res(false);
for (StreamIt it = m_StreamArray.begin(); it != m_StreamArray.end(); ++it) {
if ((*it)->m_pStream == pStream) {
@ -387,6 +393,10 @@ DefaultLogger::~DefaultLogger() {
void DefaultLogger::WriteToStreams(const char *message, ErrorSeverity ErrorSev) {
ai_assert(nullptr != message);
#ifndef ASSIMP_BUILD_SINGLETHREADED
std::lock_guard<std::mutex> lock(m_arrayMutex);
#endif
// Check whether this is a repeated message
auto thisLen = ::strlen(message);
if (thisLen == lastLen - 1 && !::strncmp(message, lastMsg, lastLen - 1)) {

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.

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.

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.
@ -225,7 +225,7 @@ static void setupExporterArray(std::vector<Exporter::ExportFormatEntry> &exporte
#endif
#ifndef ASSIMP_BUILD_NO_PBRT_EXPORTER
exporters.emplace_back("pbrt", "pbrt-v4 scene description file", "pbrt", &ExportScenePbrt, aiProcess_Triangulate | aiProcess_SortByPType);
exporters.emplace_back("pbrt", "pbrt-v4 scene description file", "pbrt", &ExportScenePbrt, aiProcess_ConvertToLeftHanded | aiProcess_Triangulate | aiProcess_SortByPType);
#endif
#ifndef ASSIMP_BUILD_NO_ASSJSON_EXPORTER
@ -595,7 +595,7 @@ bool ExportProperties::SetPropertyCallback(const char *szName, const std::functi
}
std::function<void *(void *)> ExportProperties::GetPropertyCallback(const char *szName) const {
return GetGenericProperty<std::function<void *(void *)>>(mCallbackProperties, szName, 0);
return GetGenericProperty<std::function<void *(void *)>>(mCallbackProperties, szName, nullptr);
}
bool ExportProperties::HasPropertyCallback(const char *szName) const {

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.

View file

@ -93,9 +93,7 @@ public:
}
/** Destructor. */
~FileSystemFilter() {
// empty
}
~FileSystemFilter() = default;
// -------------------------------------------------------------------
/** Tests for the existence of a file at the given path. */
@ -299,7 +297,7 @@ private:
}
const char separator = getOsSeparator();
for (it = in.begin(); it != in.end(); ++it) {
for (it = in.begin(); it < in.end(); ++it) {
const size_t remaining = std::distance(in.end(), it);
// Exclude :// and \\, which remain untouched.
// https://sourceforge.net/tracker/?func=detail&aid=3031725&group_id=226462&atid=1067632

View file

@ -122,7 +122,7 @@ inline const char* ReadHeader(uint8_t* outFile, uint32_t& fileType)
}
::memcpy(&fileType, outFile, 4);
AI_LSWAP4(fileType);
return 0;
return nullptr;
}

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.

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.
@ -482,37 +482,43 @@ bool Importer::ValidateFlags(unsigned int pFlags) const {
}
// ------------------------------------------------------------------------------------------------
const aiScene* Importer::ReadFileFromMemory( const void* pBuffer,
size_t pLength,
unsigned int pFlags,
const char* pHint /*= ""*/) {
const aiScene* Importer::ReadFileFromMemory(const void* pBuffer, size_t pLength, unsigned int pFlags, const char* pHint ) {
ai_assert(nullptr != pimpl);
ASSIMP_BEGIN_EXCEPTION_REGION();
if (!pHint) {
pHint = "";
}
if (!pBuffer || !pLength || strlen(pHint) > MaxLenHint ) {
pimpl->mErrorString = "Invalid parameters passed to ReadFileFromMemory()";
return nullptr;
}
// prevent deletion of the previous IOHandler
IOSystem* io = pimpl->mIOHandler;
pimpl->mIOHandler = nullptr;
try {
if (pHint == nullptr) {
pHint = "";
}
if (!pBuffer || !pLength || strlen(pHint) > MaxLenHint ) {
pimpl->mErrorString = "Invalid parameters passed to ReadFileFromMemory()";
return nullptr;
}
// prevent deletion of the previous IOHandler
pimpl->mIOHandler = nullptr;
SetIOHandler(new MemoryIOSystem((const uint8_t*)pBuffer,pLength,io));
SetIOHandler(new MemoryIOSystem((const uint8_t*)pBuffer,pLength,io));
// read the file and recover the previous IOSystem
static const size_t BufSize(Importer::MaxLenHint + 28);
char fbuff[BufSize];
ai_snprintf(fbuff, BufSize, "%s.%s",AI_MEMORYIO_MAGIC_FILENAME,pHint);
// read the file and recover the previous IOSystem
static const size_t BufSize(Importer::MaxLenHint + 28);
char fbuff[BufSize];
ai_snprintf(fbuff, BufSize, "%s.%s",AI_MEMORYIO_MAGIC_FILENAME,pHint);
ReadFile(fbuff,pFlags);
SetIOHandler(io);
ReadFile(fbuff,pFlags);
SetIOHandler(io);
} catch(const DeadlyImportError &e) {
pimpl->mErrorString = e.what();
pimpl->mException = std::current_exception();
SetIOHandler(io);
return ExceptionSwallower<const aiScene*>()(); \
} catch(...) {
pimpl->mErrorString = "Unknown exception";
pimpl->mException = std::current_exception();
SetIOHandler(io);
return ExceptionSwallower<const aiScene*>()(); \
}
ASSIMP_END_EXCEPTION_REGION_WITH_ERROR_STRING(const aiScene*, pimpl->mErrorString, pimpl->mException);
return pimpl->mScene;
}
@ -631,24 +637,10 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags) {
std::set<std::string> extensions;
pimpl->mImporter[a]->GetExtensionList(extensions);
// CAUTION: Do not just search for the extension!
// GetExtension() returns the part after the *last* dot, but some extensions have dots
// inside them, e.g. ogre.mesh.xml. Compare the entire end of the string.
for (std::set<std::string>::const_iterator it = extensions.cbegin(); it != extensions.cend(); ++it) {
// Yay for C++<20 not having std::string::ends_with()
std::string extension = "." + *it;
if (extension.length() <= pFile.length()) {
// Possible optimization: Fetch the lowercase filename!
if (0 == ASSIMP_stricmp(pFile.c_str() + pFile.length() - extension.length(), extension.c_str())) {
ImporterAndIndex candidate = { pimpl->mImporter[a], a };
possibleImporters.push_back(candidate);
break;
}
}
if (BaseImporter::HasExtension(pFile, extensions)) {
ImporterAndIndex candidate = { pimpl->mImporter[a], a };
possibleImporters.push_back(candidate);
}
}
// If just one importer supports this extension, pick it and close the case.
@ -779,6 +771,7 @@ const aiScene* Importer::ReadFile( const char* _pFile, unsigned int pFlags) {
#else
pimpl->mErrorString = std::string("std::exception: ") + e.what();
#endif
pimpl->mException = std::current_exception();
ASSIMP_LOG_ERROR(pimpl->mErrorString);
delete pimpl->mScene; pimpl->mScene = nullptr;
@ -856,11 +849,7 @@ const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags) {
break;
}
#ifdef ASSIMP_BUILD_DEBUG
#ifdef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
continue;
#endif // no validation
#ifndef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
// If the extra verbose mode is active, execute the ValidateDataStructureStep again - after each step
if (pimpl->bExtraVerbose) {
ASSIMP_LOG_DEBUG("Verbose Import: re-validating data structures");
@ -872,6 +861,7 @@ const aiScene* Importer::ApplyPostProcessing(unsigned int pFlags) {
break;
}
}
#endif // no validation
#endif // ! DEBUG
}
pimpl->mProgressHandler->UpdatePostProcess( static_cast<int>(pimpl->mPostProcessingSteps.size()),
@ -947,6 +937,7 @@ const aiScene* Importer::ApplyCustomizedPostProcessing( BaseProcess *rootProcess
profiler->EndRegion( "postprocess" );
}
#ifndef ASSIMP_BUILD_NO_VALIDATEDS_PROCESS
// If the extra verbose mode is active, execute the ValidateDataStructureStep again - after each step
if ( pimpl->bExtraVerbose || requestValidation ) {
ASSIMP_LOG_DEBUG( "Verbose Import: revalidating data structures" );
@ -957,6 +948,7 @@ const aiScene* Importer::ApplyCustomizedPostProcessing( BaseProcess *rootProcess
ASSIMP_LOG_ERROR( "Verbose Import: failed to revalidate data structures" );
}
}
#endif // no validation
// clear any data allocated by post-process steps
pimpl->mPPShared->Clean();
@ -1118,7 +1110,7 @@ bool Importer::SetPropertyMatrix(const char* szName, const aiMatrix4x4& value) {
// Set a configuration property
bool Importer::SetPropertyPointer(const char* szName, void* value) {
ai_assert(nullptr != pimpl);
bool existing;
ASSIMP_BEGIN_EXCEPTION_REGION();
existing = SetGenericProperty<void*>(pimpl->mPointerProperties, szName,value);
@ -1162,7 +1154,7 @@ aiMatrix4x4 Importer::GetPropertyMatrix(const char* szName, const aiMatrix4x4& i
// Get a configuration property
void* Importer::GetPropertyPointer(const char* szName, void* iErrorReturn /*= nullptr*/) const {
ai_assert(nullptr != pimpl);
return GetGenericProperty<void*>(pimpl->mPointerProperties,szName,iErrorReturn);
}

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -74,11 +74,11 @@ public:
typedef unsigned int KeyType;
// typedefs for our configuration maps.
typedef std::map<KeyType, int> IntPropertyMap;
typedef std::map<KeyType, ai_real> FloatPropertyMap;
typedef std::map<KeyType, std::string> StringPropertyMap;
typedef std::map<KeyType, aiMatrix4x4> MatrixPropertyMap;
typedef std::map<KeyType, void*> PointerPropertyMap;
using IntPropertyMap = std::map<KeyType, int>;
using FloatPropertyMap = std::map<KeyType, ai_real>;
using StringPropertyMap = std::map<KeyType, std::string>;
using MatrixPropertyMap = std::map<KeyType, aiMatrix4x4>;
using PointerPropertyMap = std::map<KeyType, void*>;
/** IO handler to use for all file accesses. */
IOSystem* mIOHandler;
@ -128,10 +128,12 @@ public:
/// The default class constructor.
ImporterPimpl() AI_NO_EXCEPT;
/// The class destructor.
~ImporterPimpl() = default;
};
inline
ImporterPimpl::ImporterPimpl() AI_NO_EXCEPT :
inline ImporterPimpl::ImporterPimpl() AI_NO_EXCEPT :
mIOHandler( nullptr ),
mIsDefaultHandler( false ),
mProgressHandler( nullptr ),

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.
@ -55,6 +55,9 @@ corresponding preprocessor flag to selectively disable formats.
// Importers
// (include_new_importers_here)
// ------------------------------------------------------------------------------------------------
#if !defined(ASSIMP_BUILD_NO_USD_IMPORTER)
#include "AssetLib/USD/USDLoader.h"
#endif
#ifndef ASSIMP_BUILD_NO_X_IMPORTER
#include "AssetLib/X/XFileImporter.h"
#endif
@ -214,7 +217,12 @@ void GetImporterInstanceList(std::vector<BaseImporter *> &out) {
// Some importers may be unimplemented or otherwise unsuitable for general use
// in their current state. Devs can set ASSIMP_ENABLE_DEV_IMPORTERS in their
// local environment to enable them, otherwise they're left out of the registry.
#if defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP
// not supported under uwp
const char *envStr = std::getenv("ASSIMP_ENABLE_DEV_IMPORTERS");
#else
const char *envStr = { "0" };
#endif
bool devImportersEnabled = envStr && strcmp(envStr, "0");
// Ensure no unused var warnings if all uses are #ifndef'd away below:
@ -225,6 +233,9 @@ void GetImporterInstanceList(std::vector<BaseImporter *> &out) {
// (register_new_importers_here)
// ----------------------------------------------------------------------------
out.reserve(64);
#if !defined(ASSIMP_BUILD_NO_USD_IMPORTER)
out.push_back(new USDImporter());
#endif
#if (!defined ASSIMP_BUILD_NO_X_IMPORTER)
out.push_back(new XFileImporter());
#endif
@ -377,9 +388,6 @@ void GetImporterInstanceList(std::vector<BaseImporter *> &out) {
#ifndef ASSIMP_BUILD_NO_IQM_IMPORTER
out.push_back(new IQMImporter());
#endif
//#ifndef ASSIMP_BUILD_NO_STEP_IMPORTER
// out.push_back(new StepFile::StepFileImporter());
//#endif
}
/** will delete all registered importers. */

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -41,6 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once
#include <assimp/ai_assert.h>
#include <utility>
namespace Assimp {
@ -48,13 +49,14 @@ namespace Assimp {
/// @tparam T The type to store.
template <typename T>
struct Maybe {
/// @brief
/// @brief
Maybe() = default;
/// @brief
/// @param val
explicit Maybe(const T &val) :
_val(val), _valid(true) {}
/// @brief
/// @param val
template <typename U>
explicit Maybe(U &&val) :
_val(std::forward<U>(val)), _valid(true) {}
/// @brief Validate the value
/// @return true if valid.
@ -64,11 +66,12 @@ struct Maybe {
/// @brief Will assign a value.
/// @param v The new valid value.
void Set(T &v) {
template <typename U>
void Set(U &&v) {
ai_assert(!_valid);
_valid = true;
_val = v;
_val = std::forward<U>(v);
}
/// @brief Will return the value when it is valid.

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -64,8 +64,14 @@ inline double GetArea2D(const T& v1, const T& v2, const T& v3) {
* The function accepts an unconstrained template parameter for use with
* both aiVector3D and aiVector2D, but generally ignores the third coordinate.*/
template <typename T>
inline bool OnLeftSideOfLine2D(const T& p0, const T& p1,const T& p2) {
return GetArea2D(p0,p2,p1) > 0;
inline int OnLeftSideOfLine2D(const T& p0, const T& p1,const T& p2) {
double area = GetArea2D(p0,p2,p1);
if(std::abs(area) < ai_epsilon)
return 0;
else if(area > 0)
return 1;
else
return -1;
}
// -------------------------------------------------------------------------------
@ -74,26 +80,11 @@ inline bool OnLeftSideOfLine2D(const T& p0, const T& p1,const T& p2) {
* both aiVector3D and aiVector2D, but generally ignores the third coordinate.*/
template <typename T>
inline bool PointInTriangle2D(const T& p0, const T& p1,const T& p2, const T& pp) {
// Point in triangle test using baryzentric coordinates
const aiVector2D v0 = p1 - p0;
const aiVector2D v1 = p2 - p0;
const aiVector2D v2 = pp - p0;
double dot00 = v0 * v0;
double dot11 = v1 * v1;
const double dot01 = v0 * v1;
const double dot02 = v0 * v2;
const double dot12 = v1 * v2;
const double denom = dot00 * dot11 - dot01 * dot01;
if (denom == 0.0) {
return false;
}
const double invDenom = 1.0 / denom;
dot11 = (dot11 * dot02 - dot01 * dot12) * invDenom;
dot00 = (dot00 * dot12 - dot01 * dot02) * invDenom;
return (dot11 > 0) && (dot00 > 0) && (dot11 + dot00 < 1);
// pp should be left side of the three triangle side, by ccw arrow
int c1 = OnLeftSideOfLine2D(p0, p1, pp);
int c2 = OnLeftSideOfLine2D(p1, p2, pp);
int c3 = OnLeftSideOfLine2D(p2, p0, pp);
return (c1 >= 0) && (c2 >= 0) && (c3 >= 0);
}
@ -128,7 +119,7 @@ inline bool IsCCW(T* in, size_t npoints) {
c = std::sqrt(cc);
theta = std::acos((bb + cc - aa) / (2 * b * c));
if (OnLeftSideOfLine2D(in[i],in[i+2],in[i+1])) {
if (OnLeftSideOfLine2D(in[i],in[i+2],in[i+1]) == 1) {
// if (convex(in[i].x, in[i].y,
// in[i+1].x, in[i+1].y,
// in[i+2].x, in[i+2].y)) {
@ -158,7 +149,7 @@ inline bool IsCCW(T* in, size_t npoints) {
//if (convex(in[npoints-2].x, in[npoints-2].y,
// in[0].x, in[0].y,
// in[1].x, in[1].y)) {
if (OnLeftSideOfLine2D(in[npoints-2],in[1],in[0])) {
if (OnLeftSideOfLine2D(in[npoints-2],in[1],in[0]) == 1) {
convex_turn = AI_MATH_PI_F - theta;
convex_sum += convex_turn;
} else {

View file

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -39,7 +39,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
/**
/**
* @file RemoveComments.cpp
* @brief Defines the CommentRemover utility class
*/

View file

@ -3,9 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -50,16 +48,13 @@ the 3ds loader handling smooth groups correctly */
using namespace Assimp;
// ------------------------------------------------------------------------------------------------
SGSpatialSort::SGSpatialSort()
{
SGSpatialSort::SGSpatialSort() {
// define the reference plane. We choose some arbitrary vector away from all basic axes
// in the hope that no model spreads all its vertices along this plane.
mPlaneNormal.Set( 0.8523f, 0.34321f, 0.5736f);
mPlaneNormal.Normalize();
}
// ------------------------------------------------------------------------------------------------
// Destructor
SGSpatialSort::~SGSpatialSort() = default;
// ------------------------------------------------------------------------------------------------
void SGSpatialSort::Add(const aiVector3D& vPosition, unsigned int index,
unsigned int smoothingGroup)

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -63,6 +63,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/scene.h>
#include <stdio.h>
#include <assimp/DefaultLogger.hpp>
#include <unordered_set>
namespace Assimp {
@ -78,7 +79,7 @@ inline void PrefixString(aiString &string, const char *prefix, unsigned int len)
if (string.length >= 1 && string.data[0] == '$')
return;
if (len + string.length >= MAXLEN - 1) {
if (len + string.length >= AI_MAXLEN - 1) {
ASSIMP_LOG_VERBOSE_DEBUG("Can't add an unique prefix because the string is too long");
ai_assert(false);
return;
@ -252,6 +253,14 @@ void SceneCombiner::AttachToGraph(aiScene *master, std::vector<NodeAttachmentInf
// ------------------------------------------------------------------------------------------------
void SceneCombiner::MergeScenes(aiScene **_dest, aiScene *master, std::vector<AttachmentInfo> &srcList, unsigned int flags) {
if (nullptr == _dest) {
std::unordered_set<aiScene *> uniqueScenes;
uniqueScenes.insert(master);
for (const auto &item : srcList) {
uniqueScenes.insert(item.scene);
}
for (const auto &item : uniqueScenes) {
delete item;
}
return;
}
@ -259,6 +268,7 @@ void SceneCombiner::MergeScenes(aiScene **_dest, aiScene *master, std::vector<At
if (srcList.empty()) {
if (*_dest) {
SceneCombiner::CopySceneFlat(_dest, master);
delete master;
} else
*_dest = master;
return;
@ -306,15 +316,6 @@ void SceneCombiner::MergeScenes(aiScene **_dest, aiScene *master, std::vector<At
boost::variate_generator<boost::mt19937&, boost::uniform_int<> > rndGen(rng, dist);
#endif
for (unsigned int i = 1; i < src.size(); ++i) {
//if (i != duplicates[i])
//{
// // duplicate scenes share the same UID
// ::strcpy( src[i].id, src[duplicates[i]].id );
// src[i].idlen = src[duplicates[i]].idlen;
// continue;
//}
src[i].idlen = ai_snprintf(src[i].id, 32, "$%.6X$_", i);
if (flags & AI_INT_MERGE_SCENE_GEN_UNIQUE_NAMES_IF_NECESSARY) {
@ -408,7 +409,7 @@ void SceneCombiner::MergeScenes(aiScene **_dest, aiScene *master, std::vector<At
// where n is the index of the texture.
// Copy here because we overwrite the string data in-place and the buffer inside of aiString
// will be a lie if we just reinterpret from prop->mData. The size of mData is not guaranteed to be
// MAXLEN in size.
// AI_MAXLEN in size.
aiString s(*(aiString *)prop->mData);
if ('*' == s.data[0]) {
// Offset the index and write it back ..
@ -1057,7 +1058,7 @@ void SceneCombiner::CopyScene(aiScene **_dest, const aiScene *src, bool allocate
dest->mFlags = src->mFlags;
// source private data might be nullptr if the scene is user-allocated (i.e. for use with the export API)
if (dest->mPrivate != nullptr) {
if (src->mPrivate != nullptr) {
ScenePriv(dest)->mPPStepsApplied = ScenePriv(src) ? ScenePriv(src)->mPPStepsApplied : 0;
}
}
@ -1349,6 +1350,9 @@ void SceneCombiner::Copy(aiMetadata **_dest, const aiMetadata *src) {
case AI_AIVECTOR3D:
out.mData = new aiVector3D(*static_cast<aiVector3D *>(in.mData));
break;
case AI_AIMETADATA:
out.mData = new aiMetadata(*static_cast<aiMetadata *>(in.mData));
break;
default:
ai_assert(false);
break;

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -106,7 +106,7 @@ void ScenePreprocessor::ProcessMesh(aiMesh *mesh) {
if (!mesh->mTextureCoords[i]) {
mesh->mNumUVComponents[i] = 0;
continue;
}
}
if (!mesh->mNumUVComponents[i]) {
mesh->mNumUVComponents[i] = 2;
@ -142,6 +142,7 @@ void ScenePreprocessor::ProcessMesh(aiMesh *mesh) {
// If the information which primitive types are there in the
// mesh is currently not available, compute it.
if (!mesh->mPrimitiveTypes) {
ai_assert(mesh->mFaces != nullptr);
for (unsigned int a = 0; a < mesh->mNumFaces; ++a) {
aiFace &face = mesh->mFaces[a];
switch (face.mNumIndices) {

View file

@ -2,8 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -56,7 +55,7 @@ class ScenePreprocessorTest;
namespace Assimp {
// ----------------------------------------------------------------------------------
/** ScenePreprocessor: Preprocess a scene before any post-processing
/** ScenePreprocessor: Pre-process a scene before any post-processing
* steps are executed.
*
* The step computes data that needn't necessarily be provided by the
@ -79,6 +78,9 @@ public:
ScenePreprocessor(aiScene *_scene) :
scene(_scene) {}
/// @brief The class destructor.
~ScenePreprocessor() = default;
// ----------------------------------------------------------------
/** Assign a (new) scene to the object.
*

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -131,32 +131,33 @@ void SkeletonMeshBuilder::CreateGeometry(const aiNode *pNode) {
// if the node has no children, it's an end node. Put a little knob there instead
aiVector3D ownpos(pNode->mTransformation.a4, pNode->mTransformation.b4, pNode->mTransformation.c4);
ai_real sizeEstimate = ownpos.Length() * ai_real(0.18);
const ai_real zero(0.0);
mVertices.emplace_back(-sizeEstimate, 0.0, 0.0);
mVertices.emplace_back(0.0, sizeEstimate, 0.0);
mVertices.emplace_back(0.0, 0.0, -sizeEstimate);
mVertices.emplace_back(0.0, sizeEstimate, 0.0);
mVertices.emplace_back(sizeEstimate, 0.0, 0.0);
mVertices.emplace_back(0.0, 0.0, -sizeEstimate);
mVertices.emplace_back(sizeEstimate, 0.0, 0.0);
mVertices.emplace_back(0.0, -sizeEstimate, 0.0);
mVertices.emplace_back(0.0, 0.0, -sizeEstimate);
mVertices.emplace_back(0.0, -sizeEstimate, 0.0);
mVertices.emplace_back(-sizeEstimate, 0.0, 0.0);
mVertices.emplace_back(0.0, 0.0, -sizeEstimate);
mVertices.emplace_back(-sizeEstimate, zero, zero);
mVertices.emplace_back(zero, sizeEstimate, zero);
mVertices.emplace_back(zero, zero, -sizeEstimate);
mVertices.emplace_back(zero, sizeEstimate, zero);
mVertices.emplace_back(sizeEstimate, zero, zero);
mVertices.emplace_back(zero, zero, -sizeEstimate);
mVertices.emplace_back(sizeEstimate, zero, zero);
mVertices.emplace_back(zero, -sizeEstimate, zero);
mVertices.emplace_back(zero, zero, -sizeEstimate);
mVertices.emplace_back(zero, -sizeEstimate, zero);
mVertices.emplace_back(-sizeEstimate, zero, zero);
mVertices.emplace_back(zero, zero, -sizeEstimate);
mVertices.emplace_back(-sizeEstimate, 0.0, 0.0);
mVertices.emplace_back(0.0, 0.0, sizeEstimate);
mVertices.emplace_back(0.0, sizeEstimate, 0.0);
mVertices.emplace_back(0.0, sizeEstimate, 0.0);
mVertices.emplace_back(0.0, 0.0, sizeEstimate);
mVertices.emplace_back(sizeEstimate, 0.0, 0.0);
mVertices.emplace_back(sizeEstimate, 0.0, 0.0);
mVertices.emplace_back(0.0, 0.0, sizeEstimate);
mVertices.emplace_back(0.0, -sizeEstimate, 0.0);
mVertices.emplace_back(0.0, -sizeEstimate, 0.0);
mVertices.emplace_back(0.0, 0.0, sizeEstimate);
mVertices.emplace_back(-sizeEstimate, 0.0, 0.0);
mVertices.emplace_back(-sizeEstimate, zero, zero);
mVertices.emplace_back(zero, zero, sizeEstimate);
mVertices.emplace_back(zero, sizeEstimate, zero);
mVertices.emplace_back(zero, sizeEstimate, zero);
mVertices.emplace_back(zero, zero, sizeEstimate);
mVertices.emplace_back(sizeEstimate, zero, zero);
mVertices.emplace_back(sizeEstimate, zero, zero);
mVertices.emplace_back(zero, zero, sizeEstimate);
mVertices.emplace_back(zero, -sizeEstimate, zero);
mVertices.emplace_back(zero, -sizeEstimate, zero);
mVertices.emplace_back(zero, zero, sizeEstimate);
mVertices.emplace_back(-sizeEstimate, zero, zero);
mFaces.emplace_back(vertexStartIndex + 0, vertexStartIndex + 1, vertexStartIndex + 2);
mFaces.emplace_back(vertexStartIndex + 3, vertexStartIndex + 4, vertexStartIndex + 5);

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.
@ -71,10 +71,6 @@ SpatialSort::SpatialSort() :
mPlaneNormal.Normalize();
}
// ------------------------------------------------------------------------------------------------
// Destructor
SpatialSort::~SpatialSort() = default;
// ------------------------------------------------------------------------------------------------
void SpatialSort::Fill(const aiVector3D *pPositions, unsigned int pNumPositions,
unsigned int pElementOffset,
@ -94,7 +90,7 @@ ai_real SpatialSort::CalculateDistance(const aiVector3D &pPosition) const {
void SpatialSort::Finalize() {
const ai_real scale = 1.0f / mPositions.size();
for (unsigned int i = 0; i < mPositions.size(); i++) {
mCentroid += scale * mPositions[i].mPosition;
mCentroid += scale * mPositions[i].mPosition;
}
for (unsigned int i = 0; i < mPositions.size(); i++) {
mPositions[i].mDistance = CalculateDistance(mPositions[i].mPosition);

View file

@ -0,0 +1,98 @@
/*
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2024, 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 StackAllocator.h
* @brief A very bare-bone allocator class that is suitable when
* allocating many small objects, e.g. during parsing.
* Individual objects are not freed, instead only the whole memory
* can be deallocated.
*/
#ifndef AI_STACK_ALLOCATOR_H_INC
#define AI_STACK_ALLOCATOR_H_INC
#include <vector>
#include <stdint.h>
#include <stddef.h>
namespace Assimp {
/** @brief A very bare-bone allocator class that is suitable when
* allocating many small objects, e.g. during parsing.
* Individual objects are not freed, instead only the whole memory
* can be deallocated.
*/
class StackAllocator {
public:
/// @brief Constructs the allocator
StackAllocator();
/// @brief Destructs the allocator and frees all memory
~StackAllocator();
// non copyable
StackAllocator(const StackAllocator &) = delete;
StackAllocator &operator=(const StackAllocator &) = delete;
/// @brief Returns a pointer to byteSize bytes of heap memory that persists
/// for the lifetime of the allocator (or until FreeAll is called).
inline void *Allocate(size_t byteSize);
/// @brief Releases all the memory owned by this allocator.
// Memory provided through function Allocate is not valid anymore after this function has been called.
inline void FreeAll();
private:
constexpr const static size_t g_maxBytesPerBlock = 64 * 1024 * 1024; // The maximum size (in bytes) of a block
constexpr const static size_t g_startBytesPerBlock = 16 * 1024; // Size of the first block. Next blocks will double in size until maximum size of g_maxBytesPerBlock
size_t m_blockAllocationSize = g_startBytesPerBlock; // Block size of the current block
size_t m_subIndex = g_maxBytesPerBlock; // The current byte offset in the current block
std::vector<uint8_t *> m_storageBlocks; // A list of blocks
};
} // namespace Assimp
/// @brief Fixes an undefined reference error when linking in certain build environments.
// May throw warnings about needing stdc++17, but should compile without issues on modern compilers.
inline const size_t Assimp::StackAllocator::g_maxBytesPerBlock;
inline const size_t Assimp::StackAllocator::g_startBytesPerBlock;
#include "StackAllocator.inl"
#endif // include guard

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2020, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -39,41 +39,44 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
/** @file Provides facilities to replace the default assert handler. */
#ifndef INCLUDED_AI_ASSERTHANDLER_H
#define INCLUDED_AI_ASSERTHANDLER_H
#include "StackAllocator.h"
#include <assimp/ai_assert.h>
#include <assimp/defs.h>
#include <algorithm>
namespace Assimp {
using namespace Assimp;
// ---------------------------------------------------------------------------
/**
* @brief Signature of functions which handle assert violations.
*/
using AiAssertHandler = void (*)(const char* failedExpression, const char* file, int line);
inline StackAllocator::StackAllocator() : m_storageBlocks() {}
// ---------------------------------------------------------------------------
/**
* @brief Set the assert handler.
*/
ASSIMP_API void setAiAssertHandler(AiAssertHandler handler);
inline StackAllocator::~StackAllocator() {
FreeAll();
}
// ---------------------------------------------------------------------------
/** The assert handler which is set by default.
*
* @brief This issues a message to stderr and calls abort.
*/
ASSIMP_API void defaultAiAssertHandler(const char* failedExpression, const char* file, int line);
inline void *StackAllocator::Allocate(size_t byteSize) {
if (m_subIndex + byteSize > m_blockAllocationSize) // start a new block
{
// double block size every time, up to maximum of g_maxBytesPerBlock.
// Block size must be at least as large as byteSize, but we want to use this for small allocations anyway.
m_blockAllocationSize = std::max<std::size_t>(std::min<std::size_t>(m_blockAllocationSize * 2, g_maxBytesPerBlock), byteSize);
uint8_t *data = new uint8_t[m_blockAllocationSize];
m_storageBlocks.emplace_back(data);
m_subIndex = byteSize;
return data;
}
// ---------------------------------------------------------------------------
/**
* @brief Dispatches an assert violation to the assert handler.
*/
ASSIMP_API void aiAssertViolation(const char* failedExpression, const char* file, int line);
uint8_t *data = m_storageBlocks.back();
data += m_subIndex;
m_subIndex += byteSize;
} // end of namespace Assimp
return data;
}
#endif // INCLUDED_AI_ASSERTHANDLER_H
inline void StackAllocator::FreeAll() {
for (size_t i = 0; i < m_storageBlocks.size(); i++) {
delete [] m_storageBlocks[i];
}
std::vector<uint8_t *> empty;
m_storageBlocks.swap(empty);
// start over:
m_blockAllocationSize = g_startBytesPerBlock;
m_subIndex = g_maxBytesPerBlock;
}

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -421,16 +421,18 @@ void StandardShapes::MakeCone(ai_real height, ai_real radius1,
positions.push_back(v3);
if (!bOpen) {
const ai_real zero(0.0);
// generate the end 'cap'
positions.emplace_back(s * radius2, halfHeight, t * radius2);
positions.emplace_back(s2 * radius2, halfHeight, t2 * radius2);
positions.emplace_back(0.0, halfHeight, 0.0);
positions.emplace_back(zero, halfHeight, zero);
if (radius1) {
// generate the other end 'cap'
positions.emplace_back(s * radius1, -halfHeight, t * radius1);
positions.emplace_back(s2 * radius1, -halfHeight, t2 * radius1);
positions.emplace_back(0.0, -halfHeight, 0.0);
positions.emplace_back(zero, -halfHeight, zero);
}
}
s = s2;
@ -466,13 +468,14 @@ void StandardShapes::MakeCircle(ai_real radius, unsigned int tess,
ai_real t = 0.0; // std::sin(angle == 0);
for (ai_real angle = 0.0; angle < angle_max;) {
positions.emplace_back(s * radius, 0.0, t * radius);
const ai_real zero(0.0);
positions.emplace_back(s * radius, zero, t * radius);
angle += angle_delta;
s = std::cos(angle);
t = std::sin(angle);
positions.emplace_back(s * radius, 0.0, t * radius);
positions.emplace_back(s * radius, zero, t * radius);
positions.emplace_back(0.0, 0.0, 0.0);
positions.emplace_back(zero, zero, zero);
}
}

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -48,6 +48,71 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma GCC diagnostic ignored "-Wunused-function"
#endif
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-function"
#endif
#ifndef STB_USE_HUNTER
/* Use prefixed names for the symbols from stb_image as it is a very commonly embedded library.
Including vanilla stb_image symbols causes duplicate symbol problems if assimp is linked
statically together with another library or executable that also embeds stb_image.
Symbols are not prefixed if using Hunter because in such case there exists a single true
stb_image library on the system that is used by assimp and can be used by all the other
libraries and executables.
The list can be regenerated using the following:
cat "path/to/stb/stb_image.h" | fgrep STBIDEF | fgrep '(' | sed -E 's/\*|\(.+//g' | \
awk '{print "#define " $(NF) " assimp_" $(NF) }' | sort | uniq
*/
#define stbi_convert_iphone_png_to_rgb assimp_stbi_convert_iphone_png_to_rgb
#define stbi_convert_iphone_png_to_rgb_thread assimp_stbi_convert_iphone_png_to_rgb_thread
#define stbi_convert_wchar_to_utf8 assimp_stbi_convert_wchar_to_utf8
#define stbi_failure_reason assimp_stbi_failure_reason
#define stbi_hdr_to_ldr_gamma assimp_stbi_hdr_to_ldr_gamma
#define stbi_hdr_to_ldr_scale assimp_stbi_hdr_to_ldr_scale
#define stbi_image_free assimp_stbi_image_free
#define stbi_info assimp_stbi_info
#define stbi_info_from_callbacks assimp_stbi_info_from_callbacks
#define stbi_info_from_file assimp_stbi_info_from_file
#define stbi_info_from_memory assimp_stbi_info_from_memory
#define stbi_is_16_bit assimp_stbi_is_16_bit
#define stbi_is_16_bit_from_callbacks assimp_stbi_is_16_bit_from_callbacks
#define stbi_is_16_bit_from_file assimp_stbi_is_16_bit_from_file
#define stbi_is_16_bit_from_memory assimp_stbi_is_16_bit_from_memory
#define stbi_is_hdr assimp_stbi_is_hdr
#define stbi_is_hdr_from_callbacks assimp_stbi_is_hdr_from_callbacks
#define stbi_is_hdr_from_file assimp_stbi_is_hdr_from_file
#define stbi_is_hdr_from_memory assimp_stbi_is_hdr_from_memory
#define stbi_ldr_to_hdr_gamma assimp_stbi_ldr_to_hdr_gamma
#define stbi_ldr_to_hdr_scale assimp_stbi_ldr_to_hdr_scale
#define stbi_load assimp_stbi_load
#define stbi_load_16 assimp_stbi_load_16
#define stbi_load_16_from_callbacks assimp_stbi_load_16_from_callbacks
#define stbi_load_16_from_memory assimp_stbi_load_16_from_memory
#define stbi_load_from_callbacks assimp_stbi_load_from_callbacks
#define stbi_load_from_file assimp_stbi_load_from_file
#define stbi_load_from_file_16 assimp_stbi_load_from_file_16
#define stbi_load_from_memory assimp_stbi_load_from_memory
#define stbi_load_gif_from_memory assimp_stbi_load_gif_from_memory
#define stbi_loadf assimp_stbi_loadf
#define stbi_loadf_from_callbacks assimp_stbi_loadf_from_callbacks
#define stbi_loadf_from_file assimp_stbi_loadf_from_file
#define stbi_loadf_from_memory assimp_stbi_loadf_from_memory
#define stbi_set_flip_vertically_on_load assimp_stbi_set_flip_vertically_on_load
#define stbi_set_flip_vertically_on_load_thread assimp_stbi_set_flip_vertically_on_load_thread
#define stbi_set_unpremultiply_on_load assimp_stbi_set_unpremultiply_on_load
#define stbi_set_unpremultiply_on_load_thread assimp_stbi_set_unpremultiply_on_load_thread
#define stbi_zlib_decode_buffer assimp_stbi_zlib_decode_buffer
#define stbi_zlib_decode_malloc assimp_stbi_zlib_decode_malloc
#define stbi_zlib_decode_malloc_guesssize assimp_stbi_zlib_decode_malloc_guesssize
#define stbi_zlib_decode_malloc_guesssize_headerflag assimp_stbi_zlib_decode_malloc_guesssize_headerflag
#define stbi_zlib_decode_noheader_buffer assimp_stbi_zlib_decode_noheader_buffer
#define stbi_zlib_decode_noheader_malloc assimp_stbi_zlib_decode_noheader_malloc
#endif
#include "stb/stb_image.h"
#if _MSC_VER
@ -56,3 +121,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma GCC diagnostic pop
#endif
#if defined(__clang__)
#pragma clang diagnostic pop
#endif

View file

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team

View file

@ -2,8 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -50,7 +49,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdio.h>
#include <unordered_map>
using namespace Assimp;
void mydummy() {}
#ifdef _MSC_VER
@ -78,7 +80,7 @@ public:
};
typedef std::vector<unsigned int> UIntVector;
typedef std::map<uint64_t, Edge> EdgeMap;
typedef std::unordered_map<uint64_t, Edge> EdgeMap;
// ---------------------------------------------------------------------------
// Hashing function to derive an index into an #EdgeMap from two given
@ -522,7 +524,11 @@ void CatmullClarkSubdivider::InternSubdivide(
}
}
ai_assert(adj[o] - moffsets[nidx].first < mp->mNumFaces);
if (mp == nullptr) {
continue;
}
ai_assert(adj[o] - moffsets[nidx].first < mp->mNumFaces);
const aiFace &f = mp->mFaces[adj[o] - moffsets[nidx].first];
bool haveit = false;

View file

@ -2,8 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.

View file

@ -2,8 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -119,12 +118,16 @@ private:
* look-at target */
class TargetAnimationHelper {
public:
/// @brief The class constructor.
TargetAnimationHelper() :
targetPositions(nullptr),
objectPositions(nullptr) {
// empty
}
/// @brief The class destructor.
~TargetAnimationHelper() = default;
// ------------------------------------------------------------------
/** Sets the target animation channel
*

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.
@ -44,15 +44,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "ScenePrivate.h"
#include <assimp/scene.h>
#include <assimp/version.h>
#include "revision.h"
#include <assimp/revision.h>
// --------------------------------------------------------------------------------
// Legal information string - don't remove this.
static const char *LEGAL_INFORMATION =
static constexpr char LEGAL_INFORMATION[] =
"Open Asset Import Library (Assimp).\n"
"A free C/C++ library to import various 3D file formats into applications\n\n"
"(c) 2006-2022, Assimp team\n"
"(c) 2006-2024, Assimp team\n"
"License under the terms and conditions of the 3-clause BSD license\n"
"https://www.assimp.org\n";
@ -118,73 +117,3 @@ ASSIMP_API const char *aiGetBranchName() {
return GitBranch;
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API aiScene::aiScene() :
mFlags(0),
mRootNode(nullptr),
mNumMeshes(0),
mMeshes(nullptr),
mNumMaterials(0),
mMaterials(nullptr),
mNumAnimations(0),
mAnimations(nullptr),
mNumTextures(0),
mTextures(nullptr),
mNumLights(0),
mLights(nullptr),
mNumCameras(0),
mCameras(nullptr),
mMetaData(nullptr),
mName(),
mNumSkeletons(0),
mSkeletons(nullptr),
mPrivate(new Assimp::ScenePrivateData()) {
// empty
}
// ------------------------------------------------------------------------------------------------
ASSIMP_API aiScene::~aiScene() {
// delete all sub-objects recursively
delete mRootNode;
// To make sure we won't crash if the data is invalid it's
// much better to check whether both mNumXXX and mXXX are
// valid instead of relying on just one of them.
if (mNumMeshes && mMeshes)
for (unsigned int a = 0; a < mNumMeshes; a++)
delete mMeshes[a];
delete[] mMeshes;
if (mNumMaterials && mMaterials) {
for (unsigned int a = 0; a < mNumMaterials; ++a) {
delete mMaterials[a];
}
}
delete[] mMaterials;
if (mNumAnimations && mAnimations)
for (unsigned int a = 0; a < mNumAnimations; a++)
delete mAnimations[a];
delete[] mAnimations;
if (mNumTextures && mTextures)
for (unsigned int a = 0; a < mNumTextures; a++)
delete mTextures[a];
delete[] mTextures;
if (mNumLights && mLights)
for (unsigned int a = 0; a < mNumLights; a++)
delete mLights[a];
delete[] mLights;
if (mNumCameras && mCameras)
for (unsigned int a = 0; a < mNumCameras; a++)
delete mCameras[a];
delete[] mCameras;
aiMetadata::Dealloc(mMetaData);
delete[] mSkeletons;
delete static_cast<Assimp::ScenePrivateData *>(mPrivate);
}

View file

@ -3,9 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.

View file

@ -3,7 +3,7 @@
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.
@ -62,13 +62,13 @@ namespace Assimp {
// ----------------------------------------------------------------
// A read-only file inside a ZIP
class ZipFile : public IOStream {
class ZipFile final : public IOStream {
friend class ZipFileInfo;
explicit ZipFile(std::string &filename, size_t size);
public:
std::string m_Filename;
virtual ~ZipFile();
~ZipFile() override = default;
// IOStream interface
size_t Read(void *pvBuffer, size_t pSize, size_t pCount) override;
@ -89,6 +89,8 @@ private:
// Wraps an existing Assimp::IOSystem for unzip
class IOSystem2Unzip {
public:
IOSystem2Unzip() = default;
~IOSystem2Unzip() = default;
static voidpf open(voidpf opaque, const char *filename, int mode);
static voidpf opendisk(voidpf opaque, voidpf stream, uint32_t number_disk, int mode);
static uLong read(voidpf opaque, voidpf stream, void *buf, uLong size);
@ -100,6 +102,7 @@ public:
static zlib_filefunc_def get(IOSystem *pIOHandler);
};
// ----------------------------------------------------------------
voidpf IOSystem2Unzip::open(voidpf opaque, const char *filename, int mode) {
IOSystem *io_system = reinterpret_cast<IOSystem *>(opaque);
@ -119,9 +122,10 @@ voidpf IOSystem2Unzip::open(voidpf opaque, const char *filename, int mode) {
return (voidpf)io_system->Open(filename, mode_fopen);
}
// ----------------------------------------------------------------
voidpf IOSystem2Unzip::opendisk(voidpf opaque, voidpf stream, uint32_t number_disk, int mode) {
ZipFile *io_stream = (ZipFile *)stream;
voidpf ret = NULL;
voidpf ret = nullptr;
int i;
char *disk_filename = (char*)malloc(io_stream->m_Filename.length() + 1);
@ -141,24 +145,28 @@ voidpf IOSystem2Unzip::opendisk(voidpf opaque, voidpf stream, uint32_t number_di
return ret;
}
// ----------------------------------------------------------------
uLong IOSystem2Unzip::read(voidpf /*opaque*/, voidpf stream, void *buf, uLong size) {
IOStream *io_stream = (IOStream *)stream;
return static_cast<uLong>(io_stream->Read(buf, 1, size));
}
// ----------------------------------------------------------------
uLong IOSystem2Unzip::write(voidpf /*opaque*/, voidpf stream, const void *buf, uLong size) {
IOStream *io_stream = (IOStream *)stream;
return static_cast<uLong>(io_stream->Write(buf, 1, size));
}
// ----------------------------------------------------------------
long IOSystem2Unzip::tell(voidpf /*opaque*/, voidpf stream) {
IOStream *io_stream = (IOStream *)stream;
return static_cast<long>(io_stream->Tell());
}
// ----------------------------------------------------------------
long IOSystem2Unzip::seek(voidpf /*opaque*/, voidpf stream, uLong offset, int origin) {
IOStream *io_stream = (IOStream *)stream;
@ -179,6 +187,7 @@ long IOSystem2Unzip::seek(voidpf /*opaque*/, voidpf stream, uLong offset, int or
return (io_stream->Seek(offset, assimp_origin) == aiReturn_SUCCESS ? 0 : -1);
}
// ----------------------------------------------------------------
int IOSystem2Unzip::close(voidpf opaque, voidpf stream) {
IOSystem *io_system = (IOSystem *)opaque;
IOStream *io_stream = (IOStream *)stream;
@ -188,10 +197,12 @@ int IOSystem2Unzip::close(voidpf opaque, voidpf stream) {
return 0;
}
// ----------------------------------------------------------------
int IOSystem2Unzip::testerror(voidpf /*opaque*/, voidpf /*stream*/) {
return 0;
}
// ----------------------------------------------------------------
zlib_filefunc_def IOSystem2Unzip::get(IOSystem *pIOHandler) {
zlib_filefunc_def mapping;
@ -213,9 +224,10 @@ zlib_filefunc_def IOSystem2Unzip::get(IOSystem *pIOHandler) {
// ----------------------------------------------------------------
// Info about a read-only file inside a ZIP
class ZipFileInfo {
class ZipFileInfo final {
public:
explicit ZipFileInfo(unzFile zip_handle, size_t size);
~ZipFileInfo() = default;
// Allocate and Extract data from the ZIP
ZipFile *Extract(std::string &filename, unzFile zip_handle) const;
@ -225,6 +237,7 @@ private:
unz_file_pos_s m_ZipFilePos;
};
// ----------------------------------------------------------------
ZipFileInfo::ZipFileInfo(unzFile zip_handle, size_t size) :
m_Size(size) {
ai_assert(m_Size != 0);
@ -234,6 +247,7 @@ ZipFileInfo::ZipFileInfo(unzFile zip_handle, size_t size) :
unzGetFilePos(zip_handle, &(m_ZipFilePos));
}
// ----------------------------------------------------------------
ZipFile *ZipFileInfo::Extract(std::string &filename, unzFile zip_handle) const {
// Find in the ZIP. This cannot fail
unz_file_pos_s *filepos = const_cast<unz_file_pos_s *>(&(m_ZipFilePos));
@ -273,14 +287,14 @@ ZipFile *ZipFileInfo::Extract(std::string &filename, unzFile zip_handle) const {
return zip_file;
}
// ----------------------------------------------------------------
ZipFile::ZipFile(std::string &filename, size_t size) :
m_Filename(filename), m_Size(size) {
ai_assert(m_Size != 0);
m_Buffer = std::unique_ptr<uint8_t[]>(new uint8_t[m_Size]);
}
ZipFile::~ZipFile() = default;
// ----------------------------------------------------------------
size_t ZipFile::Read(void *pvBuffer, size_t pSize, size_t pCount) {
// Should be impossible
ai_assert(m_Buffer != nullptr);
@ -305,10 +319,12 @@ size_t ZipFile::Read(void *pvBuffer, size_t pSize, size_t pCount) {
return pCount;
}
// ----------------------------------------------------------------
size_t ZipFile::FileSize() const {
return m_Size;
}
// ----------------------------------------------------------------
aiReturn ZipFile::Seek(size_t pOffset, aiOrigin pOrigin) {
switch (pOrigin) {
case aiOrigin_SET: {
@ -334,6 +350,7 @@ aiReturn ZipFile::Seek(size_t pOffset, aiOrigin pOrigin) {
return aiReturn_FAILURE;
}
// ----------------------------------------------------------------
size_t ZipFile::Tell() const {
return m_SeekPtr;
}
@ -365,6 +382,7 @@ private:
ZipFileInfoMap m_ArchiveMap;
};
// ----------------------------------------------------------------
ZipArchiveIOSystem::Implement::Implement(IOSystem *pIOHandler, const char *pFilename, const char *pMode) {
ai_assert(strcmp(pMode, "r") == 0);
ai_assert(pFilename != nullptr);
@ -376,12 +394,14 @@ ZipArchiveIOSystem::Implement::Implement(IOSystem *pIOHandler, const char *pFile
m_ZipFileHandle = unzOpen2(pFilename, &mapping);
}
// ----------------------------------------------------------------
ZipArchiveIOSystem::Implement::~Implement() {
if (m_ZipFileHandle != nullptr) {
unzClose(m_ZipFileHandle);
}
}
// ----------------------------------------------------------------
void ZipArchiveIOSystem::Implement::MapArchive() {
if (m_ZipFileHandle == nullptr)
return;
@ -408,10 +428,12 @@ void ZipArchiveIOSystem::Implement::MapArchive() {
} while (unzGoToNextFile(m_ZipFileHandle) != UNZ_END_OF_LIST_OF_FILE);
}
// ----------------------------------------------------------------
bool ZipArchiveIOSystem::Implement::isOpen() const {
return (m_ZipFileHandle != nullptr);
}
// ----------------------------------------------------------------
void ZipArchiveIOSystem::Implement::getFileList(std::vector<std::string> &rFileList) {
MapArchive();
rFileList.clear();
@ -421,6 +443,7 @@ void ZipArchiveIOSystem::Implement::getFileList(std::vector<std::string> &rFileL
}
}
// ----------------------------------------------------------------
void ZipArchiveIOSystem::Implement::getFileListExtension(std::vector<std::string> &rFileList, const std::string &extension) {
MapArchive();
rFileList.clear();
@ -431,6 +454,7 @@ void ZipArchiveIOSystem::Implement::getFileListExtension(std::vector<std::string
}
}
// ----------------------------------------------------------------
bool ZipArchiveIOSystem::Implement::Exists(std::string &filename) {
MapArchive();
@ -438,6 +462,7 @@ bool ZipArchiveIOSystem::Implement::Exists(std::string &filename) {
return (it != m_ArchiveMap.end());
}
// ----------------------------------------------------------------
IOStream *ZipArchiveIOSystem::Implement::OpenFile(std::string &filename) {
MapArchive();
@ -452,6 +477,7 @@ IOStream *ZipArchiveIOSystem::Implement::OpenFile(std::string &filename) {
return zip_file.Extract(filename, m_ZipFileHandle);
}
// ----------------------------------------------------------------
inline void ReplaceAll(std::string &data, const std::string &before, const std::string &after) {
size_t pos = data.find(before);
while (pos != std::string::npos) {
@ -460,6 +486,7 @@ inline void ReplaceAll(std::string &data, const std::string &before, const std::
}
}
// ----------------------------------------------------------------
inline void ReplaceAllChar(std::string &data, const char before, const char after) {
size_t pos = data.find(before);
while (pos != std::string::npos) {
@ -468,6 +495,7 @@ inline void ReplaceAllChar(std::string &data, const char before, const char afte
}
}
// ----------------------------------------------------------------
void ZipArchiveIOSystem::Implement::SimplifyFilename(std::string &filename) {
ReplaceAllChar(filename, '\\', '/');
@ -492,6 +520,7 @@ void ZipArchiveIOSystem::Implement::SimplifyFilename(std::string &filename) {
}
}
// ----------------------------------------------------------------
ZipArchiveIOSystem::ZipArchiveIOSystem(IOSystem *pIOHandler, const char *pFilename, const char *pMode) :
pImpl(new Implement(pIOHandler, pFilename, pMode)) {
}
@ -502,10 +531,12 @@ ZipArchiveIOSystem::ZipArchiveIOSystem(IOSystem *pIOHandler, const std::string &
pImpl(new Implement(pIOHandler, rFilename.c_str(), pMode)) {
}
// ----------------------------------------------------------------
ZipArchiveIOSystem::~ZipArchiveIOSystem() {
delete pImpl;
}
// ----------------------------------------------------------------
bool ZipArchiveIOSystem::Exists(const char *pFilename) const {
ai_assert(pFilename != nullptr);
@ -517,11 +548,13 @@ bool ZipArchiveIOSystem::Exists(const char *pFilename) const {
return pImpl->Exists(filename);
}
// ----------------------------------------------------------------
// This is always '/' in a ZIP
char ZipArchiveIOSystem::getOsSeparator() const {
return '/';
}
// ----------------------------------------------------------------
// Only supports Reading
IOStream *ZipArchiveIOSystem::Open(const char *pFilename, const char *pMode) {
ai_assert(pFilename != nullptr);
@ -536,22 +569,27 @@ IOStream *ZipArchiveIOSystem::Open(const char *pFilename, const char *pMode) {
return pImpl->OpenFile(filename);
}
// ----------------------------------------------------------------
void ZipArchiveIOSystem::Close(IOStream *pFile) {
delete pFile;
}
// ----------------------------------------------------------------
bool ZipArchiveIOSystem::isOpen() const {
return (pImpl->isOpen());
}
// ----------------------------------------------------------------
void ZipArchiveIOSystem::getFileList(std::vector<std::string> &rFileList) const {
return pImpl->getFileList(rFileList);
}
// ----------------------------------------------------------------
void ZipArchiveIOSystem::getFileListExtension(std::vector<std::string> &rFileList, const std::string &extension) const {
return pImpl->getFileListExtension(rFileList, extension);
}
// ----------------------------------------------------------------
bool ZipArchiveIOSystem::isZipArchive(IOSystem *pIOHandler, const char *pFilename) {
Implement tmp(pIOHandler, pFilename, "r");
return tmp.isOpen();

View file

@ -2,7 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2022, assimp team
Copyright (c) 2006-2024, assimp team
All rights reserved.

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.
@ -40,6 +40,87 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <assimp/scene.h>
#include "ScenePrivate.h"
aiScene::aiScene() :
mFlags(0),
mRootNode(nullptr),
mNumMeshes(0),
mMeshes(nullptr),
mNumMaterials(0),
mMaterials(nullptr),
mNumAnimations(0),
mAnimations(nullptr),
mNumTextures(0),
mTextures(nullptr),
mNumLights(0),
mLights(nullptr),
mNumCameras(0),
mCameras(nullptr),
mMetaData(nullptr),
mName(),
mNumSkeletons(0),
mSkeletons(nullptr),
mPrivate(new Assimp::ScenePrivateData()) {
// empty
}
aiScene::~aiScene() {
// delete all sub-objects recursively
delete mRootNode;
// To make sure we won't crash if the data is invalid it's
// much better to check whether both mNumXXX and mXXX are
// valid instead of relying on just one of them.
if (mNumMeshes && mMeshes) {
for (unsigned int a = 0; a < mNumMeshes; ++a) {
delete mMeshes[a];
}
}
delete[] mMeshes;
if (mNumMaterials && mMaterials) {
for (unsigned int a = 0; a < mNumMaterials; ++a) {
delete mMaterials[a];
}
}
delete[] mMaterials;
if (mNumAnimations && mAnimations) {
for (unsigned int a = 0; a < mNumAnimations; ++a) {
delete mAnimations[a];
}
}
delete[] mAnimations;
if (mNumTextures && mTextures) {
for (unsigned int a = 0; a < mNumTextures; ++a) {
delete mTextures[a];
}
}
delete[] mTextures;
if (mNumLights && mLights) {
for (unsigned int a = 0; a < mNumLights; ++a) {
delete mLights[a];
}
}
delete[] mLights;
if (mNumCameras && mCameras) {
for (unsigned int a = 0; a < mNumCameras; ++a) {
delete mCameras[a];
}
}
delete[] mCameras;
aiMetadata::Dealloc(mMetaData);
delete[] mSkeletons;
delete static_cast<Assimp::ScenePrivateData *>(mPrivate);
}
aiNode::aiNode() :
mName(""),
mParent(nullptr),

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.

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.