|
80 | 80 | #include <osg/Vec4> |
81 | 81 | #include <osg/Version> |
82 | 82 | #include <osgDB/WriteFile> |
| 83 | +#include <osgDB/FileUtils> |
| 84 | +#include <osgDB/FileNameUtils> |
83 | 85 | #include <osgFX/Scribe> |
84 | 86 |
|
85 | 87 | #ifdef _OPENMP |
@@ -1682,24 +1684,45 @@ bool |
1682 | 1684 | VRSceneGraph::saveScenegraph(const std::string &filename, bool storeWithMenu) |
1683 | 1685 | { |
1684 | 1686 | if (isScenegraphProtected_) |
1685 | | - { |
| 1687 | + { |
1686 | 1688 | fprintf(stderr, "Cannot store scenegraph. Not allowed!"); |
1687 | 1689 | return false; |
1688 | 1690 | } |
1689 | 1691 |
|
1690 | 1692 | if (cover->debugLevel(3)) |
1691 | 1693 | 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) |
1697 | 1703 | { |
| 1704 | + fileExt = filename.substr(dotPos + 1); |
1698 | 1705 | } |
1699 | | - else |
| 1706 | + |
| 1707 | + bool validExt = false; |
| 1708 | + if (!fileExt.empty()) |
1700 | 1709 | { |
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 | + |
1703 | 1726 | } |
1704 | 1727 |
|
1705 | 1728 | 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) |
1896 | 1919 |
|
1897 | 1920 | osg::StateSet *stateSet = new osg::StateSet(); |
1898 | 1921 | 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); |
1900 | 1924 | stateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON); |
1901 | 1925 | stateSet->setAttributeAndModes(alphaFunc, osg::StateAttribute::ON); |
1902 | 1926 | stateSet->setAttributeAndModes(blendFunc, osg::StateAttribute::ON); |
1903 | | - stateSet->setAttributeAndModes(defaultLm, osg::StateAttribute::ON); |
1904 | 1927 | return stateSet; |
1905 | 1928 | } |
1906 | 1929 |
|
@@ -2121,7 +2144,7 @@ void VRSceneGraph::setColor(osg::Geode *geode, int *color, float transparency) |
2121 | 2144 | drawable->asGeometry()->setColorBinding(Geometry::BIND_OVERALL); |
2122 | 2145 | drawable->asGeometry()->setColorArray(colorArray.get()); |
2123 | 2146 | } |
2124 | | - }*/ |
| 2147 | + }*/ |
2125 | 2148 | drawable->dirtyBound(); |
2126 | 2149 | } |
2127 | 2150 | } |
|
0 commit comments