SLProject  4.3.020
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLAssimpIOSystem Class Reference

Assimp file system handler backed by SLFileStorage. More...

#include <SLAssimpIOSystem.h>

Inherits Assimp::IOSystem.

Public Member Functions

bool Exists (const char *pFile) const override
 Returns true if pFile can be opened through SLFileStorage. More...
 
char getOsSeparator () const override
 Returns the path separator, always '/' for SLProject paths. More...
 
Assimp::IOStream * Open (const char *pFile, const char *pMode) override
 Opens pFile through SLFileStorage and wraps it in an SLAssimpIOStream. More...
 
void Close (Assimp::IOStream *pFile) override
 Closes the stream and deletes the adapter created by Open. More...
 

Detailed Description

Assimp file system handler backed by SLFileStorage.

Installed on the Assimp importer with SetIOHandler in SLAssimpImporter::load, so that every file Assimp opens is resolved through SLFileStorage rather than the C runtime. Paths are looked up with the IOK_model file kind.

Definition at line 60 of file SLAssimpIOSystem.h.

Member Function Documentation

◆ Close()

void SLAssimpIOSystem::Close ( Assimp::IOStream *  pFile)
override

Closes the stream and deletes the adapter created by Open.

Definition at line 88 of file SLAssimpIOSystem.cpp.

89 {
90  SLAssimpIOStream* stream = dynamic_cast<SLAssimpIOStream*>(pFile);
91  SLFileStorage::close(stream->stream());
92  delete stream;
93 }
Adapts a single SLIOStream to the stream interface Assimp expects.
SLIOStream * stream()
Returns the wrapped SLProject stream.
void close(SLIOStream *stream)
Closes and deletes a stream.

◆ Exists()

bool SLAssimpIOSystem::Exists ( const char *  pFile) const
override

Returns true if pFile can be opened through SLFileStorage.

Definition at line 62 of file SLAssimpIOSystem.cpp.

63 {
64  return SLFileStorage::exists(pFile, IOK_model);
65 }
@ IOK_model
Definition: SLFileStorage.h:41
bool exists(std::string path, SLIOStreamKind kind)
Checks whether a given file exists.

◆ getOsSeparator()

char SLAssimpIOSystem::getOsSeparator ( ) const
override

Returns the path separator, always '/' for SLProject paths.

Definition at line 67 of file SLAssimpIOSystem.cpp.

68 {
69  return '/';
70 }

◆ Open()

Assimp::IOStream * SLAssimpIOSystem::Open ( const char *  pFile,
const char *  pMode 
)
override

Opens pFile through SLFileStorage and wraps it in an SLAssimpIOStream.

Parameters
pFilePath of the file to open
pModeAssimp mode string ("rb", "r", "rt", "wb", "w", "wt"). Only the first character is inspected, because an SLIOStream is always binary.

Definition at line 72 of file SLAssimpIOSystem.cpp.

73 {
74  // Assimp requires the modes "wb", "w", "wt", "rb", "r" and "rt".
75  // The second character is ignored because SLIOStreams are always binary.
76  // Therefor we only need to check the first character to determine
77  // whether we are reading or writing.
78  SLIOStreamMode streamMode = IOM_read;
79  if (pMode[0] == 'r')
80  streamMode = IOM_read;
81  else if (pMode[0] == 'w')
82  streamMode = IOM_write;
83 
84  SLIOStream* stream = SLFileStorage::open(pFile, IOK_model, streamMode);
85  return new SLAssimpIOStream(stream);
86 }
SLIOStreamMode
Enum of stream opening modes.
Definition: SLFileStorage.h:49
@ IOM_read
Definition: SLFileStorage.h:50
@ IOM_write
Definition: SLFileStorage.h:51
Interface for accessing external data using streams.
Definition: SLFileStorage.h:62
SLIOStream * open(std::string path, SLIOStreamKind kind, SLIOStreamMode mode)
Opens a file stream for I/O operations.

The documentation for this class was generated from the following files: