Merge branch 'master' into shader_pipeline

This commit is contained in:
Robert Osfield 2018-02-08 09:28:40 +00:00
commit 97ba981dce
2 changed files with 73 additions and 48 deletions

View File

@ -41,48 +41,15 @@ using namespace osg;
using namespace osgGA; using namespace osgGA;
class SwitchDOFVisitor : public osg::NodeVisitor, public osgGA::GUIEventHandler class SwitchDOFHandler : public osgGA::GUIEventHandler
{ {
public: public:
SwitchDOFVisitor():
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
SwitchDOFHandler()
{ {
} }
SwitchDOFVisitor(const SwitchDOFVisitor& sdfv, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Object(sdfv, copyop),
osg::Callback(sdfv, copyop),
osg::NodeVisitor(sdfv, copyop),
osgGA::GUIEventHandler(sdfv, copyop)
{}
META_Object(osg, SwitchDOFVisitor)
virtual void apply(Group& node)
{
osgSim::MultiSwitch* pMSwitch = dynamic_cast<osgSim::MultiSwitch*>(&node);
if (pMSwitch)
{
mSwitches.push_back(pMSwitch);
}
osg::NodeVisitor::apply(node);
}
virtual void apply(Transform& node)
{
osgSim::DOFTransform* pDof = dynamic_cast<osgSim::DOFTransform*>(&node);
if (pDof)
{
mDofs.push_back(pDof);
pDof->setAnimationOn(true);
}
osg::NodeVisitor::apply(node);
}
void nextSwitch() void nextSwitch()
{ {
for (size_t i=0; i < mSwitches.size(); i++) for (size_t i=0; i < mSwitches.size(); i++)
@ -156,9 +123,53 @@ public:
return false; return false;
} }
void collectNodesOfInterest(osg::Node* node)
{
CollectNodes cn(this);
node->accept(cn);
}
private: private:
std::vector<osgSim::MultiSwitch*> mSwitches;
std::vector<osgSim::DOFTransform*> mDofs; friend class CollectNodes;
class CollectNodes : public osg::NodeVisitor
{
public:
SwitchDOFHandler* _parent;
CollectNodes(SwitchDOFHandler* parent):
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
_parent(parent)
{
}
virtual void apply(Group& node)
{
osgSim::MultiSwitch* pMSwitch = dynamic_cast<osgSim::MultiSwitch*>(&node);
if (pMSwitch)
{
_parent->mSwitches.push_back(pMSwitch);
}
traverse(node);
}
virtual void apply(Transform& node)
{
osgSim::DOFTransform* pDof = dynamic_cast<osgSim::DOFTransform*>(&node);
if (pDof)
{
_parent->mDofs.push_back(pDof);
pDof->setAnimationOn(true);
}
traverse(node);
}
};
std::vector< osg::ref_ptr<osgSim::MultiSwitch> > mSwitches;
std::vector< osg::ref_ptr<osgSim::DOFTransform> > mDofs;
}; };
void singleWindowSideBySideCameras(osgViewer::Viewer& viewer) void singleWindowSideBySideCameras(osgViewer::Viewer& viewer)
@ -267,8 +278,8 @@ int main( int argc, char **argv )
viewer.addEventHandler(new osgViewer::LODScaleHandler()); viewer.addEventHandler(new osgViewer::LODScaleHandler());
viewer.addEventHandler(new osgGA::StateSetManipulator()); viewer.addEventHandler(new osgGA::StateSetManipulator());
SwitchDOFVisitor* visit = new SwitchDOFVisitor; SwitchDOFHandler* switchOFHandler = new SwitchDOFHandler;
viewer.addEventHandler(visit); viewer.addEventHandler(switchOFHandler);
// load the scene. // load the scene.
osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments); osg::ref_ptr<osg::Node> loadedModel = osgDB::readRefNodeFiles(arguments);
@ -294,13 +305,12 @@ int main( int argc, char **argv )
group2->addChild(convertedModel.get()); group2->addChild(convertedModel.get());
group2->setNodeMask(2); group2->setNodeMask(2);
// Activate DOF animations and collect switches
loadedModel->accept(*visit);
convertedModel->accept(*visit);
group->addChild(group1); group->addChild(group1);
group->addChild(group2); group->addChild(group2);
// Activate DOF animations and collect switches
switchOFHandler->collectNodesOfInterest(group);
viewer.setSceneData(group); viewer.setSceneData(group);
viewer.setThreadingModel(osgViewer::Viewer::DrawThreadPerContext); viewer.setThreadingModel(osgViewer::Viewer::DrawThreadPerContext);

View File

@ -11,7 +11,7 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter
ReaderWriterFreeType() ReaderWriterFreeType()
{ {
supportsExtension("ttf","true type font format"); supportsExtension("ttf","true type font format");
supportsExtension("ttc","true type format"); supportsExtension("ttc","true type collection format");
supportsExtension("pfb","type1 binary format"); supportsExtension("pfb","type1 binary format");
supportsExtension("pfa","type2 ascii format"); supportsExtension("pfa","type2 ascii format");
supportsExtension("cid","Postscript CID-Fonts format"); supportsExtension("cid","Postscript CID-Fonts format");
@ -23,6 +23,7 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter
supportsExtension("woff","web open font format"); supportsExtension("woff","web open font format");
supportsOption("monochrome","Select monochrome font."); supportsOption("monochrome","Select monochrome font.");
supportsOption("index=<uint>", "Select index of font within ttc collection. Defaults to 0.");
} }
virtual const char* className() const { return "FreeType Font Reader/Writer"; } virtual const char* className() const { return "FreeType Font Reader/Writer"; }
@ -38,6 +39,20 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter
return flags; return flags;
} }
static unsigned int getIndex(const osgDB::ReaderWriter::Options* options)
{
if(!options) return 0;
std::string indexstr = options->getPluginStringData("index");
int index = std::atoi(indexstr.c_str());
if(index < 0)
{
OSG_WARN<< "Warning: invalid index string (" << indexstr << ") when loading freetype font. Attempting to use default index 0." << std::endl;
return 0;
}
else return (unsigned int)index;
}
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const
{ {
std::string ext = osgDB::getLowerCaseFileExtension(file); std::string ext = osgDB::getLowerCaseFileExtension(file);
@ -53,7 +68,7 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter
return ReadResult::ERROR_IN_READING_FILE; return ReadResult::ERROR_IN_READING_FILE;
} }
return freeTypeLibrary->getFont(fileName,0,getFlags(options)); return freeTypeLibrary->getFont(fileName, getIndex(options), getFlags(options));
} }
virtual ReadResult readObject(std::istream& stream, const osgDB::ReaderWriter::Options* options) const virtual ReadResult readObject(std::istream& stream, const osgDB::ReaderWriter::Options* options) const
@ -65,7 +80,7 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter
return ReadResult::ERROR_IN_READING_FILE; return ReadResult::ERROR_IN_READING_FILE;
} }
return freeTypeLibrary->getFont(stream, 0, getFlags(options)); return freeTypeLibrary->getFont(stream, getIndex(options), getFlags(options));
} }
}; };