Merge branch 'Artenuvielle-x3d_pugi_migration_artenuvielle' of https://github.com/assimp/assimp into Artenuvielle-x3d_pugi_migration_artenuvielle

pull/4170/head
Kim Kulling 2021-11-11 19:06:33 +01:00
commit eafb79e7dc
22 changed files with 251 additions and 141 deletions

View File

@ -53,7 +53,7 @@ IF(ASSIMP_HUNTER_ENABLED)
add_definitions(-DASSIMP_USE_HUNTER) add_definitions(-DASSIMP_USE_HUNTER)
ENDIF() ENDIF()
PROJECT( Assimp VERSION 5.0.1 ) PROJECT(Assimp VERSION 5.1.0)
# All supported options ############################################### # All supported options ###############################################

View File

@ -43,6 +43,7 @@ Take a look into the https://github.com/assimp/assimp/blob/master/Build.md file.
* [Pascal](port/AssimpPascal/Readme.md) * [Pascal](port/AssimpPascal/Readme.md)
* [Javascript (Alpha)](https://github.com/makc/assimp2json) * [Javascript (Alpha)](https://github.com/makc/assimp2json)
* [Unity 3d Plugin](https://ricardoreis.net/trilib-2/) * [Unity 3d Plugin](https://ricardoreis.net/trilib-2/)
* [Unreal Engine Plugin](https://github.com/irajsb/UE4_Assimp/)
* [JVM](https://github.com/kotlin-graphics/assimp) Full jvm port (current [status](https://github.com/kotlin-graphics/assimp/wiki/Status)) * [JVM](https://github.com/kotlin-graphics/assimp) Full jvm port (current [status](https://github.com/kotlin-graphics/assimp/wiki/Status))
* [HAXE-Port](https://github.com/longde123/assimp-haxe) The Assimp-HAXE-port. * [HAXE-Port](https://github.com/longde123/assimp-haxe) The Assimp-HAXE-port.
* [Rust](https://github.com/jkvargas/russimp) * [Rust](https://github.com/jkvargas/russimp)

View File

@ -149,7 +149,7 @@ D3MFOpcPackage::D3MFOpcPackage(IOSystem *pIOHandler, const std::string &rFile) :
IOStream *fileStream = mZipArchive->Open(file.c_str()); IOStream *fileStream = mZipArchive->Open(file.c_str());
if (nullptr == fileStream) { if (nullptr == fileStream) {
ai_assert(fileStream != nullptr); ASSIMP_LOG_ERROR("Filestream is nullptr.");
continue; continue;
} }

View File

@ -159,7 +159,6 @@ bool parseColor(const char *color, aiColor4D &diffuse) {
return false; return false;
} }
//const char *buf(color);
if ('#' != color[0]) { if ('#' != color[0]) {
return false; return false;
} }

View File

@ -451,6 +451,7 @@ void HMPImporter::ReadFirstSkin(unsigned int iNumSkins, const unsigned char *szC
// now we need to skip any other skins ... // now we need to skip any other skins ...
for (unsigned int i = 1; i < iNumSkins; ++i) { for (unsigned int i = 1; i < iNumSkins; ++i) {
SizeCheck(szCursor + 3 * sizeof(uint32_t));
iType = *((uint32_t *)szCursor); iType = *((uint32_t *)szCursor);
szCursor += sizeof(uint32_t); szCursor += sizeof(uint32_t);
iWidth = *((uint32_t *)szCursor); iWidth = *((uint32_t *)szCursor);

View File

@ -896,7 +896,7 @@ char *_m3d_safestr(char *in, int morelines) {
if (!out) return NULL; if (!out) return NULL;
while (*i == ' ' || *i == '\t' || *i == '\r' || (morelines && *i == '\n')) while (*i == ' ' || *i == '\t' || *i == '\r' || (morelines && *i == '\n'))
i++; i++;
for (; *i && (morelines || (*i != '\r' && *i != '\n')); i++) { for (; *i && (morelines || (*i != '\r' && *i != '\n')) && o - out < l; i++) {
if (*i == '\r') continue; if (*i == '\r') continue;
if (*i == '\n') { if (*i == '\n') {
if (morelines >= 3 && o > out && *(o - 1) == '\n') break; if (morelines >= 3 && o > out && *(o - 1) == '\n') break;

View File

@ -600,7 +600,7 @@ void MDLImporter::InternReadFile_3DGS_MDL345() {
// need to read all textures // need to read all textures
for (unsigned int i = 0; i < (unsigned int)pcHeader->num_skins; ++i) { for (unsigned int i = 0; i < (unsigned int)pcHeader->num_skins; ++i) {
if (szCurrent >= szEnd) { if (szCurrent + sizeof(uint32_t) > szEnd) {
throw DeadlyImportError("Texture data past end of file."); throw DeadlyImportError("Texture data past end of file.");
} }
BE_NCONST MDL::Skin *pcSkin; BE_NCONST MDL::Skin *pcSkin;

View File

@ -132,6 +132,9 @@ void MDLImporter::CreateTextureARGB8_3DGS_MDL3(const unsigned char *szData) {
pcNew->mWidth = pcHeader->skinwidth; pcNew->mWidth = pcHeader->skinwidth;
pcNew->mHeight = pcHeader->skinheight; pcNew->mHeight = pcHeader->skinheight;
if(pcNew->mWidth != 0 && pcNew->mHeight > UINT_MAX/pcNew->mWidth) {
throw DeadlyImportError("Invalid MDL file. A texture is too big.");
}
pcNew->pcData = new aiTexel[pcNew->mWidth * pcNew->mHeight]; pcNew->pcData = new aiTexel[pcNew->mWidth * pcNew->mHeight];
const unsigned char *szColorMap; const unsigned char *szColorMap;
@ -217,6 +220,9 @@ void MDLImporter::ParseTextureColorData(const unsigned char *szData,
// allocate storage for the texture image // allocate storage for the texture image
if (do_read) { if (do_read) {
if(pcNew->mWidth != 0 && pcNew->mHeight > UINT_MAX/pcNew->mWidth) {
throw DeadlyImportError("Invalid MDL file. A texture is too big.");
}
pcNew->pcData = new aiTexel[pcNew->mWidth * pcNew->mHeight]; pcNew->pcData = new aiTexel[pcNew->mWidth * pcNew->mHeight];
} }

View File

@ -325,7 +325,7 @@ std::shared_ptr<const EXPRESS::DataType> EXPRESS::DataType::Parse(const char*& i
std::transform(s.begin(),s.end(),s.begin(),&ai_tolower<char> ); std::transform(s.begin(),s.end(),s.begin(),&ai_tolower<char> );
if (schema->IsKnownToken(s)) { if (schema->IsKnownToken(s)) {
for(cur = t+1;*cur++ != '(';); for(cur = t+1;*cur++ != '(';);
const std::shared_ptr<const EXPRESS::DataType> dt = Parse(cur); std::shared_ptr<const EXPRESS::DataType> dt = Parse(cur);
inout = *cur ? cur+1 : cur; inout = *cur ? cur+1 : cur;
return dt; return dt;
} }

View File

@ -300,13 +300,14 @@ private:
const char separator = getOsSeparator(); const char separator = getOsSeparator();
for (it = in.begin(); it != in.end(); ++it) { for (it = in.begin(); it != in.end(); ++it) {
int remaining = std::distance(in.end(), it);
// Exclude :// and \\, which remain untouched. // Exclude :// and \\, which remain untouched.
// https://sourceforge.net/tracker/?func=detail&aid=3031725&group_id=226462&atid=1067632 // https://sourceforge.net/tracker/?func=detail&aid=3031725&group_id=226462&atid=1067632
if ( !strncmp(&*it, "://", 3 )) { if (remaining >= 3 && !strncmp(&*it, "://", 3 )) {
it += 3; it += 3;
continue; continue;
} }
if (it == in.begin() && !strncmp(&*it, "\\\\", 2)) { if (it == in.begin() && remaining >= 2 && !strncmp(&*it, "\\\\", 2)) {
it += 2; it += 2;
continue; continue;
} }

View File

@ -64,20 +64,28 @@ void CommentRemover::RemoveLineComments(const char* szComment,
if (len > lenBuffer) { if (len > lenBuffer) {
len = lenBuffer; len = lenBuffer;
} }
while (*szBuffer) {
char *szCurrent = szBuffer;
while (*szCurrent) {
// skip over quotes // skip over quotes
if (*szBuffer == '\"' || *szBuffer == '\'') if (*szCurrent == '\"' || *szCurrent == '\'')
while (*szBuffer++ && *szBuffer != '\"' && *szBuffer != '\''); while (*szCurrent++ && *szCurrent != '\"' && *szCurrent != '\'');
if (!strncmp(szBuffer,szComment,len)) {
while (!IsLineEnd(*szBuffer))
*szBuffer++ = chReplacement;
if (!*szBuffer) { size_t lenRemaining = lenBuffer - (szCurrent - szBuffer);
if(lenRemaining < len) {
break;
}
if (!strncmp(szCurrent,szComment,len)) {
while (!IsLineEnd(*szCurrent))
*szCurrent++ = chReplacement;
if (!*szCurrent) {
break; break;
} }
} }
++szBuffer; ++szCurrent;
} }
} }

View File

@ -58,14 +58,16 @@ const aiVector3D PlaneInit(0.8523f, 0.34321f, 0.5736f);
// define the reference plane. We choose some arbitrary vector away from all basic axes // 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. // in the hope that no model spreads all its vertices along this plane.
SpatialSort::SpatialSort(const aiVector3D *pPositions, unsigned int pNumPositions, unsigned int pElementOffset) : SpatialSort::SpatialSort(const aiVector3D *pPositions, unsigned int pNumPositions, unsigned int pElementOffset) :
mPlaneNormal(PlaneInit) { mPlaneNormal(PlaneInit),
mFinalized(false) {
mPlaneNormal.Normalize(); mPlaneNormal.Normalize();
Fill(pPositions, pNumPositions, pElementOffset); Fill(pPositions, pNumPositions, pElementOffset);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
SpatialSort::SpatialSort() : SpatialSort::SpatialSort() :
mPlaneNormal(PlaneInit) { mPlaneNormal(PlaneInit),
mFinalized(false) {
mPlaneNormal.Normalize(); mPlaneNormal.Normalize();
} }
@ -80,28 +82,41 @@ void SpatialSort::Fill(const aiVector3D *pPositions, unsigned int pNumPositions,
unsigned int pElementOffset, unsigned int pElementOffset,
bool pFinalize /*= true */) { bool pFinalize /*= true */) {
mPositions.clear(); mPositions.clear();
mFinalized = false;
Append(pPositions, pNumPositions, pElementOffset, pFinalize); Append(pPositions, pNumPositions, pElementOffset, pFinalize);
mFinalized = pFinalize;
}
// ------------------------------------------------------------------------------------------------
ai_real SpatialSort::CalculateDistance(const aiVector3D &pPosition) const {
return (pPosition - mCentroid) * mPlaneNormal;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void SpatialSort::Finalize() { 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;
}
for (unsigned int i = 0; i < mPositions.size(); i++) {
mPositions[i].mDistance = CalculateDistance(mPositions[i].mPosition);
}
std::sort(mPositions.begin(), mPositions.end()); std::sort(mPositions.begin(), mPositions.end());
mFinalized = true;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void SpatialSort::Append(const aiVector3D *pPositions, unsigned int pNumPositions, void SpatialSort::Append(const aiVector3D *pPositions, unsigned int pNumPositions,
unsigned int pElementOffset, unsigned int pElementOffset,
bool pFinalize /*= true */) { bool pFinalize /*= true */) {
ai_assert(!mFinalized && "You cannot add positions to the SpatialSort object after it has been finalized.");
// store references to all given positions along with their distance to the reference plane // store references to all given positions along with their distance to the reference plane
const size_t initial = mPositions.size(); const size_t initial = mPositions.size();
mPositions.reserve(initial + (pFinalize ? pNumPositions : pNumPositions * 2)); mPositions.reserve(initial + pNumPositions);
for (unsigned int a = 0; a < pNumPositions; a++) { for (unsigned int a = 0; a < pNumPositions; a++) {
const char *tempPointer = reinterpret_cast<const char *>(pPositions); const char *tempPointer = reinterpret_cast<const char *>(pPositions);
const aiVector3D *vec = reinterpret_cast<const aiVector3D *>(tempPointer + a * pElementOffset); const aiVector3D *vec = reinterpret_cast<const aiVector3D *>(tempPointer + a * pElementOffset);
mPositions.push_back(Entry(static_cast<unsigned int>(a + initial), *vec));
// store position by index and distance
ai_real distance = *vec * mPlaneNormal;
mPositions.push_back(Entry(static_cast<unsigned int>(a + initial), *vec, distance));
} }
if (pFinalize) { if (pFinalize) {
@ -114,7 +129,8 @@ void SpatialSort::Append(const aiVector3D *pPositions, unsigned int pNumPosition
// Returns an iterator for all positions close to the given position. // Returns an iterator for all positions close to the given position.
void SpatialSort::FindPositions(const aiVector3D &pPosition, void SpatialSort::FindPositions(const aiVector3D &pPosition,
ai_real pRadius, std::vector<unsigned int> &poResults) const { ai_real pRadius, std::vector<unsigned int> &poResults) const {
const ai_real dist = pPosition * mPlaneNormal; ai_assert(mFinalized && "The SpatialSort object must be finalized before FindPositions can be called.");
const ai_real dist = CalculateDistance(pPosition);
const ai_real minDist = dist - pRadius, maxDist = dist + pRadius; const ai_real minDist = dist - pRadius, maxDist = dist + pRadius;
// clear the array // clear the array
@ -229,6 +245,7 @@ BinFloat ToBinary(const ai_real &pValue) {
// Fills an array with indices of all positions identical to the given position. In opposite to // Fills an array with indices of all positions identical to the given position. In opposite to
// FindPositions(), not an epsilon is used but a (very low) tolerance of four floating-point units. // FindPositions(), not an epsilon is used but a (very low) tolerance of four floating-point units.
void SpatialSort::FindIdenticalPositions(const aiVector3D &pPosition, std::vector<unsigned int> &poResults) const { void SpatialSort::FindIdenticalPositions(const aiVector3D &pPosition, std::vector<unsigned int> &poResults) const {
ai_assert(mFinalized && "The SpatialSort object must be finalized before FindIdenticalPositions can be called.");
// Epsilons have a huge disadvantage: they are of constant precision, while floating-point // Epsilons have a huge disadvantage: they are of constant precision, while floating-point
// values are of log2 precision. If you apply e=0.01 to 100, the epsilon is rather small, but // values are of log2 precision. If you apply e=0.01 to 100, the epsilon is rather small, but
// if you apply it to 0.001, it is enormous. // if you apply it to 0.001, it is enormous.
@ -254,7 +271,7 @@ void SpatialSort::FindIdenticalPositions(const aiVector3D &pPosition, std::vecto
// Convert the plane distance to its signed integer representation so the ULPs tolerance can be // Convert the plane distance to its signed integer representation so the ULPs tolerance can be
// applied. For some reason, VC won't optimize two calls of the bit pattern conversion. // applied. For some reason, VC won't optimize two calls of the bit pattern conversion.
const BinFloat minDistBinary = ToBinary(pPosition * mPlaneNormal) - distanceToleranceInULPs; const BinFloat minDistBinary = ToBinary(CalculateDistance(pPosition)) - distanceToleranceInULPs;
const BinFloat maxDistBinary = minDistBinary + 2 * distanceToleranceInULPs; const BinFloat maxDistBinary = minDistBinary + 2 * distanceToleranceInULPs;
// clear the array in this strange fashion because a simple clear() would also deallocate // clear the array in this strange fashion because a simple clear() would also deallocate
@ -297,13 +314,14 @@ void SpatialSort::FindIdenticalPositions(const aiVector3D &pPosition, std::vecto
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
unsigned int SpatialSort::GenerateMappingTable(std::vector<unsigned int> &fill, ai_real pRadius) const { unsigned int SpatialSort::GenerateMappingTable(std::vector<unsigned int> &fill, ai_real pRadius) const {
ai_assert(mFinalized && "The SpatialSort object must be finalized before GenerateMappingTable can be called.");
fill.resize(mPositions.size(), UINT_MAX); fill.resize(mPositions.size(), UINT_MAX);
ai_real dist, maxDist; ai_real dist, maxDist;
unsigned int t = 0; unsigned int t = 0;
const ai_real pSquared = pRadius * pRadius; const ai_real pSquared = pRadius * pRadius;
for (size_t i = 0; i < mPositions.size();) { for (size_t i = 0; i < mPositions.size();) {
dist = mPositions[i].mPosition * mPlaneNormal; dist = (mPositions[i].mPosition - mCentroid) * mPlaneNormal;
maxDist = dist + pRadius; maxDist = dist + pRadius;
fill[mPositions[i].mIndex] = t; fill[mPositions[i].mIndex] = t;

View File

@ -292,12 +292,15 @@ char *OpenDDLParser::parseHeader(char *in, char *end) {
Property *first(nullptr); Property *first(nullptr);
in = lookForNextToken(in, end); in = lookForNextToken(in, end);
if (*in == Grammar::OpenPropertyToken[0]) { if (in != end && *in == Grammar::OpenPropertyToken[0]) {
in++; in++;
Property *prop(nullptr), *prev(nullptr); Property *prop(nullptr), *prev(nullptr);
while (*in != Grammar::ClosePropertyToken[0] && in != end) { while (in != end && *in != Grammar::ClosePropertyToken[0]) {
in = OpenDDLParser::parseProperty(in, end, &prop); in = OpenDDLParser::parseProperty(in, end, &prop);
in = lookForNextToken(in, end); in = lookForNextToken(in, end);
if(in == end) {
break;
}
if (*in != Grammar::CommaSeparator[0] && *in != Grammar::ClosePropertyToken[0]) { if (*in != Grammar::CommaSeparator[0] && *in != Grammar::ClosePropertyToken[0]) {
logInvalidTokenError(in, Grammar::ClosePropertyToken, m_logCallback); logInvalidTokenError(in, Grammar::ClosePropertyToken, m_logCallback);
@ -314,8 +317,10 @@ char *OpenDDLParser::parseHeader(char *in, char *end) {
prev = prop; prev = prop;
} }
} }
if(in != end) {
++in; ++in;
} }
}
// set the properties // set the properties
if (nullptr != first && nullptr != node) { if (nullptr != first && nullptr != node) {
@ -479,7 +484,7 @@ void OpenDDLParser::normalizeBuffer(std::vector<char> &buffer) {
// check for a comment // check for a comment
if (isCommentOpenTag(c, end)) { if (isCommentOpenTag(c, end)) {
++readIdx; ++readIdx;
while (!isCommentCloseTag(&buffer[readIdx], end)) { while (readIdx < len && !isCommentCloseTag(&buffer[readIdx], end)) {
++readIdx; ++readIdx;
} }
++readIdx; ++readIdx;
@ -489,7 +494,7 @@ void OpenDDLParser::normalizeBuffer(std::vector<char> &buffer) {
if (isComment<char>(c, end)) { if (isComment<char>(c, end)) {
++readIdx; ++readIdx;
// skip the comment and the rest of the line // skip the comment and the rest of the line
while (!isEndofLine(buffer[readIdx])) { while (readIdx < len && !isEndofLine(buffer[readIdx])) {
++readIdx; ++readIdx;
} }
} }
@ -548,8 +553,7 @@ char *OpenDDLParser::parseIdentifier(char *in, char *end, Text **id) {
// get size of id // get size of id
size_t idLen(0); size_t idLen(0);
char *start(in); char *start(in);
while (!isSeparator(*in) && while ((in != end) && !isSeparator(*in) && !isNewLine(*in) &&
!isNewLine(*in) && (in != end) &&
*in != Grammar::OpenPropertyToken[0] && *in != Grammar::OpenPropertyToken[0] &&
*in != Grammar::ClosePropertyToken[0] && *in != Grammar::ClosePropertyToken[0] &&
*in != '$') { *in != '$') {
@ -861,7 +865,7 @@ char *OpenDDLParser::parseProperty(char *in, char *end, Property **prop) {
in = parseIdentifier(in, end, &id); in = parseIdentifier(in, end, &id);
if (nullptr != id) { if (nullptr != id) {
in = lookForNextToken(in, end); in = lookForNextToken(in, end);
if (*in == '=') { if (in != end && *in == '=') {
++in; ++in;
in = getNextToken(in, end); in = getNextToken(in, end);
Value *primData(nullptr); Value *primData(nullptr);

View File

@ -318,7 +318,8 @@ static const unsigned char chartype_table[256] = {
template <class T> template <class T>
inline bool isNumeric(const T in) { inline bool isNumeric(const T in) {
return (chartype_table[static_cast<size_t>(in)] == 1); size_t idx = static_cast<size_t>(in);
return idx < sizeof(chartype_table) && (chartype_table[idx] == 1);
} }
template <class T> template <class T>

View File

@ -261,6 +261,11 @@ AI_FORCE_INLINE bool IOStreamBuffer<T>::getNextDataLine(std::vector<T> &buffer,
buffer[i] = m_cache[m_cachePos]; buffer[i] = m_cache[m_cachePos];
++m_cachePos; ++m_cachePos;
++i; ++i;
if(i == buffer.size()) {
buffer.resize(buffer.size() * 2);
}
if (m_cachePos >= size()) { if (m_cachePos >= size()) {
break; break;
} }
@ -308,6 +313,11 @@ AI_FORCE_INLINE bool IOStreamBuffer<T>::getNextLine(std::vector<T> &buffer) {
buffer[i] = m_cache[m_cachePos]; buffer[i] = m_cache[m_cachePos];
++m_cachePos; ++m_cachePos;
++i; ++i;
if(i == buffer.size()) {
buffer.resize(buffer.size() * 2);
}
if (m_cachePos >= m_cacheSize) { if (m_cachePos >= m_cacheSize) {
if (!readNextBlock()) { if (!readNextBlock()) {
return false; return false;

View File

@ -51,6 +51,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/types.h> #include <assimp/types.h>
#include <vector> #include <vector>
#include <limits>
namespace Assimp { namespace Assimp {
@ -142,24 +143,35 @@ public:
ai_real pRadius) const; ai_real pRadius) const;
protected: protected:
/** Normal of the sorting plane, normalized. The center is always at (0, 0, 0) */ /** Return the distance to the sorting plane. */
ai_real CalculateDistance(const aiVector3D &pPosition) const;
protected:
/** Normal of the sorting plane, normalized.
*/
aiVector3D mPlaneNormal; aiVector3D mPlaneNormal;
/** The centroid of the positions, which is used as a point on the sorting plane
* when calculating distance. This value is calculated in Finalize.
*/
aiVector3D mCentroid;
/** An entry in a spatially sorted position array. Consists of a vertex index, /** An entry in a spatially sorted position array. Consists of a vertex index,
* its position and its pre-calculated distance from the reference plane */ * its position and its pre-calculated distance from the reference plane */
struct Entry { struct Entry {
unsigned int mIndex; ///< The vertex referred by this entry unsigned int mIndex; ///< The vertex referred by this entry
aiVector3D mPosition; ///< Position aiVector3D mPosition; ///< Position
ai_real mDistance; ///< Distance of this vertex to the sorting plane /// Distance of this vertex to the sorting plane. This is set by Finalize.
ai_real mDistance;
Entry() AI_NO_EXCEPT Entry() AI_NO_EXCEPT
: mIndex(999999999), : mIndex(std::numeric_limits<unsigned int>::max()),
mPosition(), mPosition(),
mDistance(99999.) { mDistance(std::numeric_limits<ai_real>::max()) {
// empty // empty
} }
Entry(unsigned int pIndex, const aiVector3D &pPosition, ai_real pDistance) : Entry(unsigned int pIndex, const aiVector3D &pPosition) :
mIndex(pIndex), mPosition(pPosition), mDistance(pDistance) { mIndex(pIndex), mPosition(pPosition), mDistance(std::numeric_limits<ai_real>::max()) {
// empty // empty
} }
@ -168,6 +180,9 @@ protected:
// all positions, sorted by distance to the sorting plane // all positions, sorted by distance to the sorting plane
std::vector<Entry> mPositions; std::vector<Entry> mPositions;
/// false until the Finalize method is called.
bool mFinalized;
}; };
} // end of namespace Assimp } // end of namespace Assimp

View File

@ -98,6 +98,7 @@ struct aiVectorKey {
bool operator<(const aiVectorKey &rhs) const { bool operator<(const aiVectorKey &rhs) const {
return mTime < rhs.mTime; return mTime < rhs.mTime;
} }
bool operator>(const aiVectorKey &rhs) const { bool operator>(const aiVectorKey &rhs) const {
return mTime > rhs.mTime; return mTime > rhs.mTime;
} }
@ -131,6 +132,7 @@ struct aiQuatKey {
bool operator==(const aiQuatKey &rhs) const { bool operator==(const aiQuatKey &rhs) const {
return rhs.mValue == this->mValue; return rhs.mValue == this->mValue;
} }
bool operator!=(const aiQuatKey &rhs) const { bool operator!=(const aiQuatKey &rhs) const {
return rhs.mValue != this->mValue; return rhs.mValue != this->mValue;
} }
@ -139,6 +141,7 @@ struct aiQuatKey {
bool operator<(const aiQuatKey &rhs) const { bool operator<(const aiQuatKey &rhs) const {
return mTime < rhs.mTime; return mTime < rhs.mTime;
} }
bool operator>(const aiQuatKey &rhs) const { bool operator>(const aiQuatKey &rhs) const {
return mTime > rhs.mTime; return mTime > rhs.mTime;
} }

View File

@ -300,6 +300,10 @@ struct aiBone {
aiBone() AI_NO_EXCEPT aiBone() AI_NO_EXCEPT
: mName(), : mName(),
mNumWeights(0), mNumWeights(0),
#ifndef ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS
mArmature(nullptr),
mNode(nullptr),
#endif
mWeights(nullptr), mWeights(nullptr),
mOffsetMatrix() { mOffsetMatrix() {
// empty // empty
@ -309,6 +313,10 @@ struct aiBone {
aiBone(const aiBone &other) : aiBone(const aiBone &other) :
mName(other.mName), mName(other.mName),
mNumWeights(other.mNumWeights), mNumWeights(other.mNumWeights),
#ifndef ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS
mArmature(nullptr),
mNode(nullptr),
#endif
mWeights(nullptr), mWeights(nullptr),
mOffsetMatrix(other.mOffsetMatrix) { mOffsetMatrix(other.mOffsetMatrix) {
if (other.mWeights && other.mNumWeights) { if (other.mWeights && other.mNumWeights) {

View File

@ -2,7 +2,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
---------------------------------------------------------------------- ----------------------------------------------------------------------
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2021, assimp team
All rights reserved. All rights reserved.
Redistribution and use of this software in source and binary forms, Redistribution and use of this software in source and binary forms,
@ -54,36 +54,32 @@ namespace Assimp {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
/** Android extension to DefaultIOSystem using the standard C file functions */ /** Android extension to DefaultIOSystem using the standard C file functions */
class ASSIMP_API AndroidJNIIOSystem : public DefaultIOSystem class ASSIMP_API AndroidJNIIOSystem : public DefaultIOSystem {
{
public: public:
/** Initialize android activity data */ /** Initialize android activity data */
std::string mApkWorkspacePath; std::string mApkWorkspacePath;
AAssetManager* mApkAssetManager; AAssetManager* mApkAssetManager;
/** Constructor. */ /// Constructor.
AndroidJNIIOSystem(ANativeActivity* activity); AndroidJNIIOSystem(ANativeActivity* activity);
/** Destructor. */ /// Class constructor with past and asset manager.
AndroidJNIIOSystem(const char *internalPath, AAssetManager* assetManager);
/// Destructor.
~AndroidJNIIOSystem(); ~AndroidJNIIOSystem();
// ------------------------------------------------------------------- /// Tests for the existence of a file at the given path.
/** Tests for the existence of a file at the given path. */
bool Exists( const char* pFile) const; bool Exists( const char* pFile) const;
// ------------------------------------------------------------------- /// Opens a file at the given path, with given mode
/** Opens a file at the given path, with given mode */
IOStream* Open( const char* strFile, const char* strMode); IOStream* Open( const char* strFile, const char* strMode);
// ------------------------------------------------------------------------------------------------ /// Inits Android extractor
// Inits Android extractor
void AndroidActivityInit(ANativeActivity* activity); void AndroidActivityInit(ANativeActivity* activity);
// ------------------------------------------------------------------------------------------------ /// Extracts android asset
// Extracts android asset
bool AndroidExtractAsset(std::string name); bool AndroidExtractAsset(std::string name);
}; };
} //!ns Assimp } //!ns Assimp

View File

@ -3,7 +3,7 @@
Open Asset Import Library (assimp) Open Asset Import Library (assimp)
--------------------------------------------------------------------------- ---------------------------------------------------------------------------
Copyright (c) 2006-2020, assimp team Copyright (c) 2006-2021, assimp team
All rights reserved. All rights reserved.
@ -67,45 +67,50 @@ AndroidJNIIOSystem::AndroidJNIIOSystem(ANativeActivity* activity)
AndroidActivityInit(activity); AndroidActivityInit(activity);
} }
AndroidJNIIOSystem::AndroidJNIIOSystem(const char *internalPath, AAssetManager* assetManager) :
mApkWorkspacePath(internalPath),
mApkAssetManager(assetManager) {
// empty
}
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Destructor. // Destructor.
AndroidJNIIOSystem::~AndroidJNIIOSystem() AndroidJNIIOSystem::~AndroidJNIIOSystem() {
{
// nothing to do here // nothing to do here
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Tests for the existence of a file at the given path. // Tests for the existence of a file at the given path.
bool AndroidJNIIOSystem::Exists( const char* pFile) const bool AndroidJNIIOSystem::Exists( const char* pFile) const {
{ AAsset* asset = AAssetManager_open(mApkAssetManager, pFile, AASSET_MODE_UNKNOWN);
AAsset* asset = AAssetManager_open(mApkAssetManager, pFile,
AASSET_MODE_UNKNOWN);
FILE* file = ::fopen( (mApkWorkspacePath + getOsSeparator() + std::string(pFile)).c_str(), "rb"); FILE* file = ::fopen( (mApkWorkspacePath + getOsSeparator() + std::string(pFile)).c_str(), "rb");
if (!asset && !file) if (!asset && !file) {
{
__android_log_print(ANDROID_LOG_ERROR, "Assimp", "Asset manager can not find: %s", pFile); __android_log_print(ANDROID_LOG_ERROR, "Assimp", "Asset manager can not find: %s", pFile);
return false; return false;
} }
__android_log_print(ANDROID_LOG_ERROR, "Assimp", "Asset exists"); __android_log_print(ANDROID_LOG_ERROR, "Assimp", "Asset exists");
if (file) if (file) {
::fclose( file); ::fclose( file);
}
return true; return true;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Inits Android extractor // Inits Android extractor
void AndroidJNIIOSystem::AndroidActivityInit(ANativeActivity* activity) void AndroidJNIIOSystem::AndroidActivityInit(ANativeActivity* activity) {
{ if (activity == nullptr) {
return;
}
mApkWorkspacePath = activity->internalDataPath; mApkWorkspacePath = activity->internalDataPath;
mApkAssetManager = activity->assetManager; mApkAssetManager = activity->assetManager;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Create the directory for the extracted resource // Create the directory for the extracted resource
static int mkpath(std::string path, mode_t mode) static int mkpath(std::string path, mode_t mode) {
{
if (mkdir(path.c_str(), mode) == -1) { if (mkdir(path.c_str(), mode) == -1) {
switch(errno) { switch(errno) {
case ENOENT: case ENOENT:
@ -125,8 +130,7 @@ static int mkpath(std::string path, mode_t mode)
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Extracts android asset // Extracts android asset
bool AndroidJNIIOSystem::AndroidExtractAsset(std::string name) bool AndroidJNIIOSystem::AndroidExtractAsset(std::string name) {
{
std::string newPath = mApkWorkspacePath + getOsSeparator() + name; std::string newPath = mApkWorkspacePath + getOsSeparator() + name;
DefaultIOSystem io; DefaultIOSystem io;
@ -136,6 +140,7 @@ bool AndroidJNIIOSystem::AndroidExtractAsset(std::string name)
__android_log_print(ANDROID_LOG_DEFAULT, "Assimp", "Asset already extracted"); __android_log_print(ANDROID_LOG_DEFAULT, "Assimp", "Asset already extracted");
return true; return true;
} }
// Open file // Open file
AAsset* asset = AAssetManager_open(mApkAssetManager, name.c_str(), AAsset* asset = AAssetManager_open(mApkAssetManager, name.c_str(),
AASSET_MODE_UNKNOWN); AASSET_MODE_UNKNOWN);
@ -159,16 +164,13 @@ bool AndroidJNIIOSystem::AndroidExtractAsset(std::string name)
directoryNewPath = dirname(&directoryNewPath[0]); directoryNewPath = dirname(&directoryNewPath[0]);
if (mkpath(directoryNewPath, S_IRUSR | S_IWUSR | S_IXUSR) == -1) { if (mkpath(directoryNewPath, S_IRUSR | S_IWUSR | S_IXUSR) == -1) {
__android_log_print(ANDROID_LOG_ERROR, "assimp", __android_log_print(ANDROID_LOG_ERROR, "assimp", "Can not create the directory for the output file");
"Can not create the directory for the output file");
} }
// Prepare output buffer // Prepare output buffer
std::ofstream assetExtracted(newPath.c_str(), std::ofstream assetExtracted(newPath.c_str(), std::ios::out | std::ios::binary);
std::ios::out | std::ios::binary);
if (!assetExtracted) { if (!assetExtracted) {
__android_log_print(ANDROID_LOG_ERROR, "assimp", __android_log_print(ANDROID_LOG_ERROR, "assimp", "Can not open output file");
"Can not open output file");
} }
// Write output buffer into a file // Write output buffer into a file
@ -180,24 +182,25 @@ bool AndroidJNIIOSystem::AndroidExtractAsset(std::string name)
__android_log_print(ANDROID_LOG_ERROR, "assimp", "Asset not found: %s", name.c_str()); __android_log_print(ANDROID_LOG_ERROR, "assimp", "Asset not found: %s", name.c_str());
return false; return false;
} }
return true; return true;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// Open a new file with a given path. // Open a new file with a given path.
IOStream* AndroidJNIIOSystem::Open( const char* strFile, const char* strMode) IOStream* AndroidJNIIOSystem::Open( const char* strFile, const char* strMode) {
{ ai_assert(nullptr != strFile);
ai_assert(NULL != strFile); ai_assert(nullptr != strMode);
ai_assert(NULL != strMode);
std::string fullPath(mApkWorkspacePath + getOsSeparator() + std::string(strFile)); std::string fullPath(mApkWorkspacePath + getOsSeparator() + std::string(strFile));
if (Exists(strFile)) if (Exists(strFile)) {
AndroidExtractAsset(std::string(strFile)); AndroidExtractAsset(std::string(strFile));
}
FILE* file = ::fopen( fullPath.c_str(), strMode); FILE* file = ::fopen( fullPath.c_str(), strMode);
if (nullptr == file) {
if( NULL == file) return nullptr;
return NULL; }
__android_log_print(ANDROID_LOG_ERROR, "assimp", "AndroidIOSystem: file %s opened", fullPath.c_str()); __android_log_print(ANDROID_LOG_ERROR, "assimp", "AndroidIOSystem: file %s opened", fullPath.c_str());
return new DefaultIOStream(file, fullPath); return new DefaultIOStream(file, fullPath);

View File

@ -82,3 +82,39 @@ TEST_F(utSpatialSort, findPositionsTest) {
sSort.FindPositions(vecs[0], 0.01f, indices); sSort.FindPositions(vecs[0], 0.01f, indices);
EXPECT_EQ(1u, indices.size()); EXPECT_EQ(1u, indices.size());
} }
TEST_F(utSpatialSort, highlyDisplacedPositionsTest) {
// Make a cube of positions, and then query it using the SpatialSort object.
constexpr unsigned int verticesPerAxis = 10;
constexpr ai_real step = 0.001f;
// Note the large constant offset here.
constexpr ai_real offset = 5000.0f - (0.5f * verticesPerAxis * step);
constexpr unsigned int totalNumPositions = verticesPerAxis * verticesPerAxis * verticesPerAxis;
aiVector3D* positions = new aiVector3D[totalNumPositions];
for (unsigned int x = 0; x < verticesPerAxis; ++x) {
for (unsigned int y = 0; y < verticesPerAxis; ++y) {
for (unsigned int z = 0; z < verticesPerAxis; ++z) {
const unsigned int index = (x * verticesPerAxis * verticesPerAxis) + (y * verticesPerAxis) + z;
positions[index] = aiVector3D(offset + (x * step), offset + (y * step), offset + (z * step));
}
}
}
SpatialSort sSort;
sSort.Fill(positions, totalNumPositions, sizeof(aiVector3D));
// Enough to find a point and its 6 immediate neighbors, but not any other point.
const ai_real epsilon = 1.1f * step;
std::vector<unsigned int> indices;
// Iterate through the _interior_ points of the cube.
for (unsigned int x = 1; x < verticesPerAxis - 1; ++x) {
for (unsigned int y = 1; y < verticesPerAxis - 1; ++y) {
for (unsigned int z = 1; z < verticesPerAxis - 1; ++z) {
const unsigned int index = (x * verticesPerAxis * verticesPerAxis) + (y * verticesPerAxis) + z;
sSort.FindPositions(positions[index], epsilon, indices);
ASSERT_EQ(7u, indices.size());
}
}
}
delete[] positions;
}

View File

@ -44,16 +44,16 @@ class utVersion : public ::testing::Test {
}; };
TEST_F( utVersion, aiGetLegalStringTest ) { TEST_F( utVersion, aiGetLegalStringTest ) {
const char *lv( aiGetLegalString() ); const char *lv = aiGetLegalString();
EXPECT_NE( lv, nullptr ); EXPECT_NE( lv, nullptr );
std::string text( lv ); std::string text( lv );
size_t pos( text.find( std::string( "2021" ) ) ); size_t pos = text.find(std::string("2021"));
EXPECT_NE( pos, std::string::npos ); EXPECT_NE( pos, std::string::npos );
} }
TEST_F( utVersion, aiGetVersionMinorTest ) { TEST_F( utVersion, aiGetVersionMinorTest ) {
EXPECT_EQ( aiGetVersionMinor(), 0U ); EXPECT_EQ( aiGetVersionMinor(), 1U );
} }
TEST_F( utVersion, aiGetVersionMajorTest ) { TEST_F( utVersion, aiGetVersionMajorTest ) {