Overview
This example shows how to add nodes to the scene graph via a renderer. The plugin loads a geometry file in OpenFlight format and inserts it directly into the scene. Of particular interest in this example is how to gain access to the scene graph in order to insert a node.
Expected Result
Scene Root Result
Example details
The content that this example application displays is a geometry file in OpenFlight format. This application implements a helper function to load the geometry and add the geometry to the scene-graph.
void loadGeometryAndAddToSceneGraph(DtDe* de)
The function accepts a pointer to a display engine (DtDe) where the scene renderer can be found. The display engine passed to this function is passed in by the plugin manager when the plugin is loaded.
The geometry to display is in a file on disk. When the application loads the geometry, a small scene-graph branch is created with a transform node at its root so the geometry can be moved in the scene.
osg::ref_ptr<osg::Node> model = osgDB::readNodeFile( sharedDataPath + "/ModelData/Vehicles/FixedWing/DC-10_RED_V7.0/DB_DC10_RED_V7.0.medf" );
osg::ref_ptr<osg::PositionAttitudeTransform> pat =
new osg::PositionAttitudeTransform();
pat->addChild(model.get());
To add the geometry into the VR-Vantage scene, the renderer is retrieved from the display engine and the root-node of the geometry is added to a root of the scene.
DtOsgRenderer& renderer = (DtOsgRenderer&)de->renderer();
renderer.addNodeToRoot(pat, renderer.propRoot());
In this example, the geometry is placed under the 'propRoot' of the renderer. The renderer is responsible for managing how the scene is rendered. As such, the renderer defines several 'root domains' such as Environment, Terrain, Prop, ModelSets, etc. These domains separate the one scene into 'logical' divisions or groupings. The renderer provides access to these different groupings using an API that abstracts the logical purpose of the geometry from the detailed implementation of the scene-graph.
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/exampleSceneRootPlugin_stealth.bat (on Windows from cmd.exe) or ./bin64/exampleSceneRootPlugin_stealth.sh (on Linux). For more information about running examples, please see Running Applications and Examples.
Learn More
Example Source Files
exampleSceneRootPlugin.h
#pragma once
#ifndef exampleSceneRootPlugin_H_
#define exampleSceneRootPlugin_H_
#ifdef _WIN32
#ifdef EXAMPLESCENEROOTPLUGIN_EXPORTS
#define DT_DLL_EXAMPLESCENEROOTPLUGIN __declspec ( dllexport )
#else
#define DT_DLL_EXAMPLESCENEROOTPLUGIN __declspec ( dllimport )
#endif
#else
#define DT_DLL_EXAMPLESCENEROOTPLUGIN
#endif
#endif
#define DT_DE_PLUGIN_EXPORT_MACRO DT_DLL_EXAMPLESCENEROOTPLUGIN
namespace makVrv
{
class DtDe;
}
exampleSceneRootPlugin.cxx
#include <osgDB/ReadFile>
#include <osg/PositionAttitudeTransform>
static makVrv::vrvSignalsLib::connection postInitializeConnection;
{
return true;
}
namespace makVrv
{
void loadGeometryAndAddToSceneGraph(DtDe* de)
{
postInitializeConnection.disconnect();
std::string sharedDataPath = de->dePathConfiguration().sharedDataPath();
osg::ref_ptr<osg::Node> model = osgDB::readNodeFile( sharedDataPath + "/ModelData/Vehicles/FixedWing/DC-10_RED_V7.0/DB_DC10_RED_V7.0.medf" );
osg::ref_ptr<osg::PositionAttitudeTransform> pat =
new osg::PositionAttitudeTransform();
pat->setPosition(osg::Vec3(0, 100, 0));
pat->setAttitude(osg::Quat(
osg::DegreesToRadians(-10.0f), osg::Vec3(1.0f, 0.0f, 0.0f),
osg::DegreesToRadians(-30.0f), osg::Vec3(0.0f, 1.0f, 0.0f),
osg::DegreesToRadians(150.0f), osg::Vec3(0.0f, 0.0f, 1.0f)));
pat->addChild(model.get());
DtOsgRenderer& renderer = (DtOsgRenderer&)de->renderer();
renderer.addNodeToRoot(pat, renderer.propRoot());
}
{
if (de.isInMasterMode())
{
postInitializeConnection = de.signal_postInitialize.connect(
boost::bind(&loadGeometryAndAddToSceneGraph, &de));
}
}
}
[<< Examples] [Home] [Top of Page]