Ocular Engine
Ocular::Core::SceneManager Class Reference

#include <SceneManager.hpp>

Public Member Functions

SceneObjectcreateObject (std::string const &name="Unnamed", SceneObject *parent=nullptr)
 
template<class T >
T * createObject (std::string const &name="Unnamed", SceneObject *parent=nullptr)
 
SceneObjectcreateObjectOfType (std::string const &type, std::string const &name="Unnamed", SceneObject *parent=nullptr)
 
SceneObjectduplicateObject (SceneObject const *object)
 
void destroyObject (SceneObject *object)
 
void destroyObject (std::string const &name, bool removeAll=false)
 
void destroyObject (UUID const &uuid)
 
SceneObjectfindObject (std::string const &name) const
 
void findObjects (std::string const &name, std::vector< SceneObject * > &objects) const
 
SceneObjectfindObject (UUID const &uuid) const
 
void findTopObjects (std::vector< SceneObject * > &object) const
 
void updateUUID (UUID const &uuid)
 
void getVisibleSceneObjects (std::vector< SceneObject * > &objects, Math::Frustum const &frustum)
 
void triggerObjectDirty (UUID const &uuid, bool staticObject)
 
void createScene (std::string const &name, SceneTreeType staticType=SceneTreeType::BoundingVolumeHierarchyCPU, SceneTreeType dynamicType=SceneTreeType::BoundingVolumeHierarchyCPU)
 
bool loadScene (File const &file)
 
bool saveScene (File const &file)
 
bool isSceneActive () const
 
ComponentFactory< ARoutine > & getRoutineFactory ()
 
ComponentFactory< ARenderable > & getRenderableFactory ()
 
ComponentFactory< SceneObject > & getSceneObjectFactory ()
 
ComponentFactory< Renderer > & getRendererFactory ()
 

Protected Member Functions

void loadPersistentObjects ()
 
void addObject (SceneObject *object, SceneObject *parent=nullptr)
 
void unloadScene ()
 
void update ()
 
void render ()
 
void objectActiveChanged (SceneObject *object)
 
void objectVisibleChanged (SceneObject *object)
 
void objectStaticChanged (SceneObject *object)
 
void objectAddedRoutine (ARoutine *routine)
 
void objectRemovedRoutine (ARoutine *routine)
 
void objectParentChanged (SceneObject *object, SceneObject *oldParent)
 

Friends

class Engine
 
class SceneObject
 
class ARoutine
 

Detailed Description

The SceneManager is the owner of all Scenes and SceneObjects. It responsible for properly loading and unloading of the objects and providing access to them.

Only a single Scene may be active at a time, and any SceneObjects that are associated with it will be unloaded with it. Any SceneObjects that are created dynamically will be automatically added and associated with the current Scene.

In special circumstances, a SceneObject may be allowed to persist inbetween scenes. It is not recommended to apply this modifier often, but it may be useful in special circumstances. Any SceneObject that persists will be automatically added to a newly loaded scene.

Member Function Documentation

void Ocular::Core::SceneManager::addObject ( SceneObject object,
SceneObject parent = nullptr 
)
protected

Adds the provided SceneObject to the current Scene.

Parameters
[in]object
SceneObject * Ocular::Core::SceneManager::createObject ( std::string const &  name = "Unnamed",
SceneObject parent = nullptr 
)

Creates and adds a new empty SceneObject to the active scene.

Parameters
[in]nameNon-unique display name for the object
[in]parentOptional parent SceneObject. NULL if no parent.
Returns
Pointer to the new object. This object is managed by the manager and should NOT be deallocated by the caller.
SceneObject * Ocular::Core::SceneManager::createObjectOfType ( std::string const &  type,
std::string const &  name = "Unnamed",
SceneObject parent = nullptr 
)

Attempts to create an object of the given type.

This is an alternative to createObject<T> when the explicit type T is not directly available.

Parameters
[in]typeA valid SceneObject type name (ie "SceneObject", "Camera", etc.)
[in]nameNon-unique display name for the object
[in]parentOptional parent SceneObject. NULL if no parent.
Returns
The newly created SceneObject. May return false if the provided type is invalid (not found registered with the SceneObject factory (SceneManager::getSceneObjectFactory))
void Ocular::Core::SceneManager::createScene ( std::string const &  name,
SceneTreeType  staticType = SceneTreeType::BoundingVolumeHierarchyCPU,
SceneTreeType  dynamicType = SceneTreeType::BoundingVolumeHierarchyCPU 
)

Creates a new Scene with the specified name.

Note that if a Scene is already active, that Scene will be first unloaded. If any changes to that Scene need to be saved prior to unloading, then the saveScene method should be called prior to createScene.

Parameters
[in]name
[in]staticTypeType of SceneTree to use for static objects (default CPU BVH)
[in]dynamicTypeType of SceneTree to use for dynamic objects (default CPU BVH)

Loading a scene requires the following steps:

1. Ensure the old scene (if valid) is completely unloaded.
2. Load or create a new scene.
3. Add all persistent objects to the scene.
void Ocular::Core::SceneManager::destroyObject ( SceneObject object)

Destroys the specified SceneObject and removes it completely from the SceneManager/Scene/etc.

This will remove the object from the scene and parent. Will also destroy (delete) the object and any children.

Note
Removing by pointer is less efficient than by UUID.
Parameters
[in]objectSceneObject to remove.
void Ocular::Core::SceneManager::destroyObject ( std::string const &  name,
bool  removeAll = false 
)

Destroys the specified SceneObject and removes it completely from the SceneManager/Scene/etc.

This will remove the object from the scene and parent. Will also destroy (delete) the object and any children.

By default, if there are multiple SceneObjects with the given name, only the first object will be removed.

Parameters
[in]nameName of the SceneObject to remove.
[in]boolIf there are multiple SceneObjects with the given name, and this parameter is set TRUE, then all objects with the matching name will be removed.
void Ocular::Core::SceneManager::destroyObject ( UUID const &  uuid)

Destroys the specified SceneObject and removes it completely from the SceneManager/Scene/etc.

This will remove the object from the scene and parent. Will also destroy (delete) the object and any children.

Note
Removing by name is less efficient than by UUID.
Parameters
[in]uuidUUID of the SceneObject to remove.
SceneObject * Ocular::Core::SceneManager::duplicateObject ( SceneObject const *  object)

Creates and adds a new SceneObject to the active scene that is an exact duplicate of the provided object. The new SceneObject is added as a child to the parent of the specified SceneObject (they are siblings).

Parameters
[in]objectObject instance to duplicate.
Returns
Pointer to the new object. This object is managed by the manager and should NOT be deallocated by the caller.
SceneObject * Ocular::Core::SceneManager::findObject ( std::string const &  name) const

Finds and returns the SceneObject with the specified name.

If there are multiple SceneObjects with the given name, only the first object will be removed. If you need all objects with a given name, then use the findObjects() method.

Note
Searching by name is less efficient than by UUID.
Parameters
[in]nameName of the SceneObject to find.
Returns
Pointer to the SceneObject. Returns NULL if the specified object was not found.
SceneObject * Ocular::Core::SceneManager::findObject ( UUID const &  uuid) const

Finds and returns the SceneObject with the specified UUID.

Parameters
[in]uuidUUID of the SceneObject to find.
Returns
Pointer to the SceneObject. Returns NULL if the specified object was not found.
void Ocular::Core::SceneManager::findObjects ( std::string const &  name,
std::vector< SceneObject * > &  objects 
) const

Finds and returns all SceneObjects with names that match the specified one.

Parameters
[in]nameName of the SceneObject(s) to find.
[out]objectsCollection of all SceneObjects whose names match the provided.
void Ocular::Core::SceneManager::findTopObjects ( std::vector< SceneObject * > &  object) const

Finds and returns a container of all top-level SceneObjects (object with no parents).

void Ocular::Core::SceneManager::getVisibleSceneObjects ( std::vector< SceneObject * > &  objects,
Math::Frustum const &  frustum 
)

Returns a collection of all SceneObjects visible to the specified view frustum (see Camera::getFrustum).

The returned collection is a flat list meaning all visible SceneObjects are returned, not just top-level parents. Thus there is no need to check child visibility, as visible children will also be stored in the returned collection.

Parameters
[out]objectsAll visible SceneObjects
[in]frustumView frustum to perform frustum-culling against
bool Ocular::Core::SceneManager::isSceneActive ( ) const
Returns
TRUE if there is an active Scene running.
bool Ocular::Core::SceneManager::loadScene ( File const &  file)

Attempts to load the Scene from the specified .oscene file.

If the specified Scene can not be loaded, then an empty default Scene will be created instead.

Note that if a Scene is already active, that Scene will be first unloaded. If any changes to that Scene need to be saved prior to unloading, then the saveScene method should be called prior to loadScene.

Parameters
[in]file
Returns
TRUE if loaded successfully
void Ocular::Core::SceneManager::objectActiveChanged ( SceneObject object)
protected

Called when a SceneObject's SetActive method is envoked.

Parameters
[in]object
void Ocular::Core::SceneManager::objectAddedRoutine ( ARoutine routine)
protected

Called when a SceneObject adds a new ARoutine instance.

Parameters
[in]routine
void Ocular::Core::SceneManager::objectParentChanged ( SceneObject object,
SceneObject oldParent 
)
protected

Called when an object's parent is changed.

Parameters
[in]objectThe object that has a new parent.
[in]oldParentThe old parent of the object.
void Ocular::Core::SceneManager::objectRemovedRoutine ( ARoutine routine)
protected

Called when a SceneObject removes a ARoutine instance.

Parameters
[in]routine
void Ocular::Core::SceneManager::objectStaticChanged ( SceneObject object)
protected

Called when a SceneObject's SetStatic method is envoked.

Parameters
[in]object
void Ocular::Core::SceneManager::objectVisibleChanged ( SceneObject object)
protected

Called when a SceneObject's SetForcedVisible method is envoked.

Parameters
[in]object
void Ocular::Core::SceneManager::render ( )
protected

Tells the current Scene to retrieve all visible SceneObjects and perform envoke their render methods.

bool Ocular::Core::SceneManager::saveScene ( File const &  file)

Attempts to save the Scene to the specified .oscene file.

Parameters
[in]file
Returns
TRUE if saved successfully
void Ocular::Core::SceneManager::triggerObjectDirty ( UUID const &  uuid,
bool  staticObject 
)

Should be called when an object is dirty - the position/rotation/scale or any other variable that could effect the scene tree hierarchy - has been modified.

Typically called automatically by the base SceneObject implementation.

Parameters
[in]uuid
[in]staticObjectTRUE if the object is static; else FALSE.
void Ocular::Core::SceneManager::update ( )
protected

Tells the current Scene to update and restructure it's SceneTrees. Also calls the various update methods for all active SceneObjects.

void Ocular::Core::SceneManager::updateUUID ( UUID const &  uuid)

Updates the UUID of a SceneObject.

Note
Typically for internal engine use only

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