Shadowrun: Awakened Forums
Welcome, Guest
 
  Site Forums   Wiki   Bugs Tasks Code Docs Help Register Login  
    Page   Discussion         View source History  

OGRE

From Shadowrun: Awakened

Jump to: navigation, search
OGRE 3D Engine

OGRE (Object-Oriented Graphics Rendering Engine) is a multi-platform, open source 3D rendering library in C++.



Contents

OGRE in Awakened Engine

We hope to capitalize on OGRE's numerous built-in features to develop the game engine as rapidly as possible.

OgreSupport.lib

The Game Engine User's Manual introduces the "OgreSupport.lib" library. This library contains functionality specific to OGRE and critical for our applications. This is primarily to fill in missing functionality. While other projects may find this code useful, and are certainly encouraged to try to use it, it does exist heavily within the context of our project and does not aim to be as universal as the main OGRE SDK.

Functionality in OgreSupport.lib may rely upon Support.lib and the OGRE SDK, but should not otherwise be coupled to any other code.

Ogre::SceneManager Serialization via OgreSupport::SceneSerializer

One aspect missing from the OGRE SDK is the capability to save and load OGRE scenes to and from files. In all of the demos, scenes are programatically created. While the OGRE community has embraced the DotScene XML format, they have yet to create a useful system of exporting the format from an active SceneManager (at the moment, it's used to move scenes from third party editors, such as Blender, into Ogre). As we need to move scenes from the content editor (which uses OGRE) to the client application (which uses OGRE), we needed a way to save Ogre scene to file.

OgreSupport::SceneSerializer presents the front-end for the serialization functionality. This class controls instantiation of supporting classes and carries out the entire process. The bulk of the logic in the library deals with saving/loading the SceneNode tree held within a SceneManager. This traversal is carried out as a depth-first search through the tree. At each node, its information is saved to the stream (name, position, rotation, number of child objects, number of child nodes, etc), then its child objects (IE Ogre::Entity, Ogre:: Light, etc), then its child node's information. At load time, the structure of the tree is implied by the number of entities and child nodes for each node, causing the tree to be reconstructed in the same order it was saved.

The SceneSerializer uses a mapping from Ogre classes (Ogre::SceneNode, Ogre::Entity) to serializable classes provided by the library (OgreSupport::SceneNodeSerializable, OgreSupport::EntitySerializable) by use of reflection. This assigns a unique name to each Ogre type, then uses that name to instance a serializable. The serializable is initialized, then saved to the stream as a block of bytes preceded by the serializable type identifier, then logic within the serializable saves non-fixed length data (strings, lists, etc) and child objects. At load time, the type identifier is read first, allowing the loader to instantiate an empty instance of the serializable. The new instance is loaded with the bytes of the original from the stream, then logic within the serializable's load function reads in non-fixed length data and recreates the Ogre object. As saving and loading are done in the same order, the code infers the structure of the stream and each object can be instantiated using a small amount of code, and no extra memory is used in the file to describe the structure of the file.

The following Ogre types are supported by the SceneSerializer:

  • Ogre::SceneNode - The basic SceneNode is supported, forming the backbone for the tree data structure. Each node's position, rotation, and scale is saved. NOTE: By default, the SceneSerializer assumes an OctreeSceneManager is used, so the SceneSerializer is actually looking for instances of Ogre::OctreeNode. Other child classes of SceneManager will require registering a different SceneNode child class as having OgreSupport::SceneNodeSerializable.
  • Ogre::Entity - The basic geometry class, these are saved by name to the stream (their mesh & materials must be loaded as resources for the scene to successfully load again later)
  • Ogre::Light - Point, spot, and directional lights are each saved individually. Attributes such as shadow-casting, attenuation, and color are all saved. NOTE: Ambient lighting is saved as well, but separate from the node tree data.
  • Ogre::BillboardSet - Groups of billboards (2D sprites in 3D space) are saved as single objects. All active billboards are each saved, including their position, rotation, and color. (the corresponding material must be loaded as resources for the scene to successfully load again later).
  • Ogre::Animation - Node track animations are supported, saving the interpolation mode and each keyframe's position, rotation, and scale. NOTE: Animations that are part of the environment and should be simulated server-side, should use an NX animation technique, not an OGRE animation technique.

The feature also has the following non-obvious requirements/behaviors:

  • ALL objects to be saved must be attached to a scene node; all scene nodes must trace back to the root node
  • Instances of Ogre::ManualObject are never saved to file (to save, convert them into a mesh and make them an Ogre::Entity)
  • Instances of Ogre::Entity that are manually loaded (such as those created procedurally by converting Ogre::ManualObject into Ogre::Entity as above) are saved to .mesh files during the serialization process. The files must be loaded as resources for the scene to successfully load again later.
  • Only material names are saved, there is no special handling for materials created at runtime, all materials must be loaded as resources for the scene to successfully load again later.
  • The current skybox/dome/plane settings are not persisted by examination of the Ogre::SceneManager, but future versions will be able to save the settings as a property and set it at load time.
  • Any object found in the SceneNode tree that does not belong to a currently supported class is saved as a special "Unknown" type. This placeholder type will appear in lieu of the unknown type in the file; this should also be saved for types that are purposefully ignored (such as Ogre::ManualObject).

Related Links

Sponsored Links