VR-Vantage 2.5 API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
8.6 - Transforming Nodes Programmatically

Table of Contents

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.

Note
This feature is still experimental and can only be applied under particular circumstances on particular nodes in the scene graph.

8.6.1 Node Transformation Components

Programmatic node transformation depends on the interaction of a meta file, a properly annotated model, and supporting code.

8.6.2 Anatomy of a Meta File

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.

Note
There are several JSON editors available online (such as https://www.jsoneditoronline.org/) or plugins for NotePad++ that color code the structure of the file and indicate any errors.

8.6.2.1 Anatomy of a Meta File

The following is an example meta file:

{
"NodeFeatures": [
{
"Linkage": {
"Comment": "Traversal will match based on node name or annotation",
"NodeName": "sw1",
"AnnotationName": ""
},
"FeatureData": [
{
"FeatureName": "WindSwitchPart",
"Comment1": "Change state based on wind speed (km/h).",
"Comment2": "0-5 km/h is for switch state 0, 5-10 is for state 1, ...",
"WindSpeed": [
5,
10,
15
],
"WindState": [
0,
1,
2
]
}
]
}
]
}

The keywords in the example meta file are as follows:

8.6.3 Adding New Transforms

If you want to add your own programmatic transforms, you must:

  1. Edit the models that you want to change programmatically. To do this you need an editing tool such as Presagis Creator.

  2. 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.

  3. Write the code. DtWindSwitchTickable and DtShipFlagDirTickable are examples of custom meta file updating and configuration code. The new class must be derived from DtVirtualBaseClass. The examples that have been implemented in VR-Vantage inherit from DtTickable and DtVirtualBaseClass. However, the only required class to derive from is the DtVirtualBaseClass.
  4. Create a creator for the new object. See DtMetaObjectCreator.h. The creator class should derive from DtMetaObjectCreator.
  5. Register your object with the DtMetaObjectFactory. See examples in vrvOsg.cxx. The following code shows how to register DtWindSwitchTickable with the DtMetaObjectFactory:

    DtMetaObjectFactory& mof = DtMetaObjectFactory::instance(de);
    mof.addCreator(DtWindSwitchTickable::theWindSwitchFeatureName, new DtWindSwitchTickableCreator());

    The variable, theWindSwitchFeatureName, matches the FeatureName in the meta file. This lets VR-Vantage know what type of object to create.

  6. 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.

8.6.4 Restrictions and Limitations

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 >>]



Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)