Support loading the MTL file for an OBJ file when using MemoryIOWrapper.
This is Christian Van Brussel's patch from http://sourceforge.net/p/assimp/mailman/message/30003098/ .pull/469/head
parent
b71ded1ad0
commit
48d59df609
|
@ -494,7 +494,7 @@ const aiScene* Importer::ReadFileFromMemory( const void* pBuffer,
|
||||||
IOSystem* io = pimpl->mIOHandler;
|
IOSystem* io = pimpl->mIOHandler;
|
||||||
pimpl->mIOHandler = NULL;
|
pimpl->mIOHandler = NULL;
|
||||||
|
|
||||||
SetIOHandler(new MemoryIOSystem((const uint8_t*)pBuffer,pLength));
|
SetIOHandler(new MemoryIOSystem((const uint8_t*)pBuffer,pLength,io));
|
||||||
|
|
||||||
// read the file and recover the previous IOSystem
|
// read the file and recover the previous IOSystem
|
||||||
char fbuff[128];
|
char fbuff[128];
|
||||||
|
|
|
@ -141,8 +141,8 @@ class MemoryIOSystem : public IOSystem
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
/** Constructor. */
|
/** Constructor. */
|
||||||
MemoryIOSystem (const uint8_t* buff, size_t len)
|
MemoryIOSystem (const uint8_t* buff, size_t len, IOSystem* other)
|
||||||
: buffer (buff), length(len) {
|
: buffer (buff), length(len), other (other) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Destructor. */
|
/** Destructor. */
|
||||||
|
@ -152,19 +152,27 @@ public:
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Tests for the existence of a file at the given path. */
|
/** Tests for the existence of a file at the given path. */
|
||||||
bool Exists( const char* pFile) const {
|
bool Exists( const char* pFile) const {
|
||||||
return !strncmp(pFile,AI_MEMORYIO_MAGIC_FILENAME,AI_MEMORYIO_MAGIC_FILENAME_LENGTH);
|
if (!strncmp(pFile,AI_MEMORYIO_MAGIC_FILENAME,AI_MEMORYIO_MAGIC_FILENAME_LENGTH))
|
||||||
|
return true;
|
||||||
|
if (other)
|
||||||
|
return other->Exists(pFile);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Returns the directory separator. */
|
/** Returns the directory separator. */
|
||||||
char getOsSeparator() const {
|
char getOsSeparator() const {
|
||||||
|
if (other)
|
||||||
|
return other->getOsSeparator();
|
||||||
return '/'; // why not? it doesn't care
|
return '/'; // why not? it doesn't care
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Open a new file with a given path. */
|
/** Open a new file with a given path. */
|
||||||
IOStream* Open( const char* pFile, const char* /*pMode*/ = "rb") {
|
IOStream* Open( const char* pFile, const char* pMode = "rb") {
|
||||||
if (strncmp(pFile,AI_MEMORYIO_MAGIC_FILENAME,AI_MEMORYIO_MAGIC_FILENAME_LENGTH)) {
|
if (strncmp(pFile,AI_MEMORYIO_MAGIC_FILENAME,AI_MEMORYIO_MAGIC_FILENAME_LENGTH)) {
|
||||||
|
if (other)
|
||||||
|
return other->Open(pFile,pMode);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return new MemoryIOStream(buffer,length);
|
return new MemoryIOStream(buffer,length);
|
||||||
|
@ -172,18 +180,23 @@ public:
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Closes the given file and releases all resources associated with it. */
|
/** Closes the given file and releases all resources associated with it. */
|
||||||
void Close( IOStream* /*pFile*/) {
|
void Close( IOStream* pFile) {
|
||||||
|
if (other)
|
||||||
|
other->Close(pFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
/** Compare two paths */
|
/** Compare two paths */
|
||||||
bool ComparePaths (const char* /*one*/, const char* /*second*/) const {
|
bool ComparePaths (const char* one, const char* second) const {
|
||||||
|
if (other)
|
||||||
|
return other->ComparePaths(one,second);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const uint8_t* buffer;
|
const uint8_t* buffer;
|
||||||
size_t length;
|
size_t length;
|
||||||
|
IOSystem* other;
|
||||||
};
|
};
|
||||||
} // end namespace Assimp
|
} // end namespace Assimp
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue