diff --git a/include/osg/View b/include/osg/View index 0aeea8a3d..45166e517 100644 --- a/include/osg/View +++ b/include/osg/View @@ -115,7 +115,7 @@ class OSG_EXPORT View : public virtual osg::Object bool addSlave(osg::Camera* camera, bool useMastersSceneData=true) { return addSlave(camera, osg::Matrix::identity(), osg::Matrix::identity(), useMastersSceneData); } - bool addSlave(osg::Camera* camera, const osg::Matrix& projectionOffset, const osg::Matrix& viewOffse, bool useMastersSceneData=true); + bool addSlave(osg::Camera* camera, const osg::Matrix& projectionOffset, const osg::Matrix& viewOffset, bool useMastersSceneData=true); bool removeSlave(unsigned int pos); @@ -124,7 +124,7 @@ class OSG_EXPORT View : public virtual osg::Object Slave& getSlave(unsigned int pos) { return _slaves[pos]; } const Slave& getSlave(unsigned int pos) const { return _slaves[pos]; } - unsigned int findSlaveIndexForCamera(osg::Camera* camera); + unsigned int findSlaveIndexForCamera(osg::Camera* camera) const; Slave * findSlaveForCamera(osg::Camera* camera); diff --git a/include/osgViewer/ViewerBase b/include/osgViewer/ViewerBase index e042de489..0a17a9717 100644 --- a/include/osgViewer/ViewerBase +++ b/include/osgViewer/ViewerBase @@ -98,7 +98,7 @@ class OSGVIEWER_EXPORT ViewerBase : public virtual osg::Object }; /** Set the position of the end barrier. - * AfterSwapBuffers will may result is slightly higher framerates, by may + * AfterSwapBuffers may result in slightly higher framerates, but may * lead to inconsistent swapping between different windows. * BeforeSwapBuffers may lead to slightly lower framerate, but improve consistency in timing of swap buffers, * especially important if you are likely to consistently break frame.*/ diff --git a/src/osg/View.cpp b/src/osg/View.cpp index fc2e4b8ce..c81e0e6c3 100644 --- a/src/osg/View.cpp +++ b/src/osg/View.cpp @@ -212,7 +212,7 @@ View::Slave * View::findSlaveForCamera(osg::Camera* camera) return &(_slaves[i]); } -unsigned int View::findSlaveIndexForCamera(osg::Camera* camera) +unsigned int View::findSlaveIndexForCamera(osg::Camera* camera) const { if (_camera == camera) return _slaves.size(); diff --git a/src/osgPlugins/normals/Normals.cpp b/src/osgPlugins/normals/Normals.cpp index 7a7cc8df7..6c04e44e2 100644 --- a/src/osgPlugins/normals/Normals.cpp +++ b/src/osgPlugins/normals/Normals.cpp @@ -4,6 +4,8 @@ using namespace osg; Normals::Normals( Node *node, float scale, Mode mode ) { + setName(mode == VertexNormals ? "VertexNormals" : "SurfaceNormals"); + MakeNormalsVisitor mnv(scale,mode); node->accept( mnv ); @@ -108,7 +110,6 @@ void Normals::MakeNormalsVisitor::apply( Geode &geode ) n *= _normal_scale; _local_coords->push_back( v ); _local_coords->push_back( (v + n)); - } else { @@ -124,7 +125,6 @@ void Normals::MakeNormalsVisitor::apply( Geode &geode ) normals_index++; else normals_index+=3; - } break; } @@ -158,8 +158,27 @@ void Normals::MakeNormalsVisitor::apply( Geode &geode ) break; } case(PrimitiveSet::QUAD_STRIP): - case(PrimitiveSet::POLYGON): break; + + case(PrimitiveSet::POLYGON): + { + DrawArrayLengths* dal = dynamic_cast((*itr).get()); + if (dal) { + for (unsigned int j = 0; j < dal->size(); ++j) { + unsigned int num_prim = (*dal)[j]; + //notify(WARN) << "j=" << j << " num_prim=" << num_prim << std::endl; + _processPrimitive(num_prim, coord_index, normals_index, binding); + coord_index += num_prim; + if (binding == Geometry::BIND_PER_PRIMITIVE) { + ++normals_index; + } else { + normals_index += num_prim; + } + } + } + break; + } + default: break; } @@ -193,7 +212,7 @@ void Normals::MakeNormalsVisitor::_processPrimitive( unsigned int nv, } for( unsigned int i = 0; i < nv; i++ ) - v += *(coords++) * _mat; + v += *(coords++) * _mat; v /= (float)(nv); n *= _normal_scale; diff --git a/src/osgPlugins/normals/ReaderWriterNormals.cpp b/src/osgPlugins/normals/ReaderWriterNormals.cpp index a4d8199a7..4db1a3364 100644 --- a/src/osgPlugins/normals/ReaderWriterNormals.cpp +++ b/src/osgPlugins/normals/ReaderWriterNormals.cpp @@ -45,29 +45,29 @@ class NormalsReader: public osgDB::ReaderWriter { if( opt == "help" || opt == "HELP" ) { - osg::notify( osg::INFO ) << - "Normals Plugin usage: [-O options] .normals\n" - " options: \"scale=\" (default = 1.0)\n" - " \"mode=\" (default = VertexNormals)" << std::endl; - + usage(); } else { - int index = opt.find( "=" ); - if( opt.substr( 0, index ) == "scale" || - opt.substr( 0, index ) == "SCALE" ) - { - scale = atof( opt.substr( index+1 ).c_str() ); - } - else if( opt.substr( 0, index ) == "mode" || opt.substr( 0, index ) == "MODE" ) - { - std::string modestr = opt.substr(index+1); - if( modestr == "VertexNormals" ) - mode = Normals::VertexNormals; - else if( modestr == "SurfaceNormals" ) - mode = Normals::SurfaceNormals; - else - mode = Normals::VertexNormals; + size_t index = opt.find( "=" ); + if (index == std::string::npos) { + usage(); + } else { + std::string key = opt.substr(0, index); + std::string value = opt.substr(index+1); + if( key == "scale" || key == "SCALE" ) + { + scale = atof( value.c_str() ); + } + else if( key == "mode" || key == "MODE" ) + { + if( value == "VertexNormals" ) + mode = Normals::VertexNormals; + else if( value == "SurfaceNormals" ) + mode = Normals::SurfaceNormals; + else + mode = Normals::VertexNormals; + } } } } @@ -81,6 +81,10 @@ class NormalsReader: public osgDB::ReaderWriter { osg::ref_ptr group = new osg::Group; group->addChild( node.get() ); + + const osg::BoundingSphere& bsph = group->getBound(); + scale = bsph.radius() * 0.05f * scale; // default is 5% of bounding-sphere radius + if( mode == Normals::VertexNormals ) group->addChild( new VertexNormals( node.get(), scale )); else if( mode == Normals::SurfaceNormals ) @@ -91,6 +95,14 @@ class NormalsReader: public osgDB::ReaderWriter } return 0L; } + + private: + void usage() const { + osg::notify( osg::INFO ) << + "Normals Plugin usage: [-O options] .normals\n" + " options: \"scale=\" (default = 1.0)\n" + " \"mode=\" (default = VertexNormals)" << std::endl; + } }; REGISTER_OSGPLUGIN(normals, NormalsReader) diff --git a/src/osgPlugins/stl/ReaderWriterSTL.cpp b/src/osgPlugins/stl/ReaderWriterSTL.cpp index 690871ce5..efc0b886d 100644 --- a/src/osgPlugins/stl/ReaderWriterSTL.cpp +++ b/src/osgPlugins/stl/ReaderWriterSTL.cpp @@ -47,8 +47,9 @@ class ReaderWriterSTL : public osgDB::ReaderWriter public: ReaderWriterSTL() { - supportsExtension("stl","STL format"); - supportsExtension("sta","STL format"); + supportsExtension("stl","STL binary format"); + supportsExtension("sta","STL ASCII format"); + supportsOption("smooth", "run SmoothingVisitor"); } virtual const char* className() const { @@ -119,9 +120,8 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& fil // determine ASCII vs. binary mode FILE* fp = fopen(fileName.c_str(), "rb"); - if (!fp) { - return ReadResult::FILE_NOT_HANDLED; + return ReadResult::FILE_NOT_FOUND; } ReaderObject readerObject; @@ -130,7 +130,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& fil StlHeader header; if (fread((void*) &header, sizeof(header), 1, fp) != 1) { fclose(fp); - return ReadResult::FILE_NOT_HANDLED; + return ReadResult::ERROR_IN_READING_FILE; } bool isBinary = false; @@ -146,7 +146,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& fil { osg::notify(osg::FATAL) << "ReaderWriterSTL::readNode: Unable to stat '" << fileName << "'" << std::endl; fclose(fp); - return ReadResult::FILE_NOT_HANDLED; + return ReadResult::ERROR_IN_READING_FILE; } if (stb.st_size == expectLen) @@ -163,7 +163,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& fil else { osg::notify(osg::FATAL) << "ReaderWriterSTL::readNode(" << fileName.c_str() << ") unable to determine file format" << std::endl; fclose(fp); - return ReadResult::FILE_NOT_HANDLED; + return ReadResult::ERROR_IN_READING_FILE; } if (!isBinary) @@ -204,15 +204,7 @@ osgDB::ReaderWriter::ReadResult ReaderWriterSTL::readNode(const std::string& fil osg::Geode* geode = new osg::Geode; geode->addDrawable(geom); - bool doSmoothing = false; - - if (options && (options->getOptionString() == "smooth")) - { - doSmoothing = true; - } - - if (doSmoothing) - { + if (options && (options->getOptionString() == "smooth")) { osgUtil::SmoothingVisitor smooter; geode->accept(smooter); } diff --git a/src/osgPlugins/x/ReaderWriterDirectX.cpp b/src/osgPlugins/x/ReaderWriterDirectX.cpp index afa2f79d0..48cdac55c 100644 --- a/src/osgPlugins/x/ReaderWriterDirectX.cpp +++ b/src/osgPlugins/x/ReaderWriterDirectX.cpp @@ -51,10 +51,11 @@ public: ReaderWriterDirectX() { supportsExtension("x","DirectX scene format"); + supportsOption("flipTexture", "flip texture upside-down"); } virtual const char* className() const { - return "DirectX Reader/Writer"; + return "DirectX Reader"; } virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const; @@ -84,33 +85,34 @@ osgDB::ReaderWriter::ReadResult ReaderWriterDirectX::readNode(const std::string& // Load DirectX mesh DX::Object obj; - if (obj.load(fileName.c_str())) { - - // code for setting up the database path so that internally referenced file are searched for on relative paths. - osg::ref_ptr local_opt = options ? static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; - local_opt->setDatabasePath(osgDB::getFilePath(fileName)); - - // Options? - bool flipTexture = true; - float creaseAngle = 80.0f; - if (options) { - const std::string option = options->getOptionString(); - if (option.find("flipTexture") != std::string::npos) - flipTexture = false; - if (option.find("creaseAngle") != std::string::npos) { - // TODO - } - } - - // Convert to osg::Group - osg::Group* group = convertFromDX(obj, flipTexture, creaseAngle, local_opt.get()); - if (!group) - return ReadResult::FILE_NOT_HANDLED; - - return group; + if (obj.load(fileName.c_str()) == false) { + return ReadResult::ERROR_IN_READING_FILE; } - return ReadResult::FILE_NOT_HANDLED; + // code for setting up the database path so that internally referenced file are searched for on relative paths. + osg::ref_ptr local_opt = options ? static_cast(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; + local_opt->setDatabasePath(osgDB::getFilePath(fileName)); + + // Options? + bool flipTexture = true; + float creaseAngle = 80.0f; + if (options) { + const std::string option = options->getOptionString(); + if (option.find("flipTexture") != std::string::npos) { + flipTexture = false; + } + if (option.find("creaseAngle") != std::string::npos) { + // TODO + } + } + + // Convert to osg::Group + osg::Group* group = convertFromDX(obj, flipTexture, creaseAngle, local_opt.get()); + if (!group) { + return ReadResult::ERROR_IN_READING_FILE; + } + + return group; } // Convert DirectX object @@ -118,17 +120,19 @@ osg::Group * ReaderWriterDirectX::convertFromDX(DX::Object & obj, bool flipTexture, float creaseAngle, const osgDB::ReaderWriter::Options * options) const { - osg::Group * group = new osg::Group; + osg::ref_ptr group = new osg::Group; for (unsigned int i = 0; i < obj.getNumMeshes(); ++i) { //std::cerr << "converting mesh " << i << std::endl; DX::Mesh & mesh = *obj.getMesh(i); osg::Geode * geode = convertFromDX(mesh, flipTexture, creaseAngle, options); - if (geode) - group->addChild(geode); + if (!geode) { + return 0; + } + group->addChild(geode); } - return group; + return group.release(); } // Convert DirectX mesh to osg::Geode