Support Forum G3D Web Page |
Base class for a scene graph. More...
Inherits G3D::ReferenceCountedObject.
Classes | |
class | LoadOptions |
class | VRSettings |
Public Types | |
typedef shared_ptr< Entity >(* | EntityFactory) (const String &name, Scene *scene, AnyTableReader &propertyTable, const ModelTable &modelTable, const Scene::LoadOptions &options) |
typedef lazy_ptr< Model >(* | LazyModelFactory) (const String &name, const Any &any) |
Public Member Functions | |
virtual void | clear () |
Remove all objects. More... | |
void | clearOrder (const String &entity1Name, const String &entity2Name) |
Removes an existing constraint that entity1 simulate before entity2. More... | |
bool | contains (const shared_ptr< Camera > &c) const |
virtual shared_ptr< Entity > | createEntity (const String &name, const Any &any, const Scene::LoadOptions &options=Scene::LoadOptions()) |
Create an Entity and insert() it into the Scene. More... | |
virtual shared_ptr< Entity > | createEntity (const String &entityType, const String &name, const Any &any, const Scene::LoadOptions &options=Scene::LoadOptions()) |
For creating an entity with an explicit type such as Skybox where the any may be a simple filename instead of a named Any::TABLE. More... | |
virtual lazy_ptr< Model > | createModel (const Any &v, const String &name) |
Adds the model to the model table and returns it. More... | |
const shared_ptr< Camera > | defaultCamera () const |
Returns the default camera, set by defaultCamera = "name" in the Scene file. More... | |
const String & | description () const |
bool | editing () const |
When true, even entities with Entity::canChange = false are allowed to change. More... | |
const shared_ptr< Entity > | entity (const String &name) const |
shared_ptr< CubeMap > | environmentMapAsCubeMap () const |
Returns the first environmentMap encountered as a CubeMap, or nullptr if there is not one. More... | |
Ray | eyeRay (const shared_ptr< Camera > &camera, const Vector2 &pixel, const Rect2D &viewport, const Vector2int16 guardBandThickness) const |
Helper for calling intersect() with an eye ray. More... | |
void | getCameraNames (Array< String > &names) const |
Note that because Cameras are Entitys, these also appear in the entity array. More... | |
void | getDescendants (const Array< String > &root, Array< String > &descendants) const |
Returns a unique set of all (recursive) descendants of the root set, not including the root set, according to setOrder() More... | |
void | getEntityArray (Array< shared_ptr< Entity > > &array) const |
Append all Entitys (which include Cameras and Lights) to the array. More... | |
void | getEntityArray (const Array< String > &names, Array< shared_ptr< Entity > > &array) const |
void | getEntityNames (Array< String > &names) const |
template<class EntitySubclass > | |
void | getTypedEntityArray (Array< shared_ptr< EntitySubclass > > &array) const |
Append all Entitys that are subclasses of EntitySubclass to array. More... | |
void | getVisibleBounds (AABox &box) const |
virtual shared_ptr< Entity > | insert (const shared_ptr< Entity > &entity) |
Add an Entity to the Scene (and return it). More... | |
virtual shared_ptr< Model > | insert (const shared_ptr< Model > &model) |
Add a Model to the Scene's modelTable() (and return it). More... | |
virtual shared_ptr< Entity > | intersect (const Ray &ray, float &distance=ignoreFloat, bool intersectMarkers=false, const Array< shared_ptr< Entity > > &exclude=Array< shared_ptr< Entity > >(), Model::HitInfo &info=Model::HitInfo::ignore) const |
Performs very precise (usually, ray-triangle) intersection, and is much slower than intersectBounds. More... | |
virtual shared_ptr< Entity > | intersectBounds (const Ray &ray, float &distance=ignoreFloat, bool intersectMarkers=false, const Array< shared_ptr< Entity > > &exclude=Array< shared_ptr< Entity > >()) const |
Returns the Entity whose conservative bounds are first intersected by ray, excluding Entitys in exclude. More... | |
RealTime | lastEditingTime () const |
Last (wall clock) time that the Scene was in editing() mode. More... | |
RealTime | lastLightChangeTime () const |
Does not track changes to environment lighting. More... | |
RealTime | lastStructuralChangeTime () const |
Wall-clock time at which the scene contents last changed, e.g., by reloading, adding or removing Entitys, etc. More... | |
RealTime | lastVisibleChangeTime () const |
Wall-clock time at which a VisibleEntity in scene last changed at all, e.g., by moving. More... | |
const LightingEnvironment & | lightingEnvironment () const |
LightingEnvironment & | lightingEnvironment () |
virtual Any | load (const String &sceneName, const LoadOptions &loadOptions=LoadOptions()) |
Replace the current scene with a new one parsed from a file. More... | |
const ModelTable & | modelTable () const |
const String & | name () const |
virtual void | onPose (Array< shared_ptr< Surface > > &surfaceArray) |
virtual void | onSimulation (SimTime deltaTime) |
void | registerEntitySubclass (const String &name, EntityFactory factory, bool errorIfAlreadyRegistered=true) |
Register a new subclass of G3D::Entity so that it can be constructed from a .Scene.Any file. More... | |
void | registerModelSubclass (const String &name, LazyModelFactory factory, bool errorIfAlreadyRegistered=true) |
Register a new subclass of G3D::Model so that it can be constructed from a .Scene.Any file. More... | |
virtual void | remove (const shared_ptr< Entity > &entity) |
Remove an entity that must already be in the scene. More... | |
virtual void | remove (const shared_ptr< Model > &model) |
Remove a model from modelTable. More... | |
virtual void | removeEntity (const String &entityName) |
virtual void | removeModel (const String &modelName) |
void | setDescription (const String &d) |
void | setEditing (bool b) |
void | setOrder (const String &entity1Name, const String &entity2Name) |
Places a constraint on the Scene that when iterating for simulation, posing, etc., entity1 always be processed before entity2 (although not necessarily immediately before). More... | |
virtual void | setTime (const SimTime t) |
Discontinuously change the current time. More... | |
shared_ptr< CubeMap > | skyboxAsCubeMap () const |
Returns the first skybox encountered as a CubeMap, or nullptr if there is not one. More... | |
SimTime | time () const |
Any | toAny (const bool forceAll=false) const |
Creates an Any representing this scene by updating the one from which it was loaded with the current Entity positions. More... | |
const shared_ptr< TriTree > & | tritree () |
template<class EntitySubclass > | |
const shared_ptr< EntitySubclass > | typedEntity (const String &name) const |
Get an entity by name and downcast to the desired type. More... | |
void | visualize (RenderDevice *rd, const shared_ptr< Entity > &selectedEntity, const Array< shared_ptr< Surface > > &allSurfaces, const SceneVisualizationSettings &v, const shared_ptr< Camera > &camera) |
Draws debugging information about the current scene to the render device. More... | |
const VRSettings & | vrSettings () const |
Static Public Member Functions | |
static void | appendSceneSearchPaths (const Array< String > &paths) |
Directories in addition to the default search directories in which loadScene() and getSceneNames() will search for Scene.Any files. More... | |
static shared_ptr< Scene > | create (const shared_ptr< AmbientOcclusion > &ambientOcclusion) |
static Array< String > | sceneNames () |
Enumerate the names of all available scenes. More... | |
static String | sceneNameToFilename (const String &scene) |
If scene is a filename, returns it, else look up the string in the filename table and return the value. More... | |
static void | setSceneSearchPaths (const Array< String > &paths) |
Directories in which loadScene() and getSceneNames() will search for .scn.any files. More... | |
Protected Types | |
typedef SmallArray< String, 2 > | DependencyList |
typedef Table< String, DependencyList > | DependencyTable |
List of the names of all entities that must run before a given entity. More... | |
enum | VisitorState { NOT_VISITED, VISITING, ALREADY_VISITED } |
Protected Member Functions | |
Scene (const shared_ptr< AmbientOcclusion > &ambientOcclusion) | |
const shared_ptr< Entity > | _entity (const String &name) const |
void | sortEntitiesByDependency () |
If m_needEntitySort, sort Entitys to resolve dependencies and set m_needEntitySort = false. More... | |
Static Protected Member Functions | |
template<class T , class ... ArgTypes> | |
static shared_ptr< T > | createShared (ArgTypes &&... args) |
Like std::make_shared, but works for protected constructors. More... | |
Base class for a scene graph.
G3D presents a layered API in which the scene graph is available for convenience but can be subclassed and overridden, completely replaced, or simply ignored by applications if it is not a good fit.
The major classes involved in the scene graph API are:
Although the analogy is imperfect, the Pose-Model-Entity design pattern is similar to the Model-Viewer-Controller design pattern. Entity combines the operations of a MVC "Viewer" and MVC "Controller" in abstracting an object from the user (here, Scene/GApp). Pose and Model represent the instance-specific and instance-independent state of the MVC "Model".
|
protected |
|
protected |
List of the names of all entities that must run before a given entity.
This is often empty.
typedef shared_ptr<Entity>(* G3D::Scene::EntityFactory) (const String &name, Scene *scene, AnyTableReader &propertyTable, const ModelTable &modelTable, const Scene::LoadOptions &options) |
|
protected |
|
protected |
Directories in addition to the default search directories in which loadScene() and getSceneNames() will search for Scene.Any files.
Called in GApp::loadScene() to add App specific data directories.
|
virtual |
Remove all objects.
Removes an existing constraint that entity1 simulate before entity2.
It is an error to remove a constraint that does not exist
bool G3D::Scene::contains | ( | const shared_ptr< Camera > & | c | ) | const |
|
static |
ambientOcclusion | Object to use for the LightingEnvironment |
|
virtual |
Create an Entity and insert() it into the Scene.
|
virtual |
For creating an entity with an explicit type such as Skybox where the any may be a simple filename instead of a named Any::TABLE.
Adds the model to the model table and returns it.
|
inlinestaticprotectedinherited |
Like std::make_shared, but works for protected constructors.
Call as createShared<myclass>.
const shared_ptr<Camera> G3D::Scene::defaultCamera | ( | ) | const |
Returns the default camera, set by defaultCamera = "name" in the Scene file.
|
inline |
|
inline |
When true, even entities with Entity::canChange = false are allowed to change.
This is primarily used when the developer is actively editing the scene, versus when the program is in its normal operation mode. The SceneEditorWindow GUI will automatically modify this.
Referenced by getTypedEntityArray(), and typedEntity().
shared_ptr<CubeMap> G3D::Scene::environmentMapAsCubeMap | ( | ) | const |
Returns the first environmentMap encountered as a CubeMap, or nullptr if there is not one.
Ray G3D::Scene::eyeRay | ( | const shared_ptr< Camera > & | camera, |
const Vector2 & | pixel, | ||
const Rect2D & | viewport, | ||
const Vector2int16 | guardBandThickness | ||
) | const |
Helper for calling intersect() with an eye ray.
pixel | The pixel centers are at (0.5, 0.5). Pixel is taken relative to viewport before the guard band was applied. |
Note that because Cameras are Entitys, these also appear in the entity array.
void G3D::Scene::getDescendants | ( | const Array< String > & | root, |
Array< String > & | descendants | ||
) | const |
Returns a unique set of all (recursive) descendants of the root set, not including the root set, according to setOrder()
Append all Entitys (which include Cameras and Lights) to the array.
void G3D::Scene::getEntityArray | ( | const Array< String > & | names, |
Array< shared_ptr< Entity > > & | array | ||
) | const |
|
inline |
Append all Entitys that are subclasses of EntitySubclass to array.
void G3D::Scene::getVisibleBounds | ( | AABox & | box | ) | const |
Add an Entity to the Scene (and return it).
Assumes that no entity with the same name is present in the scene.
Add a Model to the Scene's modelTable() (and return it).
Assumes that no model with the same name is present in the scene.
|
virtual |
Performs very precise (usually, ray-triangle) intersection, and is much slower than intersectBounds.
If G3D::Model::setUseOptimizedIntersect was set to true before the current scene was loaded then this method will be optimized for run-time performance at the cost of memory and loading time. It may then be called tens of times per frame without significant CPU impact on frame rate.
Invisible VisibleEntitys cannot be hit.
intersectMarkers | If true, allow MarkerEntity instances to be intersected. Default is false. |
exclude | any entity in this array |
ray | The Ray in world space. |
|
virtual |
Returns the Entity whose conservative bounds are first intersected by ray, excluding Entitys in exclude.
Useful for mouse selection and coarse hit-scan collision detection.
Returns nullptr if none are intersected.
Note that this may not return the closest Entity if another's bounds project in front of it.
Invisible VisibleEntitys cannot be hit.
ray | World space ray |
distance | Maximum distance at which to allow selection (e.g., finf()). On return, this is the distance to the object. |
exclude | Entities to ignore when searching for occlusions. This is convenient to use when avoiding self-collisions, for example. |
intersectMarkers | If true, allow MarkerEntity instances to be intersected. Default is false. |
|
inline |
|
inline |
Does not track changes to environment lighting.
|
inline |
Wall-clock time at which the scene contents last changed, e.g., by reloading, adding or removing Entitys, etc.
Moving objects do not count as structural changes. This is used by the GUI for tracking when to update the SceneEditorWindow, for example.
|
inline |
Wall-clock time at which a VisibleEntity in scene last changed at all, e.g., by moving.
|
inline |
|
inline |
|
virtual |
Replace the current scene with a new one parsed from a file.
See the starter project for examples Entitys may have already moved since creation because they are simulated for 0s at start.
sceneName | The 'name' field specified inside the scene file, or the filename of the scene file |
|
inline |
|
inline |
Referenced by typedEntity().
|
virtual |
void G3D::Scene::registerEntitySubclass | ( | const String & | name, |
EntityFactory | factory, | ||
bool | errorIfAlreadyRegistered = true |
||
) |
Register a new subclass of G3D::Entity so that it can be constructed from a .Scene.Any file.
You can also override Scene::createEntity to add support for new Entity types.
void G3D::Scene::registerModelSubclass | ( | const String & | name, |
LazyModelFactory | factory, | ||
bool | errorIfAlreadyRegistered = true |
||
) |
Register a new subclass of G3D::Model so that it can be constructed from a .Scene.Any file.
You can also override Scene::createModel to add support for new Model types.
|
virtual |
Remove an entity that must already be in the scene.
Does not change the order of the other Entitys in the scene (i.e., entityArray())
Note that removal occurs immediately, so be avoid invoking this in the middle of iterating through entityArray().
|
virtual |
Remove a model from modelTable.
Does not affect Entitys currently using that model, only ones later instantiated with createEntity().
|
virtual |
|
virtual |
Enumerate the names of all available scenes.
This is recomputed each time that it is called.
If scene is a filename, returns it, else look up the string in the filename table and return the value.
If no entry exists, throw an exception
|
inline |
void G3D::Scene::setEditing | ( | bool | b | ) |
Places a constraint on the Scene that when iterating for simulation, posing, etc., entity1 always be processed before entity2 (although not necessarily immediately before).
It is an error to create a cycle between multiple entities.
This method takes names instead of pointers so that it can be invoked before both entities exist, e.g., during entity creation. If one of the entities is later removed, this constraint is removed.
Useful when entity2 is a child of entity1 and defines itself relative, e.g., entity1 is a jeep and entity2 is a character driving the jeep.
Do not invoke this method unless you actually require an ordering constraint because it causes extra work for the iteration system.
Directories in which loadScene() and getSceneNames() will search for .scn.any files.
By default, the search path for scene files is the current directory (as of the time that the first scene is loaded or getSceneNames() is invoked), the paths specified by the G3D10DATA environment variable, and the directory containing System::findDataFile("scene/CornellBox-Glossy.scn.any") if not already invluded in G3D10Data.
This does not affect the directories that models and include statements search to load other resources.
|
virtual |
shared_ptr<CubeMap> G3D::Scene::skyboxAsCubeMap | ( | ) | const |
Returns the first skybox encountered as a CubeMap, or nullptr if there is not one.
|
protected |
If m_needEntitySort, sort Entitys to resolve dependencies and set m_needEntitySort = false.
Called fromOnSimulation
|
inline |
Any G3D::Scene::toAny | ( | const bool | forceAll = false | ) | const |
const shared_ptr<TriTree>& G3D::Scene::tritree | ( | ) |
|
inline |
Get an entity by name and downcast to the desired type.
Returns nullptr if the entity does not exist or does not have that type.
void G3D::Scene::visualize | ( | RenderDevice * | rd, |
const shared_ptr< Entity > & | selectedEntity, | ||
const Array< shared_ptr< Surface > > & | allSurfaces, | ||
const SceneVisualizationSettings & | v, | ||
const shared_ptr< Camera > & | camera | ||
) |
Draws debugging information about the current scene to the render device.
|
inline |
|
protected |
Simulation dependencies.
m_ancestorTable[Descendant] includes Ancestor. Used by setOrder and clearOrder
|
protected |
|
protected |
|
protected |
Referenced by description(), and setDescription().
|
protected |
Referenced by editing().
All Entitys, including Cameras, Lights, and MarkerEntitys.
Referenced by getEntityArray(), and getTypedEntityArray().
|
protected |
All Entitys, including Cameras, Lights, and MarkerEntitys, by name.
|
protected |
|
protected |
Referenced by lastEditingTime().
|
protected |
Referenced by lastLightChangeTime().
|
protected |
Referenced by lastStructuralChangeTime().
|
protected |
Referenced by lastVisibleChangeTime().
|
protected |
Referenced by lightingEnvironment().
|
protected |
|
protected |
|
protected |
Referenced by modelTable().
|
protected |
When true, the m_entityArray needs to be re-sorted based on dependencies before iterating.
|
protected |
|
protected |
|
protected |
Referenced by vrSettings().