virtual ReadResult readNode(const std::string &fileName, const osgDB::ReaderWriter::Options *options) const { std::string ext = osgDB::getLowerCaseFileExtension(fileName); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; OSG_INFO << "ReaderWriterROT( \"" << fileName << "\" )" << std::endl; // strip the pseudo-loader extension std::string tmpName = osgDB::getNameLessExtension(fileName); if (tmpName.empty()) return ReadResult::FILE_NOT_HANDLED; std::string subFileName, params; if (!getFilenameAndParams(tmpName, subFileName, params)) { return ReadResult::FILE_NOT_HANDLED; } if (subFileName.empty()) { OSG_WARN << "Missing subfilename for " EXTENSION_NAME " pseudo-loader" << std::endl; return ReadResult::FILE_NOT_HANDLED; } OSG_INFO << " params = \"" << params << "\"" << std::endl; OSG_INFO << " subFileName = \"" << subFileName << "\"" << std::endl; float rx, ry, rz; int count = sscanf(params.c_str(), "%f,%f,%f", &rx, &ry, &rz); if (count != 3) { OSG_WARN << "Bad parameters for " EXTENSION_NAME " pseudo-loader: \"" << params << "\"" << std::endl; return ReadResult::FILE_NOT_HANDLED; } // recursively load the subfile. osg::Node *node = osgDB::readNodeFile(subFileName, options); if (!node) { // propagate the read failure upwards OSG_WARN << "Subfile \"" << subFileName << "\" could not be loaded" << std::endl; return ReadResult::FILE_NOT_HANDLED; } osg::MatrixTransform *xform = new osg::MatrixTransform; xform->setDataVariance(osg::Object::STATIC); xform->setMatrix(osg::Matrix::rotate( osg::DegreesToRadians(rx), osg::Vec3(1, 0, 0), osg::DegreesToRadians(ry), osg::Vec3(0, 1, 0), osg::DegreesToRadians(rz), osg::Vec3(0, 0, 1))); xform->addChild(node); return xform; }
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(fileName); if( !acceptsExtension(ext) ) return ReadResult::FILE_NOT_HANDLED; // strip the pseudo-loader extension std::string tmpName = osgDB::getNameLessExtension( fileName ); if (tmpName.empty()) return ReadResult::FILE_NOT_HANDLED; std::string subFileName, params; if (!getFilenameAndParams(tmpName, subFileName, params)) { return ReadResult::FILE_NOT_HANDLED; } if( subFileName.empty()) { OSG_WARN << "Missing subfilename for " EXTENSION_NAME " pseudo-loader" << std::endl; return ReadResult::FILE_NOT_HANDLED; } OSG_INFO << " params = \"" << params << "\"" << std::endl; OSG_INFO << " subFileName = \"" << subFileName << "\"" << std::endl; osg::ref_ptr<osgShadow::ShadowTechnique> technique; if (!params.empty()) { if (params=="ShadowVolume" || params=="sv") technique = new osgShadow::ShadowVolume; else if (params=="ShadowTexture" || params=="st") technique = new osgShadow::ShadowTexture; else if (params=="ShadowMap" || params=="sm") technique = new osgShadow::ShadowMap; // else if (params=="ParallelSplitShadowMap" || params=="pssm") technique = new osgShadow::ParallelSplitShadowMap; else subFileName += std::string(".") + params; } // default fallback to using ShadowVolume if (!technique) technique = new osgShadow::ShadowVolume; // recursively load the subfile. osg::Node *node = osgDB::readNodeFile( subFileName, options ); if( !node ) { // propagate the read failure upwards OSG_WARN << "Subfile \"" << subFileName << "\" could not be loaded" << std::endl; return ReadResult::FILE_NOT_HANDLED; } osgShadow::ShadowedScene* shadowedScene = new osgShadow::ShadowedScene; shadowedScene->setShadowTechnique(technique.get()); shadowedScene->addChild( node ); return shadowedScene; }
virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { std::string ext = osgDB::getLowerCaseFileExtension(fileName); if( !acceptsExtension(ext) ) return ReadResult::FILE_NOT_HANDLED; OSG_INFO << "ReaderWriterSCALE( \"" << fileName << "\" )" << std::endl; // strip the pseudo-loader extension std::string tmpName = osgDB::getNameLessExtension( fileName ); if (tmpName.empty()) return ReadResult::FILE_NOT_HANDLED; std::string subFileName, params; if (!getFilenameAndParams(tmpName, subFileName, params)) { return ReadResult::FILE_NOT_HANDLED; } if( subFileName.empty()) { OSG_WARN << "Missing subfilename for " EXTENSION_NAME " pseudo-loader" << std::endl; return ReadResult::FILE_NOT_HANDLED; } OSG_INFO << " params = \"" << params << "\"" << std::endl; OSG_INFO << " subFileName = \"" << subFileName << "\"" << std::endl; float sx, sy, sz; int count = sscanf( params.c_str(), "%f,%f,%f", &sx, &sy, &sz ); if( count == 1 ) { // if only one value supplied, apply uniform scaling sy = sx; sz = sx; } else if( count != 3 ) { OSG_WARN << "Bad parameters for " EXTENSION_NAME " pseudo-loader: \"" << params << "\"" << std::endl; return ReadResult::FILE_NOT_HANDLED; } // recursively load the subfile. osg::Node *node = osgDB::readNodeFile( subFileName, options ); if( !node ) { // propagate the read failure upwards OSG_WARN << "Subfile \"" << subFileName << "\" could not be loaded" << std::endl; return ReadResult::FILE_NOT_HANDLED; } osg::MatrixTransform *xform = new osg::MatrixTransform; xform->setDataVariance( osg::Object::STATIC ); xform->setMatrix( osg::Matrix::scale( sx, sy, sz ) ); xform->addChild( node ); #ifndef OSG_GLES2_AVAILABLE // turn on GL_NORMALIZE to prevent problems with scaled normals osg::StateSet* ss = xform->getOrCreateStateSet(); ss->setMode( GL_NORMALIZE, osg::StateAttribute::ON ); #endif return xform; }