commit
9b694a8645
|
@ -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,
|
||||
|
@ -43,7 +41,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
/** @file Implementation of the 3ds importer class */
|
||||
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_3DS_IMPORTER
|
||||
|
||||
// internal headers
|
||||
|
|
|
@ -322,7 +322,7 @@ struct Face : public FaceWithSmoothingGroup {
|
|||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
# pragma warning(disable : 4315)
|
||||
#pragma warning(disable : 4315)
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
@ -441,30 +441,52 @@ struct Material {
|
|||
// empty
|
||||
}
|
||||
|
||||
Material(const Material &other) = default;
|
||||
Material &operator=(const Material &other) = default;
|
||||
Material(const Material &other) :
|
||||
mName(other.mName),
|
||||
mDiffuse(other.mDiffuse),
|
||||
mSpecularExponent(other.mSpecularExponent),
|
||||
mShininessStrength(other.mShininessStrength),
|
||||
mSpecular(other.mSpecular),
|
||||
mAmbient(other.mAmbient),
|
||||
mShading(other.mShading),
|
||||
mTransparency(other.mTransparency),
|
||||
sTexDiffuse(other.sTexDiffuse),
|
||||
sTexOpacity(other.sTexOpacity),
|
||||
sTexSpecular(other.sTexSpecular),
|
||||
sTexReflective(other.sTexReflective),
|
||||
sTexBump(other.sTexBump),
|
||||
sTexEmissive(other.sTexEmissive),
|
||||
sTexShininess(other.sTexShininess),
|
||||
mBumpHeight(other.mBumpHeight),
|
||||
mEmissive(other.mEmissive),
|
||||
sTexAmbient(other.sTexAmbient),
|
||||
mTwoSided(other.mTwoSided) {
|
||||
// empty
|
||||
|
||||
}
|
||||
|
||||
//! Move constructor. This is explicitly written because MSVC doesn't support defaulting it
|
||||
Material(Material &&other) AI_NO_EXCEPT
|
||||
: mName(std::move(other.mName)),
|
||||
mDiffuse(std::move(other.mDiffuse)),
|
||||
mSpecularExponent(std::move(other.mSpecularExponent)),
|
||||
mShininessStrength(std::move(other.mShininessStrength)),
|
||||
mSpecular(std::move(other.mSpecular)),
|
||||
mAmbient(std::move(other.mAmbient)),
|
||||
mShading(std::move(other.mShading)),
|
||||
mTransparency(std::move(other.mTransparency)),
|
||||
sTexDiffuse(std::move(other.sTexDiffuse)),
|
||||
sTexOpacity(std::move(other.sTexOpacity)),
|
||||
sTexSpecular(std::move(other.sTexSpecular)),
|
||||
sTexReflective(std::move(other.sTexReflective)),
|
||||
sTexBump(std::move(other.sTexBump)),
|
||||
sTexEmissive(std::move(other.sTexEmissive)),
|
||||
sTexShininess(std::move(other.sTexShininess)),
|
||||
mBumpHeight(std::move(other.mBumpHeight)),
|
||||
mEmissive(std::move(other.mEmissive)),
|
||||
sTexAmbient(std::move(other.sTexAmbient)),
|
||||
mTwoSided(std::move(other.mTwoSided)) {
|
||||
Material(Material &&other) AI_NO_EXCEPT :
|
||||
mName(std::move(other.mName)),
|
||||
mDiffuse(std::move(other.mDiffuse)),
|
||||
mSpecularExponent(std::move(other.mSpecularExponent)),
|
||||
mShininessStrength(std::move(other.mShininessStrength)),
|
||||
mSpecular(std::move(other.mSpecular)),
|
||||
mAmbient(std::move(other.mAmbient)),
|
||||
mShading(std::move(other.mShading)),
|
||||
mTransparency(std::move(other.mTransparency)),
|
||||
sTexDiffuse(std::move(other.sTexDiffuse)),
|
||||
sTexOpacity(std::move(other.sTexOpacity)),
|
||||
sTexSpecular(std::move(other.sTexSpecular)),
|
||||
sTexReflective(std::move(other.sTexReflective)),
|
||||
sTexBump(std::move(other.sTexBump)),
|
||||
sTexEmissive(std::move(other.sTexEmissive)),
|
||||
sTexShininess(std::move(other.sTexShininess)),
|
||||
mBumpHeight(std::move(other.mBumpHeight)),
|
||||
mEmissive(std::move(other.mEmissive)),
|
||||
sTexAmbient(std::move(other.sTexAmbient)),
|
||||
mTwoSided(std::move(other.mTwoSided)) {
|
||||
// empty
|
||||
}
|
||||
|
||||
Material &operator=(Material &&other) AI_NO_EXCEPT {
|
||||
|
|
|
@ -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,
|
||||
|
@ -72,7 +70,6 @@ static const aiImporterDesc desc = {
|
|||
"3ds prj"
|
||||
};
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Begins a new parsing block
|
||||
// - Reads the current chunk and validates it
|
||||
|
@ -141,15 +138,13 @@ bool Discreet3DSImporter::CanRead( const std::string& pFile, IOSystem* pIOHandle
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Loader registry entry
|
||||
const aiImporterDesc* Discreet3DSImporter::GetInfo () const
|
||||
{
|
||||
const aiImporterDesc* Discreet3DSImporter::GetInfo () const {
|
||||
return &desc;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Setup configuration properties
|
||||
void Discreet3DSImporter::SetupProperties(const Importer* /*pImp*/)
|
||||
{
|
||||
void Discreet3DSImporter::SetupProperties(const Importer* /*pImp*/) {
|
||||
// nothing to be done for the moment
|
||||
}
|
||||
|
||||
|
@ -200,7 +195,7 @@ void Discreet3DSImporter::InternReadFile( const std::string& pFile,
|
|||
ComputeNormalsWithSmoothingsGroups<D3DS::Face>(mesh);
|
||||
}
|
||||
|
||||
// Replace all occurences of the default material with a
|
||||
// Replace all occurrences of the default material with a
|
||||
// valid material. Generate it if no material containing
|
||||
// DEFAULT in its name has been found in the file
|
||||
ReplaceDefaultMaterial();
|
||||
|
@ -227,8 +222,7 @@ void Discreet3DSImporter::InternReadFile( const std::string& pFile,
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Applies a master-scaling factor to the imported scene
|
||||
void Discreet3DSImporter::ApplyMasterScale(aiScene* pScene)
|
||||
{
|
||||
void Discreet3DSImporter::ApplyMasterScale(aiScene* pScene) {
|
||||
// There are some 3DS files with a zero scaling factor
|
||||
if (!mMasterScale)mMasterScale = 1.0f;
|
||||
else mMasterScale = 1.0f / mMasterScale;
|
||||
|
@ -1084,7 +1078,7 @@ void Discreet3DSImporter::ParseMeshChunk()
|
|||
mMesh.mFaceMaterials.resize(mMesh.mFaces.size(),0xcdcdcdcd);
|
||||
|
||||
// Larger 3DS files could have multiple FACE chunks here
|
||||
chunkSize = stream->GetRemainingSizeToLimit();
|
||||
chunkSize = (int)stream->GetRemainingSizeToLimit();
|
||||
if ( chunkSize > (int) sizeof(Discreet3DS::Chunk ) )
|
||||
ParseFaceChunk();
|
||||
}
|
||||
|
|
|
@ -65,15 +65,11 @@ using namespace D3DS;
|
|||
// ---------------------------------------------------------------------------------
|
||||
/** Importer class for 3D Studio r3 and r4 3DS files
|
||||
*/
|
||||
class Discreet3DSImporter : public BaseImporter
|
||||
{
|
||||
class Discreet3DSImporter : public BaseImporter {
|
||||
public:
|
||||
|
||||
Discreet3DSImporter();
|
||||
~Discreet3DSImporter();
|
||||
|
||||
public:
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** Returns whether the class can handle the format of the given file.
|
||||
* See BaseImporter::CanRead() for details.
|
||||
|
|
|
@ -9,6 +9,9 @@ For details, see http://sourceforge.net/projects/libb64
|
|||
|
||||
const int CHARS_PER_LINE = 72;
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4244)
|
||||
|
||||
void base64_init_encodestate(base64_encodestate* state_in)
|
||||
{
|
||||
state_in->step = step_A;
|
||||
|
@ -107,3 +110,4 @@ int base64_encode_blockend(char* code_out, base64_encodestate* state_in)
|
|||
return (int)(codechar - code_out);
|
||||
}
|
||||
|
||||
#pragma warning(pop)
|
||||
|
|
|
@ -50,7 +50,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp/Exporter.hpp>
|
||||
|
||||
namespace Assimp {
|
||||
namespace Assimp {
|
||||
|
||||
void ExportSceneAssxml(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/)
|
||||
{
|
||||
|
|
|
@ -206,7 +206,7 @@ void BlenderImporter::InternReadFile( const std::string& pFile,
|
|||
inflateInit2(&zstream, 16+MAX_WBITS);
|
||||
|
||||
zstream.next_in = reinterpret_cast<Bytef*>( reader->GetPtr() );
|
||||
zstream.avail_in = reader->GetRemainingSize();
|
||||
zstream.avail_in = (uInt) reader->GetRemainingSize();
|
||||
|
||||
size_t total = 0l;
|
||||
|
||||
|
|
|
@ -178,7 +178,7 @@ void CSMImporter::InternReadFile( const std::string& pFile,
|
|||
*ot++ = *buffer++;
|
||||
|
||||
*ot = '\0';
|
||||
nda->mNodeName.length = (ai_uint32)(ot-nda->mNodeName.data);
|
||||
nda->mNodeName.length = static_cast<ai_uint32>(ot-nda->mNodeName.data);
|
||||
}
|
||||
|
||||
anim->mNumChannels = static_cast<unsigned int>(anims_temp.size());
|
||||
|
|
|
@ -1483,6 +1483,7 @@ void IRRImporter::InternReadFile( const std::string& pFile,
|
|||
*/
|
||||
|
||||
delete root;
|
||||
delete reader;
|
||||
}
|
||||
|
||||
#endif // !! ASSIMP_BUILD_NO_IRR_IMPORTER
|
||||
|
|
|
@ -189,42 +189,42 @@ M3D_INDEX addMaterial(const Assimp::M3DWrapper &m3d, const aiMaterial *mat) {
|
|||
continue;
|
||||
if (aiProps[k].pKey) {
|
||||
switch (m3d_propertytypes[k].format) {
|
||||
case m3dpf_color:
|
||||
if (mat->Get(aiProps[k].pKey, aiProps[k].type,
|
||||
aiProps[k].index, c) == AI_SUCCESS)
|
||||
addProp(&m3d->material[mi],
|
||||
m3d_propertytypes[k].id, mkColor(&c));
|
||||
break;
|
||||
case m3dpf_float:
|
||||
if (mat->Get(aiProps[k].pKey, aiProps[k].type,
|
||||
aiProps[k].index, f) == AI_SUCCESS)
|
||||
addProp(&m3d->material[mi],
|
||||
m3d_propertytypes[k].id,
|
||||
/* not (uint32_t)f, because we don't want to convert
|
||||
case m3dpf_color:
|
||||
if (mat->Get(aiProps[k].pKey, aiProps[k].type,
|
||||
aiProps[k].index, c) == AI_SUCCESS)
|
||||
addProp(&m3d->material[mi],
|
||||
m3d_propertytypes[k].id, mkColor(&c));
|
||||
break;
|
||||
case m3dpf_float:
|
||||
if (mat->Get(aiProps[k].pKey, aiProps[k].type,
|
||||
aiProps[k].index, f) == AI_SUCCESS)
|
||||
addProp(&m3d->material[mi],
|
||||
m3d_propertytypes[k].id,
|
||||
/* not (uint32_t)f, because we don't want to convert
|
||||
* it, we want to see it as 32 bits of memory */
|
||||
*((uint32_t *)&f));
|
||||
break;
|
||||
case m3dpf_uint8:
|
||||
if (mat->Get(aiProps[k].pKey, aiProps[k].type,
|
||||
aiProps[k].index, j) == AI_SUCCESS) {
|
||||
// special conversion for illumination model property
|
||||
if (m3d_propertytypes[k].id == m3dp_il) {
|
||||
switch (j) {
|
||||
case aiShadingMode_NoShading: j = 0; break;
|
||||
case aiShadingMode_Phong: j = 2; break;
|
||||
default: j = 1; break;
|
||||
}
|
||||
*((uint32_t *)&f));
|
||||
break;
|
||||
case m3dpf_uint8:
|
||||
if (mat->Get(aiProps[k].pKey, aiProps[k].type,
|
||||
aiProps[k].index, j) == AI_SUCCESS) {
|
||||
// special conversion for illumination model property
|
||||
if (m3d_propertytypes[k].id == m3dp_il) {
|
||||
switch (j) {
|
||||
case aiShadingMode_NoShading: j = 0; break;
|
||||
case aiShadingMode_Phong: j = 2; break;
|
||||
default: j = 1; break;
|
||||
}
|
||||
addProp(&m3d->material[mi],
|
||||
m3d_propertytypes[k].id, j);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (mat->Get(aiProps[k].pKey, aiProps[k].type,
|
||||
aiProps[k].index, j) == AI_SUCCESS)
|
||||
addProp(&m3d->material[mi],
|
||||
m3d_propertytypes[k].id, j);
|
||||
break;
|
||||
addProp(&m3d->material[mi],
|
||||
m3d_propertytypes[k].id, j);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (mat->Get(aiProps[k].pKey, aiProps[k].type,
|
||||
aiProps[k].index, j) == AI_SUCCESS)
|
||||
addProp(&m3d->material[mi],
|
||||
m3d_propertytypes[k].id, j);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (aiTxProps[k].pKey &&
|
||||
|
@ -292,8 +292,8 @@ void ExportSceneM3D(
|
|||
// Prototyped and registered in Exporter.cpp
|
||||
void ExportSceneM3DA(
|
||||
const char *,
|
||||
IOSystem*,
|
||||
const aiScene*,
|
||||
IOSystem *,
|
||||
const aiScene *,
|
||||
const ExportProperties *
|
||||
|
||||
) {
|
||||
|
@ -312,7 +312,9 @@ void ExportSceneM3DA(
|
|||
M3DExporter::M3DExporter(const aiScene *pScene, const ExportProperties *pProperties) :
|
||||
mScene(pScene),
|
||||
mProperties(pProperties),
|
||||
outfile() {}
|
||||
outfile() {
|
||||
// empty
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void M3DExporter::doExport(
|
||||
|
@ -352,6 +354,9 @@ void M3DExporter::doExport(
|
|||
// explicitly release file pointer,
|
||||
// so we don't have to rely on class destruction.
|
||||
outfile.reset();
|
||||
|
||||
M3D_FREE(m3d->name);
|
||||
m3d->name = nullptr;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
|
|
@ -50,15 +50,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#ifdef ASSIMP_USE_M3D_READFILECB
|
||||
|
||||
# if (__cplusplus >= 201103L) || !defined(_MSC_VER) || (_MSC_VER >= 1900) // C++11 and MSVC 2015 onwards
|
||||
# define threadlocal thread_local
|
||||
# else
|
||||
# if defined(_MSC_VER) && (_MSC_VER >= 1800) // there's an alternative for MSVC 2013
|
||||
# define threadlocal __declspec(thread)
|
||||
# else
|
||||
# define threadlocal
|
||||
# endif
|
||||
# endif
|
||||
#if (__cplusplus >= 201103L) || !defined(_MSC_VER) || (_MSC_VER >= 1900) // C++11 and MSVC 2015 onwards
|
||||
#define threadlocal thread_local
|
||||
#else
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1800) // there's an alternative for MSVC 2013
|
||||
#define threadlocal __declspec(thread)
|
||||
#else
|
||||
#define threadlocal
|
||||
#endif
|
||||
#endif
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
@ -66,37 +66,37 @@ extern "C" {
|
|||
threadlocal void *m3dimporter_pIOHandler;
|
||||
|
||||
unsigned char *m3dimporter_readfile(char *fn, unsigned int *size) {
|
||||
ai_assert(nullptr != fn);
|
||||
ai_assert(nullptr != size);
|
||||
std::string file(fn);
|
||||
std::unique_ptr<Assimp::IOStream> pStream(
|
||||
(reinterpret_cast<Assimp::IOSystem *>(m3dimporter_pIOHandler))->Open(file, "rb"));
|
||||
size_t fileSize = 0;
|
||||
unsigned char *data = NULL;
|
||||
// sometimes pStream is nullptr in a single-threaded scenario too for some reason
|
||||
// (should be an empty object returning nothing I guess)
|
||||
if (pStream) {
|
||||
fileSize = pStream->FileSize();
|
||||
// should be allocated with malloc(), because the library will call free() to deallocate
|
||||
data = (unsigned char *)malloc(fileSize);
|
||||
if (!data || !pStream.get() || !fileSize || fileSize != pStream->Read(data, 1, fileSize)) {
|
||||
pStream.reset();
|
||||
*size = 0;
|
||||
// don't throw a deadly exception, it's not fatal if we can't read an external asset
|
||||
return nullptr;
|
||||
}
|
||||
pStream.reset();
|
||||
}
|
||||
*size = (int)fileSize;
|
||||
return data;
|
||||
ai_assert(nullptr != fn);
|
||||
ai_assert(nullptr != size);
|
||||
std::string file(fn);
|
||||
std::unique_ptr<Assimp::IOStream> pStream(
|
||||
(reinterpret_cast<Assimp::IOSystem *>(m3dimporter_pIOHandler))->Open(file, "rb"));
|
||||
size_t fileSize = 0;
|
||||
unsigned char *data = NULL;
|
||||
// sometimes pStream is nullptr in a single-threaded scenario too for some reason
|
||||
// (should be an empty object returning nothing I guess)
|
||||
if (pStream) {
|
||||
fileSize = pStream->FileSize();
|
||||
// should be allocated with malloc(), because the library will call free() to deallocate
|
||||
data = (unsigned char *)malloc(fileSize);
|
||||
if (!data || !pStream.get() || !fileSize || fileSize != pStream->Read(data, 1, fileSize)) {
|
||||
pStream.reset();
|
||||
*size = 0;
|
||||
// don't throw a deadly exception, it's not fatal if we can't read an external asset
|
||||
return nullptr;
|
||||
}
|
||||
pStream.reset();
|
||||
}
|
||||
*size = (int)fileSize;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace Assimp {
|
||||
M3DWrapper::M3DWrapper() {
|
||||
// use malloc() here because m3d_free() will call free()
|
||||
m3d_ = (m3d_t *)calloc(1, sizeof(m3d_t));
|
||||
// use malloc() here because m3d_free() will call free()
|
||||
m3d_ = (m3d_t *)calloc(1, sizeof(m3d_t));
|
||||
}
|
||||
|
||||
M3DWrapper::M3DWrapper(IOSystem *pIOHandler, const std::vector<unsigned char> &buffer) {
|
||||
|
@ -105,41 +105,42 @@ M3DWrapper::M3DWrapper(IOSystem *pIOHandler, const std::vector<unsigned char> &b
|
|||
}
|
||||
|
||||
#ifdef ASSIMP_USE_M3D_READFILECB
|
||||
// pass this IOHandler to the C callback in a thread-local pointer
|
||||
m3dimporter_pIOHandler = pIOHandler;
|
||||
m3d_ = m3d_load(const_cast<unsigned char *>(buffer.data()), m3dimporter_readfile, free, nullptr);
|
||||
// Clear the C callback
|
||||
m3dimporter_pIOHandler = nullptr;
|
||||
// pass this IOHandler to the C callback in a thread-local pointer
|
||||
m3dimporter_pIOHandler = pIOHandler;
|
||||
m3d_ = m3d_load(const_cast<unsigned char *>(buffer.data()), m3dimporter_readfile, free, nullptr);
|
||||
// Clear the C callback
|
||||
m3dimporter_pIOHandler = nullptr;
|
||||
#else
|
||||
m3d_ = m3d_load(const_cast<unsigned char *>(buffer.data()), nullptr, nullptr, nullptr);
|
||||
m3d_ = m3d_load(const_cast<unsigned char *>(buffer.data()), nullptr, nullptr, nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
M3DWrapper::~M3DWrapper() {
|
||||
reset();
|
||||
reset();
|
||||
}
|
||||
|
||||
void M3DWrapper::reset() {
|
||||
ClearSave();
|
||||
if (m3d_)
|
||||
m3d_free(m3d_);
|
||||
m3d_ = nullptr;
|
||||
ClearSave();
|
||||
if (m3d_) {
|
||||
m3d_free(m3d_);
|
||||
}
|
||||
m3d_ = nullptr;
|
||||
}
|
||||
|
||||
unsigned char *M3DWrapper::Save(int quality, int flags, unsigned int &size) {
|
||||
#if (!(ASSIMP_BUILD_NO_EXPORT || ASSIMP_BUILD_NO_M3D_EXPORTER))
|
||||
ClearSave();
|
||||
saved_output_ = m3d_save(m3d_, quality, flags, &size);
|
||||
return saved_output_;
|
||||
ClearSave();
|
||||
saved_output_ = m3d_save(m3d_, quality, flags, &size);
|
||||
return saved_output_;
|
||||
#else
|
||||
return nullptr;
|
||||
return nullptr;
|
||||
#endif
|
||||
}
|
||||
|
||||
void M3DWrapper::ClearSave() {
|
||||
if (saved_output_)
|
||||
M3D_FREE(saved_output_);
|
||||
saved_output_ = nullptr;
|
||||
if (saved_output_)
|
||||
M3D_FREE(saved_output_);
|
||||
saved_output_ = nullptr;
|
||||
}
|
||||
} // namespace Assimp
|
||||
|
||||
|
|
|
@ -5440,13 +5440,13 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size
|
|||
out += 2;
|
||||
break;
|
||||
case 4:
|
||||
*((float *)out) = vrtx[i].data.x;
|
||||
memcpy(out, &vrtx[i].data.x, sizeof(float));
|
||||
out += 4;
|
||||
*((float *)out) = vrtx[i].data.y;
|
||||
memcpy(out, &vrtx[i].data.y, sizeof(float));
|
||||
out += 4;
|
||||
*((float *)out) = vrtx[i].data.z;
|
||||
memcpy(out, &vrtx[i].data.z, sizeof(float));
|
||||
out += 4;
|
||||
*((float *)out) = vrtx[i].data.w;
|
||||
memcpy(out, &vrtx[i].data.w, sizeof(float));
|
||||
out += 4;
|
||||
break;
|
||||
case 8:
|
||||
|
@ -5474,9 +5474,11 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size
|
|||
}
|
||||
out = _m3d_addidx(out, sk_s, vrtx[i].data.skinid);
|
||||
}
|
||||
*length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t *)h + len));
|
||||
uint32_t v = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t *)h + len));
|
||||
memcpy(length, &v, sizeof(uint32_t));
|
||||
//*length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t *)h + len));
|
||||
out = NULL;
|
||||
len += *length;
|
||||
len += v;
|
||||
}
|
||||
/* bones chunk */
|
||||
if (model->numbone && model->bone && !(flags & M3D_EXP_NOBONE)) {
|
||||
|
@ -5660,8 +5662,9 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size
|
|||
out = _m3d_addidx(out, vi_s, vrtxidx[face[i].data.normal[j]]);
|
||||
}
|
||||
}
|
||||
*length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t *)h + len));
|
||||
len += *length;
|
||||
uint32_t v = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t *)h + len));
|
||||
memcpy(length, &v, sizeof(uint32_t));
|
||||
len += v;
|
||||
out = NULL;
|
||||
}
|
||||
/* mathematical shapes face */
|
||||
|
@ -5721,8 +5724,9 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size
|
|||
}
|
||||
}
|
||||
}
|
||||
*length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t *)h + len));
|
||||
len += *length;
|
||||
uint32_t v = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t *)h + len));
|
||||
memcpy( length, &v, sizeof(uint32_t));
|
||||
len += v;
|
||||
out = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -5765,8 +5769,9 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size
|
|||
out = _m3d_addidx(out, si_s, _m3d_stridx(str, numstr, model->label[l].text));
|
||||
}
|
||||
if (length) {
|
||||
*length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t *)h + len));
|
||||
len += *length;
|
||||
uint32_t v = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t *)h + len));
|
||||
memcpy( length, &v, sizeof(uint32_t));
|
||||
len += v;
|
||||
}
|
||||
out = NULL;
|
||||
sn = sl = NULL;
|
||||
|
@ -5796,8 +5801,9 @@ unsigned char *m3d_save(m3d_t *model, int quality, int flags, unsigned int *size
|
|||
out = _m3d_addidx(out, vi_s, vrtxidx[a->frame[i].transform[k].ori]);
|
||||
}
|
||||
}
|
||||
*length = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t *)h + len));
|
||||
len += *length;
|
||||
uint32_t v = (uint32_t)((uintptr_t)out - (uintptr_t)((uint8_t *)h + len));
|
||||
memcpy( length, &v, sizeof(uint32_t));
|
||||
len += v;
|
||||
out = NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -503,7 +503,7 @@ aiReturn aiMaterial::AddBinaryProperty (const void* pInput,
|
|||
pcNew->mData = new char[pSizeInBytes];
|
||||
memcpy (pcNew->mData,pInput,pSizeInBytes);
|
||||
|
||||
pcNew->mKey.length = (ai_uint32)::strlen(pKey);
|
||||
pcNew->mKey.length = static_cast<ai_uint32>( ::strlen(pKey) );
|
||||
ai_assert ( MAXLEN > pcNew->mKey.length);
|
||||
strcpy( pcNew->mKey.data, pKey );
|
||||
|
||||
|
|
|
@ -617,7 +617,7 @@ bool Q3BSPFileImporter::importTextureFromArchive( const Q3BSP::Q3BSPModel *model
|
|||
// We'll leave it up to the user to figure out which extension the file has.
|
||||
aiString name;
|
||||
strncpy( name.data, pTexture->strName, sizeof name.data );
|
||||
name.length = (ai_uint32)strlen( name.data );
|
||||
name.length = static_cast<ai_uint32>(strlen( name.data ));
|
||||
pMatHelper->AddProperty( &name, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -616,7 +616,7 @@ void SMDImporter::CreateOutputMaterials() {
|
|||
if (aszTextures[iMat].length())
|
||||
{
|
||||
::strncpy(szName.data, aszTextures[iMat].c_str(),MAXLEN-1);
|
||||
szName.length = (ai_uint32)aszTextures[iMat].length();
|
||||
szName.length = static_cast<ai_uint32>( aszTextures[iMat].length() );
|
||||
pcMat->AddProperty(&szName,AI_MATKEY_TEXTURE_DIFFUSE(0));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
@ -43,17 +41,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
/** @file Implementation of the Terragen importer class */
|
||||
|
||||
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_TERRAGEN_IMPORTER
|
||||
|
||||
#include "TerragenLoader.h"
|
||||
#include <assimp/StreamReader.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp/importerdesc.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/importerdesc.h>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp/Importer.hpp>
|
||||
|
||||
using namespace Assimp;
|
||||
|
||||
|
@ -72,78 +68,72 @@ static const aiImporterDesc desc = {
|
|||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor to be privately used by Importer
|
||||
TerragenImporter::TerragenImporter()
|
||||
: configComputeUVs (false)
|
||||
{}
|
||||
TerragenImporter::TerragenImporter() :
|
||||
configComputeUVs(false) {}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Destructor, private as well
|
||||
TerragenImporter::~TerragenImporter()
|
||||
{}
|
||||
TerragenImporter::~TerragenImporter() {}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Returns whether the class can handle the format of the given file.
|
||||
bool TerragenImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
|
||||
{
|
||||
bool TerragenImporter::CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const {
|
||||
// check file extension
|
||||
std::string extension = GetExtension(pFile);
|
||||
|
||||
if( extension == "ter")
|
||||
if (extension == "ter")
|
||||
return true;
|
||||
|
||||
if( !extension.length() || checkSig) {
|
||||
if (!extension.length() || checkSig) {
|
||||
/* If CanRead() is called in order to check whether we
|
||||
* support a specific file extension in general pIOHandler
|
||||
* might be NULL and it's our duty to return true here.
|
||||
*/
|
||||
if (!pIOHandler)return true;
|
||||
const char* tokens[] = {"terragen"};
|
||||
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1);
|
||||
if (!pIOHandler) return true;
|
||||
const char *tokens[] = { "terragen" };
|
||||
return SearchFileHeaderForToken(pIOHandler, pFile, tokens, 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Build a string of all file extensions supported
|
||||
const aiImporterDesc* TerragenImporter::GetInfo () const
|
||||
{
|
||||
const aiImporterDesc *TerragenImporter::GetInfo() const {
|
||||
return &desc;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Setup import properties
|
||||
void TerragenImporter::SetupProperties(const Importer* pImp)
|
||||
{
|
||||
void TerragenImporter::SetupProperties(const Importer *pImp) {
|
||||
// AI_CONFIG_IMPORT_TER_MAKE_UVS
|
||||
configComputeUVs = ( 0 != pImp->GetPropertyInteger(AI_CONFIG_IMPORT_TER_MAKE_UVS,0) );
|
||||
configComputeUVs = (0 != pImp->GetPropertyInteger(AI_CONFIG_IMPORT_TER_MAKE_UVS, 0));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Imports the given file into the given scene structure.
|
||||
void TerragenImporter::InternReadFile( const std::string& pFile,
|
||||
aiScene* pScene, IOSystem* pIOHandler)
|
||||
{
|
||||
IOStream* file = pIOHandler->Open( pFile, "rb");
|
||||
void TerragenImporter::InternReadFile(const std::string &pFile,
|
||||
aiScene *pScene, IOSystem *pIOHandler) {
|
||||
IOStream *file = pIOHandler->Open(pFile, "rb");
|
||||
|
||||
// Check whether we can read from the file
|
||||
if( file == NULL)
|
||||
throw DeadlyImportError( "Failed to open TERRAGEN TERRAIN file " + pFile + ".");
|
||||
if (file == NULL)
|
||||
throw DeadlyImportError("Failed to open TERRAGEN TERRAIN file " + pFile + ".");
|
||||
|
||||
// Construct a stream reader to read all data in the correct endianness
|
||||
StreamReaderLE reader(file);
|
||||
if(reader.GetRemainingSize() < 16)
|
||||
throw DeadlyImportError( "TER: file is too small" );
|
||||
if (reader.GetRemainingSize() < 16)
|
||||
throw DeadlyImportError("TER: file is too small");
|
||||
|
||||
// Check for the existence of the two magic strings 'TERRAGEN' and 'TERRAIN '
|
||||
if (::strncmp((const char*)reader.GetPtr(),AI_TERR_BASE_STRING,8))
|
||||
throw DeadlyImportError( "TER: Magic string \'TERRAGEN\' not found" );
|
||||
if (::strncmp((const char *)reader.GetPtr(), AI_TERR_BASE_STRING, 8))
|
||||
throw DeadlyImportError("TER: Magic string \'TERRAGEN\' not found");
|
||||
|
||||
if (::strncmp((const char*)reader.GetPtr()+8,AI_TERR_TERRAIN_STRING,8))
|
||||
throw DeadlyImportError( "TER: Magic string \'TERRAIN\' not found" );
|
||||
if (::strncmp((const char *)reader.GetPtr() + 8, AI_TERR_TERRAIN_STRING, 8))
|
||||
throw DeadlyImportError("TER: Magic string \'TERRAIN\' not found");
|
||||
|
||||
unsigned int x = 0,y = 0,mode = 0;
|
||||
unsigned int x = 0, y = 0, mode = 0;
|
||||
|
||||
aiNode* root = pScene->mRootNode = new aiNode();
|
||||
aiNode *root = pScene->mRootNode = new aiNode();
|
||||
root->mName.Set("<TERRAGEN.TERRAIN>");
|
||||
|
||||
// Default scaling is 30
|
||||
|
@ -151,104 +141,98 @@ void TerragenImporter::InternReadFile( const std::string& pFile,
|
|||
|
||||
// Now read all chunks until we're finished or an EOF marker is encountered
|
||||
reader.IncPtr(16);
|
||||
while (reader.GetRemainingSize() >= 4)
|
||||
{
|
||||
const char* head = (const char*)reader.GetPtr();
|
||||
while (reader.GetRemainingSize() >= 4) {
|
||||
const char *head = (const char *)reader.GetPtr();
|
||||
reader.IncPtr(4);
|
||||
|
||||
// EOF, break in every case
|
||||
if (!::strncmp(head,AI_TERR_EOF_STRING,4))
|
||||
if (!::strncmp(head, AI_TERR_EOF_STRING, 4))
|
||||
break;
|
||||
|
||||
// Number of x-data points
|
||||
if (!::strncmp(head,AI_TERR_CHUNK_XPTS,4))
|
||||
{
|
||||
if (!::strncmp(head, AI_TERR_CHUNK_XPTS, 4)) {
|
||||
x = (uint16_t)reader.GetI2();
|
||||
}
|
||||
// Number of y-data points
|
||||
else if (!::strncmp(head,AI_TERR_CHUNK_YPTS,4))
|
||||
{
|
||||
else if (!::strncmp(head, AI_TERR_CHUNK_YPTS, 4)) {
|
||||
y = (uint16_t)reader.GetI2();
|
||||
}
|
||||
// Squared terrains width-1.
|
||||
else if (!::strncmp(head,AI_TERR_CHUNK_SIZE,4))
|
||||
{
|
||||
x = y = (uint16_t)reader.GetI2()+1;
|
||||
else if (!::strncmp(head, AI_TERR_CHUNK_SIZE, 4)) {
|
||||
x = y = (uint16_t)reader.GetI2() + 1;
|
||||
}
|
||||
// terrain scaling
|
||||
else if (!::strncmp(head,AI_TERR_CHUNK_SCAL,4))
|
||||
{
|
||||
else if (!::strncmp(head, AI_TERR_CHUNK_SCAL, 4)) {
|
||||
root->mTransformation.a1 = reader.GetF4();
|
||||
root->mTransformation.b2 = reader.GetF4();
|
||||
root->mTransformation.c3 = reader.GetF4();
|
||||
}
|
||||
// mapping == 1: earth radius
|
||||
else if (!::strncmp(head,AI_TERR_CHUNK_CRAD,4))
|
||||
{
|
||||
else if (!::strncmp(head, AI_TERR_CHUNK_CRAD, 4)) {
|
||||
reader.GetF4();
|
||||
}
|
||||
// mapping mode
|
||||
else if (!::strncmp(head,AI_TERR_CHUNK_CRVM,4))
|
||||
{
|
||||
else if (!::strncmp(head, AI_TERR_CHUNK_CRVM, 4)) {
|
||||
mode = reader.GetI1();
|
||||
if (0 != mode)
|
||||
ASSIMP_LOG_ERROR("TER: Unsupported mapping mode, a flat terrain is returned");
|
||||
}
|
||||
// actual terrain data
|
||||
else if (!::strncmp(head,AI_TERR_CHUNK_ALTW,4))
|
||||
{
|
||||
float hscale = (float)reader.GetI2() / 65536;
|
||||
else if (!::strncmp(head, AI_TERR_CHUNK_ALTW, 4)) {
|
||||
float hscale = (float)reader.GetI2() / 65536;
|
||||
float bheight = (float)reader.GetI2();
|
||||
|
||||
if (!hscale)hscale = 1;
|
||||
if (!hscale) hscale = 1;
|
||||
|
||||
// Ensure we have enough data
|
||||
if (reader.GetRemainingSize() < x*y*2)
|
||||
if (reader.GetRemainingSize() < x * y * 2)
|
||||
throw DeadlyImportError("TER: ALTW chunk is too small");
|
||||
|
||||
if (x <= 1 || y <= 1)
|
||||
throw DeadlyImportError("TER: Invalid terrain size");
|
||||
|
||||
// Allocate the output mesh
|
||||
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes = 1];
|
||||
aiMesh* m = pScene->mMeshes[0] = new aiMesh();
|
||||
pScene->mMeshes = new aiMesh *[pScene->mNumMeshes = 1];
|
||||
aiMesh *m = pScene->mMeshes[0] = new aiMesh();
|
||||
|
||||
// We return quads
|
||||
aiFace* f = m->mFaces = new aiFace[m->mNumFaces = (x-1)*(y-1)];
|
||||
aiVector3D* pv = m->mVertices = new aiVector3D[m->mNumVertices = m->mNumFaces*4];
|
||||
aiFace *f = m->mFaces = new aiFace[m->mNumFaces = (x - 1) * (y - 1)];
|
||||
aiVector3D *pv = m->mVertices = new aiVector3D[m->mNumVertices = m->mNumFaces * 4];
|
||||
|
||||
aiVector3D *uv( NULL );
|
||||
float step_y( 0.0f ), step_x( 0.0f );
|
||||
aiVector3D *uv(NULL);
|
||||
float step_y(0.0f), step_x(0.0f);
|
||||
if (configComputeUVs) {
|
||||
uv = m->mTextureCoords[0] = new aiVector3D[m->mNumVertices];
|
||||
step_y = 1.f/y;
|
||||
step_x = 1.f/x;
|
||||
step_y = 1.f / y;
|
||||
step_x = 1.f / x;
|
||||
}
|
||||
const int16_t* data = (const int16_t*)reader.GetPtr();
|
||||
const int16_t *data = (const int16_t *)reader.GetPtr();
|
||||
|
||||
for (unsigned int yy = 0, t = 0; yy < y-1;++yy) {
|
||||
for (unsigned int xx = 0; xx < x-1;++xx,++f) {
|
||||
for (unsigned int yy = 0, t = 0; yy < y - 1; ++yy) {
|
||||
for (unsigned int xx = 0; xx < x - 1; ++xx, ++f) {
|
||||
|
||||
// make verts
|
||||
const float fy = (float)yy, fx = (float)xx;
|
||||
unsigned tmp,tmp2;
|
||||
*pv++ = aiVector3D(fx,fy, (float)data[(tmp2=x*yy) + xx] * hscale + bheight);
|
||||
*pv++ = aiVector3D(fx,fy+1, (float)data[(tmp=x*(yy+1)) + xx] * hscale + bheight);
|
||||
*pv++ = aiVector3D(fx+1,fy+1,(float)data[tmp + xx+1] * hscale + bheight);
|
||||
*pv++ = aiVector3D(fx+1,fy, (float)data[tmp2 + xx+1] * hscale + bheight);
|
||||
unsigned tmp, tmp2;
|
||||
*pv++ = aiVector3D(fx, fy, (float)data[(tmp2 = x * yy) + xx] * hscale + bheight);
|
||||
*pv++ = aiVector3D(fx, fy + 1, (float)data[(tmp = x * (yy + 1)) + xx] * hscale + bheight);
|
||||
*pv++ = aiVector3D(fx + 1, fy + 1, (float)data[tmp + xx + 1] * hscale + bheight);
|
||||
*pv++ = aiVector3D(fx + 1, fy, (float)data[tmp2 + xx + 1] * hscale + bheight);
|
||||
|
||||
// also make texture coordinates, if necessary
|
||||
if (configComputeUVs) {
|
||||
*uv++ = aiVector3D( step_x*xx, step_y*yy, 0.f );
|
||||
*uv++ = aiVector3D( step_x*xx, step_y*(yy+1), 0.f );
|
||||
*uv++ = aiVector3D( step_x*(xx+1), step_y*(yy+1), 0.f );
|
||||
*uv++ = aiVector3D( step_x*(xx+1), step_y*yy, 0.f );
|
||||
*uv++ = aiVector3D(step_x * xx, step_y * yy, 0.f);
|
||||
*uv++ = aiVector3D(step_x * xx, step_y * (yy + 1), 0.f);
|
||||
*uv++ = aiVector3D(step_x * (xx + 1), step_y * (yy + 1), 0.f);
|
||||
*uv++ = aiVector3D(step_x * (xx + 1), step_y * yy, 0.f);
|
||||
}
|
||||
|
||||
// make indices
|
||||
f->mIndices = new unsigned int[f->mNumIndices = 4];
|
||||
for (unsigned int i = 0; i < 4;++i)
|
||||
f->mIndices[i] = t++;
|
||||
for (unsigned int i = 0; i < 4; ++i) {
|
||||
f->mIndices[i] = t;
|
||||
t++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,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,
|
||||
|
@ -47,21 +46,21 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#define INCLUDED_AI_TERRAGEN_TERRAIN_LOADER_H
|
||||
|
||||
#include <assimp/BaseImporter.h>
|
||||
namespace Assimp {
|
||||
namespace Assimp {
|
||||
|
||||
// Magic strings
|
||||
#define AI_TERR_BASE_STRING "TERRAGEN"
|
||||
#define AI_TERR_TERRAIN_STRING "TERRAIN "
|
||||
#define AI_TERR_EOF_STRING "EOF "
|
||||
#define AI_TERR_BASE_STRING "TERRAGEN"
|
||||
#define AI_TERR_TERRAIN_STRING "TERRAIN "
|
||||
#define AI_TERR_EOF_STRING "EOF "
|
||||
|
||||
// Chunka
|
||||
#define AI_TERR_CHUNK_XPTS "XPTS"
|
||||
#define AI_TERR_CHUNK_YPTS "YPTS"
|
||||
#define AI_TERR_CHUNK_SIZE "SIZE"
|
||||
#define AI_TERR_CHUNK_SCAL "SCAL"
|
||||
#define AI_TERR_CHUNK_CRAD "CRAD"
|
||||
#define AI_TERR_CHUNK_CRVM "CRVM"
|
||||
#define AI_TERR_CHUNK_ALTW "ALTW"
|
||||
#define AI_TERR_CHUNK_XPTS "XPTS"
|
||||
#define AI_TERR_CHUNK_YPTS "YPTS"
|
||||
#define AI_TERR_CHUNK_SIZE "SIZE"
|
||||
#define AI_TERR_CHUNK_SCAL "SCAL"
|
||||
#define AI_TERR_CHUNK_CRAD "CRAD"
|
||||
#define AI_TERR_CHUNK_CRVM "CRVM"
|
||||
#define AI_TERR_CHUNK_ALTW "ALTW"
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** @brief Importer class to load Terragen (0.9) terrain files.
|
||||
|
@ -69,33 +68,28 @@ namespace Assimp {
|
|||
* The loader is basing on the information found here:
|
||||
* http://www.planetside.co.uk/terragen/dev/tgterrain.html#chunks
|
||||
*/
|
||||
class TerragenImporter : public BaseImporter
|
||||
{
|
||||
class TerragenImporter : public BaseImporter {
|
||||
public:
|
||||
TerragenImporter();
|
||||
~TerragenImporter();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
|
||||
bool checkSig) const;
|
||||
bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
|
||||
bool checkSig) const;
|
||||
|
||||
protected:
|
||||
// -------------------------------------------------------------------
|
||||
const aiImporterDesc *GetInfo() const;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
const aiImporterDesc* GetInfo () const;
|
||||
void InternReadFile(const std::string &pFile, aiScene *pScene,
|
||||
IOSystem *pIOHandler);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
void InternReadFile( const std::string& pFile, aiScene* pScene,
|
||||
IOSystem* pIOHandler);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
void SetupProperties(const Importer* pImp);
|
||||
void SetupProperties(const Importer *pImp);
|
||||
|
||||
private:
|
||||
|
||||
bool configComputeUVs;
|
||||
|
||||
}; //! class TerragenImporter
|
||||
|
|
|
@ -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,
|
||||
|
@ -48,26 +46,112 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
* http://local.wasp.uwa.edu.au/~pbourke/dataformats/unreal/
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_3D_IMPORTER
|
||||
|
||||
#include "Unreal/UnrealLoader.h"
|
||||
#include "PostProcessing/ConvertToLHProcess.h"
|
||||
|
||||
#include <assimp/StreamReader.h>
|
||||
#include <assimp/ParsingUtils.h>
|
||||
#include <assimp/StreamReader.h>
|
||||
#include <assimp/fast_atof.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/importerdesc.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/DefaultLogger.hpp>
|
||||
#include <assimp/IOSystem.hpp>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/importerdesc.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <memory>
|
||||
|
||||
using namespace Assimp;
|
||||
|
||||
namespace Unreal {
|
||||
|
||||
/*
|
||||
0 = Normal one-sided
|
||||
1 = Normal two-sided
|
||||
2 = Translucent two-sided
|
||||
3 = Masked two-sided
|
||||
4 = Modulation blended two-sided
|
||||
8 = Placeholder triangle for weapon positioning (invisible)
|
||||
*/
|
||||
enum MeshFlags {
|
||||
MF_NORMAL_OS = 0,
|
||||
MF_NORMAL_TS = 1,
|
||||
MF_NORMAL_TRANS_TS = 2,
|
||||
MF_NORMAL_MASKED_TS = 3,
|
||||
MF_NORMAL_MOD_TS = 4,
|
||||
MF_WEAPON_PLACEHOLDER = 8
|
||||
};
|
||||
|
||||
// a single triangle
|
||||
struct Triangle {
|
||||
uint16_t mVertex[3]; // Vertex indices
|
||||
char mType; // James' Mesh Type
|
||||
char mColor; // Color for flat and Gourand Shaded
|
||||
unsigned char mTex[3][2]; // Texture UV coordinates
|
||||
unsigned char mTextureNum; // Source texture offset
|
||||
char mFlags; // Unreal Mesh Flags (unused)
|
||||
unsigned int matIndex;
|
||||
};
|
||||
|
||||
// temporary representation for a material
|
||||
struct TempMat {
|
||||
TempMat() :
|
||||
type(MF_NORMAL_OS), tex(), numFaces(0) {}
|
||||
|
||||
explicit TempMat(const Triangle &in) :
|
||||
type((Unreal::MeshFlags)in.mType), tex(in.mTextureNum), numFaces(0) {}
|
||||
|
||||
// type of mesh
|
||||
Unreal::MeshFlags type;
|
||||
|
||||
// index of texture
|
||||
unsigned int tex;
|
||||
|
||||
// number of faces using us
|
||||
unsigned int numFaces;
|
||||
|
||||
// for std::find
|
||||
bool operator==(const TempMat &o) {
|
||||
return (tex == o.tex && type == o.type);
|
||||
}
|
||||
};
|
||||
|
||||
struct Vertex {
|
||||
int32_t X : 11;
|
||||
int32_t Y : 11;
|
||||
int32_t Z : 10;
|
||||
};
|
||||
|
||||
// UNREAL vertex compression
|
||||
inline void CompressVertex(const aiVector3D &v, uint32_t &out) {
|
||||
union {
|
||||
Vertex n;
|
||||
int32_t t;
|
||||
};
|
||||
t = 0;
|
||||
n.X = (int32_t)v.x;
|
||||
n.Y = (int32_t)v.y;
|
||||
n.Z = (int32_t)v.z;
|
||||
::memcpy(&out, &t, sizeof(int32_t));
|
||||
}
|
||||
|
||||
// UNREAL vertex decompression
|
||||
inline void DecompressVertex(aiVector3D &v, int32_t in) {
|
||||
union {
|
||||
Vertex n;
|
||||
int32_t i;
|
||||
};
|
||||
i = in;
|
||||
|
||||
v.x = (float)n.X;
|
||||
v.y = (float)n.Y;
|
||||
v.z = (float)n.Z;
|
||||
}
|
||||
|
||||
} // end namespace Unreal
|
||||
|
||||
static const aiImporterDesc desc = {
|
||||
"Unreal Mesh Importer",
|
||||
"",
|
||||
|
@ -81,79 +165,70 @@ static const aiImporterDesc desc = {
|
|||
"3d uc"
|
||||
};
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor to be privately used by Importer
|
||||
UnrealImporter::UnrealImporter()
|
||||
: configFrameID (0)
|
||||
, configHandleFlags (true)
|
||||
{}
|
||||
UnrealImporter::UnrealImporter() :
|
||||
mConfigFrameID(0), mConfigHandleFlags(true) {}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Destructor, private as well
|
||||
UnrealImporter::~UnrealImporter()
|
||||
{}
|
||||
UnrealImporter::~UnrealImporter() {}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Returns whether the class can handle the format of the given file.
|
||||
bool UnrealImporter::CanRead( const std::string& pFile, IOSystem* /*pIOHandler*/, bool /*checkSig*/) const
|
||||
{
|
||||
return SimpleExtensionCheck(pFile,"3d","uc");
|
||||
bool UnrealImporter::CanRead(const std::string &pFile, IOSystem * /*pIOHandler*/, bool /*checkSig*/) const {
|
||||
return SimpleExtensionCheck(pFile, "3d", "uc");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Build a string of all file extensions supported
|
||||
const aiImporterDesc* UnrealImporter::GetInfo () const
|
||||
{
|
||||
const aiImporterDesc *UnrealImporter::GetInfo() const {
|
||||
return &desc;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Setup configuration properties for the loader
|
||||
void UnrealImporter::SetupProperties(const Importer* pImp)
|
||||
{
|
||||
void UnrealImporter::SetupProperties(const Importer *pImp) {
|
||||
// The
|
||||
// AI_CONFIG_IMPORT_UNREAL_KEYFRAME option overrides the
|
||||
// AI_CONFIG_IMPORT_GLOBAL_KEYFRAME option.
|
||||
configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_UNREAL_KEYFRAME,-1);
|
||||
if(static_cast<unsigned int>(-1) == configFrameID) {
|
||||
configFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_GLOBAL_KEYFRAME,0);
|
||||
mConfigFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_UNREAL_KEYFRAME, -1);
|
||||
if (static_cast<unsigned int>(-1) == mConfigFrameID) {
|
||||
mConfigFrameID = pImp->GetPropertyInteger(AI_CONFIG_IMPORT_GLOBAL_KEYFRAME, 0);
|
||||
}
|
||||
|
||||
// AI_CONFIG_IMPORT_UNREAL_HANDLE_FLAGS, default is true
|
||||
configHandleFlags = (0 != pImp->GetPropertyInteger(AI_CONFIG_IMPORT_UNREAL_HANDLE_FLAGS,1));
|
||||
mConfigHandleFlags = (0 != pImp->GetPropertyInteger(AI_CONFIG_IMPORT_UNREAL_HANDLE_FLAGS, 1));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Imports the given file into the given scene structure.
|
||||
void UnrealImporter::InternReadFile( const std::string& pFile,
|
||||
aiScene* pScene, IOSystem* pIOHandler)
|
||||
{
|
||||
void UnrealImporter::InternReadFile(const std::string &pFile,
|
||||
aiScene *pScene, IOSystem *pIOHandler) {
|
||||
// For any of the 3 files being passed get the three correct paths
|
||||
// First of all, determine file extension
|
||||
std::string::size_type pos = pFile.find_last_of('.');
|
||||
std::string extension = GetExtension(pFile);
|
||||
|
||||
std::string d_path,a_path,uc_path;
|
||||
if (extension == "3d") {
|
||||
std::string d_path, a_path, uc_path;
|
||||
if (extension == "3d") {
|
||||
// jjjj_d.3d
|
||||
// jjjj_a.3d
|
||||
pos = pFile.find_last_of('_');
|
||||
if (std::string::npos == pos) {
|
||||
throw DeadlyImportError("UNREAL: Unexpected naming scheme");
|
||||
}
|
||||
extension = pFile.substr(0,pos);
|
||||
}
|
||||
else {
|
||||
extension = pFile.substr(0,pos);
|
||||
extension = pFile.substr(0, pos);
|
||||
} else {
|
||||
extension = pFile.substr(0, pos);
|
||||
}
|
||||
|
||||
// build proper paths
|
||||
d_path = extension+"_d.3d";
|
||||
a_path = extension+"_a.3d";
|
||||
uc_path = extension+".uc";
|
||||
d_path = extension + "_d.3d";
|
||||
a_path = extension + "_a.3d";
|
||||
uc_path = extension + ".uc";
|
||||
|
||||
ASSIMP_LOG_DEBUG_F( "UNREAL: data file is ", d_path);
|
||||
ASSIMP_LOG_DEBUG_F("UNREAL: data file is ", d_path);
|
||||
ASSIMP_LOG_DEBUG_F("UNREAL: aniv file is ", a_path);
|
||||
ASSIMP_LOG_DEBUG_F("UNREAL: uc file is ", uc_path);
|
||||
|
||||
|
@ -174,11 +249,11 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
|
|||
|
||||
// collect triangles
|
||||
std::vector<Unreal::Triangle> triangles(numTris);
|
||||
for (auto & tri : triangles) {
|
||||
for (unsigned int i = 0; i < 3;++i) {
|
||||
for (auto &tri : triangles) {
|
||||
for (unsigned int i = 0; i < 3; ++i) {
|
||||
|
||||
tri.mVertex[i] = d_reader.GetI2();
|
||||
if (tri.mVertex[i] >= numTris) {
|
||||
if (tri.mVertex[i] >= numTris) {
|
||||
ASSIMP_LOG_WARN("UNREAL: vertex index out of range");
|
||||
tri.mVertex[i] = 0;
|
||||
}
|
||||
|
@ -186,7 +261,7 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
|
|||
tri.mType = d_reader.GetI1();
|
||||
|
||||
// handle mesh flagss?
|
||||
if (configHandleFlags)
|
||||
if (mConfigHandleFlags)
|
||||
tri.mType = Unreal::MF_NORMAL_OS;
|
||||
else {
|
||||
// ignore MOD and MASKED for the moment, treat them as two-sided
|
||||
|
@ -195,12 +270,12 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
|
|||
}
|
||||
d_reader.IncPtr(1);
|
||||
|
||||
for (unsigned int i = 0; i < 3;++i)
|
||||
for (unsigned int i2 = 0; i2 < 2;++i2)
|
||||
for (unsigned int i = 0; i < 3; ++i)
|
||||
for (unsigned int i2 = 0; i2 < 2; ++i2)
|
||||
tri.mTex[i][i2] = d_reader.GetI1();
|
||||
|
||||
tri.mTextureNum = d_reader.GetI1();
|
||||
maxTexIdx = std::max(maxTexIdx,(unsigned int)tri.mTextureNum);
|
||||
maxTexIdx = std::max(maxTexIdx, (unsigned int)tri.mTextureNum);
|
||||
d_reader.IncPtr(1);
|
||||
}
|
||||
|
||||
|
@ -211,63 +286,64 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
|
|||
|
||||
// read number of frames
|
||||
const uint32_t numFrames = a_reader.GetI2();
|
||||
if (configFrameID >= numFrames) {
|
||||
if (mConfigFrameID >= numFrames) {
|
||||
throw DeadlyImportError("UNREAL: The requested frame does not exist");
|
||||
}
|
||||
|
||||
uint32_t st = a_reader.GetI2();
|
||||
if (st != numVert*4u)
|
||||
if (st != numVert * 4u)
|
||||
throw DeadlyImportError("UNREAL: Unexpected aniv file length");
|
||||
|
||||
// skip to our frame
|
||||
a_reader.IncPtr(configFrameID *numVert*4);
|
||||
a_reader.IncPtr(mConfigFrameID * numVert * 4);
|
||||
|
||||
// collect vertices
|
||||
std::vector<aiVector3D> vertices(numVert);
|
||||
for (auto &vertex : vertices) {
|
||||
for (auto &vertex : vertices) {
|
||||
int32_t val = a_reader.GetI4();
|
||||
Unreal::DecompressVertex(vertex ,val);
|
||||
Unreal::DecompressVertex(vertex, val);
|
||||
}
|
||||
|
||||
// list of textures.
|
||||
std::vector< std::pair<unsigned int, std::string> > textures;
|
||||
std::vector<std::pair<unsigned int, std::string>> textures;
|
||||
|
||||
// allocate the output scene
|
||||
aiNode* nd = pScene->mRootNode = new aiNode();
|
||||
aiNode *nd = pScene->mRootNode = new aiNode();
|
||||
nd->mName.Set("<UnrealRoot>");
|
||||
|
||||
// we can live without the uc file if necessary
|
||||
std::unique_ptr<IOStream> pb (pIOHandler->Open(uc_path));
|
||||
if (pb.get()) {
|
||||
std::unique_ptr<IOStream> pb(pIOHandler->Open(uc_path));
|
||||
if (pb.get()) {
|
||||
|
||||
std::vector<char> _data;
|
||||
TextFileToBuffer(pb.get(),_data);
|
||||
const char* data = &_data[0];
|
||||
TextFileToBuffer(pb.get(), _data);
|
||||
const char *data = &_data[0];
|
||||
|
||||
std::vector< std::pair< std::string,std::string > > tempTextures;
|
||||
std::vector<std::pair<std::string, std::string>> tempTextures;
|
||||
|
||||
// do a quick search in the UC file for some known, usually texture-related, tags
|
||||
for (;*data;++data) {
|
||||
if (TokenMatchI(data,"#exec",5)) {
|
||||
for (; *data; ++data) {
|
||||
if (TokenMatchI(data, "#exec", 5)) {
|
||||
SkipSpacesAndLineEnd(&data);
|
||||
|
||||
// #exec TEXTURE IMPORT [...] NAME=jjjjj [...] FILE=jjjj.pcx [...]
|
||||
if (TokenMatchI(data,"TEXTURE",7)) {
|
||||
if (TokenMatchI(data, "TEXTURE", 7)) {
|
||||
SkipSpacesAndLineEnd(&data);
|
||||
|
||||
if (TokenMatchI(data,"IMPORT",6)) {
|
||||
tempTextures.push_back(std::pair< std::string,std::string >());
|
||||
std::pair< std::string,std::string >& me = tempTextures.back();
|
||||
for (;!IsLineEnd(*data);++data) {
|
||||
if (!::ASSIMP_strincmp(data,"NAME=",5)) {
|
||||
const char *d = data+=5;
|
||||
for (;!IsSpaceOrNewLine(*data);++data);
|
||||
me.first = std::string(d,(size_t)(data-d));
|
||||
}
|
||||
else if (!::ASSIMP_strincmp(data,"FILE=",5)) {
|
||||
const char *d = data+=5;
|
||||
for (;!IsSpaceOrNewLine(*data);++data);
|
||||
me.second = std::string(d,(size_t)(data-d));
|
||||
if (TokenMatchI(data, "IMPORT", 6)) {
|
||||
tempTextures.push_back(std::pair<std::string, std::string>());
|
||||
std::pair<std::string, std::string> &me = tempTextures.back();
|
||||
for (; !IsLineEnd(*data); ++data) {
|
||||
if (!::ASSIMP_strincmp(data, "NAME=", 5)) {
|
||||
const char *d = data += 5;
|
||||
for (; !IsSpaceOrNewLine(*data); ++data)
|
||||
;
|
||||
me.first = std::string(d, (size_t)(data - d));
|
||||
} else if (!::ASSIMP_strincmp(data, "FILE=", 5)) {
|
||||
const char *d = data += 5;
|
||||
for (; !IsSpaceOrNewLine(*data); ++data)
|
||||
;
|
||||
me.second = std::string(d, (size_t)(data - d));
|
||||
}
|
||||
}
|
||||
if (!me.first.length() || !me.second.length())
|
||||
|
@ -276,65 +352,61 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
|
|||
}
|
||||
// #exec MESHMAP SETTEXTURE MESHMAP=box NUM=1 TEXTURE=Jtex1
|
||||
// #exec MESHMAP SCALE MESHMAP=box X=0.1 Y=0.1 Z=0.2
|
||||
else if (TokenMatchI(data,"MESHMAP",7)) {
|
||||
else if (TokenMatchI(data, "MESHMAP", 7)) {
|
||||
SkipSpacesAndLineEnd(&data);
|
||||
|
||||
if (TokenMatchI(data,"SETTEXTURE",10)) {
|
||||
if (TokenMatchI(data, "SETTEXTURE", 10)) {
|
||||
|
||||
textures.push_back(std::pair<unsigned int, std::string>());
|
||||
std::pair<unsigned int, std::string>& me = textures.back();
|
||||
std::pair<unsigned int, std::string> &me = textures.back();
|
||||
|
||||
for (;!IsLineEnd(*data);++data) {
|
||||
if (!::ASSIMP_strincmp(data,"NUM=",4)) {
|
||||
for (; !IsLineEnd(*data); ++data) {
|
||||
if (!::ASSIMP_strincmp(data, "NUM=", 4)) {
|
||||
data += 4;
|
||||
me.first = strtoul10(data,&data);
|
||||
}
|
||||
else if (!::ASSIMP_strincmp(data,"TEXTURE=",8)) {
|
||||
me.first = strtoul10(data, &data);
|
||||
} else if (!::ASSIMP_strincmp(data, "TEXTURE=", 8)) {
|
||||
data += 8;
|
||||
const char *d = data;
|
||||
for (;!IsSpaceOrNewLine(*data);++data);
|
||||
me.second = std::string(d,(size_t)(data-d));
|
||||
for (; !IsSpaceOrNewLine(*data); ++data)
|
||||
;
|
||||
me.second = std::string(d, (size_t)(data - d));
|
||||
|
||||
// try to find matching path names, doesn't care if we don't find them
|
||||
for (std::vector< std::pair< std::string,std::string > >::const_iterator it = tempTextures.begin();
|
||||
it != tempTextures.end(); ++it) {
|
||||
if ((*it).first == me.second) {
|
||||
for (std::vector<std::pair<std::string, std::string>>::const_iterator it = tempTextures.begin();
|
||||
it != tempTextures.end(); ++it) {
|
||||
if ((*it).first == me.second) {
|
||||
me.second = (*it).second;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (TokenMatchI(data,"SCALE",5)) {
|
||||
} else if (TokenMatchI(data, "SCALE", 5)) {
|
||||
|
||||
for (;!IsLineEnd(*data);++data) {
|
||||
if (data[0] == 'X' && data[1] == '=') {
|
||||
data = fast_atoreal_move<float>(data+2,(float&)nd->mTransformation.a1);
|
||||
}
|
||||
else if (data[0] == 'Y' && data[1] == '=') {
|
||||
data = fast_atoreal_move<float>(data+2,(float&)nd->mTransformation.b2);
|
||||
}
|
||||
else if (data[0] == 'Z' && data[1] == '=') {
|
||||
data = fast_atoreal_move<float>(data+2,(float&)nd->mTransformation.c3);
|
||||
for (; !IsLineEnd(*data); ++data) {
|
||||
if (data[0] == 'X' && data[1] == '=') {
|
||||
data = fast_atoreal_move<float>(data + 2, (float &)nd->mTransformation.a1);
|
||||
} else if (data[0] == 'Y' && data[1] == '=') {
|
||||
data = fast_atoreal_move<float>(data + 2, (float &)nd->mTransformation.b2);
|
||||
} else if (data[0] == 'Z' && data[1] == '=') {
|
||||
data = fast_atoreal_move<float>(data + 2, (float &)nd->mTransformation.c3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ASSIMP_LOG_ERROR("Unable to open .uc file");
|
||||
}
|
||||
|
||||
std::vector<Unreal::TempMat> materials;
|
||||
materials.reserve(textures.size()*2+5);
|
||||
materials.reserve(textures.size() * 2 + 5);
|
||||
|
||||
// find out how many output meshes and materials we'll have and build material indices
|
||||
for (Unreal::Triangle &tri : triangles) {
|
||||
for (Unreal::Triangle &tri : triangles) {
|
||||
Unreal::TempMat mat(tri);
|
||||
std::vector<Unreal::TempMat>::iterator nt = std::find(materials.begin(),materials.end(),mat);
|
||||
std::vector<Unreal::TempMat>::iterator nt = std::find(materials.begin(), materials.end(), mat);
|
||||
if (nt == materials.end()) {
|
||||
// add material
|
||||
tri.matIndex = static_cast<unsigned int>(materials.size());
|
||||
|
@ -342,9 +414,8 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
|
|||
materials.push_back(mat);
|
||||
|
||||
++pScene->mNumMeshes;
|
||||
}
|
||||
else {
|
||||
tri.matIndex = static_cast<unsigned int>(nt-materials.begin());
|
||||
} else {
|
||||
tri.matIndex = static_cast<unsigned int>(nt - materials.begin());
|
||||
++nt->numFaces;
|
||||
}
|
||||
}
|
||||
|
@ -354,65 +425,65 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
|
|||
}
|
||||
|
||||
// allocate meshes and bind them to the node graph
|
||||
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
|
||||
pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials = pScene->mNumMeshes];
|
||||
pScene->mMeshes = new aiMesh *[pScene->mNumMeshes];
|
||||
pScene->mMaterials = new aiMaterial *[pScene->mNumMaterials = pScene->mNumMeshes];
|
||||
|
||||
nd->mNumMeshes = pScene->mNumMeshes;
|
||||
nd->mNumMeshes = pScene->mNumMeshes;
|
||||
nd->mMeshes = new unsigned int[nd->mNumMeshes];
|
||||
for (unsigned int i = 0; i < pScene->mNumMeshes;++i) {
|
||||
aiMesh* m = pScene->mMeshes[i] = new aiMesh();
|
||||
for (unsigned int i = 0; i < pScene->mNumMeshes; ++i) {
|
||||
aiMesh *m = pScene->mMeshes[i] = new aiMesh();
|
||||
m->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
|
||||
|
||||
const unsigned int num = materials[i].numFaces;
|
||||
m->mFaces = new aiFace [num];
|
||||
m->mVertices = new aiVector3D [num*3];
|
||||
m->mTextureCoords[0] = new aiVector3D [num*3];
|
||||
m->mFaces = new aiFace[num];
|
||||
m->mVertices = new aiVector3D[num * 3];
|
||||
m->mTextureCoords[0] = new aiVector3D[num * 3];
|
||||
|
||||
nd->mMeshes[i] = i;
|
||||
|
||||
// create materials, too
|
||||
aiMaterial* mat = new aiMaterial();
|
||||
aiMaterial *mat = new aiMaterial();
|
||||
pScene->mMaterials[i] = mat;
|
||||
|
||||
// all white by default - texture rulez
|
||||
aiColor3D color(1.f,1.f,1.f);
|
||||
aiColor3D color(1.f, 1.f, 1.f);
|
||||
|
||||
aiString s;
|
||||
::ai_snprintf( s.data, MAXLEN, "mat%u_tx%u_",i,materials[i].tex );
|
||||
::ai_snprintf(s.data, MAXLEN, "mat%u_tx%u_", i, materials[i].tex);
|
||||
|
||||
// set the two-sided flag
|
||||
if (materials[i].type == Unreal::MF_NORMAL_TS) {
|
||||
const int twosided = 1;
|
||||
mat->AddProperty(&twosided,1,AI_MATKEY_TWOSIDED);
|
||||
::strcat(s.data,"ts_");
|
||||
}
|
||||
else ::strcat(s.data,"os_");
|
||||
mat->AddProperty(&twosided, 1, AI_MATKEY_TWOSIDED);
|
||||
::strcat(s.data, "ts_");
|
||||
} else
|
||||
::strcat(s.data, "os_");
|
||||
|
||||
// make TRANS faces 90% opaque that RemRedundantMaterials won't catch us
|
||||
if (materials[i].type == Unreal::MF_NORMAL_TRANS_TS) {
|
||||
if (materials[i].type == Unreal::MF_NORMAL_TRANS_TS) {
|
||||
const float opac = 0.9f;
|
||||
mat->AddProperty(&opac,1,AI_MATKEY_OPACITY);
|
||||
::strcat(s.data,"tran_");
|
||||
}
|
||||
else ::strcat(s.data,"opaq_");
|
||||
mat->AddProperty(&opac, 1, AI_MATKEY_OPACITY);
|
||||
::strcat(s.data, "tran_");
|
||||
} else
|
||||
::strcat(s.data, "opaq_");
|
||||
|
||||
// a special name for the weapon attachment point
|
||||
if (materials[i].type == Unreal::MF_WEAPON_PLACEHOLDER) {
|
||||
s.length = ::ai_snprintf( s.data, MAXLEN, "$WeaponTag$" );
|
||||
color = aiColor3D(0.f,0.f,0.f);
|
||||
s.length = ::ai_snprintf(s.data, MAXLEN, "$WeaponTag$");
|
||||
color = aiColor3D(0.f, 0.f, 0.f);
|
||||
}
|
||||
|
||||
// set color and name
|
||||
mat->AddProperty(&color,1,AI_MATKEY_COLOR_DIFFUSE);
|
||||
s.length = (ai_uint32)::strlen(s.data);
|
||||
mat->AddProperty(&s,AI_MATKEY_NAME);
|
||||
mat->AddProperty(&color, 1, AI_MATKEY_COLOR_DIFFUSE);
|
||||
s.length = static_cast<ai_uint32>(::strlen(s.data));
|
||||
mat->AddProperty(&s, AI_MATKEY_NAME);
|
||||
|
||||
// set texture, if any
|
||||
const unsigned int tex = materials[i].tex;
|
||||
for (std::vector< std::pair< unsigned int, std::string > >::const_iterator it = textures.begin();it != textures.end();++it) {
|
||||
for (std::vector<std::pair<unsigned int, std::string>>::const_iterator it = textures.begin(); it != textures.end(); ++it) {
|
||||
if ((*it).first == tex) {
|
||||
s.Set((*it).second);
|
||||
mat->AddProperty(&s,AI_MATKEY_TEXTURE_DIFFUSE(0));
|
||||
mat->AddProperty(&s, AI_MATKEY_TEXTURE_DIFFUSE(0));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -421,17 +492,17 @@ void UnrealImporter::InternReadFile( const std::string& pFile,
|
|||
// fill them.
|
||||
for (const Unreal::Triangle &tri : triangles) {
|
||||
Unreal::TempMat mat(tri);
|
||||
std::vector<Unreal::TempMat>::iterator nt = std::find(materials.begin(),materials.end(),mat);
|
||||
std::vector<Unreal::TempMat>::iterator nt = std::find(materials.begin(), materials.end(), mat);
|
||||
|
||||
aiMesh* mesh = pScene->mMeshes[nt-materials.begin()];
|
||||
aiFace& f = mesh->mFaces[mesh->mNumFaces++];
|
||||
f.mIndices = new unsigned int[f.mNumIndices = 3];
|
||||
aiMesh *mesh = pScene->mMeshes[nt - materials.begin()];
|
||||
aiFace &f = mesh->mFaces[mesh->mNumFaces++];
|
||||
f.mIndices = new unsigned int[f.mNumIndices = 3];
|
||||
|
||||
for (unsigned int i = 0; i < 3;++i,mesh->mNumVertices++) {
|
||||
for (unsigned int i = 0; i < 3; ++i, mesh->mNumVertices++) {
|
||||
f.mIndices[i] = mesh->mNumVertices;
|
||||
|
||||
mesh->mVertices[mesh->mNumVertices] = vertices[ tri.mVertex[i] ];
|
||||
mesh->mTextureCoords[0][mesh->mNumVertices] = aiVector3D( tri.mTex[i][0] / 255.f, 1.f - tri.mTex[i][1] / 255.f, 0.f);
|
||||
mesh->mVertices[mesh->mNumVertices] = vertices[tri.mVertex[i]];
|
||||
mesh->mTextureCoords[0][mesh->mNumVertices] = aiVector3D(tri.mTex[i][0] / 255.f, 1.f - tri.mTex[i][1] / 255.f, 0.f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,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,
|
||||
|
@ -47,161 +46,57 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#define INCLUDED_AI_3D_LOADER_H
|
||||
|
||||
#include <assimp/BaseImporter.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace Assimp {
|
||||
namespace Unreal {
|
||||
|
||||
/*
|
||||
0 = Normal one-sided
|
||||
1 = Normal two-sided
|
||||
2 = Translucent two-sided
|
||||
3 = Masked two-sided
|
||||
4 = Modulation blended two-sided
|
||||
8 = Placeholder triangle for weapon positioning (invisible)
|
||||
*/
|
||||
enum MeshFlags {
|
||||
MF_NORMAL_OS = 0,
|
||||
MF_NORMAL_TS = 1,
|
||||
MF_NORMAL_TRANS_TS = 2,
|
||||
MF_NORMAL_MASKED_TS = 3,
|
||||
MF_NORMAL_MOD_TS = 4,
|
||||
MF_WEAPON_PLACEHOLDER = 8
|
||||
};
|
||||
|
||||
// a single triangle
|
||||
struct Triangle {
|
||||
uint16_t mVertex[3]; // Vertex indices
|
||||
char mType; // James' Mesh Type
|
||||
char mColor; // Color for flat and Gourand Shaded
|
||||
unsigned char mTex[3][2]; // Texture UV coordinates
|
||||
unsigned char mTextureNum; // Source texture offset
|
||||
char mFlags; // Unreal Mesh Flags (unused)
|
||||
|
||||
unsigned int matIndex;
|
||||
};
|
||||
|
||||
// temporary representation for a material
|
||||
struct TempMat {
|
||||
TempMat()
|
||||
: type()
|
||||
, tex()
|
||||
, numFaces (0)
|
||||
{}
|
||||
|
||||
explicit TempMat(const Triangle& in)
|
||||
: type ((Unreal::MeshFlags)in.mType)
|
||||
, tex (in.mTextureNum)
|
||||
, numFaces (0)
|
||||
{}
|
||||
|
||||
// type of mesh
|
||||
Unreal::MeshFlags type;
|
||||
|
||||
// index of texture
|
||||
unsigned int tex;
|
||||
|
||||
// number of faces using us
|
||||
unsigned int numFaces;
|
||||
|
||||
// for std::find
|
||||
bool operator == (const TempMat& o ) {
|
||||
return (tex == o.tex && type == o.type);
|
||||
}
|
||||
};
|
||||
|
||||
struct Vertex
|
||||
{
|
||||
int32_t X : 11;
|
||||
int32_t Y : 11;
|
||||
int32_t Z : 10;
|
||||
};
|
||||
|
||||
// UNREAL vertex compression
|
||||
inline void CompressVertex(const aiVector3D& v, uint32_t& out)
|
||||
{
|
||||
union {
|
||||
Vertex n;
|
||||
int32_t t;
|
||||
};
|
||||
n.X = (int32_t)v.x;
|
||||
n.Y = (int32_t)v.y;
|
||||
n.Z = (int32_t)v.z;
|
||||
::memcpy( &out, &t, sizeof(int32_t));
|
||||
//out = t;
|
||||
}
|
||||
|
||||
// UNREAL vertex decompression
|
||||
inline void DecompressVertex(aiVector3D& v, int32_t in)
|
||||
{
|
||||
union {
|
||||
Vertex n;
|
||||
int32_t i;
|
||||
};
|
||||
i = in;
|
||||
|
||||
v.x = (float)n.X;
|
||||
v.y = (float)n.Y;
|
||||
v.z = (float)n.Z;
|
||||
}
|
||||
|
||||
} // end namespace Unreal
|
||||
namespace Assimp {
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/** @brief Importer class to load UNREAL files (*.3d)
|
||||
*/
|
||||
class UnrealImporter : public BaseImporter
|
||||
{
|
||||
class UnrealImporter : public BaseImporter {
|
||||
public:
|
||||
UnrealImporter();
|
||||
~UnrealImporter();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** @brief Returns whether we can handle the format of the given file
|
||||
*
|
||||
* See BaseImporter::CanRead() for details.
|
||||
**/
|
||||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler,
|
||||
bool checkSig) const;
|
||||
bool CanRead(const std::string &pFile, IOSystem *pIOHandler,
|
||||
bool checkSig) const;
|
||||
|
||||
protected:
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** @brief Called by Importer::GetExtensionList()
|
||||
*
|
||||
* See #BaseImporter::GetInfo for the details
|
||||
*/
|
||||
const aiImporterDesc* GetInfo () const;
|
||||
|
||||
const aiImporterDesc *GetInfo() const;
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** @brief Setup properties for the importer
|
||||
*
|
||||
* See BaseImporter::SetupProperties() for details
|
||||
*/
|
||||
void SetupProperties(const Importer* pImp);
|
||||
|
||||
void SetupProperties(const Importer *pImp);
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
/** @brief Imports the given file into the given scene structure.
|
||||
*
|
||||
* See BaseImporter::InternReadFile() for details
|
||||
*/
|
||||
void InternReadFile( const std::string& pFile, aiScene* pScene,
|
||||
IOSystem* pIOHandler);
|
||||
void InternReadFile(const std::string &pFile, aiScene *pScene,
|
||||
IOSystem *pIOHandler);
|
||||
|
||||
private:
|
||||
|
||||
//! frame to be loaded
|
||||
uint32_t configFrameID;
|
||||
uint32_t mConfigFrameID;
|
||||
|
||||
//! process surface flags
|
||||
bool configHandleFlags;
|
||||
bool mConfigHandleFlags;
|
||||
|
||||
}; // !class UnrealImporter
|
||||
|
||||
} // end of namespace Assimp
|
||||
|
||||
#endif // AI_UNREALIMPORTER_H_INC
|
||||
|
|
|
@ -176,7 +176,7 @@ void XGLImporter::InternReadFile( const std::string& pFile,
|
|||
raw_reader->IncPtr(2);
|
||||
|
||||
zstream.next_in = reinterpret_cast<Bytef*>( raw_reader->GetPtr() );
|
||||
zstream.avail_in = raw_reader->GetRemainingSize();
|
||||
zstream.avail_in = (uInt) raw_reader->GetRemainingSize();
|
||||
|
||||
size_t total = 0l;
|
||||
|
||||
|
|
|
@ -15,7 +15,11 @@ if ( MSVC )
|
|||
endif ( MSVC )
|
||||
|
||||
IF(CMAKE_SYSTEM_NAME MATCHES "(Darwin|FreeBSD)")
|
||||
add_library(IrrXML ${IrrXML_SRCS})
|
||||
IF(APPLE)
|
||||
add_library(IrrXML STATIC ${IrrXML_SRCS})
|
||||
ELSE()
|
||||
add_library(IrrXML ${IrrXML_SRCS})
|
||||
ENDIF()
|
||||
ELSE()
|
||||
add_library(IrrXML STATIC ${IrrXML_SRCS})
|
||||
ENDIF()
|
||||
|
|
|
@ -8,16 +8,7 @@
|
|||
#include "irrXML.h"
|
||||
#include "irrString.h"
|
||||
#include "irrArray.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <stdlib.h>
|
||||
#include <cctype>
|
||||
#include <cstdint>
|
||||
//using namespace Assimp;
|
||||
|
||||
// For locale independent number conversion
|
||||
#include <sstream>
|
||||
#include <locale>
|
||||
#include "fast_atof.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define IRR_DEBUGPRINT(x) printf((x));
|
||||
|
@ -37,14 +28,23 @@ template<class char_type, class superclass>
|
|||
class CXMLReaderImpl : public IIrrXMLReader<char_type, superclass>
|
||||
{
|
||||
public:
|
||||
|
||||
//! Constructor
|
||||
CXMLReaderImpl(IFileReadCallBack* callback, bool deleteCallBack = true)
|
||||
: TextData(0), P(0), TextBegin(0), TextSize(0), CurrentNodeType(EXN_NONE),
|
||||
SourceFormat(ETF_ASCII), TargetFormat(ETF_ASCII)
|
||||
{
|
||||
if (!callback)
|
||||
CXMLReaderImpl(IFileReadCallBack* callback, bool deleteCallBack = true)
|
||||
: TextData(0)
|
||||
, P(0)
|
||||
, TextBegin(0)
|
||||
, TextSize(0)
|
||||
, CurrentNodeType(EXN_NONE)
|
||||
, SourceFormat(ETF_ASCII)
|
||||
, TargetFormat(ETF_ASCII)
|
||||
, NodeName ()
|
||||
, EmptyString()
|
||||
, IsEmptyElement(false)
|
||||
, SpecialCharacters()
|
||||
, Attributes() {
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
storeTargetFormat();
|
||||
|
||||
|
@ -168,8 +168,7 @@ public:
|
|||
return 0;
|
||||
|
||||
core::stringc c = attr->Value.c_str();
|
||||
return static_cast<float>(atof(c.c_str()));
|
||||
//return fast_atof(c.c_str());
|
||||
return core::fast_atof(c.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
@ -181,11 +180,7 @@ public:
|
|||
return 0;
|
||||
|
||||
core::stringc c = attrvalue;
|
||||
std::istringstream sstr(c.c_str());
|
||||
sstr.imbue(std::locale("C")); // Locale free number convert
|
||||
float fNum;
|
||||
sstr >> fNum;
|
||||
return fNum;
|
||||
return core::fast_atof(c.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
@ -228,7 +223,7 @@ private:
|
|||
{
|
||||
char_type* start = P;
|
||||
|
||||
// move forward until '<' found
|
||||
// more forward until '<' found
|
||||
while(*P != L'<' && *P)
|
||||
++P;
|
||||
|
||||
|
@ -438,10 +433,6 @@ private:
|
|||
while(*P != L'>')
|
||||
++P;
|
||||
|
||||
// remove trailing whitespace, if any
|
||||
while( std::isspace( P[-1]))
|
||||
--P;
|
||||
|
||||
NodeName = core::string<char_type>(pBeginClose, (int)(P - pBeginClose));
|
||||
++P;
|
||||
}
|
||||
|
@ -676,12 +667,8 @@ private:
|
|||
|
||||
TextData = new char_type[sizeWithoutHeader];
|
||||
|
||||
// MSVC debugger complains here about loss of data ...
|
||||
size_t numShift = sizeof( char_type) * 8;
|
||||
assert(numShift < 64);
|
||||
const src_char_type cc = (src_char_type)(((uint64_t(1u) << numShift) - 1));
|
||||
for (int i=0; i<sizeWithoutHeader; ++i)
|
||||
TextData[i] = char_type( source[i] & cc);
|
||||
TextData[i] = (char_type)source[i];
|
||||
|
||||
TextBegin = TextData;
|
||||
TextSize = sizeWithoutHeader;
|
||||
|
|
|
@ -0,0 +1,139 @@
|
|||
// Copyright (C) 2002-2005 Nikolaus Gebhardt
|
||||
// This file is part of the "Irrlicht Engine" and the "irrXML" project.
|
||||
// For conditions of distribution and use, see copyright notice in irrlicht.h and irrXML.h
|
||||
|
||||
#ifndef __FAST_A_TO_F_H_INCLUDED__
|
||||
#define __FAST_A_TO_F_H_INCLUDED__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace core
|
||||
{
|
||||
|
||||
const float fast_atof_table[] = {
|
||||
0.f,
|
||||
0.1f,
|
||||
0.01f,
|
||||
0.001f,
|
||||
0.0001f,
|
||||
0.00001f,
|
||||
0.000001f,
|
||||
0.0000001f,
|
||||
0.00000001f,
|
||||
0.000000001f,
|
||||
0.0000000001f,
|
||||
0.00000000001f,
|
||||
0.000000000001f,
|
||||
0.0000000000001f,
|
||||
0.00000000000001f,
|
||||
0.000000000000001f
|
||||
};
|
||||
|
||||
//! Provides a fast function for converting a string into a float,
|
||||
//! about 6 times faster than atof in win32.
|
||||
// If you find any bugs, please send them to me, niko (at) irrlicht3d.org.
|
||||
inline char* fast_atof_move(char* c, float& out)
|
||||
{
|
||||
bool inv = false;
|
||||
char *t;
|
||||
float f;
|
||||
|
||||
if (*c=='-')
|
||||
{
|
||||
c++;
|
||||
inv = true;
|
||||
}
|
||||
|
||||
f = (float)strtol(c, &t, 10);
|
||||
|
||||
c = t;
|
||||
|
||||
if (*c == '.')
|
||||
{
|
||||
c++;
|
||||
|
||||
float pl = (float)strtol(c, &t, 10);
|
||||
pl *= fast_atof_table[t-c];
|
||||
|
||||
f += pl;
|
||||
|
||||
c = t;
|
||||
|
||||
if (*c == 'e')
|
||||
{
|
||||
++c;
|
||||
float exp = (float)strtol(c, &t, 10);
|
||||
f *= (float)pow(10.0f, exp);
|
||||
c = t;
|
||||
}
|
||||
}
|
||||
|
||||
if (inv)
|
||||
f *= -1.0f;
|
||||
|
||||
out = f;
|
||||
return c;
|
||||
}
|
||||
|
||||
//! Provides a fast function for converting a string into a float,
|
||||
//! about 6 times faster than atof in win32.
|
||||
// If you find any bugs, please send them to me, niko (at) irrlicht3d.org.
|
||||
inline const char* fast_atof_move_const(const char* c, float& out)
|
||||
{
|
||||
bool inv = false;
|
||||
char *t;
|
||||
float f;
|
||||
|
||||
if (*c=='-')
|
||||
{
|
||||
c++;
|
||||
inv = true;
|
||||
}
|
||||
|
||||
f = (float)strtol(c, &t, 10);
|
||||
|
||||
c = t;
|
||||
|
||||
if (*c == '.')
|
||||
{
|
||||
c++;
|
||||
|
||||
float pl = (float)strtol(c, &t, 10);
|
||||
pl *= fast_atof_table[t-c];
|
||||
|
||||
f += pl;
|
||||
|
||||
c = t;
|
||||
|
||||
if (*c == 'e')
|
||||
{
|
||||
++c;
|
||||
f32 exp = (f32)strtol(c, &t, 10);
|
||||
f *= (f32)powf(10.0f, exp);
|
||||
c = t;
|
||||
}
|
||||
}
|
||||
|
||||
if (inv)
|
||||
f *= -1.0f;
|
||||
|
||||
out = f;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
inline float fast_atof(const char* c)
|
||||
{
|
||||
float ret;
|
||||
fast_atof_move_const(c, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // end namespace core
|
||||
}// end namespace irr
|
||||
|
||||
#endif
|
||||
|
|
@ -21,7 +21,8 @@ class array
|
|||
{
|
||||
|
||||
public:
|
||||
array()
|
||||
|
||||
array()
|
||||
: data(0), allocated(0), used(0),
|
||||
free_when_destroyed(true), is_sorted(true)
|
||||
{
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
|
||||
//! Default constructor
|
||||
string()
|
||||
: array(0), allocated(1), used(1)
|
||||
: array(0), allocated(1), used(1)
|
||||
{
|
||||
array = new T[1];
|
||||
array[0] = 0x0;
|
||||
|
@ -39,7 +39,7 @@ public:
|
|||
|
||||
//! Constructor
|
||||
string(const string<T>& other)
|
||||
: array(0), allocated(0), used(0)
|
||||
: array(0), allocated(0), used(0)
|
||||
{
|
||||
*this = other;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public:
|
|||
|
||||
//! Constructs a string from an int
|
||||
string(int number)
|
||||
: array(0), allocated(0), used(0)
|
||||
: array(0), allocated(0), used(0)
|
||||
{
|
||||
// store if negative and make positive
|
||||
|
||||
|
@ -117,7 +117,7 @@ public:
|
|||
//! Constructor for unicode and ascii strings
|
||||
template <class B>
|
||||
string(const B* c)
|
||||
: array(0),allocated(0), used(0)
|
||||
: array(0), allocated(0), used(0)
|
||||
{
|
||||
*this = c;
|
||||
}
|
||||
|
|
|
@ -79,13 +79,8 @@ typedef unsigned short wchar_t;
|
|||
#endif // microsoft compiler
|
||||
|
||||
//! define a break macro for debugging only in Win32 mode.
|
||||
// WORKAROUND (assimp): remove __asm
|
||||
#if defined(WIN32) && defined(_MSC_VER) && defined(_DEBUG)
|
||||
#if defined(_M_IX86)
|
||||
#define _IRR_DEBUG_BREAK_IF( _CONDITION_ ) /*if (_CONDITION_) {_asm int 3}*/
|
||||
#else
|
||||
#define _IRR_DEBUG_BREAK_IF( _CONDITION_ )
|
||||
#endif
|
||||
#if !defined(_WIN64) && defined(WIN32) && defined(_MSC_VER) && defined(_DEBUG)
|
||||
#define _IRR_DEBUG_BREAK_IF( _CONDITION_ ) if (_CONDITION_) {_asm int 3}
|
||||
#else
|
||||
#define _IRR_DEBUG_BREAK_IF( _CONDITION_ )
|
||||
#endif
|
||||
|
@ -96,10 +91,8 @@ When you call unmanaged code that returns a bool type value of false from manage
|
|||
the return value may appear as true. See
|
||||
http://support.microsoft.com/default.aspx?kbid=823071 for details.
|
||||
Compiler version defines: VC6.0 : 1200, VC7.0 : 1300, VC7.1 : 1310, VC8.0 : 1400*/
|
||||
|
||||
// WORKAROUND (assimp): remove __asm
|
||||
#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER > 1299) && (_MSC_VER < 1400)
|
||||
#define _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX /*__asm mov eax,100*/
|
||||
#if !defined(_WIN64) && defined(WIN32) && defined(_MSC_VER) && (_MSC_VER > 1299) && (_MSC_VER < 1400)
|
||||
#define _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX __asm mov eax,100
|
||||
#else
|
||||
#define _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX
|
||||
#endif // _IRR_MANAGED_MARSHALLING_BUGFIX
|
||||
|
|
|
@ -2,14 +2,10 @@
|
|||
// This file is part of the "Irrlicht Engine" and the "irrXML" project.
|
||||
// For conditions of distribution and use, see copyright notice in irrlicht.h and/or irrXML.h
|
||||
|
||||
// Need to include Assimp, too. We're using Assimp's version of fast_atof
|
||||
// so we need stdint.h. But no PCH.
|
||||
|
||||
|
||||
#include "irrXML.h"
|
||||
#include "irrString.h"
|
||||
#include "irrArray.h"
|
||||
//#include <assimp/fast_atof.h>
|
||||
#include "fast_atof.h"
|
||||
#include "CXMLReaderImpl.h"
|
||||
|
||||
namespace irr
|
||||
|
@ -18,7 +14,7 @@ namespace io
|
|||
{
|
||||
|
||||
//! Implementation of the file read callback for ordinary files
|
||||
class IRRXML_API CFileReadCallBack : public IFileReadCallBack
|
||||
class CFileReadCallBack : public IFileReadCallBack
|
||||
{
|
||||
public:
|
||||
|
||||
|
|
|
@ -7,12 +7,6 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
# define IRRXML_API __declspec(dllexport)
|
||||
#else
|
||||
# define IRRXML_API __attribute__ ((visibility("default")))
|
||||
#endif // _WIN32
|
||||
|
||||
/** \mainpage irrXML 1.2 API documentation
|
||||
<div align="center"><img src="logobig.png" ></div>
|
||||
|
||||
|
@ -178,7 +172,7 @@ namespace io
|
|||
ETF_UTF32_BE,
|
||||
|
||||
//! UTF-32 format, little endian
|
||||
ETF_UTF32_LE
|
||||
ETF_UTF32_LE,
|
||||
};
|
||||
|
||||
|
||||
|
@ -215,7 +209,7 @@ namespace io
|
|||
two methods to read your data and give a pointer to an instance of
|
||||
your implementation when calling createIrrXMLReader(),
|
||||
createIrrXMLReaderUTF16() or createIrrXMLReaderUTF32() */
|
||||
class IRRXML_API IFileReadCallBack
|
||||
class IFileReadCallBack
|
||||
{
|
||||
public:
|
||||
|
||||
|
@ -415,7 +409,7 @@ namespace io
|
|||
\return Returns a pointer to the created xml parser. This pointer should be
|
||||
deleted using 'delete' after no longer needed. Returns 0 if an error occured
|
||||
and the file could not be opened. */
|
||||
IRRXML_API IrrXMLReader* createIrrXMLReader(const char* filename);
|
||||
IrrXMLReader* createIrrXMLReader(const char* filename);
|
||||
|
||||
//! Creates an instance of an UFT-8 or ASCII character xml parser.
|
||||
/** This means that all character data will be returned in 8 bit ASCII or UTF-8. The file to read can
|
||||
|
@ -427,7 +421,7 @@ namespace io
|
|||
\return Returns a pointer to the created xml parser. This pointer should be
|
||||
deleted using 'delete' after no longer needed. Returns 0 if an error occured
|
||||
and the file could not be opened. */
|
||||
IRRXML_API IrrXMLReader* createIrrXMLReader(FILE* file);
|
||||
IrrXMLReader* createIrrXMLReader(FILE* file);
|
||||
|
||||
//! Creates an instance of an UFT-8 or ASCII character xml parser.
|
||||
/** This means that all character data will be returned in 8 bit ASCII or UTF-8. The file to read can
|
||||
|
@ -440,7 +434,7 @@ namespace io
|
|||
\return Returns a pointer to the created xml parser. This pointer should be
|
||||
deleted using 'delete' after no longer needed. Returns 0 if an error occured
|
||||
and the file could not be opened. */
|
||||
IRRXML_API IrrXMLReader* createIrrXMLReader(IFileReadCallBack* callback);
|
||||
IrrXMLReader* createIrrXMLReader(IFileReadCallBack* callback);
|
||||
|
||||
//! Creates an instance of an UFT-16 xml parser.
|
||||
/** This means that
|
||||
|
@ -452,7 +446,7 @@ namespace io
|
|||
\return Returns a pointer to the created xml parser. This pointer should be
|
||||
deleted using 'delete' after no longer needed. Returns 0 if an error occured
|
||||
and the file could not be opened. */
|
||||
IRRXML_API IrrXMLReaderUTF16* createIrrXMLReaderUTF16(const char* filename);
|
||||
IrrXMLReaderUTF16* createIrrXMLReaderUTF16(const char* filename);
|
||||
|
||||
//! Creates an instance of an UFT-16 xml parser.
|
||||
/** This means that all character data will be returned in UTF-16. The file to read can
|
||||
|
@ -464,7 +458,7 @@ namespace io
|
|||
\return Returns a pointer to the created xml parser. This pointer should be
|
||||
deleted using 'delete' after no longer needed. Returns 0 if an error occured
|
||||
and the file could not be opened. */
|
||||
IRRXML_API IrrXMLReaderUTF16* createIrrXMLReaderUTF16(FILE* file);
|
||||
IrrXMLReaderUTF16* createIrrXMLReaderUTF16(FILE* file);
|
||||
|
||||
//! Creates an instance of an UFT-16 xml parser.
|
||||
/** This means that all character data will be returned in UTF-16. The file to read can
|
||||
|
@ -477,7 +471,7 @@ namespace io
|
|||
\return Returns a pointer to the created xml parser. This pointer should be
|
||||
deleted using 'delete' after no longer needed. Returns 0 if an error occured
|
||||
and the file could not be opened. */
|
||||
IRRXML_API IrrXMLReaderUTF16* createIrrXMLReaderUTF16(IFileReadCallBack* callback);
|
||||
IrrXMLReaderUTF16* createIrrXMLReaderUTF16(IFileReadCallBack* callback);
|
||||
|
||||
|
||||
//! Creates an instance of an UFT-32 xml parser.
|
||||
|
@ -489,7 +483,7 @@ namespace io
|
|||
\return Returns a pointer to the created xml parser. This pointer should be
|
||||
deleted using 'delete' after no longer needed. Returns 0 if an error occured
|
||||
and the file could not be opened. */
|
||||
IRRXML_API IrrXMLReaderUTF32* createIrrXMLReaderUTF32(const char* filename);
|
||||
IrrXMLReaderUTF32* createIrrXMLReaderUTF32(const char* filename);
|
||||
|
||||
//! Creates an instance of an UFT-32 xml parser.
|
||||
/** This means that all character data will be returned in UTF-32. The file to read can
|
||||
|
@ -501,7 +495,7 @@ namespace io
|
|||
\return Returns a pointer to the created xml parser. This pointer should be
|
||||
deleted using 'delete' after no longer needed. Returns 0 if an error occured
|
||||
and the file could not be opened. */
|
||||
IRRXML_API IrrXMLReaderUTF32* createIrrXMLReaderUTF32(FILE* file);
|
||||
IrrXMLReaderUTF32* createIrrXMLReaderUTF32(FILE* file);
|
||||
|
||||
//! Creates an instance of an UFT-32 xml parser.
|
||||
/** This means that
|
||||
|
@ -515,7 +509,7 @@ namespace io
|
|||
\return Returns a pointer to the created xml parser. This pointer should be
|
||||
deleted using 'delete' after no longer needed. Returns 0 if an error occured
|
||||
and the file could not be opened. */
|
||||
IRRXML_API IrrXMLReaderUTF32* createIrrXMLReaderUTF32(IFileReadCallBack* callback);
|
||||
IrrXMLReaderUTF32* createIrrXMLReaderUTF32(IFileReadCallBack* callback);
|
||||
|
||||
|
||||
/*! \file irrxml.h
|
||||
|
|
|
@ -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,
|
||||
|
@ -49,13 +47,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#define AI_STREAMREADER_H_INCLUDED
|
||||
|
||||
#ifdef __GNUC__
|
||||
# pragma GCC system_header
|
||||
#pragma GCC system_header
|
||||
#endif
|
||||
|
||||
#include <assimp/IOStream.hpp>
|
||||
#include <assimp/Defines.h>
|
||||
#include <assimp/ByteSwapper.h>
|
||||
#include <assimp/Defines.h>
|
||||
#include <assimp/Exceptional.h>
|
||||
#include <assimp/IOStream.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
@ -74,10 +72,8 @@ namespace Assimp {
|
|||
template <bool SwapEndianess = false, bool RuntimeSwitch = false>
|
||||
class StreamReader {
|
||||
public:
|
||||
// FIXME: use these data types throughout the whole library,
|
||||
// then change them to 64 bit values :-)
|
||||
using diff = int;
|
||||
using pos = unsigned int;
|
||||
using diff = size_t;
|
||||
using pos = size_t;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
/** Construction from a given stream with a well-defined endianness.
|
||||
|
@ -91,40 +87,45 @@ public:
|
|||
* stream is in little endian byte order. Otherwise the
|
||||
* endianness information is contained in the @c SwapEndianess
|
||||
* template parameter and this parameter is meaningless. */
|
||||
StreamReader(std::shared_ptr<IOStream> stream, bool le = false)
|
||||
: stream(stream)
|
||||
, le(le)
|
||||
{
|
||||
StreamReader(std::shared_ptr<IOStream> stream, bool le = false) :
|
||||
mStream(stream),
|
||||
mBuffer(nullptr),
|
||||
mCurrent(nullptr),
|
||||
mEnd(nullptr),
|
||||
mLimit(nullptr),
|
||||
mLe(le) {
|
||||
ai_assert(stream);
|
||||
InternBegin();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
StreamReader(IOStream* stream, bool le = false)
|
||||
: stream(std::shared_ptr<IOStream>(stream))
|
||||
, le(le)
|
||||
{
|
||||
ai_assert(stream);
|
||||
StreamReader(IOStream *stream, bool le = false) :
|
||||
mStream(std::shared_ptr<IOStream>(stream)),
|
||||
mBuffer(nullptr),
|
||||
mCurrent(nullptr),
|
||||
mEnd(nullptr),
|
||||
mLimit(nullptr),
|
||||
mLe(le) {
|
||||
ai_assert(nullptr != stream);
|
||||
InternBegin();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
~StreamReader() {
|
||||
delete[] buffer;
|
||||
delete[] mBuffer;
|
||||
}
|
||||
|
||||
// deprecated, use overloaded operator>> instead
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
/** Read a float from the stream */
|
||||
float GetF4()
|
||||
{
|
||||
/// Read a float from the stream.
|
||||
float GetF4() {
|
||||
return Get<float>();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
/** Read a double from the stream */
|
||||
double GetF8() {
|
||||
/// Read a double from the stream.
|
||||
double GetF8() {
|
||||
return Get<double>();
|
||||
}
|
||||
|
||||
|
@ -136,7 +137,7 @@ public:
|
|||
|
||||
// ---------------------------------------------------------------------
|
||||
/** Read a signed 8 bit integer from the stream */
|
||||
int8_t GetI1() {
|
||||
int8_t GetI1() {
|
||||
return Get<int8_t>();
|
||||
}
|
||||
|
||||
|
@ -154,55 +155,55 @@ public:
|
|||
|
||||
// ---------------------------------------------------------------------
|
||||
/** Read a unsigned 16 bit integer from the stream */
|
||||
uint16_t GetU2() {
|
||||
uint16_t GetU2() {
|
||||
return Get<uint16_t>();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
/** Read a unsigned 8 bit integer from the stream */
|
||||
/// Read a unsigned 8 bit integer from the stream
|
||||
uint8_t GetU1() {
|
||||
return Get<uint8_t>();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
/** Read an unsigned 32 bit integer from the stream */
|
||||
uint32_t GetU4() {
|
||||
/// Read an unsigned 32 bit integer from the stream
|
||||
uint32_t GetU4() {
|
||||
return Get<uint32_t>();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
/** Read a unsigned 64 bit integer from the stream */
|
||||
uint64_t GetU8() {
|
||||
/// Read a unsigned 64 bit integer from the stream
|
||||
uint64_t GetU8() {
|
||||
return Get<uint64_t>();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
/** Get the remaining stream size (to the end of the stream) */
|
||||
unsigned int GetRemainingSize() const {
|
||||
return (unsigned int)(end - current);
|
||||
/// Get the remaining stream size (to the end of the stream)
|
||||
size_t GetRemainingSize() const {
|
||||
return (unsigned int)(mEnd - mCurrent);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
/** Get the remaining stream size (to the current read limit). The
|
||||
* return value is the remaining size of the stream if no custom
|
||||
* read limit has been set. */
|
||||
unsigned int GetRemainingSizeToLimit() const {
|
||||
return (unsigned int)(limit - current);
|
||||
size_t GetRemainingSizeToLimit() const {
|
||||
return (unsigned int)(mLimit - mCurrent);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
/** Increase the file pointer (relative seeking) */
|
||||
void IncPtr(intptr_t plus) {
|
||||
current += plus;
|
||||
if (current > limit) {
|
||||
void IncPtr(intptr_t plus) {
|
||||
mCurrent += plus;
|
||||
if (mCurrent > mLimit) {
|
||||
throw DeadlyImportError("End of file or read limit was reached");
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
/** Get the current file pointer */
|
||||
int8_t* GetPtr() const {
|
||||
return current;
|
||||
int8_t *GetPtr() const {
|
||||
return mCurrent;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
@ -211,9 +212,9 @@ public:
|
|||
* large chunks of data at once.
|
||||
* @param p The new pointer, which is validated against the size
|
||||
* limit and buffer boundaries. */
|
||||
void SetPtr(int8_t* p) {
|
||||
current = p;
|
||||
if (current > limit || current < buffer) {
|
||||
void SetPtr(int8_t *p) {
|
||||
mCurrent = p;
|
||||
if (mCurrent > mLimit || mCurrent < mBuffer) {
|
||||
throw DeadlyImportError("End of file or read limit was reached");
|
||||
}
|
||||
}
|
||||
|
@ -222,21 +223,20 @@ public:
|
|||
/** Copy n bytes to an external buffer
|
||||
* @param out Destination for copying
|
||||
* @param bytes Number of bytes to copy */
|
||||
void CopyAndAdvance(void* out, size_t bytes) {
|
||||
int8_t* ur = GetPtr();
|
||||
SetPtr(ur+bytes); // fire exception if eof
|
||||
void CopyAndAdvance(void *out, size_t bytes) {
|
||||
int8_t *ur = GetPtr();
|
||||
SetPtr(ur + bytes); // fire exception if eof
|
||||
|
||||
::memcpy(out,ur,bytes);
|
||||
::memcpy(out, ur, bytes);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
/** Get the current offset from the beginning of the file */
|
||||
int GetCurrentPos() const {
|
||||
return (unsigned int)(current - buffer);
|
||||
/// @brief Get the current offset from the beginning of the file
|
||||
int GetCurrentPos() const {
|
||||
return (unsigned int)(mCurrent - mBuffer);
|
||||
}
|
||||
|
||||
void SetCurrentPos(size_t pos) {
|
||||
SetPtr(buffer + pos);
|
||||
SetPtr(mBuffer + pos);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
@ -246,15 +246,15 @@ public:
|
|||
* the beginning of the file. Specifying UINT_MAX
|
||||
* resets the limit to the original end of the stream.
|
||||
* Returns the previously set limit. */
|
||||
unsigned int SetReadLimit(unsigned int _limit) {
|
||||
unsigned int SetReadLimit(unsigned int _limit) {
|
||||
unsigned int prev = GetReadLimit();
|
||||
if (UINT_MAX == _limit) {
|
||||
limit = end;
|
||||
mLimit = mEnd;
|
||||
return prev;
|
||||
}
|
||||
|
||||
limit = buffer + _limit;
|
||||
if (limit > end) {
|
||||
mLimit = mBuffer + _limit;
|
||||
if (mLimit > mEnd) {
|
||||
throw DeadlyImportError("StreamReader: Invalid read limit");
|
||||
}
|
||||
return prev;
|
||||
|
@ -263,21 +263,21 @@ public:
|
|||
// ---------------------------------------------------------------------
|
||||
/** Get the current read limit in bytes. Reading over this limit
|
||||
* accidentally raises an exception. */
|
||||
unsigned int GetReadLimit() const {
|
||||
return (unsigned int)(limit - buffer);
|
||||
unsigned int GetReadLimit() const {
|
||||
return (unsigned int)(mLimit - mBuffer);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
/** Skip to the read limit in bytes. Reading over this limit
|
||||
* accidentally raises an exception. */
|
||||
void SkipToReadLimit() {
|
||||
current = limit;
|
||||
void SkipToReadLimit() {
|
||||
mCurrent = mLimit;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
/** overload operator>> and allow chaining of >> ops. */
|
||||
template <typename T>
|
||||
StreamReader& operator >> (T& f) {
|
||||
StreamReader &operator>>(T &f) {
|
||||
f = Get<T>();
|
||||
return *this;
|
||||
}
|
||||
|
@ -286,14 +286,14 @@ public:
|
|||
/** Generic read method. ByteSwap::Swap(T*) *must* be defined */
|
||||
template <typename T>
|
||||
T Get() {
|
||||
if ( current + sizeof(T) > limit) {
|
||||
if (mCurrent + sizeof(T) > mLimit) {
|
||||
throw DeadlyImportError("End of file or stream limit was reached");
|
||||
}
|
||||
|
||||
T f;
|
||||
::memcpy (&f, current, sizeof(T));
|
||||
Intern::Getter<SwapEndianess,T,RuntimeSwitch>() (&f,le);
|
||||
current += sizeof(T);
|
||||
::memcpy(&f, mCurrent, sizeof(T));
|
||||
Intern::Getter<SwapEndianess, T, RuntimeSwitch>()(&f, mLe);
|
||||
mCurrent += sizeof(T);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
@ -301,46 +301,44 @@ public:
|
|||
private:
|
||||
// ---------------------------------------------------------------------
|
||||
void InternBegin() {
|
||||
if (!stream) {
|
||||
// in case someone wonders: StreamReader is frequently invoked with
|
||||
// no prior validation whether the input stream is valid. Since
|
||||
// no one bothers changing the error message, this message here
|
||||
// is passed down to the caller and 'unable to open file'
|
||||
// simply describes best what happened.
|
||||
if (nullptr == mStream) {
|
||||
throw DeadlyImportError("StreamReader: Unable to open file");
|
||||
}
|
||||
|
||||
const size_t s = stream->FileSize() - stream->Tell();
|
||||
if (!s) {
|
||||
const size_t filesize = mStream->FileSize() - mStream->Tell();
|
||||
if (0 == filesize) {
|
||||
throw DeadlyImportError("StreamReader: File is empty or EOF is already reached");
|
||||
}
|
||||
|
||||
current = buffer = new int8_t[s];
|
||||
const size_t read = stream->Read(current,1,s);
|
||||
mCurrent = mBuffer = new int8_t[filesize];
|
||||
const size_t read = mStream->Read(mCurrent, 1, filesize);
|
||||
// (read < s) can only happen if the stream was opened in text mode, in which case FileSize() is not reliable
|
||||
ai_assert(read <= s);
|
||||
end = limit = &buffer[read-1] + 1;
|
||||
ai_assert(read <= filesize);
|
||||
mEnd = mLimit = &mBuffer[read - 1] + 1;
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<IOStream> stream;
|
||||
int8_t *buffer, *current, *end, *limit;
|
||||
bool le;
|
||||
std::shared_ptr<IOStream> mStream;
|
||||
int8_t *mBuffer;
|
||||
int8_t *mCurrent;
|
||||
int8_t *mEnd;
|
||||
int8_t *mLimit;
|
||||
bool mLe;
|
||||
};
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
// `static` StreamReaders. Their byte order is fixed and they might be a little bit faster.
|
||||
#ifdef AI_BUILD_BIG_ENDIAN
|
||||
typedef StreamReader<true> StreamReaderLE;
|
||||
typedef StreamReader<false> StreamReaderBE;
|
||||
typedef StreamReader<true> StreamReaderLE;
|
||||
typedef StreamReader<false> StreamReaderBE;
|
||||
#else
|
||||
typedef StreamReader<true> StreamReaderBE;
|
||||
typedef StreamReader<false> StreamReaderLE;
|
||||
typedef StreamReader<true> StreamReaderBE;
|
||||
typedef StreamReader<false> StreamReaderLE;
|
||||
#endif
|
||||
|
||||
// `dynamic` StreamReader. The byte order of the input data is specified in the
|
||||
// c'tor. This involves runtime branching and might be a little bit slower.
|
||||
typedef StreamReader<true,true> StreamReaderAny;
|
||||
typedef StreamReader<true, true> StreamReaderAny;
|
||||
|
||||
} // end namespace Assimp
|
||||
|
||||
|
|
|
@ -76,10 +76,12 @@ SET( COMMON
|
|||
unit/utProfiler.cpp
|
||||
unit/utSharedPPData.cpp
|
||||
unit/utStringUtils.cpp
|
||||
unit/Common/uiScene.cpp
|
||||
unit/Common/utLineSplitter.cpp
|
||||
)
|
||||
|
||||
SET( IMPORTERS
|
||||
unit/ImportExport/Assxml/utAssxmlImportExport.cpp
|
||||
unit/utLWSImportExport.cpp
|
||||
unit/utLWOImportExport.cpp
|
||||
unit/utSMDImportExport.cpp
|
||||
|
@ -136,6 +138,9 @@ SET( IMPORTERS
|
|||
unit/ImportExport/MDL/utMDLImporter_HL1_ImportSettings.cpp
|
||||
unit/ImportExport/MDL/utMDLImporter_HL1_Materials.cpp
|
||||
unit/ImportExport/MDL/utMDLImporter_HL1_Nodes.cpp
|
||||
#unit/ImportExport/IRR/utIrrImportExport.cpp
|
||||
unit/ImportExport/RAW/utRAWImportExport.cpp
|
||||
unit/ImportExport/Terragen/utTerragenImportExport.cpp
|
||||
)
|
||||
|
||||
SET( MATERIAL
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
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,
|
||||
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.
|
||||
---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "UnitTestPCH.h"
|
||||
|
||||
#include <assimp/scene.h>
|
||||
|
||||
|
||||
using namespace Assimp;
|
||||
|
||||
class utScene : public ::testing::Test {
|
||||
protected:
|
||||
aiScene *scene;
|
||||
|
||||
void SetUp() override {
|
||||
scene = new aiScene;
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
delete scene;
|
||||
scene = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(utScene, findNodeTest) {
|
||||
scene->mRootNode = new aiNode();
|
||||
scene->mRootNode->mName.Set("test");
|
||||
aiNode *child = new aiNode;
|
||||
child->mName.Set("child");
|
||||
scene->mRootNode->addChildren(1, &child);
|
||||
aiNode *found = scene->mRootNode->FindNode("child");
|
||||
EXPECT_EQ(child, found);
|
||||
}
|
||||
|
||||
TEST_F(utScene, sceneHasContentTest) {
|
||||
EXPECT_FALSE(scene->HasAnimations());
|
||||
EXPECT_FALSE(scene->HasMaterials());
|
||||
EXPECT_FALSE(scene->HasMeshes());
|
||||
EXPECT_FALSE(scene->HasCameras());
|
||||
EXPECT_FALSE(scene->HasLights());
|
||||
EXPECT_FALSE(scene->HasTextures());
|
||||
}
|
||||
|
||||
TEST_F(utScene, getShortFilenameTest) {
|
||||
std::string long_filename1 = "foo_bar/name";
|
||||
const char *name1 = scene->GetShortFilename(long_filename1.c_str());
|
||||
EXPECT_NE(nullptr, name1);
|
||||
|
||||
std::string long_filename2 = "foo_bar\\name";
|
||||
const char *name2 = scene->GetShortFilename(long_filename2.c_str());
|
||||
EXPECT_NE(nullptr, name2);
|
||||
}
|
||||
|
||||
TEST_F(utScene, getEmbeddedTextureTest) {
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2019, 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.
|
||||
---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "AbstractImportExportBase.h"
|
||||
#include "SceneDiffer.h"
|
||||
#include "UnitTestPCH.h"
|
||||
|
||||
#include <assimp/postprocess.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/Exporter.hpp>
|
||||
|
||||
using namespace Assimp;
|
||||
|
||||
class utAssxmlImportExport : public AbstractImportExportBase {
|
||||
public:
|
||||
bool importerTest() override {
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_EXPORT
|
||||
bool exporterTest() override {
|
||||
Assimp::Importer importer;
|
||||
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/OBJ/spider.obj", aiProcess_ValidateDataStructure);
|
||||
EXPECT_NE(scene, nullptr );
|
||||
|
||||
::Assimp::Exporter exporter;
|
||||
return AI_SUCCESS == exporter.Export(scene, "assxml", ASSIMP_TEST_MODELS_DIR "/OBJ/spider_out.assxml");
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_EXPORT
|
||||
|
||||
TEST_F(utAssxmlImportExport, exportAssxmlTest) {
|
||||
EXPECT_TRUE(exporterTest());
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
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,
|
||||
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.
|
||||
---------------------------------------------------------------------------
|
||||
*/
|
||||
#include "AbstractImportExportBase.h"
|
||||
#include "UnitTestPCH.h"
|
||||
#include <assimp/postprocess.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
|
||||
using namespace Assimp;
|
||||
|
||||
class utIrrImportExport : public AbstractImportExportBase {
|
||||
public:
|
||||
virtual bool importerTest() {
|
||||
Assimp::Importer importer;
|
||||
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/IRR/box.irr", aiProcess_ValidateDataStructure);
|
||||
return nullptr != scene;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(utIrrImportExport, importSimpleIrrTest) {
|
||||
EXPECT_TRUE(importerTest());
|
||||
}
|
||||
|
||||
TEST_F(utIrrImportExport, importSGIrrTest) {
|
||||
Assimp::Importer importer;
|
||||
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/IRR/dawfInCellar_SameHierarchy.irr", aiProcess_ValidateDataStructure);
|
||||
EXPECT_NE( nullptr,scene);
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
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,
|
||||
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.
|
||||
---------------------------------------------------------------------------
|
||||
*/
|
||||
#include "AbstractImportExportBase.h"
|
||||
#include "UnitTestPCH.h"
|
||||
#include <assimp/postprocess.h>
|
||||
#include <assimp/scene.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
|
||||
using namespace Assimp;
|
||||
|
||||
class utRAWImportExport : public AbstractImportExportBase {
|
||||
public:
|
||||
virtual bool importerTest() {
|
||||
Assimp::Importer importer;
|
||||
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/RAW/Wuson.raw", aiProcess_ValidateDataStructure);
|
||||
#ifndef ASSIMP_BUILD_NO_RAW_IMPORTER
|
||||
return nullptr != scene;
|
||||
#else
|
||||
return nullptr == scene;
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(utRAWImportExport, importSimpleRAWTest) {
|
||||
EXPECT_TRUE(importerTest());
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
---------------------------------------------------------------------------
|
||||
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,
|
||||
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.
|
||||
---------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "AbstractImportExportBase.h"
|
||||
#include "UnitTestPCH.h"
|
||||
|
||||
#include <assimp/postprocess.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
|
||||
class utTerragenImportExport : public AbstractImportExportBase {
|
||||
public:
|
||||
virtual bool importerTest() {
|
||||
/*Assimp::Importer importer;
|
||||
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/TER/RealisticTerrain.ter", aiProcess_ValidateDataStructure);
|
||||
return nullptr != scene;*/
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(utTerragenImportExport, importX3DFromFileTest) {
|
||||
EXPECT_TRUE(importerTest());
|
||||
}
|
|
@ -43,6 +43,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "AbstractImportExportBase.h"
|
||||
#include "UnitTestPCH.h"
|
||||
|
||||
#include <assimp/Importer.hpp>
|
||||
#include <assimp/Exporter.hpp>
|
||||
#include <assimp/postprocess.h>
|
||||
#include <assimp/Importer.hpp>
|
||||
|
||||
|
@ -50,17 +52,33 @@ using namespace Assimp;
|
|||
|
||||
class utM3DImportExport : public AbstractImportExportBase {
|
||||
public:
|
||||
virtual bool importerTest() {
|
||||
bool importerTest() override {
|
||||
Assimp::Importer importer;
|
||||
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/M3D/cube_normals.m3d", aiProcess_ValidateDataStructure);
|
||||
#ifndef ASSIMP_BUILD_NO_M3D_IMPORTER
|
||||
return nullptr != scene;
|
||||
return nullptr != scene;
|
||||
#else
|
||||
return nullptr == scene;
|
||||
#endif // ASSIMP_BUILD_NO_M3D_IMPORTER
|
||||
}
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_EXPORT
|
||||
bool exporterTest() override {
|
||||
Assimp::Importer importer;
|
||||
const aiScene *scene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/M3D/cube_normals.m3d", aiProcess_ValidateDataStructure);
|
||||
Exporter exporter;
|
||||
aiReturn ret = exporter.Export(scene, "m3d", ASSIMP_TEST_MODELS_DIR "/M3D/cube_normals_out.m3d");
|
||||
return ret == AI_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
TEST_F(utM3DImportExport, importM3DFromFileTest) {
|
||||
EXPECT_TRUE(importerTest());
|
||||
}
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_EXPORT
|
||||
TEST_F(utM3DImportExport, exportM3DFromFileTest) {
|
||||
EXPECT_TRUE(exporterTest());
|
||||
}
|
||||
#endif // ASSIMP_BUILD_NO_EXPORT
|
||||
|
|
|
@ -402,13 +402,12 @@ int CMaterialManager::FindValidPath(aiString* p_szString)
|
|||
}
|
||||
fclose(pFile);
|
||||
|
||||
// copy the result string back to the aiString
|
||||
const size_t iLen = strlen(szTemp);
|
||||
size_t iLen2 = iLen+1;
|
||||
iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2;
|
||||
memcpy(p_szString->data,szTemp,iLen2);
|
||||
p_szString->length = static_cast<ai_uint32>(iLen);
|
||||
|
||||
// copy the result string back to the aiStr
|
||||
const size_t len = strlen(szTemp);
|
||||
size_t len2 = len+1;
|
||||
len2 = len2 > MAXLEN ? MAXLEN : len2;
|
||||
memcpy(p_szString->data, szTemp, len2);
|
||||
p_szString->length = static_cast<ai_uint32>(len);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -1490,4 +1489,5 @@ int CMaterialManager::EndMaterial (AssetHelper::MeshHelper* pcMesh)
|
|||
|
||||
return 1;
|
||||
}
|
||||
}; // end namespace AssimpView
|
||||
|
||||
} // end namespace AssimpView
|
||||
|
|
Loading…
Reference in New Issue