Implemented support for calling scripts from with Present3D.

This commit is contained in:
Robert Osfield 2013-12-19 10:02:16 +00:00
parent 591c5bae42
commit a8dc460085
3 changed files with 352 additions and 50 deletions

View File

@ -23,6 +23,7 @@
#include <osg/TransferFunction>
#include <osg/ImageStream>
#include <osg/ImageSequence>
#include <osg/ScriptEngine>
#include <osgText/Text>
#include <osgGA/GUIEventAdapter>
@ -354,6 +355,24 @@ public:
osg::Vec4 color;
};
enum ScriptCallbackType
{
UPDATE_SCRIPT,
EVENT_SCRIPT
};
typedef std::pair<ScriptCallbackType, std::string> ScriptPair;
struct ScriptData
{
ScriptData() {}
typedef std::vector<ScriptPair> Scripts;
Scripts scripts;
bool hasScripts() const { return !scripts.empty(); }
};
SlideShowConstructor(osgDB::Options* options);
void createPresentation();
@ -372,6 +391,11 @@ public:
void setPresentationDuration(double duration);
void addScriptEngine(const std::string& scriptEngineName);
void addScriptFile(const std::string& name, const std::string& filename);
void addScript(const std::string& name, const std::string& language, const std::string& script);
void addSlide();
@ -442,31 +466,37 @@ public:
void addPropertyAnimation(PresentationContext presentationContext, PropertyAnimation* propertyAnimation);
void addScriptCallback(PresentationContext presentationContext, ScriptCallbackType scriptCallbackType, const std::string& functionName);
void addScriptToNode(ScriptCallbackType scriptCallbackType, const std::string& name, osg::Node* node);
void addScriptsToNode(const ScriptData& scriptData, osg::Node* node);
void addToCurrentLayer(osg::Node* subgraph);
void addBullet(const std::string& bullet, PositionData& positionData, FontData& fontData);
void addBullet(const std::string& bullet, PositionData& positionData, FontData& fontData, const ScriptData& scriptData);
void addParagraph(const std::string& paragraph, PositionData& positionData, FontData& fontData);
void addParagraph(const std::string& paragraph, PositionData& positionData, FontData& fontData, const ScriptData& scriptData);
osg::Image* readImage(const std::string& filename, const ImageData& imageData);
void addImage(const std::string& filename,const PositionData& positionData, const ImageData& imageData);
void addImage(const std::string& filename,const PositionData& positionData, const ImageData& imageData, const ScriptData& scriptData);
void addStereoImagePair(const std::string& filenameLeft, const ImageData& imageDataLeft, const std::string& filenameRight,const ImageData& imageDataRight, const PositionData& positionData);
void addStereoImagePair(const std::string& filenameLeft, const ImageData& imageDataLeft, const std::string& filenameRight,const ImageData& imageDataRight, const PositionData& positionData, const ScriptData& scriptData);
void addGraph(const std::string& filename,const PositionData& positionData, const ImageData& imageData);
void addVNC(const std::string& filename,const PositionData& positionData, const ImageData& imageData, const std::string& password);
void addBrowser(const std::string& filename,const PositionData& positionData, const ImageData& imageData);
void addPDF(const std::string& filename,const PositionData& positionData, const ImageData& imageData);
osg::Image* addInteractiveImage(const std::string& filename,const PositionData& positionData, const ImageData& imageData);
void addGraph(const std::string& filename,const PositionData& positionData, const ImageData& imageData, const ScriptData& scriptData);
void addVNC(const std::string& filename,const PositionData& positionData, const ImageData& imageData, const std::string& password, const ScriptData& scriptData);
void addBrowser(const std::string& filename,const PositionData& positionData, const ImageData& imageData, const ScriptData& scriptData);
void addPDF(const std::string& filename,const PositionData& positionData, const ImageData& imageData, const ScriptData& scriptData);
osg::Image* addInteractiveImage(const std::string& filename,const PositionData& positionData, const ImageData& imageData, const ScriptData& scriptData);
void addModel(osg::Node* subgraph, const PositionData& positionData, const ModelData& modelData);
void addModel(osg::Node* subgraph, const PositionData& positionData, const ModelData& modelData, const ScriptData& scriptData);
void addModel(const std::string& filename, const PositionData& positionData, const ModelData& modelData);
void addModel(const std::string& filename, const PositionData& positionData, const ModelData& modelData, const ScriptData& scriptData);
void setUpVolumeScalarProperty(osgVolume::VolumeTile* tile, osgVolume::ScalarProperty* property, const std::string& source);
void addVolume(const std::string& filename, const PositionData& positionData, const VolumeData& volumeData);
void addVolume(const std::string& filename, const PositionData& positionData, const VolumeData& volumeData, const ScriptData& scriptData);
osg::Group* takePresentation() { return _root.release(); }
@ -568,6 +598,12 @@ protected:
osg::ref_ptr<osg::Group> _root;
osg::ref_ptr<osg::Switch> _presentationSwitch;
typedef std::map< std::string, osg::ref_ptr<osg::ScriptEngine> > ScriptEngineMap;
ScriptEngineMap _scriptEngines;
typedef std::map< std::string, osg::ref_ptr<osg::Script> > ScriptMap;
ScriptMap _scripts;
osg::ref_ptr<osg::ClearNode> _slideClearNode;
osg::ref_ptr<osg::Switch> _slide;
std::string _slideTitle;

View File

@ -203,6 +203,7 @@ public:
bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::FontData& value) const;
bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ModelData& value) const;
bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ImageData& value) const;
bool getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ScriptData& value) const;
bool getJumpProperties(osgDB::XmlNode*cur, osgPresentation::JumpData& jumpData) const;
@ -1018,6 +1019,26 @@ bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::Slid
return propertiesRead;
}
bool ReaderWriterP3DXML::getProperties(osgDB::XmlNode*cur, osgPresentation::SlideShowConstructor::ScriptData& value) const
{
bool propertiesRead=false;
std::string name;
if (getProperty(cur, "update_script", name))
{
value.scripts.push_back(osgPresentation::SlideShowConstructor::ScriptPair(osgPresentation::SlideShowConstructor::UPDATE_SCRIPT, name));
propertiesRead = true;
}
if (getProperty(cur, "event_script", name))
{
value.scripts.push_back(osgPresentation::SlideShowConstructor::ScriptPair(osgPresentation::SlideShowConstructor::EVENT_SCRIPT, name));
propertiesRead = true;
}
return propertiesRead;
}
bool ReaderWriterP3DXML::parseProperties(osgDB::XmlNode* root, osg::UserDataContainer& udc) const
{
bool readProperties = false;
@ -1155,10 +1176,13 @@ void ReaderWriterP3DXML::parseModel(osgPresentation::SlideShowConstructor& const
{
osgPresentation::SlideShowConstructor::PositionData positionData = constructor.getModelPositionData();
bool positionRead = getProperties(cur,positionData);
bool positionRead = getProperties(cur, positionData);
osgPresentation::SlideShowConstructor::ModelData modelData;// = constructor.getModelData();
getProperties(cur,modelData);
getProperties(cur, modelData);
osgPresentation::SlideShowConstructor::ScriptData scriptData;
getProperties(cur, scriptData);
std::string filename = cur->getTrimmedContents();
@ -1166,7 +1190,9 @@ void ReaderWriterP3DXML::parseModel(osgPresentation::SlideShowConstructor& const
{
constructor.addModel(filename,
positionRead ? positionData : constructor.getModelPositionData(),
modelData);
modelData,
scriptData
);
}
}
@ -1312,12 +1338,17 @@ void ReaderWriterP3DXML::parseVolume(osgPresentation::SlideShowConstructor& cons
}
}
osgPresentation::SlideShowConstructor::ScriptData scriptData;
getProperties(cur, scriptData);
std::string filename = cur->getTrimmedContents();
if (!filename.empty())
{
constructor.addVolume(filename,
positionRead ? positionData : constructor.getModelPositionData(),
volumeData);
volumeData,
scriptData
);
}
}
@ -1371,14 +1402,17 @@ void ReaderWriterP3DXML::parseStereoPair(osgPresentation::SlideShowConstructor&
}
}
osgPresentation::SlideShowConstructor::ScriptData scriptData;
getProperties(cur, scriptData);
OSG_INFO<<" filenameLeft="<<filenameLeft<<std::endl;
OSG_INFO<<" filenameRight="<<filenameRight<<std::endl;
if (!filenameLeft.empty() && !filenameRight.empty())
constructor.addStereoImagePair(filenameLeft,imageDataLeft,
filenameRight, imageDataRight,
positionRead ? positionData : constructor.getImagePositionData());
positionRead ? positionData : constructor.getImagePositionData(),
scriptData);
}
@ -1616,9 +1650,14 @@ bool ReaderWriterP3DXML::parseLayerChild(osgPresentation::SlideShowConstructor&
osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData();
bool fontRead = getProperties(cur,fontData);
osgPresentation::SlideShowConstructor::ScriptData scriptData;
getProperties(cur, scriptData);
constructor.addBullet(cur->contents,
positionRead ? positionData : constructor.getTextPositionData(),
fontRead ? fontData : constructor.getTextFontData());
fontRead ? fontData : constructor.getTextFontData(),
scriptData
);
return true;
}
else if (cur->name == "paragraph")
@ -1629,9 +1668,14 @@ bool ReaderWriterP3DXML::parseLayerChild(osgPresentation::SlideShowConstructor&
osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData();
bool fontRead = getProperties(cur,fontData);
osgPresentation::SlideShowConstructor::ScriptData scriptData;
getProperties(cur, scriptData);
constructor.addParagraph(cur->contents,
positionRead ? positionData : constructor.getTextPositionData(),
fontRead ? fontData : constructor.getTextFontData());
fontRead ? fontData : constructor.getTextFontData(),
scriptData
);
return true;
}
else if (cur->name == "image")
@ -1642,9 +1686,14 @@ bool ReaderWriterP3DXML::parseLayerChild(osgPresentation::SlideShowConstructor&
osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData();
getProperties(cur,imageData);
osgPresentation::SlideShowConstructor::ScriptData scriptData;
getProperties(cur, scriptData);
constructor.addImage(cur->getTrimmedContents(),
positionRead ? positionData : constructor.getImagePositionData(),
imageData);
imageData,
scriptData
);
return true;
}
else if (cur->name == "imagesequence")
@ -1656,9 +1705,14 @@ bool ReaderWriterP3DXML::parseLayerChild(osgPresentation::SlideShowConstructor&
imageData.imageSequence = true;
getProperties(cur,imageData);
osgPresentation::SlideShowConstructor::ScriptData scriptData;
getProperties(cur, scriptData);
constructor.addImage(cur->getTrimmedContents(),
positionRead ? positionData : constructor.getImagePositionData(),
imageData);
imageData,
scriptData
);
return true;
}
else if (cur->name == "graph")
@ -1672,9 +1726,14 @@ bool ReaderWriterP3DXML::parseLayerChild(osgPresentation::SlideShowConstructor&
std::string options;
getProperty(cur, "options", options);
osgPresentation::SlideShowConstructor::ScriptData scriptData;
getProperties(cur, scriptData);
constructor.addGraph(cur->getTrimmedContents(),
positionRead ? positionData : constructor.getImagePositionData(),
imageData);
imageData,
scriptData
);
return true;
}
else if (cur->name == "vnc")
@ -1688,10 +1747,14 @@ bool ReaderWriterP3DXML::parseLayerChild(osgPresentation::SlideShowConstructor&
std::string password;
getProperty(cur, "password", password);
osgPresentation::SlideShowConstructor::ScriptData scriptData;
getProperties(cur, scriptData);
constructor.addVNC(cur->getTrimmedContents(),
positionRead ? positionData : constructor.getImagePositionData(),
imageData,
password
password,
scriptData
);
return true;
}
@ -1703,9 +1766,13 @@ bool ReaderWriterP3DXML::parseLayerChild(osgPresentation::SlideShowConstructor&
osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData();
getProperties(cur,imageData);
osgPresentation::SlideShowConstructor::ScriptData scriptData;
getProperties(cur, scriptData);
constructor.addBrowser(cur->getTrimmedContents(),
positionRead ? positionData : constructor.getImagePositionData(),
imageData);
imageData,
scriptData);
return true;
}
else if (cur->name == "pdf")
@ -1716,9 +1783,14 @@ bool ReaderWriterP3DXML::parseLayerChild(osgPresentation::SlideShowConstructor&
osgPresentation::SlideShowConstructor::ImageData imageData;// = constructor.getImageData();
getProperties(cur,imageData);
osgPresentation::SlideShowConstructor::ScriptData scriptData;
getProperties(cur, scriptData);
constructor.addPDF(cur->getTrimmedContents(),
positionRead ? positionData : constructor.getImagePositionData(),
imageData);
imageData,
scriptData
);
return true;
}
else if (cur->name == "stereo_pair")
@ -1773,6 +1845,17 @@ void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& const
float totalIndent = 0.0f;
osgPresentation::SlideShowConstructor::ScriptData scriptData;
if (getProperties(root, scriptData))
{
for(osgPresentation::SlideShowConstructor::ScriptData::Scripts::iterator itr = scriptData.scripts.begin();
itr != scriptData.scripts.end();
++itr)
{
constructor.addScriptCallback(osgPresentation::SlideShowConstructor::CURRENT_LAYER, itr->first, itr->second);
}
}
for(osgDB::XmlNode::Children::iterator itr = root->children.begin();
itr != root->children.end();
++itr)
@ -1948,9 +2031,14 @@ void ReaderWriterP3DXML::parseBullets(osgPresentation::SlideShowConstructor& con
osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData();
bool fontRead = getProperties(cur,fontData);
osgPresentation::SlideShowConstructor::ScriptData scriptData;
getProperties(cur,scriptData);
constructor.addBullet(cur->contents,
positionRead ? positionData : constructor.getTextPositionData(),
fontRead ? fontData : constructor.getTextFontData());
fontRead ? fontData : constructor.getTextFontData(),
scriptData
);
}
@ -1965,9 +2053,14 @@ void ReaderWriterP3DXML::parseText(osgPresentation::SlideShowConstructor& constr
osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData();
bool fontRead = getProperties(cur,fontData);
osgPresentation::SlideShowConstructor::ScriptData scriptData;
getProperties(cur,scriptData);
constructor.addParagraph(cur->contents,
positionRead ? positionData : constructor.getTextPositionData(),
fontRead ? fontData : constructor.getTextFontData());
fontRead ? fontData : constructor.getTextFontData(),
scriptData
);
}
void ReaderWriterP3DXML::parsePage(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const
@ -2005,9 +2098,14 @@ void ReaderWriterP3DXML::parsePage(osgPresentation::SlideShowConstructor& constr
osgPresentation::SlideShowConstructor::FontData fontData = constructor.getTextFontData();
bool fontRead = getProperties(cur,fontData);
osgPresentation::SlideShowConstructor::ScriptData scriptData;
getProperties(cur, scriptData);
constructor.addParagraph(cur->contents,
positionRead ? positionData : constructor.getTextPositionData(),
fontRead ? fontData : constructor.getTextFontData());
fontRead ? fontData : constructor.getTextFontData(),
scriptData
);
}
void ReaderWriterP3DXML::parsePdfDocument(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const
@ -2046,7 +2144,10 @@ void ReaderWriterP3DXML::parsePdfDocument(osgPresentation::SlideShowConstructor&
imageData.page = 0;
getProperties(cur,imageData);
osg::Image* image = constructor.addInteractiveImage(cur->contents, positionData, imageData);
osgPresentation::SlideShowConstructor::ScriptData scriptData;
getProperties(cur, scriptData);
osg::Image* image = constructor.addInteractiveImage(cur->contents, positionData, imageData, scriptData);
osgWidget::PdfImage* pdfImage = dynamic_cast<osgWidget::PdfImage*>(image);
if (pdfImage)
{
@ -2080,7 +2181,7 @@ void ReaderWriterP3DXML::parsePdfDocument(osgPresentation::SlideShowConstructor&
constructor.addLayer(true,false);
constructor.addPDF(cur->getTrimmedContents(), positionData, imageData);
constructor.addPDF(cur->getTrimmedContents(), positionData, imageData, scriptData);
}
}
@ -2096,6 +2197,17 @@ void ReaderWriterP3DXML::parseSlide (osgPresentation::SlideShowConstructor& cons
// create a keyPosition just in case we need it.
osgPresentation::KeyPosition keyPosition;
osgPresentation::SlideShowConstructor::ScriptData scriptData;
if (getProperties(root, scriptData))
{
for(osgPresentation::SlideShowConstructor::ScriptData::Scripts::iterator itr = scriptData.scripts.begin();
itr != scriptData.scripts.end();
++itr)
{
constructor.addScriptCallback(osgPresentation::SlideShowConstructor::CURRENT_SLIDE, itr->first, itr->second);
}
}
for(osgDB::XmlNode::Children::iterator itr = root->children.begin();
itr != root->children.end();
++itr)
@ -2808,7 +2920,25 @@ osg::Node* ReaderWriterP3DXML::parseXmlGraph(osgDB::XmlNode* root, bool readOnly
{
osgDB::XmlNode* cur = itr->get();
if (cur->name == "name")
if (cur->name == "script_engine")
{
constructor.addScriptEngine(cur->contents);
}
else if (cur->name == "script_file")
{
std::string name;
getProperty(cur, "name", name);
constructor.addScriptFile(name, cur->contents);
}
else if (cur->name == "script")
{
std::string name;
getProperty(cur, "name", name);
std::string language("lua");
getProperty(cur, "language", language);
constructor.addScript(name, language, cur->contents);
}
else if (cur->name == "name")
{
constructor.setPresentationName(cur->contents);
}
@ -2946,6 +3076,17 @@ osg::Node* ReaderWriterP3DXML::parseXmlGraph(osgDB::XmlNode* root, bool readOnly
}
}
osgPresentation::SlideShowConstructor::ScriptData scriptData;
if (getProperties(root, scriptData))
{
for(osgPresentation::SlideShowConstructor::ScriptData::Scripts::iterator itr = scriptData.scripts.begin();
itr != scriptData.scripts.end();
++itr)
{
constructor.addScriptCallback(osgPresentation::SlideShowConstructor::CURRENT_PRESENTATION, itr->first, itr->second);
}
}
osgDB::getDataFilePathList() = previousPaths;
return constructor.takePresentation();

View File

@ -240,6 +240,15 @@ void SlideShowConstructor::createPresentation()
//_root->addEventCallback(_propertyEventCallback.get());
_presentationSwitch->setEventCallback(_propertyEventCallback.get());
for(ScriptEngineMap::iterator itr = _scriptEngines.begin();
itr != _scriptEngines.end();
++itr)
{
OSG_NOTICE<<"Assigning '"<<itr->first<<"' ScriptEngine to Presentation in createPresentation()."<<std::endl;
_presentationSwitch->getOrCreateUserDataContainer()->addUserObject(itr->second.get());
}
}
LayerAttributes* SlideShowConstructor::getOrCreateLayerAttributes(osg::Node* node)
@ -290,6 +299,48 @@ void SlideShowConstructor::setPresentationDuration(double duration)
}
}
void SlideShowConstructor::addScriptEngine(const std::string& scriptEngineName)
{
if (_scriptEngines.count(scriptEngineName)!=0)
{
OSG_NOTICE<<"Script engine "<<scriptEngineName<<" already loaded."<<std::endl;
}
osg::ref_ptr<osg::ScriptEngine> scriptEngine = osgDB::readFile<osg::ScriptEngine>(std::string("ScriptEngine.")+scriptEngineName);
if (scriptEngine.valid())
{
_scriptEngines[scriptEngineName] = scriptEngine;
if (_presentationSwitch.valid())
{
_presentationSwitch->getOrCreateUserDataContainer()->addUserObject(scriptEngine.get());
}
}
else
{
OSG_NOTICE<<"Warning: Failed to load "<<scriptEngineName<<" engine, scripts will not work."<<std::endl;
}
}
void SlideShowConstructor::addScriptFile(const std::string& name, const std::string& filename)
{
OSG_NOTICE<<"addScriptFile() name="<<name<<", filename = "<<filename<<std::endl;
osg::ref_ptr<osg::Script> script = osgDB::readFile<osg::Script>(filename);
if (script.valid())
{
_scripts[name] = script;
}
}
void SlideShowConstructor::addScript(const std::string& name, const std::string& language, const std::string& scriptContents)
{
OSG_NOTICE<<"addScript() language="<<language<<", name="<<name<<", script = "<<scriptContents<<std::endl;
osg::ref_ptr<osg::Script> script = new osg::Script;
script->setLanguage(language);
script->setScript(scriptContents);
_scripts[name] = script;
}
void SlideShowConstructor::addSlide()
{
if (!_presentationSwitch) createPresentation();
@ -642,6 +693,68 @@ void SlideShowConstructor::addPropertyAnimation(PresentationContext presentation
}
}
void SlideShowConstructor::addScriptCallback(PresentationContext presentationContext, ScriptCallbackType scriptCallbackType, const std::string& name)
{
switch(presentationContext)
{
case(CURRENT_PRESENTATION):
OSG_NOTICE<<" Adding ScriptCallback to presentation."<<std::endl;
if (!_presentationSwitch) createPresentation();
if (_presentationSwitch.valid()) addScriptToNode(scriptCallbackType, name, _presentationSwitch.get());
break;
case(CURRENT_SLIDE):
OSG_NOTICE<<" Adding ScriptCallback to slide."<<std::endl;
if (!_slide) addSlide();
if (_slide.valid()) addScriptToNode(scriptCallbackType, name, _slide.get());
break;
case(CURRENT_LAYER):
OSG_NOTICE<<" Adding ScriptCallback to layer."<<std::endl;
if (!_currentLayer) addLayer();
if (_currentLayer.valid())
{
addScriptToNode(scriptCallbackType, name, _currentLayer.get());
}
break;
}
}
void SlideShowConstructor::addScriptToNode(ScriptCallbackType scriptCallbackType, const std::string& name, osg::Node* node)
{
std::string::size_type colon_position = name.find(':');
std::string script_name = (colon_position==std::string::npos) ? name : name.substr(0, colon_position);
std::string entry_point = (colon_position==std::string::npos) ? std::string() : name.substr(colon_position+1,std::string::npos);
ScriptMap::iterator script_itr = _scripts.find(script_name);
if (script_itr!=_scripts.end())
{
switch(scriptCallbackType)
{
case(UPDATE_SCRIPT) :
node->addUpdateCallback(new osg::ScriptCallback(script_itr->second.get(), entry_point));
break;
case(EVENT_SCRIPT) :
node->addEventCallback(new osg::ScriptCallback(script_itr->second.get(), entry_point));
break;
}
}
else
{
OSG_NOTICE<<"Warning: script '"<<name<<"' not defined."<<std::endl;
}
}
void SlideShowConstructor::addScriptsToNode(const ScriptData& scriptData, osg::Node* node)
{
if (!node) return;
for(ScriptData::Scripts::const_iterator itr = scriptData.scripts.begin();
itr != scriptData.scripts.end();
++itr)
{
addScriptToNode(itr->first, itr->second, node);
}
}
osg::Node* SlideShowConstructor::decorateSubgraphForPosition(osg::Node* node, PositionData& positionData)
{
@ -675,7 +788,7 @@ osg::Node* SlideShowConstructor::decorateSubgraphForPosition(osg::Node* node, Po
return subgraph;
}
void SlideShowConstructor::addBullet(const std::string& bullet, PositionData& positionData, FontData& fontData)
void SlideShowConstructor::addBullet(const std::string& bullet, PositionData& positionData, FontData& fontData, const ScriptData& scriptData)
{
osg::Geode* geode = new osg::Geode;
@ -721,9 +834,11 @@ void SlideShowConstructor::addBullet(const std::string& bullet, PositionData& po
{
updatePositionFromInModelCoords(localPosition, _textPositionData);
}
if (scriptData.hasScripts()) addScriptsToNode(scriptData, geode);
}
void SlideShowConstructor::addParagraph(const std::string& paragraph, PositionData& positionData, FontData& fontData)
void SlideShowConstructor::addParagraph(const std::string& paragraph, PositionData& positionData, FontData& fontData, const ScriptData& scriptData)
{
osg::Geode* geode = new osg::Geode;
@ -768,6 +883,8 @@ void SlideShowConstructor::addParagraph(const std::string& paragraph, PositionDa
{
updatePositionFromInModelCoords(localPosition, _textPositionData);
}
if (scriptData.hasScripts()) addScriptsToNode(scriptData, geode);
}
class FindImageStreamsVisitor : public osg::NodeVisitor
@ -1180,7 +1297,7 @@ void SlideShowConstructor::setUpMovieVolume(osg::Node* subgraph, osg::ImageStrea
}
}
void SlideShowConstructor::addImage(const std::string& filename, const PositionData& positionData, const ImageData& imageData)
void SlideShowConstructor::addImage(const std::string& filename, const PositionData& positionData, const ImageData& imageData, const ScriptData& scriptData)
{
osg::ref_ptr<osg::Image> image = readImage(filename, imageData);
if (!image) return;
@ -1338,9 +1455,11 @@ void SlideShowConstructor::addImage(const std::string& filename, const PositionD
}
addToCurrentLayer(subgraph);
if (scriptData.hasScripts()) addScriptsToNode(scriptData, subgraph);
}
void SlideShowConstructor::addStereoImagePair(const std::string& filenameLeft, const ImageData& imageDataLeft, const std::string& filenameRight, const ImageData& imageDataRight,const PositionData& positionData)
void SlideShowConstructor::addStereoImagePair(const std::string& filenameLeft, const ImageData& imageDataLeft, const std::string& filenameRight, const ImageData& imageDataRight,const PositionData& positionData, const ScriptData& scriptData)
{
osg::ref_ptr<osg::Image> imageLeft = readImage(filenameLeft, imageDataLeft);
osg::ref_ptr<osg::Image> imageRight = (filenameRight==filenameLeft) ? imageLeft.get() : readImage(filenameRight, imageDataRight);
@ -1560,9 +1679,11 @@ void SlideShowConstructor::addStereoImagePair(const std::string& filenameLeft, c
}
addToCurrentLayer(subgraph);
if (scriptData.hasScripts()) addScriptsToNode(scriptData, subgraph);
}
void SlideShowConstructor::addGraph(const std::string& contents, const PositionData& positionData, const ImageData& imageData)
void SlideShowConstructor::addGraph(const std::string& contents, const PositionData& positionData, const ImageData& imageData, const ScriptData& scriptData)
{
static int s_count=0;
@ -1620,7 +1741,7 @@ void SlideShowConstructor::addGraph(const std::string& contents, const PositionD
_options = _options.valid() ? _options->cloneOptions() : (new osgDB::Options);
_options->setObjectCacheHint(osgDB::Options::CACHE_NONE);
addImage(tmpSvgFileName, positionData, imageData);
addImage(tmpSvgFileName, positionData, imageData, scriptData);
_options = previousOptions;
@ -1630,7 +1751,7 @@ void SlideShowConstructor::addGraph(const std::string& contents, const PositionD
}
void SlideShowConstructor::addVNC(const std::string& hostname, const PositionData& positionData, const ImageData& imageData, const std::string& password)
void SlideShowConstructor::addVNC(const std::string& hostname, const PositionData& positionData, const ImageData& imageData, const std::string& password, const ScriptData& scriptData)
{
if (!password.empty())
{
@ -1639,17 +1760,17 @@ void SlideShowConstructor::addVNC(const std::string& hostname, const PositionDat
osgDB::Registry::instance()->getAuthenticationMap()->addAuthenticationDetails(hostname, new osgDB::AuthenticationDetails("", password));
}
addInteractiveImage(hostname+".vnc", positionData, imageData);
addInteractiveImage(hostname+".vnc", positionData, imageData, scriptData);
}
void SlideShowConstructor::addBrowser(const std::string& url, const PositionData& positionData, const ImageData& imageData)
void SlideShowConstructor::addBrowser(const std::string& url, const PositionData& positionData, const ImageData& imageData, const ScriptData& scriptData)
{
addInteractiveImage(url+".gecko", positionData, imageData);
addInteractiveImage(url+".gecko", positionData, imageData, scriptData);
}
void SlideShowConstructor::addPDF(const std::string& filename, const PositionData& positionData, const ImageData& imageData)
void SlideShowConstructor::addPDF(const std::string& filename, const PositionData& positionData, const ImageData& imageData, const ScriptData& scriptData)
{
addInteractiveImage(filename, positionData, imageData);
addInteractiveImage(filename, positionData, imageData, scriptData);
}
class SetPageCallback: public LayerCallback
@ -1676,7 +1797,7 @@ public:
};
osg::Image* SlideShowConstructor::addInteractiveImage(const std::string& filename, const PositionData& positionData, const ImageData& imageData)
osg::Image* SlideShowConstructor::addInteractiveImage(const std::string& filename, const PositionData& positionData, const ImageData& imageData, const ScriptData& scriptData)
{
osg::ref_ptr<osgDB::Options> options = _options;
if (!imageData.options.empty())
@ -1819,6 +1940,7 @@ osg::Image* SlideShowConstructor::addInteractiveImage(const std::string& filenam
}
if (scriptData.hasScripts()) addScriptsToNode(scriptData, subgraph);
return image;
}
@ -1902,7 +2024,7 @@ protected:
};
void SlideShowConstructor::addModel(const std::string& filename, const PositionData& positionData, const ModelData& modelData)
void SlideShowConstructor::addModel(const std::string& filename, const PositionData& positionData, const ModelData& modelData, const ScriptData& scriptData)
{
OSG_INFO<<"SlideShowConstructor::addModel("<<filename<<")"<<std::endl;
@ -1986,18 +2108,19 @@ void SlideShowConstructor::addModel(const std::string& filename, const PositionD
if (subgraph.valid())
{
addModel(subgraph.get(), positionData, modelData);
addModel(subgraph.get(), positionData, modelData, scriptData);
}
else
{
OSG_NOTICE<<"Could not loaded model file : "<<filename<<std::endl;
}
OSG_INFO<<"end of SlideShowConstructor::addModel("<<filename<<")"<<std::endl<<std::endl;
}
void SlideShowConstructor::addModel(osg::Node* subgraph, const PositionData& positionData, const ModelData& modelData)
void SlideShowConstructor::addModel(osg::Node* subgraph, const PositionData& positionData, const ModelData& modelData, const ScriptData& scriptData)
{
osg::Object::DataVariance defaultMatrixDataVariance = osg::Object::DYNAMIC; // STATIC
@ -2165,6 +2288,8 @@ void SlideShowConstructor::addModel(osg::Node* subgraph, const PositionData& pos
findImageStreamsAndAddCallbacks(subgraph);
addToCurrentLayer(subgraph);
if (scriptData.hasScripts()) addScriptsToNode(scriptData, subgraph);
}
class DraggerVolumeTileCallback : public osgManipulator::DraggerCallback
@ -2378,7 +2503,7 @@ void SlideShowConstructor::setUpVolumeScalarProperty(osgVolume::VolumeTile* tile
}
void SlideShowConstructor::addVolume(const std::string& filename, const PositionData& in_positionData, const VolumeData& volumeData)
void SlideShowConstructor::addVolume(const std::string& filename, const PositionData& in_positionData, const VolumeData& volumeData, const ScriptData& scriptData)
{
// osg::Object::DataVariance defaultMatrixDataVariance = osg::Object::DYNAMIC; // STATIC
@ -2724,7 +2849,7 @@ void SlideShowConstructor::addVolume(const std::string& filename, const Position
}
ModelData modelData;
addModel(model.get(), positionData, modelData);
addModel(model.get(), positionData, modelData, scriptData);
}
bool SlideShowConstructor::attachTexMat(osg::StateSet* stateset, const ImageData& imageData, float s, float t, bool textureRectangle)