LightsprintSDK 2021.08.08
rr::RRScene Class Reference

#include <RRScene.h>

Inheritance diagram for rr::RRScene:
rr::RRUniformlyAllocatedNonCopyable rr::RRUniformlyAllocated

Public Types

typedef RRSceneLoader(const RRString &filename, RRFileLocator *textureLocator, bool *aborting)
 
typedef bool Saver(const RRScene *scene, const RRString &filename)
 

Public Member Functions

 RRScene ()
 
 RRScene (const RRString &filename, RRFileLocator *textureLocator=nullptr, bool *aborting=nullptr)
 
bool save (const RRString &filename) const
 
virtual ~RRScene ()
 
void transform (const RRMatrix3x4 &transformation)
 
void normalizeUnits (float currentUnitLengthInMeters)
 
void normalizeUpAxis (unsigned currentUpAxis)
 
void getAllBuffers (RRVector< RRBuffer * > &buffers, const RRVector< unsigned > *layers) const
 
RRScenepreprocessScene (bool splitMultimaterials, unsigned copyLayerToMaterialLightmaps)
 
- Public Member Functions inherited from rr::RRUniformlyAllocated
void * operator new (std::size_t n)
 
void * operator new[] (std::size_t n)
 
void operator delete (void *p, std::size_t n)
 
void operator delete[] (void *p, std::size_t n)
 

Static Public Member Functions

static void registerLoader (const char *extensions, Loader *loader)
 
static void registerSaver (const char *extensions, Saver *saver)
 
static const char * getSupportedLoaderExtensions ()
 
static const char * getSupportedSaverExtensions ()
 

Public Attributes

RRObjects objects
 
RRLights lights
 
RRBufferenvironment
 
RRCameras cameras
 

Protected Attributes

RRObjectsprotectedObjects
 
RRLightsprotectedLights
 

Additional Inherited Members

- Protected Member Functions inherited from rr::RRUniformlyAllocatedNonCopyable
 RRUniformlyAllocatedNonCopyable ()
 
 ~RRUniformlyAllocatedNonCopyable ()
 

Detailed Description

3d scene.

Member Typedef Documentation

◆ Loader

typedef RRScene * rr::RRScene::Loader(const RRString &filename, RRFileLocator *textureLocator, bool *aborting)

Template of custom scene loader.

◆ Saver

typedef bool rr::RRScene::Saver(const RRScene *scene, const RRString &filename)

Template of custom scene saver.

Constructor & Destructor Documentation

◆ RRScene() [1/2]

rr::RRScene::RRScene ( )

Creates empty scene.

◆ RRScene() [2/2]

rr::RRScene::RRScene ( const RRString filename,
RRFileLocator textureLocator = nullptr,
bool *  aborting = nullptr 
)

Loads 3d scene from file.

Scene load is attempted using loaders registered via registerLoader(). Loaders for ~35 formats (Supported formats) are implemented in LightsprintIO library, rr_io::registerIO() will register all of them for you.

Our loaders try to load all textures from proper paths specified by scene file, but if it fails, additional attempts are made as specified by textureLocator. textureLocator tells also what to do when texture is not found at all (create stub texture or create material without texture?)

If file contains information on units or up direction, our importers convert units to meters and up to Y.

Parameters
filenameFilename of scene. If it is empty, scene will be empty.
textureLocatorOptional custom file locator, for finding texture files in unusual location. nullptr = default locator will be used.
abortingImport may be asynchronously aborted by setting *aborting to true.

◆ ~RRScene()

virtual rr::RRScene::~RRScene ( )
virtual

Deletes scene including all objects and lights.

Member Function Documentation

◆ save()

bool rr::RRScene::save ( const RRString filename) const

Saves 3d scene to file.

Scene save is attempted using savers registered via registerSaver(). One saver is implemented in LightsprintIO library, rr_io::registerSavers() will register it for you. See rr_io::registerSavers() for details on formats/features supported.

Parameters
filenameName of file to be created.

◆ transform()

void rr::RRScene::transform ( const RRMatrix3x4 transformation)

Transforms scene by given matrix (i.e. transforms all object matrices and lights).

This function reads contents of scene from objects and lights, not protectedObjects and protectedLights, so if you call it from your RRScene constructor, fill objects and lights first.

◆ normalizeUnits()

void rr::RRScene::normalizeUnits ( float  currentUnitLengthInMeters)

Changes units to meters.

Using meters is not strictly necessary, global illumination works on all scales. However, it is recommended to import scenes in meters. This function reads contents of scene from objects and lights, not protectedObjects and protectedLights, so if you call it from your RRScene constructor, fill objects and lights first.

◆ normalizeUpAxis()

void rr::RRScene::normalizeUpAxis ( unsigned  currentUpAxis)

Changes up axist to Y.

Using up Y is not strictly necessary, global illumination works in all directions. However, it is recommended to import scenes so that Y is up. This function reads contents of scene from objects and lights, not protectedObjects and protectedLights, so if you call it from your RRScene constructor, fill objects and lights first.

Parameters
currentUpAxis0=X, 1=Y, 2=Z

◆ getAllBuffers()

void rr::RRScene::getAllBuffers ( RRVector< RRBuffer * > &  buffers,
const RRVector< unsigned > *  layers 
) const

Inserts all buffers found in scene's materials, lights, environment and illumination layers into collection.

Can be used to gather all texture filenames, to pause all videos etc.

Parameters
buffersIn-out collection of buffers. Unique input buffers are preserved, new buffers from scene are added to collection. Ordering of input buffers may change and duplicates and nullptr buffers are removed.
layersIllumination from given layers will be gathered too.

◆ preprocessScene()

RRScene * rr::RRScene::preprocessScene ( bool  splitMultimaterials,
unsigned  copyLayerToMaterialLightmaps 
)

Preprocess scene before saving.

Various fileformats have various limitations, and preprocessing scene before save() can work around them. Created scene is intended only for saving, delete it after save().

Parameters
splitMultimaterialsSplit objects with multiple facegroups(materials) into multiple object with one facegroup(material). This is recommended for .scn (SmallLuxGPU) and Assimp based exporters.
copyLayerToMaterialLightmapsCopy lighting from this layer into RRMaterial::lightmap. This is recommended for Assimp based exporters, if you wish to export lightmaps or ambient maps.

◆ registerLoader()

static void rr::RRScene::registerLoader ( const char *  extensions,
Loader loader 
)
static

Registers scene loader so it can be used by RRScene constructor.

Extensions are case insensitive, in "*.dae;*.3ds;*.md5mesh" format.

Several loaders are implemented in LightsprintIO library, rr_io::registerIO() will register all of them for you (by calling this function several times).

Multiple loaders may be registered, even for the same extension. If first loader fails to load scene, second one is tried etc.

◆ registerSaver()

static void rr::RRScene::registerSaver ( const char *  extensions,
Saver saver 
)
static

Similar to registerLoader().

◆ getSupportedLoaderExtensions()

static const char * rr::RRScene::getSupportedLoaderExtensions ( )
static

Returns list of supported loader extensions in "*.dae;*.3ds;*.md5mesh" format.

All extensions of registered loaders are returned in one static string, don't free() it. nullptr is returned if no loaders were registered.

◆ getSupportedSaverExtensions()

static const char * rr::RRScene::getSupportedSaverExtensions ( )
static

Returns list of supported saver extensions in "*.dae;*.3ds;*.md5mesh" format.

All extensions of registered savers are returned in one static string, don't free() it. nullptr is returned if no savers were registered.

Member Data Documentation

◆ objects

RRObjects rr::RRScene::objects

Collection of objects in scene. May be freely modified, does not delete objects in destructor.

◆ lights

RRLights rr::RRScene::lights

Collection of lights in scene. May be freely modified, does not delete lights in destructor.

◆ environment

RRBuffer* rr::RRScene::environment

Scene environment, skybox. May be modified, but carefully, scene owns environment and deletes it in destructor, so delete old environment before setting new one.

◆ cameras

RRCameras rr::RRScene::cameras

Collection of cameras in scene. May be freely modified.

◆ protectedObjects

RRObjects* rr::RRScene::protectedObjects
protected

Protected collection of objects in scene, owns objects, deletes them in destructor.

◆ protectedLights

RRLights* rr::RRScene::protectedLights
protected

Protected collection of lights in scene, owns lights, deletes them in destructor.