Overview
When VR-Vantage destroys an entity (typically due to a DIS or HLA/RPR event) it does a number of things. It switches the model from its normal state to it's damaged state. It adds / starts a detonation effect (which is a particle system) that looks like an explosion, with pieces of a generic vehicle flying through the air; it makes a previously placed flame effect on the entity visible(also a particle system); and it makes a previously placed smoke plume visible (particle system).
Expected Result
Effect Plugin Result
Example details
This example loads a terrain (ground_DB II); creates a truck entity using the DtEntityFacade class; shows how to switch between states in a model; and how to create, add and control the three different effects. It also demonstrates how to extend the DtOsgParticleSystemModel to include the ability to modify the model's color through a shader (using code from exampleCustomShaders). Control of the entity's damage state and the smoke color when displayed are bound to keyboard commands.
The method createEntityFacade() creates and add the three particle systems to the entity; one for the detonation, one for the flames, and one for the smoke plume. The smoke plume uses the extended particle system that allows the color to be changed using a shader (see further down). All the effects are made invisible.
The method toggleDamage() checks the current state, and then makes all the effects visible or invisible to create the destroyed or restored effects. The detonation effect is special since it has a specific start and end rather than just a loop; so it is restarted in toggleDamage() when the entity is destroyed. toggleDamage() also toggles the internal model switch to show its damaged state or normal state. This method is called when the 'x' key is pressed. The key binding is set up in the plugin initialization code (found in exampleEffectsPluginInit.cxx). This assumes that the model has been configured with comments on switch node that controls the damage state using the WRM Specification (Fred, you can point to that).
To add the shader from exampleCustomShader that changes the color of the smoke (and all other particle systems that use the new VR-Vantage particle system system), the DtOsgParticleSystemModel class is extended. This class has a distributed (agent-based) interface and is agent-created; therefore a .ocdx file has to be created for it as well (using the dcgen application). This file is used to generate the related agent classes for the object.
The extended class overrides the setInstance() method in the model to be notified when the model instance is created or destroyed, and uses it to set up the shader manager from the shader example. The changeColorOverride() method is added to its distributed interface (so its defined in the .ocdx file as well) and it calls the shader manager's changeColorOverride() method. By extending the distributed model object in this manner, the color change ability will work on remote displays as well as master displays. A final changeColorOverride() method is added to the DtExampleEffectsDriver, which is bound to several different keys (r, <shift-r>, g, <shift-g>, b, and <shift-b>); it in turn calls the equivalent colorChangeOverride() method in the extended particle system.
Building the Example
VR-Vantage includes pre-built versions of the example plug-in. To build it yourself, follow the instructions at Building VR-Vantage Examples, Applications, and Plug-ins.
Running the Example
This example is a plug-in. You can run it by running ./bin64/exampleEffectPlugin_stealth.bat (on Windows) or ./bin64/exampleEffectPlugin_stealth.sh (on Linux). Use the key "x" to toggle the destroyed state and use the keys r, <shift-r>, g, <shift-g>, b, and <shift-b> to change the color of the smoke. The example plug-in is loaded on a master display. Note that any remote displays should also be configured to load the plug-in in order to see the extended distributed model.
For more information about running examples, please see Running Applications and Examples.
Example Source Files
DtExampleEffectsDriver.cxx
, myEntityFacade( 0 )
, myDamagedFlag( false )
, myFlamesAgent( 0 )
, mySmokePlumeAgent( 0 )
, myDetonationAgent( 0 )
{
}
{
}
{
static std::string name = "DtExampleEffectsDriver";
return name;
}
{
{
{
}
else
{
DtModelSemanticsMapper::States::damage, 3 );
}
}
}
{
std::string groundDbPath =
myAgentManager.de().dePathConfiguration().sharedDataPath();
groundDbPath += "/TerrainData/TerrainConfiguration/Ground_DB II.mtf";
std::string entityDisplayName = "M-939A Truck";
const DtModelSetRealizationManager::ModelSetRealizations& setsToRealize =
myAgentManager.de().sharedState().modelSetRealizationManager().modelSetRealizations();
myEntityFacade->setGroundClampingMode( DtGroundClampingUpdater::GroundClampingMode::ClampPositionAndUpright );
std::vector<DtUniqueID> objects;
DtInputDriver& inputDriver =
myAgentManager.de().driverManager().inputDriver();
return true;
}
{
{
}
return true;
}
{
return true;
}
{
}
{
DtEntityFacade* facade = new DtEntityFacade( am,
DtSharedSettingsManager::instance( am.
de() ), elementId, modelSets,
distribute );
if ( facade3d )
{
}
return facade;
}
{
{
}
}
Contains makVrv:DtAgentManager class.
Contains makVrv::DtDataBank class.
Contains makVrv::DtDe class.
Contains makVrv::DtDeSharedState class.
Contains makVrv:DtMasterScene class.
Contains makVrv::DtElementAttributes class.
Contains makVrv::DtElementData class.
Contains makVrv::DtEntity3dFacade class.
Contains makVrv::DtEntityFacade class.
Contains makVrv::DtModelSemanticsMapper class.
Contains makVrv::DtObserver class.
Contains makVrv::DtObserverSettingsManager class.
Contains makVrv::DtScene class.
makVrv::DtEntityFacade * createEntityFacade(makVrv::DtAgentManager &am, makVrv::DtElementID elementId, const makVrv::DtModelSetRealizationManager::ModelSetRealizations &modelSets, bool distribute)
virtual void toggleDamage(makVrv::DtDe &de)
Function for changing the state of the entity.
makVrv::DtParticleSystemModelAgent * myDetonationAgent
Definition DtExampleEffectsDriver.h:94
virtual void changeColorOverride(int color, float deltaChange)
SceneObjectIdsByModelSet mySceneObjectIds
Definition DtExampleEffectsDriver.h:83
bool myDamagedFlag
Definition DtExampleEffectsDriver.h:87
makVrv::MyParticleSystemModelAgent * mySmokePlumeAgent
Definition DtExampleEffectsDriver.h:93
virtual const std::string & className() const
makVrv::DtParticleSystemModelAgent * myFlamesAgent
Definition DtExampleEffectsDriver.h:92
makVrv::DtEntityFacade * myEntityFacade
Definition DtExampleEffectsDriver.h:85
DtExampleEffectsDriver(makVrv::DtAgentManager &am)
CTOR.
virtual ~DtExampleEffectsDriver()
Virtual DTOR.
virtual void slot_displayEngineAdded(const makVrv::DtDeRecord &igRecord)
DtUniqueID uniqueId() const
inline accessor
Definition DtAgent.inl:55
The DtAgentManager manages the distributed scene object framework. This includes the objects and upda...
Definition DtAgentManager.h:39
DtDe & de()
Get the scene manager's Ig object.
Definition DtAgentManager.h:107
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer,...
Definition DtDe.h:77
A Record of an IG instance.
Definition DtDeRecord.h:25
The DtDriver is an abstract class. Developers derive from this to create logic that "directs" things ...
Definition DtDriver.h:32
DtAgentManager & myAgentManager
Definition DtDriver.h:190
void reportElementCreated(DtElementID id, DtElementID parentId, DtElementEntry::ElementType type)
Report an element created.
void start()
Start the driver. Called by the Master Scene. Calls installAccessories().
void stop()
Stop the driver. Called by the Master Scene. Calls uninstallAccessories().
void reportElementDestroyed(DtElementID id)
Report an element destroyed.
void reportElementAttribute(DtElementID id, DtElementAttribute *attribute)
Report an element attribute changed.
virtual void setSwitchState(int switchToSet, int value)
Sets a switch state.
Definition DtEntity3dFacade.inl:115
DtSceneObjectAgent & sceneObjectAgent()
Returns the scene object agent for this facade.
Definition DtEntity3dFacade.inl:153
virtual void setArticulatedModelDefinition(const std::string &modelName)
Set the entity's model definition names.
Definition DtEntity3dFacade.inl:294
virtual DtModelSetId modelSet() const
Returns the model set being visualized.
Definition DtEntity3dFacade.inl:148
The DtEntityFacade is a facade around agents that make up an entity. This entity facade represents a ...
Definition DtEntityFacade.h:36
const DtEntity3dFacade * findFacadeFor3d() const
Definition DtEntityFacade.inl:125
virtual void setVisible(bool isVisible)=0
Set the model visible or invisible.
std::map< DtModelSetId, bool > ModelSetRealizations
Definition DtModelSetRealizationManager.h:42
void setPrimaryAttachment(const ElementList &elements)
bool loadTerrain(const DtUnicode &filePath)
Load the terrain from a file.
virtual void addModel(makVrv::DtModelAgent *modelInstanceOwner, int visualizerType)=0
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
DtUniqueElementAttribute< std::string, DtElementAttributes::DisplayName > DtElementAttributeDisplayName
Definition DtElementAttributes.h:88
DtModelSetId
Definition DtModelSetEnums.h:20
DtUniqueID DtElementID
Definition DtUniqueID.h:23
DtUniqueElementAttribute< unsigned int, DtElementAttributes::ElementSubtype > DtElementAttributeElementSubtype
Definition DtElementAttributes.h:121
DtUniqueElementAttribute< bool, DtElementAttributes::ObjectVisibility > DtElementAttributeVisibility
Definition DtElementAttributes.h:97
DtUniqueElementAttribute< std::string, DtElementAttributes::DriverType > DtElementAttributeDriverType
Definition DtElementAttributes.h:118
@ damage
Definition DtModelSemanticsMapper.h:45
DtExampleEffectsDriver.h
#pragma once
#include <unordered_map>
#include <matrix/vlTaitBryan.h>
#include <matrix/vlVector.h>
{
class DtDe;
class DtEntityFacade;
class DtParticleSystemModelAgent;
class MyParticleSystemModelAgent;
}
{
public:
virtual const std::string&
className()
const;
virtual void changeColorOverride(int color, float deltaChange);
protected:
protected:
typedef std::unordered_map<int,makVrv::DtUniqueID> SceneObjectIdsByModelSet;
SceneObjectIdsByModelSet mySceneObjectIds;
bool myDamagedFlag;
};
Contains makVrv:DtDriver class.
Contains makVrv::DtModelSetRealizationManager class.
Definition DtExampleEffectsDriver.h:33
virtual const std::string & className() const =0
Get this driver's class name.
virtual void slot_displayEngineAdded(const DtDeRecord &igRecord)
Called when a display engine is added. Override if you want the driver to do something when a display...
virtual bool onStart()=0
Start the host output. Create all objects for an existing host connection.
virtual bool onTick()=0
Tick.
virtual bool onStop()=0
Stop the host output. All scene object created by the host should be destroyed.
Agent class for the scene object class: DtParticleSystemModel.
Definition DtParticleSystemModelAgent.hpp:25
Agent class for the scene object class: MyParticleSystemModel.
Definition MyParticleSystemModelAgent.hpp:25
Contains DLL export macros.
#define DT_DLL_EXAMPLEEFFECTSPLUGIN
Definition exampleEffectsPlugin.h:18
exampleEffectsPlugin.h
#pragma once
#ifdef _WIN32
#ifdef EXAMPLEEFFECTSPLUGIN_EXPORTS
#define DT_DLL_EXAMPLEEFFECTSPLUGIN __declspec ( dllexport )
#else
#define DT_DLL_EXAMPLEEFFECTSPLUGIN __declspec ( dllimport )
#endif
#else
#define DT_DLL_EXAMPLEEFFECTSPLUGIN
#endif
exampleEffectsPluginInit.cxx
{
return true;
}
{
{
static vrvSignalsLib::connection postInitializeConnection;
void installDriverAndKeyBindings(
DtDe& de)
{
postInitializeConnection.disconnect();
if ( obsFrame )
{
}
}
{
{
&installDriverAndKeyBindings, std::ref(de) ));
}
}
}
}
#define DT_DE_INIT_ONCE(de)
This macro is called by modules in their init() function. This macro ensures that the module is only ...
Definition DtDe.h:30
Contains makVrv::DtDeMainWindow class.
Contains makVrv::DtKeyMap and related classes.
Contains makVrv::DtKeyMapManager class.
Contains makVrv::DtQtDeMainWindow class.
DtAgentManager & agentManager()
Get the scene manager.
virtual bool isInMasterMode() const
Returns true if the DtDe is in master mode.
virtual DtDriverManager & driverManager()
The DtMasterScene accessor. The function will throw before the initialize function is called.
boost::signalslib::signal< void()> signal_postInitialize
Definition DtDe.h:535
The abstract main window class.
Definition DtDeMainWindow.h:25
DtDeMainWindow & igMainWindow()
Use this accessor to lazily create the singleton instance of the DtDeMainWindow;.
static DtDeMainWindowProvider & instance(DtDe &de)
Get the main window provider instance for a DtDe.
void addDriver(DtDriver *driver)
Add a host driver to the master scene. The host is now owned by the Master Scene.
DtInputDriver & inputDriver()
Return the DtInputDriver associated with the master scene.
void startDriver(DtDriver *driver)
Start a driver driver modifying the scene.
a Key Map contains a map of keys to FunctionMapEntrys, as well as a list of functions to execute when...
Definition DtKeyMap.h:313
The manager for owning key maps.
Definition DtKeyMapManager.h:32
@ Miscellaneous
Definition DtKeyMapManager.h:45
@ Rendering
Definition DtKeyMapManager.h:43
static DtKeyMapManager & instance(DtDe &de)
Get an instance of the key map.
virtual void addKeyFunction(const std::string &functionName, const KeyFunction &function, FunctionCategory functionCategory, bool categorize=true)
bind a function to string name that can be used in a key map (or binary function set)
virtual DtKeyMap * findKeyMap(const std::string &mapName)
look up a key map
@ KEY_X
Definition DtKeyState.h:79
@ KEY_B
Definition DtKeyState.h:57
@ KEY_G
Definition DtKeyState.h:62
@ KEY_R
Definition DtKeyState.h:73
@ SHIFT_MODIFIER
Definition DtKeyState.h:140
@ NO_MODIFIER
Definition DtKeyState.h:137
The Qt main window. There will be only one of these per DtDe instance. Note, this window will be dest...
Definition DtQtDeMainWindow.h:46
virtual void hideStartupDialog()
Hide startup dialog.
DT_DE_PLUGIN_EXPORT_MACRO bool initDeModule(makVrv::DtDe *de)
Definition exampleEffectsPluginInit.h:22
DT_DLL_EXAMPLEEFFECTSPLUGIN void init(DtDe &anIG)
exampleEffectsPluginInit.h
#pragma once
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLEEFFECTSPLUGIN
{
class DtDe;
namespace vrvExampleEffectsPlugin
{
}
}
MyParticleSystemModel.cxx
#include <osg/Uniform>
{
: myDe(de)
, myModelStateSet(ss)
{
myColorToAdd = ss->getOrCreateUniform("colorToAdd", osg::Uniform::FLOAT_VEC3);
myColorToAdd->set(osg::Vec3(0.0f,0.0f,0.0f));
myVirtualProgram = osgEarth::VirtualProgram::getOrCreate(ss);
myVirtualProgram->setFunction("customLightingFunction", R"(
uniform vec3 colorToAdd;
void customLightingFunction(inout vec4 color)
{
color.rgb += colorToAdd;
}
)",
osgEarth::VirtualProgram::LOCATION_FRAGMENT_LIGHTING,
NULL,
100.0
);
}
{
}
{
osg::Vec3 curVal;
myColorToAdd->get(curVal);
switch(color)
{
case 0:
curVal.x() += deltaChange;
curVal.x() = curVal.x() < -1.0 ? -1.0 : curVal.x();
curVal.x() = curVal.x() > 1.0 ? 1.0 : curVal.x();
break;
case 1:
curVal.y() += deltaChange;
curVal.y() = curVal.y() < -1.0 ? -1.0 : curVal.y();
curVal.y() = curVal.y() > 1.0 ? 1.0 : curVal.y();
break;
case 2:
curVal.z() += deltaChange;
curVal.z() = curVal.z() < -1.0 ? -1.0 : curVal.z();
curVal.z() = curVal.z() > 1.0 ? 1.0 : curVal.z();
break;
default:
break;
}
myColorToAdd->set(curVal);
}
{
}
{
}
{
if (!theShaderManager)
{
}
}
{
if (theShaderManager)
{
theShaderManager->changeColorOverride( color, deltaChange );
}
}
}
Contains makVrv::DtFxOsgParticleDrawable class.
Contains makVrv::DtOsgModelInstance class.
Contains makVrv::MyParticleSystemModel class.
The OSG wrapper for the opengl rendering code. sets up the right shaders, figures out camera matrix a...
Definition DtFxOsgParticleDrawable.h:30
virtual osg::StateSet * particleSystemStateSet()
actual stateset used insetad of the osg::Drawable::_stateset
virtual void setModelInstance(DtModelInstance *modelInstance)
The base class for all model instances.
Definition DtModelInstance.h:44
A model of a particle system.
Definition DtOsgParticleSystemModel.h:32
static DtParticleSystemManagerInterface & instance(DtDe &de)
gets interface
MyParticleSystemModel(DtDe &de, DtUniqueID &id)
CTOR.
virtual void changeColorOverride(int color, float deltaChange)
static MyShaderManager * theShaderManager
Definition MyParticleSystemModel.h:84
virtual void setModelInstance(DtModelInstance *modelInstance)
virtual ~MyParticleSystemModel()
virtual DTOR
Definition MyParticleSystemModel.h:30
virtual ~MyShaderManager()
DTOR.
MyShaderManager(DtDe &de, osg::StateSet *ss)
virtual void changeColorOverride(int color, float deltaChange)
MyParticleSystemModel.h
#pragma once
#include <osgEarth/VirtualProgram>
#include <osg/ref_ptr>
{
class StateSet;
class Uniform;
}
{
class DtDe;
{
public:
MyShaderManager(DtDe& de, osg::StateSet *ss);
virtual ~MyShaderManager();
virtual void changeColorOverride(int color, float deltaChange);
protected:
DtDe& myDe;
osg::ref_ptr<osg::StateSet> myModelStateSet;
osg::ref_ptr<osg::Uniform> myColorToAdd;
osg::ref_ptr<osgEarth::VirtualProgram> myVirtualProgram;
};
: public DtOsgParticleSystemModel
{
public:
MyParticleSystemModel(DtDe& de, DtUniqueID& id);
virtual ~MyParticleSystemModel();
virtual void setModelInstance(DtModelInstance* modelInstance );
virtual void changeColorOverride( int color, float deltaChange );
protected:
static MyShaderManager* theShaderManager;
};
}
Contains makVrv::DtOsgParticleSystemModel class.
Contains makVrv::DtUniqueID type.
Definition DtOverlayPolygonModelInstance.h:28