![]() |
VR-Vantage 3.0.3 API Documentation
|
You can associate code with particular nodes in a scene graph using a configuration file called a meta file.
A meta file lets you change the behavior of an object without having to recompile code. This approach is used to animate windsocks, and flags on terrain and ships. For example, windsocks rotate based on wind direction and change state based on the speed of the wind. The parameters that control how the windsock responds are in its meta file.
Programmatic node transformation depends on the interaction of a meta file, a properly annotated model, and supporting code.
Meta file. A meta file is a JSON document that describes the matching criteria for a node (node name or annotation), the type of code object to be created when a match is found (for example, the code for rotating flags), and configuration information (for example, which wind speed corresponds to which switch state).
You can associate meta files with objects and with terrains.
To associate a meta file with an object, you add the metaFileName attribute to its model definition and specify the meta file.
To associate a meta file with a terrain, place the meta file in the same directory as the medf file. The meta file must have the same name as the medf file, but with the extension meta. For example, for the terrain file ./data/Terrain/myTerrain/Geometry/mountain.medf, the meta file should be ./data/Terrain/myTerrain/Geometry/mountain.meta.
Code. If you are creating a custom action, add your code to VR-Vantage and register it with the DtMetaFileManager. When a node matches the criteria in a meta file (by name or by annotation), an object of the type requested is created. In the VR-Vantage code, the objects are derived from DtTickable and added to the DtTickableManager so that they are executed every frame. However, it is not necessary to derive from DtTickable in every case.
A meta file uses a JSON format and parser to convert the document into data that VR-Vantage can use. As with all JSON files, braces ({}) are used to hold different name/value pairs, square brackets ([]) are used for arrays, and name:value is used for name/value pairs. VR-Vantage emits a warning message when there is a syntax error. It is usually easier to copy a working file and modify it than to write one from scratch.
The following is an example meta file:
The keywords in the example meta file are as follows:
NodeFeatures. Indicates an array of Linkage and FeatureData data.
Linkage. The Linkage specifies which node attributes will be used to search for matching nodes. In the example, the Linkage component has three members: Comment, NodeName, and AnnotationName.
If you want to add your own programmatic transforms, you must:
Edit the models that you want to change programmatically. To do this you need an editing tool such as Presagis Creator.
Create a new meta file. Specify the node names or annotations to match. Specify the feature name that matches the name of the meta object in the code. Specify an additional parameters for the object.
Register your object with the DtMetaObjectFactory. See examples in vrvOsg.cxx. The following code shows how to register DtWindSwitchTickable with the DtMetaObjectFactory:
The variable, theWindSwitchFeatureName, matches the FeatureName in the meta file. This lets VR-Vantage know what type of object to create.
For objects that have model definitions, add a metaFileName entry to the model definition. For items such as terrain patches, which do not have model definitions, put the meta file in the same directory as the medf file for the terrain.
The following are restrictions and limitations apply to prgrammatically transforming nodes:
It is easier to use similar orientations and facing directions for multiple nodes (ex. multiple flags on terrain). Different orientations (ex. A circle of flags oriented in different directions) would need more sophisticated code to undo the local transforms and put the flags into a common space for calculating wind direction.
For an example of how to use meta files and code, see Example of Transforming Nodes Programmatically.
[<< Making OpenGL Calls from OSG Drawables] [Home] [Top of Page] [Example of Transforming Nodes Programmatically >>]