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

Adapts a single SLIOStream to the stream interface Assimp expects. More...

#include <SLAssimpIOSystem.h>

Inherits Assimp::IOStream.

Public Member Functions

 SLAssimpIOStream (SLIOStream *stream)
 
size_t Read (void *pvBuffer, size_t pSize, size_t pCount) override
 Reads pCount records of pSize bytes into pvBuffer, returns records read. More...
 
size_t Write (const void *pvBuffer, size_t pSize, size_t pCount) override
 Writes pCount records of pSize bytes from pvBuffer, returns bytes written. More...
 
aiReturn Seek (size_t pOffset, aiOrigin pOrigin) override
 Moves the read position to pOffset relative to pOrigin. More...
 
size_t Tell () const override
 Returns the current read position in bytes. More...
 
size_t FileSize () const override
 Returns the total size of the stream in bytes. More...
 
void Flush () override
 Flushes the wrapped stream. More...
 
SLIOStreamstream ()
 Returns the wrapped SLProject stream. More...
 

Private Attributes

SLIOStream_stream
 Wrapped SLProject stream, not owned. More...
 

Detailed Description

Adapts a single SLIOStream to the stream interface Assimp expects.

Assimp reads model files through its own Assimp::IOStream abstraction. This class forwards each of those calls to an SLIOStream, so that Assimp reads through the same storage layer as the rest of SLProject. That matters on Emscripten in particular, where an asset is not a file on disk but data fetched over the network or held in browser storage.

Definition at line 25 of file SLAssimpIOSystem.h.

Constructor & Destructor Documentation

◆ SLAssimpIOStream()

SLAssimpIOStream::SLAssimpIOStream ( SLIOStream stream)
Parameters
streamStream to read from; ownership stays with the caller

Definition at line 13 of file SLAssimpIOSystem.cpp.

14  : _stream(stream)
15 {
16 }
SLIOStream * stream()
Returns the wrapped SLProject stream.
SLIOStream * _stream
Wrapped SLProject stream, not owned.

Member Function Documentation

◆ FileSize()

size_t SLAssimpIOStream::FileSize ( ) const
override

Returns the total size of the stream in bytes.

Definition at line 52 of file SLAssimpIOSystem.cpp.

53 {
54  return _stream->size();
55 }
virtual size_t size()
Definition: SLFileStorage.h:76

◆ Flush()

void SLAssimpIOStream::Flush ( )
override

Flushes the wrapped stream.

Definition at line 57 of file SLAssimpIOSystem.cpp.

58 {
59  _stream->flush();
60 }
virtual void flush()
Definition: SLFileStorage.h:77

◆ Read()

size_t SLAssimpIOStream::Read ( void pvBuffer,
size_t  pSize,
size_t  pCount 
)
override

Reads pCount records of pSize bytes into pvBuffer, returns records read.

Definition at line 18 of file SLAssimpIOSystem.cpp.

19 {
20  char* dest = (char*)pvBuffer;
21  size_t totalSize = pCount * pSize;
22  size_t sizeRead = _stream->read(dest, totalSize);
23  return sizeRead / pSize;
24 }
virtual size_t read(void *buffer, size_t size)
Definition: SLFileStorage.h:72

◆ Seek()

aiReturn SLAssimpIOStream::Seek ( size_t  pOffset,
aiOrigin  pOrigin 
)
override

Moves the read position to pOffset relative to pOrigin.

Definition at line 33 of file SLAssimpIOSystem.cpp.

34 {
36  if (pOrigin == aiOrigin_SET)
37  streamOrigin = SLIOStream::IOO_beg;
38  else if (pOrigin == aiOrigin_CUR)
39  streamOrigin = SLIOStream::IOO_cur;
40  else if (pOrigin == aiOrigin_END)
41  streamOrigin = SLIOStream::IOO_end;
42 
43  bool successful = _stream->seek(pOffset, streamOrigin);
44  return successful ? aiReturn_SUCCESS : aiReturn_FAILURE;
45 }
virtual bool seek(size_t offset, Origin origin)
Definition: SLFileStorage.h:75

◆ stream()

SLIOStream* SLAssimpIOStream::stream ( )
inline

Returns the wrapped SLProject stream.

Definition at line 50 of file SLAssimpIOSystem.h.

50 { return _stream; }

◆ Tell()

size_t SLAssimpIOStream::Tell ( ) const
override

Returns the current read position in bytes.

Definition at line 47 of file SLAssimpIOSystem.cpp.

48 {
49  return _stream->tell();
50 }
virtual size_t tell()
Definition: SLFileStorage.h:74

◆ Write()

size_t SLAssimpIOStream::Write ( const void pvBuffer,
size_t  pSize,
size_t  pCount 
)
override

Writes pCount records of pSize bytes from pvBuffer, returns bytes written.

Definition at line 26 of file SLAssimpIOSystem.cpp.

27 {
28  const char* dest = (const char*)pvBuffer;
29  size_t totalSize = pCount * pSize;
30  return _stream->write(dest, totalSize);
31 }
virtual size_t write(const void *buffer, size_t size)
Definition: SLFileStorage.h:73

Member Data Documentation

◆ _stream

SLIOStream* SLAssimpIOStream::_stream
private

Wrapped SLProject stream, not owned.

Definition at line 53 of file SLAssimpIOSystem.h.


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