fix possible warnings
parent
22d6b761e6
commit
4c177ad72e
|
@ -322,7 +322,7 @@ struct Face : public FaceWithSmoothingGroup {
|
|||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
# pragma warning(disable : 4315)
|
||||
#pragma warning(disable : 4315)
|
||||
#endif
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
@ -441,30 +441,53 @@ 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
|
||||
|
||||
}
|
||||
//Material &operator=(const Material &other) = default;
|
||||
|
||||
//! 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,
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
|
|
@ -140,6 +140,7 @@ SET( IMPORTERS
|
|||
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.
|
@ -48,17 +48,17 @@ using namespace Assimp;
|
|||
|
||||
class utRAWImportExport : public AbstractImportExportBase {
|
||||
public:
|
||||
virtual bool importerTest() {
|
||||
Assimp::Importer importer;
|
||||
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;
|
||||
return nullptr != scene;
|
||||
#else
|
||||
return nullptr == scene;
|
||||
return nullptr == scene;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(utRAWImportExport, importSimpleRAWTest) {
|
||||
EXPECT_TRUE(importerTest());
|
||||
EXPECT_TRUE(importerTest());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue