bool Gui::SoFCDB::writeToVRML(SoNode* node, const char* filename, bool binary) { SoVRMLAction vrml2; vrml2.setOverrideMode(true); vrml2.apply(node); SoToVRML2Action tovrml2; tovrml2.apply(node); SoVRMLGroup* vrmlRoot = tovrml2.getVRML2SceneGraph(); vrmlRoot->setInstancePrefix(SbString("o")); vrmlRoot->ref(); std::string buffer = SoFCDB::writeNodesToString(vrmlRoot); vrmlRoot->unref(); // release the memory as soon as possible // restore old settings vrml2.setOverrideMode(false); vrml2.apply(node); Base::FileInfo fi(filename); if (binary) { // We want to write compressed VRML but Coin 2.4.3 doesn't do it even though // SoOutput::getAvailableCompressionMethods() delivers a string list that // contains 'GZIP'. setCompression() was called directly after opening the file, // returned TRUE and no error message appeared but anyway it didn't work. // Strange is that reading GZIPped VRML files works. // So, we do the compression on our own. Base::ofstream str(fi, std::ios::out | std::ios::binary); zipios::GZIPOutputStream gzip(str); if (gzip) { gzip << buffer; gzip.close(); return true; } } else { Base::ofstream str(fi, std::ios::out); if (str) { str << buffer; str.close(); return true; } } return false; }