Added <switch> tag to .p3d to allow one to provide multiple ways to render children within a layer.

This commit is contained in:
Robert Osfield 2013-12-20 09:57:35 +00:00
parent a72508bc71
commit 865a47bd6b
3 changed files with 46 additions and 20 deletions

View File

@ -506,7 +506,7 @@ public:
osg::Switch* getCurrentSlide() { return _slide.get(); } osg::Switch* getCurrentSlide() { return _slide.get(); }
void pushCurrentLayer(); void pushCurrentLayer(osg::Group* newLayerGroup);
void popCurrentLayer(); void popCurrentLayer();
osg::Group* getCurrentLayer() { return _currentLayer.get(); } osg::Group* getCurrentLayer() { return _currentLayer.get(); }

View File

@ -42,7 +42,7 @@ public:
ReaderWriterP3DXML() ReaderWriterP3DXML()
{ {
supportsOption("suppressEnvTags", "if set to (true|1) all env-tags in the p3d-file will be suppressed"); supportsOption("suppressEnvTags", "if set to (true|1) all env-tags in the p3d-file will be suppressed");
_colorMap["WHITE"] .set(1.0f,1.0f,1.0f,1.0f); _colorMap["WHITE"] .set(1.0f,1.0f,1.0f,1.0f);
_colorMap["BLACK"] .set(0.0f,0.0f,0.0f,1.0f); _colorMap["BLACK"] .set(0.0f,0.0f,0.0f,1.0f);
_colorMap["PURPLE"] .set(1.0f,0.0f,1.0f,1.0f); _colorMap["PURPLE"] .set(1.0f,0.0f,1.0f,1.0f);
@ -114,7 +114,7 @@ public:
return osgDB::equalCaseInsensitive(extension,"p3d") || return osgDB::equalCaseInsensitive(extension,"p3d") ||
osgDB::equalCaseInsensitive(extension,"xml") ; osgDB::equalCaseInsensitive(extension,"xml") ;
} }
virtual ReadResult readNode(const std::string& fileName, virtual ReadResult readNode(const std::string& fileName,
const osgDB::ReaderWriter::Options* options) const; const osgDB::ReaderWriter::Options* options) const;
@ -133,10 +133,13 @@ public:
osg::TransferFunction1D* readTransferFunctionFile(const std::string& filename, float scale) const; osg::TransferFunction1D* readTransferFunctionFile(const std::string& filename, float scale) const;
void parseVolume(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; void parseVolume(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const;
void parseStereoPair(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; void parseStereoPair(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const;
void parseTimeout(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; void parseTimeout(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const;
void parseSwitch(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const;
bool parseLayerChild(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* cur, float& totalIndent) const; bool parseLayerChild(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* cur, float& totalIndent) const;
void parseLayer(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const; void parseLayer(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const;
@ -178,7 +181,7 @@ public:
inline bool read(const char* str, osg::Vec2& value) const; inline bool read(const char* str, osg::Vec2& value) const;
inline bool read(const char* str, osg::Vec3& value) const; inline bool read(const char* str, osg::Vec3& value) const;
inline bool read(const char* str, osg::Vec4& value) const; inline bool read(const char* str, osg::Vec4& value) const;
inline bool read(const std::string& str, bool& value) const; inline bool read(const std::string& str, bool& value) const;
inline bool read(const std::string& str, int& value) const; inline bool read(const std::string& str, int& value) const;
inline bool read(const std::string& str, float& value) const; inline bool read(const std::string& str, float& value) const;
@ -1478,7 +1481,7 @@ bool ReaderWriterP3DXML::getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation
// v in range 0.0 to 1, from bottom to top // v in range 0.0 to 1, from bottom to top
y = v*2.0f-1.0f; y = v*2.0f-1.0f;
} }
bool forward_to_devices = false; bool forward_to_devices = false;
getProperty(cur, "forward_to_devices", forward_to_devices); getProperty(cur, "forward_to_devices", forward_to_devices);
@ -1526,10 +1529,10 @@ bool ReaderWriterP3DXML::getKeyPositionInner(osgDB::XmlNode*cur, osgPresentation
void ReaderWriterP3DXML::parseTimeout(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* root) const void ReaderWriterP3DXML::parseTimeout(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* root) const
{ {
// to allow the timeout to be nested with a Layer but still behave like a Layer itself we push the timeout as a Layer, saving the original Layer osg::ref_ptr<osgPresentation::Timeout> timeout = new osgPresentation::Timeout(constructor.getHUDSettings());
constructor.pushCurrentLayer();
osg::ref_ptr<osgPresentation::Timeout> timeout = constructor.addTimeout(); // to allow the timeout to be nested with a Layer but still behave like a Layer itself we push the timeout as a Layer, saving the original Layer
constructor.pushCurrentLayer(timeout.get());
OSG_NOTICE<<"parseTimeout"<<std::endl; OSG_NOTICE<<"parseTimeout"<<std::endl;
@ -1641,10 +1644,10 @@ void ReaderWriterP3DXML::parseTimeout(osgPresentation::SlideShowConstructor& con
} }
constructor.popCurrentLayer(); // return the parent level
constructor.popCurrentLayer(); // return the
} }
bool ReaderWriterP3DXML::parseLayerChild(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* cur, float& totalIndent) const bool ReaderWriterP3DXML::parseLayerChild(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* cur, float& totalIndent) const
{ {
if (cur->name == "newline") if (cur->name == "newline")
@ -1864,6 +1867,23 @@ bool ReaderWriterP3DXML::parseLayerChild(osgPresentation::SlideShowConstructor&
return false; return false;
} }
void ReaderWriterP3DXML::parseSwitch(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode*cur) const
{
osg::ref_ptr<osg::Switch> switchNode = new osg::Switch;;
// to allow the timeout to be nested with a Layer but still behave like a Layer itself we push the timeout as a Layer, saving the original Layer
constructor.pushCurrentLayer(switchNode.get());
OSG_NOTICE<<"parseSwitch"<<std::endl;
parseLayer(constructor, cur);
switchNode->setSingleChildOn(0);
constructor.popCurrentLayer(); // return the parent level
}
void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* root) const void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& constructor, osgDB::XmlNode* root) const
{ {
OSG_INFO<<std::endl<<"parseLayer"<<std::endl; OSG_INFO<<std::endl<<"parseLayer"<<std::endl;
@ -1890,6 +1910,10 @@ void ReaderWriterP3DXML::parseLayer(osgPresentation::SlideShowConstructor& const
{ {
// no need to do anything // no need to do anything
} }
else if (cur->name == "switch")
{
parseSwitch(constructor, cur);
}
else if (cur->name == "timeout") else if (cur->name == "timeout")
{ {
parseTimeout(constructor, cur); parseTimeout(constructor, cur);

View File

@ -409,18 +409,16 @@ void SlideShowConstructor::setSlideDuration(double duration)
} }
} }
void SlideShowConstructor::pushCurrentLayer(osg::Group* group)
Timeout* SlideShowConstructor::addTimeout()
{ {
osg::ref_ptr<osgPresentation::Timeout> timeout = new osgPresentation::Timeout(_hudSettings.get()); if (_currentLayer.valid())
if (_currentLayer.valid()) _currentLayer->addChild(timeout.get()); {
_currentLayer = timeout.get(); _currentLayer->addChild(group);
return timeout.release(); _layerStack.push_back(_currentLayer.get());
} }
_currentLayer = group;
void SlideShowConstructor::pushCurrentLayer()
{
_layerStack.push_back(_currentLayer.get());
} }
void SlideShowConstructor::popCurrentLayer() void SlideShowConstructor::popCurrentLayer()
@ -430,6 +428,10 @@ void SlideShowConstructor::popCurrentLayer()
_currentLayer = _layerStack.back(); _currentLayer = _layerStack.back();
_layerStack.pop_back(); _layerStack.pop_back();
} }
else
{
_currentLayer = 0;
}
} }
void SlideShowConstructor::addLayer(bool inheritPreviousLayers, bool defineAsBaseLayer) void SlideShowConstructor::addLayer(bool inheritPreviousLayers, bool defineAsBaseLayer)