fix all unittests.

pull/3012/head
Kim Kulling 2020-03-15 10:17:54 +01:00
parent 255758e6ff
commit 0357333c81
9 changed files with 1360 additions and 1475 deletions

View File

@ -49,12 +49,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "AssbinFileWriter.h"
#include <assimp/scene.h>
#include <assimp/IOSystem.hpp>
#include <assimp/Exporter.hpp>
#include <assimp/IOSystem.hpp>
namespace Assimp {
void ExportSceneAssbin(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/) {
void ExportSceneAssbin(const char *pFile, IOSystem *pIOSystem, const aiScene *pScene, const ExportProperties * /*pProperties*/) {
DumpSceneToAssbin(
pFile,
"\0", // no command(s).

File diff suppressed because it is too large Load Diff

View File

@ -5,8 +5,6 @@ Open Asset Import Library (assimp)
Copyright (c) 2006-2020, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
@ -105,8 +103,9 @@ template <typename T>
T Read(IOStream *stream) {
T t;
size_t res = stream->Read(&t, sizeof(T), 1);
if (res != 1)
if (res != 1) {
throw DeadlyImportError("Unexpected EOF");
}
return t;
}
@ -313,6 +312,7 @@ void AssbinImporter::ReadBinaryBone(IOStream *stream, aiBone *b) {
static bool fitsIntoUI16(unsigned int mNumVertices) {
return (mNumVertices < (1u << 16));
}
// -----------------------------------------------------------------------------------
void AssbinImporter::ReadBinaryMesh(IOStream *stream, aiMesh *mesh) {
if (Read<uint32_t>(stream) != ASSBIN_CHUNK_AIMESH)

View File

@ -618,7 +618,7 @@ inline void Image::Read(Value &obj, Asset &r) {
if (!mDataLength) {
Value *curUri = FindString(obj, "uri");
if (nullptr != curUri ) {
if (nullptr != curUri) {
const char *uristr = curUri->GetString();
glTFCommon::Util::DataURI dataURI;
@ -1272,13 +1272,9 @@ inline void Asset::ReadBinaryHeader(IOStream &stream) {
inline void Asset::Load(const std::string &pFile, bool isBinary) {
mCurrentAssetDir.clear();
int pos = std::max(int(pFile.rfind('/')), int(pFile.rfind('\\')));
if (pos != int(std::string::npos)) mCurrentAssetDir = pFile.substr(0, pos + 1);
/* std::string::size_type pos = std::max(pFile.rfind('/'), pFile.rfind('\\'));
if (pos != std::string::npos) {
mCurrentAssetDir = pFile.substr(0, pos + 1);
}*/
/*int pos = std::max(int(pFile.rfind('/')), int(pFile.rfind('\\')));
if (pos != int(std::string::npos)) mCurrentAssetDir = pFile.substr(0, pos + 1);*/
mCurrentAssetDir = getCurrentAssetDir(pFile);
shared_ptr<IOStream> stream(OpenFile(pFile.c_str(), "rb", true));
if (!stream) {
@ -1373,9 +1369,9 @@ inline void Asset::ReadExtensionsUsed(Document &doc) {
#undef CHECK_EXT
}
inline IOStream *Asset::OpenFile(std::string path, const char *mode, bool absolute ) {
inline IOStream *Asset::OpenFile(std::string path, const char *mode, bool absolute) {
#ifdef ASSIMP_API
(void) absolute;
(void)absolute;
return mIOSystem->Open(path, mode);
#else
if (path.size() < 2) return 0;

View File

@ -46,7 +46,7 @@ using namespace glTFCommon::Util;
namespace Util {
size_t DecodeBase64(const char* in, size_t inLength, uint8_t*& out) {
size_t DecodeBase64(const char *in, size_t inLength, uint8_t *&out) {
ai_assert(inLength % 4 == 0);
if (inLength < 4) {
@ -88,7 +88,7 @@ size_t DecodeBase64(const char* in, size_t inLength, uint8_t*& out) {
return outLength;
}
void EncodeBase64(const uint8_t* in, size_t inLength, std::string& out) {
void EncodeBase64(const uint8_t *in, size_t inLength, std::string &out) {
size_t outLength = ((inLength + 2) / 3) * 4;
size_t j = out.size();
@ -110,13 +110,11 @@ void EncodeBase64(const uint8_t* in, size_t inLength, std::string& out) {
b = in[i + 2] & 0x3F;
out[j++] = EncodeCharBase64(b);
}
else {
} else {
out[j++] = EncodeCharBase64(b);
out[j++] = '=';
}
}
else {
} else {
out[j++] = EncodeCharBase64(b);
out[j++] = '=';
out[j++] = '=';
@ -124,7 +122,7 @@ void EncodeBase64(const uint8_t* in, size_t inLength, std::string& out) {
}
}
bool ParseDataURI(const char* const_uri, size_t uriLen, DataURI& out) {
bool ParseDataURI(const char *const_uri, size_t uriLen, DataURI &out) {
if (nullptr == const_uri) {
return false;
}
@ -139,7 +137,7 @@ bool ParseDataURI(const char* const_uri, size_t uriLen, DataURI& out) {
out.charset = "US-ASCII";
out.base64 = false;
char* uri = const_cast<char*>(const_uri);
char *uri = const_cast<char *>(const_uri);
if (uri[0] != 0x10) {
uri[0] = 0x10;
uri[1] = uri[2] = uri[3] = uri[4] = 0;
@ -159,16 +157,14 @@ bool ParseDataURI(const char* const_uri, size_t uriLen, DataURI& out) {
if (strncmp(uri + j, "charset=", 8) == 0) {
uri[2] = char(j + 8);
}
else if (strncmp(uri + j, "base64", 6) == 0) {
} else if (strncmp(uri + j, "base64", 6) == 0) {
uri[3] = char(j);
}
}
if (i < uriLen) {
uri[i++] = '\0';
uri[4] = char(i);
}
else {
} else {
uri[1] = uri[2] = uri[3] = 0;
uri[4] = 5;
}
@ -189,5 +185,5 @@ bool ParseDataURI(const char* const_uri, size_t uriLen, DataURI& out) {
return true;
}
}
}
} // namespace Util
} // namespace glTFCommon

View File

@ -45,71 +45,74 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/Exceptional.h>
#include <map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <stdexcept>
#include <string>
#include <vector>
#define RAPIDJSON_HAS_STDSTRING 1
#include <rapidjson/rapidjson.h>
#include <rapidjson/document.h>
#include <rapidjson/error/en.h>
#include <rapidjson/rapidjson.h>
#ifdef ASSIMP_API
# include <memory>
# include <assimp/DefaultIOSystem.h>
# include <assimp/ByteSwapper.h>
#include <assimp/ByteSwapper.h>
#include <assimp/DefaultIOSystem.h>
#include <memory>
#else
# include <memory>
# define AI_SWAP4(p)
# define ai_assert
#include <memory>
#define AI_SWAP4(p)
#define ai_assert
#endif
#if _MSC_VER > 1500 || (defined __GNUC___)
# define ASSIMP_GLTF_USE_UNORDERED_MULTIMAP
# else
# define gltf_unordered_map map
#define ASSIMP_GLTF_USE_UNORDERED_MULTIMAP
#else
#define gltf_unordered_map map
#endif
#ifdef ASSIMP_GLTF_USE_UNORDERED_MULTIMAP
# include <unordered_map>
# if _MSC_VER > 1600
# define gltf_unordered_map unordered_map
# else
# define gltf_unordered_map tr1::unordered_map
# endif
#include <unordered_map>
#if _MSC_VER > 1600
#define gltf_unordered_map unordered_map
#else
#define gltf_unordered_map tr1::unordered_map
#endif
#endif
namespace glTFCommon {
#ifdef ASSIMP_API
using Assimp::IOStream;
using Assimp::IOSystem;
using std::shared_ptr;
using Assimp::IOStream;
using Assimp::IOSystem;
using std::shared_ptr;
#else
using std::shared_ptr;
using std::shared_ptr;
typedef std::runtime_error DeadlyImportError;
typedef std::runtime_error DeadlyExportError;
typedef std::runtime_error DeadlyImportError;
typedef std::runtime_error DeadlyExportError;
enum aiOrigin {
enum aiOrigin {
aiOrigin_SET = 0,
aiOrigin_CUR = 1,
aiOrigin_END = 2
};
};
class IOSystem;
class IOSystem;
class IOStream {
public:
IOStream(FILE* file) : f(file) {}
~IOStream() { fclose(f); f = 0; }
class IOStream {
public:
IOStream(FILE *file) :
f(file) {}
~IOStream() {
fclose(f);
f = 0;
}
size_t Read(void* b, size_t sz, size_t n) { return fread(b, sz, n, f); }
size_t Write(const void* b, size_t sz, size_t n) { return fwrite(b, sz, n, f); }
size_t Read(void *b, size_t sz, size_t n) { return fread(b, sz, n, f); }
size_t Write(const void *b, size_t sz, size_t n) { return fwrite(b, sz, n, f); }
int Seek(size_t off, aiOrigin orig) { return fseek(f, off, int(orig)); }
size_t Tell() const { return ftell(f); }
@ -118,98 +121,115 @@ namespace glTFCommon {
return size_t((Seek(p, aiOrigin_SET), len));
}
private:
FILE* f;
};
private:
FILE *f;
};
#endif
// Vec/matrix types, as raw float arrays
typedef float(vec3)[3];
typedef float(vec4)[4];
typedef float(mat4)[16];
// Vec/matrix types, as raw float arrays
typedef float(vec3)[3];
typedef float(vec4)[4];
typedef float(mat4)[16];
inline
void CopyValue(const glTFCommon::vec3& v, aiColor4D& out) {
inline void CopyValue(const glTFCommon::vec3 &v, aiColor4D &out) {
out.r = v[0];
out.g = v[1];
out.b = v[2];
out.a = 1.0;
}
}
inline
void CopyValue(const glTFCommon::vec4& v, aiColor4D& out) {
inline void CopyValue(const glTFCommon::vec4 &v, aiColor4D &out) {
out.r = v[0];
out.g = v[1];
out.b = v[2];
out.a = v[3];
}
}
inline
void CopyValue(const glTFCommon::vec4& v, aiColor3D& out) {
inline void CopyValue(const glTFCommon::vec4 &v, aiColor3D &out) {
out.r = v[0];
out.g = v[1];
out.b = v[2];
}
}
inline
void CopyValue(const glTFCommon::vec3& v, aiColor3D& out) {
inline void CopyValue(const glTFCommon::vec3 &v, aiColor3D &out) {
out.r = v[0];
out.g = v[1];
out.b = v[2];
}
}
inline
void CopyValue(const glTFCommon::vec3& v, aiVector3D& out) {
inline void CopyValue(const glTFCommon::vec3 &v, aiVector3D &out) {
out.x = v[0];
out.y = v[1];
out.z = v[2];
}
}
inline
void CopyValue(const glTFCommon::vec4& v, aiQuaternion& out) {
inline void CopyValue(const glTFCommon::vec4 &v, aiQuaternion &out) {
out.x = v[0];
out.y = v[1];
out.z = v[2];
out.w = v[3];
}
inline void CopyValue(const glTFCommon::mat4 &v, aiMatrix4x4 &o) {
o.a1 = v[0];
o.b1 = v[1];
o.c1 = v[2];
o.d1 = v[3];
o.a2 = v[4];
o.b2 = v[5];
o.c2 = v[6];
o.d2 = v[7];
o.a3 = v[8];
o.b3 = v[9];
o.c3 = v[10];
o.d3 = v[11];
o.a4 = v[12];
o.b4 = v[13];
o.c4 = v[14];
o.d4 = v[15];
}
#pragma warning(push)
#pragma warning(disable : 4310)
inline std::string getCurrentAssetDir(const std::string &pFile) {
std::string path = pFile;
int pos = std::max(int(pFile.rfind('/')), int(pFile.rfind('\\')));
if (pos != int(std::string::npos)) {
path = pFile.substr(0, pos + 1);
}
inline
void CopyValue(const glTFCommon::mat4& v, aiMatrix4x4& o) {
o.a1 = v[0]; o.b1 = v[1]; o.c1 = v[2]; o.d1 = v[3];
o.a2 = v[4]; o.b2 = v[5]; o.c2 = v[6]; o.d2 = v[7];
o.a3 = v[8]; o.b3 = v[9]; o.c3 = v[10]; o.d3 = v[11];
o.a4 = v[12]; o.b4 = v[13]; o.c4 = v[14]; o.d4 = v[15];
}
return path;
}
#pragma warning(pop)
namespace Util {
namespace Util {
void EncodeBase64(const uint8_t* in, size_t inLength, std::string& out);
void EncodeBase64(const uint8_t *in, size_t inLength, std::string &out);
size_t DecodeBase64(const char* in, size_t inLength, uint8_t*& out);
size_t DecodeBase64(const char *in, size_t inLength, uint8_t *&out);
inline
size_t DecodeBase64(const char* in, uint8_t*& out) {
inline size_t DecodeBase64(const char *in, uint8_t *&out) {
return DecodeBase64(in, strlen(in), out);
}
}
struct DataURI {
const char* mediaType;
const char* charset;
struct DataURI {
const char *mediaType;
const char *charset;
bool base64;
const char* data;
const char *data;
size_t dataLength;
};
};
//! Check if a uri is a data URI
bool ParseDataURI(const char* const_uri, size_t uriLen, DataURI& out);
//! Check if a uri is a data URI
bool ParseDataURI(const char *const_uri, size_t uriLen, DataURI &out);
template<bool B>
struct DATA {
template <bool B>
struct DATA {
static const uint8_t tableDecodeBase64[128];
};
};
template<bool B>
const uint8_t DATA<B>::tableDecodeBase64[128] = {
template <bool B>
const uint8_t DATA<B>::tableDecodeBase64[128] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63,
@ -218,27 +238,25 @@ namespace glTFCommon {
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0, 0, 0, 0, 0,
0, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0, 0, 0, 0, 0
};
};
inline
char EncodeCharBase64(uint8_t b) {
inline char EncodeCharBase64(uint8_t b) {
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="[size_t(b)];
}
}
inline
uint8_t DecodeCharBase64(char c) {
inline uint8_t DecodeCharBase64(char c) {
return DATA<true>::tableDecodeBase64[size_t(c)]; // TODO faster with lookup table or ifs?
}
}
size_t DecodeBase64(const char* in, size_t inLength, uint8_t*& out);
size_t DecodeBase64(const char *in, size_t inLength, uint8_t *&out);
void EncodeBase64(const uint8_t* in, size_t inLength, std::string& out);
} // namespace Util
void EncodeBase64(const uint8_t *in, size_t inLength, std::string &out);
} // namespace Util
#define CHECK_EXT(EXT) \
if (exts.find(#EXT) != exts.end()) extensionsUsed.EXT = true;
}
} // namespace glTFCommon
#endif // ASSIMP_BUILD_NO_GLTF_IMPORTER

File diff suppressed because it is too large Load Diff

View File

@ -40,6 +40,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------------
*/
#include "glTF/glTFCommon.h"
#include <assimp/StringUtils.h>
// Header files, Assimp
@ -901,7 +902,7 @@ inline int Compare(const char *attr, const char (&str)[N]) {
}
#pragma warning(push)
#pragma warning(disable: 4706 )
#pragma warning(disable : 4706)
inline bool GetAttribVector(Mesh::Primitive &p, const char *attr, Mesh::AccessorList *&v, int &pos) {
if ((pos = Compare(attr, "POSITION"))) {
v = &(p.attributes.position);
@ -1106,7 +1107,7 @@ inline void Node::Read(Value &obj, Asset &r) {
}
Value *curMesh = FindUInt(obj, "mesh");
if (nullptr != curMesh ) {
if (nullptr != curMesh) {
unsigned int numMeshes = 1;
this->meshes.reserve(numMeshes);
Ref<Mesh> meshRef = r.meshes.Retrieve((*curMesh).GetUint());
@ -1116,12 +1117,12 @@ inline void Node::Read(Value &obj, Asset &r) {
}
Value *curSkin = FindUInt(obj, "skin");
if (nullptr != curSkin ) {
if (nullptr != curSkin) {
this->skin = r.skins.Retrieve(curSkin->GetUint());
}
Value *curCamera = FindUInt(obj, "camera");
if (nullptr != curCamera ) {
if (nullptr != curCamera) {
this->camera = r.cameras.Retrieve(curCamera->GetUint());
if (this->camera) {
this->camera->id = this->id;
@ -1328,8 +1329,10 @@ inline void Asset::ReadBinaryHeader(IOStream &stream, std::vector<char> &sceneDa
inline void Asset::Load(const std::string &pFile, bool isBinary) {
mCurrentAssetDir.clear();
int pos = std::max(int(pFile.rfind('/')), int(pFile.rfind('\\')));
if (pos != int(std::string::npos)) mCurrentAssetDir = pFile.substr(0, pos + 1);
/*int pos = std::max(int(pFile.rfind('/')), int(pFile.rfind('\\')));
if (pos != int(std::string::npos)) */
mCurrentAssetDir = glTFCommon::getCurrentAssetDir(pFile);
shared_ptr<IOStream> stream(OpenFile(pFile.c_str(), "rb", true));
if (!stream) {
@ -1516,6 +1519,6 @@ inline std::string Asset::FindUniqueID(const std::string &str, const char *suffi
return id;
}
#pragma warning( pop )
#pragma warning(pop)
} // namespace glTF2

View File

@ -110,8 +110,9 @@ const aiImporterDesc *glTF2Importer::GetInfo() const {
bool glTF2Importer::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool /* checkSig */) const {
const std::string &extension = GetExtension(pFile);
if (extension != "gltf" && extension != "glb")
if (extension != "gltf" && extension != "glb") {
return false;
}
if (pIOHandler) {
glTF2::Asset asset(pIOHandler);