Skip to content

Commit 36e2448

Browse files
author
hpcdgrie
committed
Reorganized supported formats:
If no supportedFormats.toml config exists osgDB supported formats are stored there. To keep it simple only important formats are shown.
1 parent b160c11 commit 36e2448

3 files changed

Lines changed: 249 additions & 62 deletions

File tree

src/OpenCOVER/cover/VRSceneGraph.cpp

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
#include <osg/Vec4>
8181
#include <osg/Version>
8282
#include <osgDB/WriteFile>
83+
#include <osgDB/FileUtils>
84+
#include <osgDB/FileNameUtils>
8385
#include <osgFX/Scribe>
8486

8587
#ifdef _OPENMP
@@ -1682,24 +1684,45 @@ bool
16821684
VRSceneGraph::saveScenegraph(const std::string &filename, bool storeWithMenu)
16831685
{
16841686
if (isScenegraphProtected_)
1685-
{
1687+
{
16861688
fprintf(stderr, "Cannot store scenegraph. Not allowed!");
16871689
return false;
16881690
}
16891691

16901692
if (cover->debugLevel(3))
16911693
fprintf(stderr, "save file as: %s\n", filename.c_str());
1692-
size_t len = filename.length();
1693-
if ((len > 4 && (!strcmp(filename.c_str() + len - 4, ".ive") || !strcmp(filename.c_str() + len - 4, ".osg")))
1694-
|| (len > 5 && (!strcmp(filename.c_str() + len - 5, ".osgt")
1695-
|| !strcmp(filename.c_str() + len - 5, ".osgb")
1696-
|| !strcmp(filename.c_str() + len - 5, ".osgx"))))
1694+
1695+
1696+
auto supportedExtentions = coVRFileManager::instance()->getSupportedOsgExtentions();
1697+
std::string popularExtentions = coVRFileManager::instance()->getWriteFilterList();
1698+
1699+
// Check if filename extension is supported
1700+
std::string fileExt;
1701+
size_t dotPos = filename.find_last_of('.');
1702+
if (dotPos != std::string::npos && dotPos < filename.size() - 1)
16971703
{
1704+
fileExt = filename.substr(dotPos + 1);
16981705
}
1699-
else
1706+
1707+
bool validExt = false;
1708+
if (!fileExt.empty())
17001709
{
1701-
if (cover->debugLevel(1))
1702-
std::cerr << "Writing to \"" << filename << "\": unknown extension, use .ive, .osg, .osgt, .osgb, or .osgx." << std::endl;
1710+
for (const auto& ext : supportedExtentions)
1711+
{
1712+
if (osg::iequals(fileExt, ext))
1713+
{
1714+
validExt = true;
1715+
break;
1716+
}
1717+
}
1718+
}
1719+
1720+
// If not, print the supported popular extensions
1721+
if (!validExt && cover->debugLevel(1))
1722+
{
1723+
std::cerr << "Writing to \"" << filename << "\": unknown extension. Supported extensions are: ";
1724+
std::cerr << coVRFileManager::instance()->getWriteFilterList() << std::endl;
1725+
17031726
}
17041727

17051728
if (osgDB::writeNodeFile(storeWithMenu ? *static_cast<osg::Group *>(m_scene) : *m_objectsRoot, filename.c_str()))
@@ -1896,11 +1919,11 @@ VRSceneGraph::loadDefaultGeostate(osg::Material::ColorMode mode)
18961919

18971920
osg::StateSet *stateSet = new osg::StateSet();
18981921
stateSet->setRenderingHint(osg::StateSet::OPAQUE_BIN);
1899-
stateSet->setAttributeAndModes(material, osg::StateAttribute::ON);
1922+
stateSet->setAttribute(material, osg::StateAttribute::ON);
1923+
stateSet->setAttribute(defaultLm, osg::StateAttribute::ON);
19001924
stateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON);
19011925
stateSet->setAttributeAndModes(alphaFunc, osg::StateAttribute::ON);
19021926
stateSet->setAttributeAndModes(blendFunc, osg::StateAttribute::ON);
1903-
stateSet->setAttributeAndModes(defaultLm, osg::StateAttribute::ON);
19041927
return stateSet;
19051928
}
19061929

@@ -2121,7 +2144,7 @@ void VRSceneGraph::setColor(osg::Geode *geode, int *color, float transparency)
21212144
drawable->asGeometry()->setColorBinding(Geometry::BIND_OVERALL);
21222145
drawable->asGeometry()->setColorArray(colorArray.get());
21232146
}
2124-
}*/
2147+
}*/
21252148
drawable->dirtyBound();
21262149
}
21272150
}

0 commit comments

Comments
 (0)