From 6dc3f547866ce9e3f684235c9939d0ffa2f19215 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 19 Nov 2009 16:06:30 +0000 Subject: [PATCH] From Jan Ciger, build fixes to work with OpenVRML 0.18.3. Tweaks to this submission from Robert Osfield to fix missing elements in submission. --- src/osgPlugins/vrml/IndexedFaceSet.cpp | 2 - src/osgPlugins/vrml/Primitives.cpp | 1 - src/osgPlugins/vrml/ReaderWriterVRML2.cpp | 66 ++++++++++------------- src/osgPlugins/vrml/ReaderWriterVRML2.h | 2 +- 4 files changed, 30 insertions(+), 41 deletions(-) diff --git a/src/osgPlugins/vrml/IndexedFaceSet.cpp b/src/osgPlugins/vrml/IndexedFaceSet.cpp index d47a7f95a..630d6d505 100644 --- a/src/osgPlugins/vrml/IndexedFaceSet.cpp +++ b/src/osgPlugins/vrml/IndexedFaceSet.cpp @@ -9,7 +9,6 @@ # pragma warning(disable: 4800) #endif -#include #include #include @@ -19,7 +18,6 @@ osg::ref_ptr ReaderWriterVRML2::convertVRML97IndexedFaceSet(openv osg::ref_ptr osg_geom = new osg::Geometry(); osg_geom->addPrimitiveSet(new osg::DrawArrayLengths(osg::PrimitiveSet::POLYGON)); - //osg::StateSet *osg_stateset = osg_geom->getOrCreateStateSet(); // get array of vertex coordinate_nodes if(vrml_ifs->type().id() == "IndexedFaceSet") diff --git a/src/osgPlugins/vrml/Primitives.cpp b/src/osgPlugins/vrml/Primitives.cpp index 3307bac0b..e83f66a3e 100644 --- a/src/osgPlugins/vrml/Primitives.cpp +++ b/src/osgPlugins/vrml/Primitives.cpp @@ -10,7 +10,6 @@ # pragma warning(disable: 4800) #endif -#include #include #include diff --git a/src/osgPlugins/vrml/ReaderWriterVRML2.cpp b/src/osgPlugins/vrml/ReaderWriterVRML2.cpp index 1fd15d4dd..c86585ace 100644 --- a/src/osgPlugins/vrml/ReaderWriterVRML2.cpp +++ b/src/osgPlugins/vrml/ReaderWriterVRML2.cpp @@ -29,7 +29,6 @@ # pragma warning(disable: 4800) #endif -#include #include #include @@ -176,21 +175,26 @@ osgDB::ReaderWriter::ReadResult ReaderWriterVRML2::readNode(const std::string& f if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; - // code for setting up the database path so that internally referenced file are searched for on relative paths. - osg::ref_ptr local_opt = opt ? static_cast(opt->clone(osg::CopyOp::SHALLOW_COPY)) : new osgDB::Options; - local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName)); + // convert possible Windows backslashes to Unix slashes + // OpenVRML doesn't like backslashes, even on Windows + std::string unixFileName = osgDB::convertFileNameToUnixStyle(fileName); - std::ifstream vrml_stream(fileName.c_str()); +#ifdef WIN32 + if(unixFileName[1] == ':') // absolute path + fileName = "file:///" + unixFileName; +#else + if (unixFileName[0] == '/') // absolute path + fileName = "file://" + unixFileName; +#endif + else + // relative path + fileName = unixFileName; - return readNode(vrml_stream, local_opt.get()); -} - -osgDB::ReaderWriter::ReadResult ReaderWriterVRML2::readNode(std::istream& vrml_stream, const osgDB::Options* opt) const -{ std::fstream null; resource_fetcher fetcher; + openvrml::browser *b = new openvrml::browser(fetcher, null, null); - std::auto_ptr b(new openvrml::browser(fetcher, null, null)); + std::ifstream vrml_stream(fileName.c_str()); try { @@ -205,24 +209,22 @@ osgDB::ReaderWriter::ReadResult ReaderWriterVRML2::readNode(std::istream& vrml_s 0, -1, 0, 0, 0, 0, 0, 1)); - + osgDB::getDataFilePathList().push_front(osgDB::getFilePath(unixFileName)); for (unsigned i = 0; i < mfn.size(); i++) { openvrml::node *vrml_node = mfn[i].get(); - osg_root->addChild(convertFromVRML(vrml_node, opt)); + osg_root->addChild(convertFromVRML(vrml_node).get()); } - + osgDB::getDataFilePathList().pop_front(); return osg_root.get(); } } catch (openvrml::invalid_vrml) { return ReadResult::FILE_NOT_HANDLED; } catch (std::invalid_argument) { return ReadResult::FILE_NOT_HANDLED; } - - return ReadResult::FILE_NOT_HANDLED; } -osg::Node* ReaderWriterVRML2::convertFromVRML(openvrml::node *obj, const osgDB::Options* opt) const +osg::ref_ptr ReaderWriterVRML2::convertFromVRML(openvrml::node *obj) const { //static int osgLightNum = 0; //light @@ -247,7 +249,7 @@ osg::Node* ReaderWriterVRML2::convertFromVRML(openvrml::node *obj, const osgDB:: for (it_npv = node_ptr_vector.begin(); it_npv != node_ptr_vector.end(); it_npv++) { openvrml::node *node = (*(it_npv)).get(); - osg_group->addChild(convertFromVRML(node, opt)); + osg_group->addChild(convertFromVRML(node)); } } } @@ -256,7 +258,7 @@ osg::Node* ReaderWriterVRML2::convertFromVRML(openvrml::node *obj, const osgDB:: // no children } - return osg_group.release(); + return osg_group.get(); } @@ -282,7 +284,7 @@ osg::Node* ReaderWriterVRML2::convertFromVRML(openvrml::node *obj, const osgDB:: for (it_npv = node_ptr_vector.begin(); it_npv != node_ptr_vector.end(); it_npv++) { openvrml::node *node = (*(it_npv)).get(); - osg_m->addChild(convertFromVRML(node, opt)); + osg_m->addChild(convertFromVRML(node).get()); } } } @@ -291,7 +293,7 @@ osg::Node* ReaderWriterVRML2::convertFromVRML(openvrml::node *obj, const osgDB:: // no children } - return osg_m.release(); + return osg_m.get(); } @@ -349,8 +351,8 @@ osg::Node* ReaderWriterVRML2::convertFromVRML(openvrml::node *obj, const osgDB:: const openvrml::sfnode *sfn = dynamic_cast(fv.get()); openvrml::appearance_node *vrml_app = dynamic_cast(sfn->value().get()); - const boost::intrusive_ptr vrml_material_node = vrml_app ? vrml_app->material() : 0; - const boost::intrusive_ptr vrml_texture_node = vrml_app ? vrml_app->texture() : 0; + const boost::intrusive_ptr vrml_material_node = vrml_app->material(); + const boost::intrusive_ptr vrml_texture_node = vrml_app->texture(); const openvrml::material_node *vrml_material = dynamic_cast(vrml_material_node.get()); if (vrml_material != NULL) @@ -382,9 +384,8 @@ osg::Node* ReaderWriterVRML2::convertFromVRML(openvrml::node *obj, const osgDB:: { osg_mat->setTransparency(osg::Material::FRONT_AND_BACK, vrml_material->transparency()); osg_stateset->setMode(GL_BLEND, osg::StateAttribute::ON); + osg_stateset->setAttribute(new osg::Depth(osg::Depth::LESS, 0.0, 1.0, false)); // GvdB: transparent objects do not write depth osg_stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - // commenting out osg:::Depth entry as it's not usual for transparent objects to disable depth. - // osg_stateset->setAttribute(new osg::Depth(osg::Depth::LESS, 0.0, 1.0, false)); // GvdB: transparent objects do not write depth } else { @@ -403,7 +404,7 @@ osg::Node* ReaderWriterVRML2::convertFromVRML(openvrml::node *obj, const osgDB:: const openvrml::mfstring *mfs = dynamic_cast(texture_url_fv.get()); const std::string &url = mfs->value()[0]; - osg::ref_ptr image = osgDB::readRefImageFile(url, opt); + osg::ref_ptr image = osgDB::readRefImageFile(url); if (image != 0) { @@ -436,7 +437,7 @@ osg::Node* ReaderWriterVRML2::convertFromVRML(openvrml::node *obj, const osgDB:: const openvrml::sfbool *sfb = dynamic_cast(wrap_fv.get()); if (!sfb->value()) - texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP); + texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP); } catch (...) { @@ -445,15 +446,6 @@ osg::Node* ReaderWriterVRML2::convertFromVRML(openvrml::node *obj, const osgDB:: osg_stateset->setTextureAttributeAndModes(0, texture.get()); //osg_stateset->setMode(GL_BLEND,osg::StateAttribute::ON); //bhbn - if(image->isImageTranslucent()) - { - osg_stateset->setMode(GL_BLEND, osg::StateAttribute::ON); - osg_stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); - // commenting out osg:::Depth entry as it's not usual for transparent objects to disable depth. - osg_stateset->setAttribute(new osg::Depth(osg::Depth::LESS, 0.0, 1.0, false)); // GvdB: transparent objects do not write depth - } - - } else @@ -464,7 +456,7 @@ osg::Node* ReaderWriterVRML2::convertFromVRML(openvrml::node *obj, const osgDB:: } } - return osg_geode.release(); + return osg_geode.get(); } else { diff --git a/src/osgPlugins/vrml/ReaderWriterVRML2.h b/src/osgPlugins/vrml/ReaderWriterVRML2.h index f93be1e00..ad210ab57 100644 --- a/src/osgPlugins/vrml/ReaderWriterVRML2.h +++ b/src/osgPlugins/vrml/ReaderWriterVRML2.h @@ -81,7 +81,7 @@ private: typedef std::map > ConeLibrary; typedef std::map > CylinderLibrary; - osg::Node* convertFromVRML(openvrml::node *obj, const osgDB::Options* opt) const; + osg::ref_ptr convertFromVRML(openvrml::node *obj) const; osg::ref_ptr convertVRML97IndexedFaceSet(openvrml::node *vrml_ifs) const;