![]() |
VR-Forces Developer's Guide
|
Scenes are made up of terrain, models, and the environment.
A scene contains an environment, the time of day, and possibly, a terrain. Scenes are composed on the master display engine by creating a set of distributed visualization objects, which are then created (typically as OSG nodes) on each distributed display engine node. The basic visualization object is the model (DtModel, each of which is owned by a DtSceneObject. One scene object can contain any number of models and provides an interface for positioning and orienting them as a single unit. The distributed scene objects are in turn owned by a variety of facade objects that organize them and provide convenient interfaces to drive and manipulate their appearance. This chapter summarizes the various types of models, scene objects, and their containers, and how to use them to construct scenes.
Data is organized into a structure called a scene graph. To add objects to the scene, you add nodes to the scene graph. For an example of how to add a node to the scene graph, please see the exampleSceneRootPlugin example.
A DtModel is the basic unit of scene composition. One model corresponds to one renderable object on each display engine. For example, visualizing a tank might involve one model for the tank's geometry, one model for its dust cloud, and another to display its track history. The basic types of models in VR-Forces, and their uses are:
The details required to draw a model, such as geometry, filename, scale, or texture are provided by a DtModelDefinition. A model definition is a set of parameters, whose names and types are defined by a DtSchema. The DtModelDefinitionManager saves and loads model definitions and schemas and maintains settings for model instancing and caching. Model definitions and schemas are distributed, but not by the usual agent mechanism. Instead, the DtDeSharedState distributes them directly.
A DtModel is only the distributed interface of a renderable scene element. It does not directly modify the scene graph of a display engine. Instead, when the model is given a model definition through its setModelDefinition() method, it creates a local DtModelInstance on each display engine, which is then responsible for putting the appropriate nodes in that display engine's scene graph. The attributes of the model instance are determined by the model definition's parameters and schema type.
Model instance types follow the Creator pattern. (For information about the Creator pattern, please see 9.5 - The Creator Pattern.) Each model instance type has a creator registered with the DtModelInstanceFactory, which the model uses to generate its instance. Once created, the instance sets itself up according to the model definition. The setup can either be from scratch, which typically means importing OSG nodes from a file, or if model instancing is enabled, by copying a cached instance from the model definition's local instance cache. When the model is added to a scene object, the instance inserts the appropriate nodes into the scene graph, usually (but not always) under the scene object's position and orientation transform nodes.
A terrain (DtTerrain) in VR-Forces is a facade around a set of DtTerrainPatch and DtFeatureLayer objects. The terrain maintains records of each operation performed on it (such as adding or removing a terrain patch), which are saved and loaded to MTF files. The DtTerrain is not a distributed object, so it exists only on the master display engine. If you are using external display engines, each display engine must have the same terrain files on its local computer.
A DtTerrainPatch is a facade around a DtTerrainPatchObject, which is a distributed object that combines the functionality of a model and a scene object. The terrain patch maintains a history of operations performed on it, such as extracting props or adding an overlay image. This history is included when the terrain is saved and executed when it is loaded. Each DtTerrainPatchObject has a model definition that specifies where to find the geometry (typically through the filename parameter) and a coordinate system (through the terrainCoordinateSystem and terrainCoordinateSystemParameters parameters).
Terrain patches are located in the scene graph under the terrain root node. They are included in intersection tests for ground clamping and navigation, but excluded for selection.
A DtFeatureLayer is a facade around a collection of DtProp objects, which represent distinct terrain-like features such as lampposts and buildings. Feature layers are created in VR-Forces by:
VR-Forces provides the convenience class DtPropAdder to load point features from files. The prop adder finds point features that match a rule specified by a DtAddPropsRuleRecord. Then it creates a prop at the location of each point feature, using the model definition specified in the rule. In order for the feature layer to correctly maintain its state, the DtPropAdder should not be used directly. Use the DtFeatureLayer's addProps() method, which makes the correct calls on the DtPropAdder for you. For instance, suppose you wanted to add SpeedTrees at the sites of tree point features in a GDB file. You could:
A DtTerrainPatch can find nodes in its scene graph and move them into DtModel objects. The DtModel for each prop must be created in the driver to be distributed to all display engines, but creating them requires knowledge of the scene graph. Therefore, basic prop extraction happens in a multi-step process:
VR-Forces implements environmental and lighting effects through SilverLining. It provides two interfaces to set SilverLining state, the DtDeTimeManager and the DtEnvironment. The DtDeTimeManager controls date and time. The DtEnvironment controls SilverLining's clouds, precipitation, air turbidity, and visibility effects.
The DtEnvironment is a member of a DtScene. It provides a serializable interface to SilverLining environmental effects and it maintains records of its state, which can be saved or loaded with the makArchives::DtEnvironmentRecord. A DtEnvironment wraps a DtSkyObject, which is the distributed interface to the SilverLining clouds, precipitation, turbidity, and visibility effects. To set your scene's environmental effects, you might do something like the following:
The DtDeTimeManager maintains the scene's time and date, as well as changing the time each tick according to its time scale setting. The DtDeTimeManager's settings are distributed to all nodes by the DtDeSharedState. This means that you should never modify the DtDeTimeManager directly; instead, use the functions DtDeSharedState::setDateAndTime() and DtDeSharedState::setTimeScale(). The date and time are the main determinants of the lighting model's state.
SpeedTrees are implemented as members of a single SpeedTree forest on each display engine. The DtForest is a facade around the distributed DtForestObject. The DtForestObject, like the DtTerrainPatchObject, combines some of the functionality of a scene object and a model into a single object.
The forest is located in the scene graph under the object root node, but since SpeedTrees are drawn outside of OSG, they are not included in any intersection tests.
A scene object (DtSceneObject) groups together models with shared spatial data and represents one conceptual element in the scene within one model set. For example, one scene object could represent a single tree in the 3D Models model set, or the main model, flames, and trajectory history line associated with a tank. Scene objects track the element ID of the simulated element they represent.
Each scene object contains a vector of positions and orientations associated with it. It is up to the scene object's models to determine how those kinematic parameters are used. For example, a simple model might use its scene object's first position and orientation values to position and orient itself in the scene, while a polygon model might use several of the scene object's positions to define its vertices.
A scene object is given a model set when it is created. When adding a model to a scene object, the model's visual type is also specified. Available visual types are defined in the visual type manager (DtVisualTypeManager). The combination of model set and visual type is used to determine which models to render on a particular channel. For example, a model added to a scene object in the XR model set with the visual type "dust_clouds" is rendered only on channels that are displaying the XR model set and have dust clouds turned on. VR-Forces implements this render control by creating a root node in the scene graph for each visual type in a model set (as illustrated). The nodes for each model are placed under the appropriate root node, and during a channel's render traversal the roots that should not be rendered are skipped.
If a scene object's spatial data changes frequently, it may have an updater (DtUpdater) associated with it. The updater is responsible for any changes that need to be made to the scene object (usually position and orientation) on a per-frame basis, such as dead reckoning and ground clamping.
Entities are represented in the scene by scene objects, to which models are attached. The GUI APIprovides some common kinds of entity primitives. These are called facades and show how models and model instances are added to a scene object.
Although you can place individual entities in a scene using the DtEntityFacade, it is common to use a DtVrlinkConnection (which is created by one of the drivers based on the DtVrlinkDriver) to populate a scene. This section describes how entities are created within a connection.
Individual entities are handled by the DtEntityElementProcessor. The DtEntityElementProcessor is registered as a singleton instance with the DtVrlinkConnection. The DtEntityElementProcessor uses (or creates if it does not exist) a singleton instance of a DtEntityExistenceListener registered with the connection as "DtEntityListener" at construction; a different (derived) existence listener may be registered, but this must occur before the creation of the DtEntityElementProcessor. The DtEntityElementProcessor also looks up the DtVisualizerCreationSettings instance registered with the connection, which will be used to determine which visualizers need to be created when an entity is discovered (as described in 6.7.1.2 The Visualizer Creation Settings Manager). It also connects to the signal_visualizerCreationEnabled and signal_visualizerCreationDisabled signals of the DtVisualizerCreationSettingsSignaler, which tells the DtEntityElementProcessor when visualizers need to be created or deleted for entities, as well as allowing it to keep the DtVisualizerCreationSettings up-to-date.
When the DtEntityExistenceListener discovers a new entity, it allocates a DtVrlinkEntityStateListener for use with the entity, which in turn allocates a unique ID for that entity. The DtEntityExistenceListener sends a signal to the DtEntityElementProcessor informing it about the new entity, and includes the new DtVrlinkEntityStateListener as part of that signal. The DtEntityElementProcessor then creates and initializes a DtEntityElement, using the unique ID allocated by the DtVrlinkEntityStateListener as the entity's DtElementID. The DtElementID can be used to look up the DtVrlinkEntityStateListener or the DtEntityElement for that entity. The new DtElementID is registered with the DtEntityElementProcessor's DtAggregateEchelonManager, and finally, the DtEntityElementProcessor raises its signal_elementCreated signal (which includes both the new DtEntityElement and its associated DtVrlinkEntityStateListener).
When constructed, the DtEntityElement looks up the name of the element definition for its entity type. When it is initialized by the DtEntityElementProcessor (by calling DtEntityElement::visualize()), it looks up the DtEntityElementProcessor instance (in the connection) and, for each model set that can be visualized (please see 6.6 - Scene Objects for a discussion of model sets), creates a DtEntityVisualizerSet. Each DtEntityVisualizerSet is in turn initialized by calling DtEntityVisualizerSet::visualize() with the name of the element definition to use and the DtVisualizerCreationSettings from the DtEntityElementProcessor.
DtEntityVisualizerSet::visualize() looks up the DtElementDefinitionTypeManager instance (also in the connection), and then looks up the DtElementDefinitionNew for the element definition argument in the DtElementDefinitionTypeManager. It then calls its base class DtVisualizerSet::visualize() method with the element definition name, the DtElementDefinitionNew that was looked up, and the DtVisualizerCreationSettings from the DtEntityElementProcessor.
DtElementDefinitionNew contains a DtVisualizerDefinitionSet for every model set defined. Since the DtVisualizerSet was initialized with its model set specified, it can find the DtVisualizerDefinitionSet for the model set it needs to visualize. The DtVisualizerDefinitionSet is a list of DtVisualizerDefinitions, that describe the visualizers that exist for the entity in this model set. The DtVisualizerSet iterates through the DtVisualizerDefinitionSet, and if the DtVisualizerCreationSettings indicates that visualizers with the visual type of a DtVisualizerDefinition, that DtVisualizerDefinition will be realized into some type of DtStateVisualizer, using the DtStateVisualizerFactory.
DtVisualizerCreationSettings indicate that a visualizer should not be created for a given model set only if that visualizer has a visual type that has been specified in the DtVisualizerCreationSettingsManager::VisualTypeVisualizerCreationStrategyMap as being 'create-as-needed' and that visual type is not currently being displayed for any observer using that model set. Note that many visualizers have no real defined visual type (and so have their visual type set to 0). These visualizers will always be created. The defined visual types are:
By default, these all have the 'create-as-needed' strategy. The visual type is assigned to a visualizer definition (and on the DtStateVisualizer that realizes it) in the Visual Definition Editor.
The DtVisualizerCreationSettingsManager maintains a map of visualizer creation strategy (either create-always or create-as needed) by visual type. It can also provide, on request, a map of which visualizers, based on visual type and model set, should be created given that visual type's creation strategy and the current observer settings in use. That map is wrapped in a DtVirtualBaseClass called DtVisualizerCreationSettings. So if, for example, the creation strategy for visual type "track_histories" is create-as-needed and none of the observers that are currently using an observer mode that both uses model set 0 and has track histories enabled, then visualizers with the "track_histories" visual type do not need to be created for model set 0.
When a new connection is created, it will ask the DtVisualizerCreationSettingsManager to create and initialize a DtVisualizerCreationSettings object and register it with the connection. It will then be available for the DtEntityElementProcessor that the connection will subsequently create, providing it with an up-to-date initial state. The DtVisualizerCreationSettingsManager also listens to changes to observer mode selections and observer mode model set and settings changes, and generates signals whenever it becomes appropriate to enable or disable the creation of a specific visual type for a given model set. The DtEntityElementProcessor listens for these signals and updates its DtVisualizerCreationSettings, as well as creating or destroying visualizers as needed for entities that already exist.
To visualize aggregates, you must first be connected to a communications protocol. This can be DIS, HLA13, HLA1516 or HLA Evolved and occurs in the respective simulation driver. Once connected, there must be traffic on that network that VR-Vantage can identify as an aggregate. This happens when an application publishes an Aggregate State PDU on the network. When VR-Forces recognizes this PDU, it internally maps the entity type of the aggregate to an aggregate element definition.
A visual definition is a series of visual components that are used to visualize an object on the 2D overlay or as 3D geometry. An aggregate visual definition will usually contain the following visualizers:
The DtVrlinkAggregateExistenceListener listens to the network. For each aggregate, it communicates with the DtAggregateElementProcessor to create new aggregate visuals. The DtAggregateElementProcessor, when notified of a new aggregate, creates a DtAggregateElement. For each visualized model set, the DtAggregateElement creates a DtAggregateVisualizerSet. This DtAggregateVisualizerSet uses the supplied visual definition set (as discovered from the aggregate type mapping) to visualize the elements contained within.
The DtAggregateElementProcessor also uses the DtAggregateEchelonManager class to manage the echelon hierarchy. The DtAggregateEchelonManager manipulates a DtElementIDHierarchy in order to keep parent/child relationships of elements that are created in the system. The DtAggregateElementProcessor is also responsible for hiding and showing aggregate elements based on the DtAggregateSettingsRecord as well as the expanded/collapsed state of the aggregate. This expanded/collapsed state is communicated from the UI thread to the simulation driver thread via element attributes, specifically the DtElementIDHierarchyDisplayStateAttribute attribute.
As the entities are placed in the scene, the ones that support emitter systems are created with emitter volume visualizers (DtVrlinkEntitySensorVolumeVisualizer for 3D model sets, and DtVrlink2DEntitySensorVolumeVisualizer for 2D model sets). These visualizers listen for the creation and destruction of emitter systems by connecting to the signals emitted by the emitter system existence listener (DtEmitterSystemExistenceListener).
When an emitter system (DtEmitterSystemRepository) is created, a custom implementation is used (DtVrlinkEmitterStateInterceptor) to intercept calls that change the state of the emitter system and signals the emitter system's state listener (DtVrlinkEmitterStateListener). Visualizers now connect to the additional signals provided by the state listener (for more detailed information about the system's emitter beams and overall configuration), and creates a visual representation for all emitter beams already attached to the discovered emitter system. As new emitter beams are discovered, or when existing emitter beams change, the visualizer updates the emitter volume visualization accordingly.
Props are scene elements that act like pieces of terrain, but can be individually manipulated. Props are owned by a DtTerrainLayer, which is an interface implemented by the DtFeatureLayer and DtTerrainPatch. The DtProp class is a facade around a DtSceneObject and a DtModel. It maintains state information on the master side for saving and loading and GUI display.
The DtEffectModel is used to display a variety of special effects in VR-Forces, such as flames and track histories. Effects come in three major types: ribbon and decal effects, particle effects, and animation effects. The type of effect is determined by the schema used for its model definition. The DtEffectModelInstance creates different types of geometry depending on the schema name and parameters provided.
A ribbon effect is a flat "ribbon" that stretches out behind a moving scene object. It can be colored, textured, faded out, and moved, depending on the model definition schema used to define it. The OSG node classes in vrvOsg that inherit DtOsgRibbon are all implementations of ribbon effect variants. Ribbons are located in the scene graph under the effect root node and contain a reference to the scene object that owns them. At each frame, the ribbon finds the location of its scene object and extends itself, if necessary.
The most basic ribbon effect is the DtOsgTrackHistoryRibbon, which is a simple colored quad strip with a line along each edge. It is created for the ribbon model schema. Track history effects position and size themselves automatically according to the bounding box of the scene object that they are attached to. Therefore, it is important to add track history effects to a scene object after its main model is added. Track history ribbons have a maximum length parameter to prevent them from growing too large for fast-moving scene objects. Quads that are beyond this length are quickly faded out.
The DtOsgDecalRibbon is similar to the track history ribbon, with the addition of a texture. The width and relative position of a decal ribbon must be specified in its model definition, with the PointA/PointB parameters. If PointC/PointD are also specified, a DtOsgMultiRibbon is created instead, which is a composite of two decal ribbons. This technique is used, for example, to create the default missile trail effect. Like track history ribbons, decal ribbons use a maximum length to limit their size.
The most complex ribbon effect is the DtOsgParticleRibbon. Particle ribbons look similar to decal ribbons, with the addition of motion and lifetime-based fadeout. The ParticleVelocity parameter specifies the speed in meters per second at which each horizontal pair of points moves apart. The AlphaVelocity parameter sets the change in segment alpha per second, and thereby determines the time in seconds that it takes for a pair of points to fade out. The particle ribbon is used for the default wake effect, which spreads and fades out over time.
VR-Forces uses the osgParticle package to create particle effects. Each particle effect model instance has a particle emitter node that is added to the parent scene object, and a particle geometry node that is placed under the effects root. This allows the particles, once emitted, to move independently from their parent scene object. Particle effects are usually loaded from files. These files can be created programmatically or with an editor such as the Delta3D particle system editor. Particle effects use the effect schema.
Animated effects are used by VR-Forces to create particle-like effects with less use of resources. An animated effect is created by setting the filename parameter in an effect with the effect schema. This file is loaded at the location of the effect's parent scene object. Animated billboards are loaded as animated effects for default detonations.
VR-Forces draws grid lines on a per-channel basis. Channel grid lines use the DtChannelKeywordObject mechanism to create distributed channel grid line objects (one for each channel on which lines are drawn).
DtChannelKeywordGridLines inherits from DtChannelKeywordObject, and depends on the GridLines channel keyword. When all the necessary conditions are met to draw grid lines (terrain loaded, 2D mode, grid lines enabled) DtChannelKeywordGridLines creates a DtChannelGridLines distributed object (which in turn creates a DtOsgChannelGridLinesInstance).
The standard DialogPage pattern is used to provide a page for setting grid lines settings (DtGridLinesPage, DtGridLinesLogic, DtGridLinesInterface).
The standard archival methodology is use to store and back up settings (a DtGridLinesSettingsRecord is created, and settings are read from and written to default_GridLinesSettings.grdx).
Scenes are made up of terrain, models, and the environment.