Changeset 8624

Show
Ignore:
Timestamp:
07/17/08 15:51:14
Author:
robert
Message:

From Ulrich Hertlein, "attached are some minor tweaks:

- fixed typos in osgViewer/ViewerBase
- const-ness in include/osg/View findSlaveIndexForCamera
- supported options for STL reader, fixed return values to reflect proper errors
- supported options for DirectX reader, fixed return values
- normals pseudo-loader: scaling normals to a const (but variable) fraction of the bounding sphere radius
"

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OpenSceneGraph/trunk/include/osg/View

    r7668 r8624  
    116116        bool addSlave(osg::Camera* camera, bool useMastersSceneData=true) { return addSlave(camera, osg::Matrix::identity(), osg::Matrix::identity(), useMastersSceneData); } 
    117117 
    118         bool addSlave(osg::Camera* camera, const osg::Matrix& projectionOffset, const osg::Matrix& viewOffse, bool useMastersSceneData=true); 
     118        bool addSlave(osg::Camera* camera, const osg::Matrix& projectionOffset, const osg::Matrix& viewOffset, bool useMastersSceneData=true); 
    119119 
    120120        bool removeSlave(unsigned int pos); 
     
    125125        const Slave& getSlave(unsigned int pos) const { return _slaves[pos]; } 
    126126 
    127         unsigned int findSlaveIndexForCamera(osg::Camera* camera)
     127        unsigned int findSlaveIndexForCamera(osg::Camera* camera) const
    128128 
    129129        Slave * findSlaveForCamera(osg::Camera* camera); 
  • OpenSceneGraph/trunk/include/osgViewer/ViewerBase

    r8406 r8624  
    9999         
    100100         /** Set the position of the end barrier. 
    101           * AfterSwapBuffers will may result is slightly higher framerates, by may 
     101          * AfterSwapBuffers may result in slightly higher framerates, but may 
    102102          * lead to inconsistent swapping between different windows. 
    103103          * BeforeSwapBuffers may lead to slightly lower framerate, but improve consistency in timing of swap buffers, 
  • OpenSceneGraph/trunk/src/osg/View.cpp

    r8439 r8624  
    213213} 
    214214 
    215 unsigned int View::findSlaveIndexForCamera(osg::Camera* camera) 
     215unsigned int View::findSlaveIndexForCamera(osg::Camera* camera) const 
    216216{ 
    217217    if (_camera == camera) return _slaves.size(); 
  • OpenSceneGraph/trunk/src/osgPlugins/normals/Normals.cpp

    r7648 r8624  
    55Normals::Normals( Node *node, float scale, Mode mode ) 
    66{ 
     7    setName(mode == VertexNormals ? "VertexNormals" : "SurfaceNormals"); 
     8 
    79    MakeNormalsVisitor mnv(scale,mode); 
    810    node->accept( mnv ); 
     
    109111                        _local_coords->push_back( v ); 
    110112                        _local_coords->push_back( (v + n)); 
    111  
    112113                    } 
    113114                    else  
     
    125126                                    else  
    126127                                        normals_index+=3; 
    127                                      
    128128                                } 
    129129                                break; 
     
    159159                            } 
    160160                            case(PrimitiveSet::QUAD_STRIP): 
     161                                break; 
     162 
    161163                            case(PrimitiveSet::POLYGON): 
    162                                 break; 
     164                            { 
     165                                DrawArrayLengths* dal = dynamic_cast<DrawArrayLengths*>((*itr).get()); 
     166                                if (dal) { 
     167                                    for (unsigned int j = 0; j < dal->size(); ++j) { 
     168                                        unsigned int num_prim = (*dal)[j]; 
     169                                        //notify(WARN) << "j=" << j << " num_prim=" << num_prim << std::endl; 
     170                                        _processPrimitive(num_prim, coord_index, normals_index, binding); 
     171                                        coord_index += num_prim; 
     172                                        if (binding == Geometry::BIND_PER_PRIMITIVE) { 
     173                                            ++normals_index; 
     174                                        } else { 
     175                                            normals_index += num_prim; 
     176                                        } 
     177                                    } 
     178                                } 
     179                                break; 
     180                            } 
     181 
    163182                            default: 
    164183                                break; 
     
    194213 
    195214        for( unsigned int i = 0; i < nv; i++ ) 
    196             v += *(coords++) * _mat; 
     215            v += *(coords++) * _mat; 
    197216        v /= (float)(nv); 
    198217 
  • OpenSceneGraph/trunk/src/osgPlugins/normals/ReaderWriterNormals.cpp

    r8578 r8624  
    4646                    if( opt == "help" || opt == "HELP" ) 
    4747                    { 
    48                         osg::notify( osg::INFO ) <<  
    49                             "Normals Plugin usage:  <application> [-O options] <model.ext>.normals\n" 
    50                             "     options: \"scale=<scale>\"                        (default = 1.0)\n" 
    51                             "              \"mode=<VertexNormals|SurfaceNormals>\"  (default = VertexNormals)" << std::endl; 
    52  
     48                        usage(); 
    5349                    } 
    5450                    else 
    5551                    { 
    56                         int index = opt.find( "=" ); 
    57                         if( opt.substr( 0, index ) == "scale" || 
    58                             opt.substr( 0, index ) == "SCALE" ) 
    59                         { 
    60                             scale = atof( opt.substr( index+1 ).c_str() ); 
    61                         } 
    62                         else if( opt.substr( 0, index ) == "mode" || opt.substr( 0, index ) == "MODE" ) 
    63                         { 
    64                             std::string modestr = opt.substr(index+1); 
    65                             if( modestr == "VertexNormals" ) 
    66                                 mode = Normals::VertexNormals; 
    67                             else if( modestr == "SurfaceNormals" ) 
    68                                 mode = Normals::SurfaceNormals; 
    69                             else 
    70                                 mode = Normals::VertexNormals; 
     52                        size_t index = opt.find( "=" ); 
     53                        if (index == std::string::npos) { 
     54                            usage(); 
     55                        } else { 
     56                            std::string key = opt.substr(0, index); 
     57                            std::string value = opt.substr(index+1); 
     58                            if( key == "scale" || key == "SCALE" ) 
     59                            { 
     60                                scale = atof( value.c_str() ); 
     61                            } 
     62                            else if( key == "mode" || key == "MODE" ) 
     63                            { 
     64                                if( value == "VertexNormals" ) 
     65                                    mode = Normals::VertexNormals; 
     66                                else if( value == "SurfaceNormals" ) 
     67                                    mode = Normals::SurfaceNormals; 
     68                                else 
     69                                    mode = Normals::VertexNormals; 
     70                            } 
    7171                        } 
    7272                    } 
     
    8282                    osg::ref_ptr<osg::Group> group = new osg::Group; 
    8383                    group->addChild( node.get() ); 
     84 
     85                    const osg::BoundingSphere& bsph = group->getBound(); 
     86                    scale = bsph.radius() * 0.05f * scale; // default is 5% of bounding-sphere radius 
     87 
    8488                    if( mode == Normals::VertexNormals )  
    8589                        group->addChild( new VertexNormals( node.get(), scale )); 
     
    9296            return 0L; 
    9397        } 
     98 
     99    private: 
     100        void usage() const { 
     101            osg::notify( osg::INFO ) <<  
     102                "Normals Plugin usage:  <application> [-O options] <model.ext>.normals\n" 
     103                "     options: \"scale=<scale>\"                        (default = 1.0)\n" 
     104                "              \"mode=<VertexNormals|SurfaceNormals>\"  (default = VertexNormals)" << std::endl; 
     105        } 
    94106}; 
    95107 
  • OpenSceneGraph/trunk/src/osgPlugins/stl/ReaderWriterSTL.cpp

    r8578 r8624  
    4848    ReaderWriterSTL() 
    4949    { 
    50         supportsExtension("stl","STL format"); 
    51         supportsExtension("sta","STL format"); 
     50        supportsExtension("stl","STL binary format"); 
     51        supportsExtension("sta","STL ASCII format"); 
     52        supportsOption("smooth", "run SmoothingVisitor"); 
    5253    } 
    5354 
     
    120121    // determine ASCII vs. binary mode 
    121122    FILE* fp = fopen(fileName.c_str(), "rb"); 
    122  
    123123    if (!fp) { 
    124         return ReadResult::FILE_NOT_HANDLED; 
     124        return ReadResult::FILE_NOT_FOUND; 
    125125    } 
    126126 
     
    131131    if (fread((void*) &header, sizeof(header), 1, fp) != 1) { 
    132132        fclose(fp); 
    133         return ReadResult::FILE_NOT_HANDLED
     133        return ReadResult::ERROR_IN_READING_FILE
    134134    } 
    135135    bool isBinary = false; 
     
    147147        osg::notify(osg::FATAL) << "ReaderWriterSTL::readNode: Unable to stat '" << fileName << "'" << std::endl; 
    148148        fclose(fp); 
    149         return ReadResult::FILE_NOT_HANDLED
     149        return ReadResult::ERROR_IN_READING_FILE
    150150    } 
    151151 
     
    164164        osg::notify(osg::FATAL) << "ReaderWriterSTL::readNode(" << fileName.c_str() << ") unable to determine file format" << std::endl; 
    165165        fclose(fp); 
    166         return ReadResult::FILE_NOT_HANDLED
     166        return ReadResult::ERROR_IN_READING_FILE
    167167    } 
    168168 
     
    205205    geode->addDrawable(geom); 
    206206     
    207     bool doSmoothing = false; 
    208      
    209     if (options && (options->getOptionString() == "smooth")) 
    210     { 
    211         doSmoothing = true; 
    212     }  
    213      
    214     if (doSmoothing) 
    215     { 
     207    if (options && (options->getOptionString() == "smooth")) { 
    216208        osgUtil::SmoothingVisitor smooter; 
    217209        geode->accept(smooter); 
  • OpenSceneGraph/trunk/src/osgPlugins/x/ReaderWriterDirectX.cpp

    r8578 r8624  
    5252    { 
    5353        supportsExtension("x","DirectX scene format"); 
     54        supportsOption("flipTexture", "flip texture upside-down"); 
    5455    } 
    5556 
    5657    virtual const char* className() const { 
    57         return "DirectX Reader/Writer"; 
     58        return "DirectX Reader"; 
    5859    } 
    5960 
     
    8586    // Load DirectX mesh 
    8687    DX::Object obj; 
    87     if (obj.load(fileName.c_str())) { 
    88  
    89         // code for setting up the database path so that internally referenced file are searched for on relative paths.  
    90         osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; 
    91         local_opt->setDatabasePath(osgDB::getFilePath(fileName)); 
    92  
    93         // Options? 
    94         bool flipTexture = true; 
    95         float creaseAngle = 80.0f; 
    96         if (options) { 
    97             const std::string option = options->getOptionString(); 
    98             if (option.find("flipTexture") != std::string::npos) 
    99                 flipTexture = false; 
    100             if (option.find("creaseAngle") != std::string::npos) { 
    101                 // TODO 
    102             } 
    103         } 
    104  
    105         // Convert to osg::Group 
    106         osg::Group* group = convertFromDX(obj, flipTexture, creaseAngle, local_opt.get()); 
    107         if (!group) 
    108             return ReadResult::FILE_NOT_HANDLED; 
    109  
    110         return group; 
    111     } 
    112  
    113     return ReadResult::FILE_NOT_HANDLED; 
     88    if (obj.load(fileName.c_str()) == false) { 
     89        return ReadResult::ERROR_IN_READING_FILE; 
     90    } 
     91 
     92    // code for setting up the database path so that internally referenced file are searched for on relative paths.  
     93    osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; 
     94    local_opt->setDatabasePath(osgDB::getFilePath(fileName)); 
     95 
     96    // Options? 
     97    bool flipTexture = true; 
     98    float creaseAngle = 80.0f; 
     99    if (options) { 
     100        const std::string option = options->getOptionString(); 
     101        if (option.find("flipTexture") != std::string::npos) { 
     102            flipTexture = false; 
     103        } 
     104        if (option.find("creaseAngle") != std::string::npos) { 
     105            // TODO 
     106        } 
     107    } 
     108 
     109    // Convert to osg::Group 
     110    osg::Group* group = convertFromDX(obj, flipTexture, creaseAngle, local_opt.get()); 
     111    if (!group) { 
     112        return ReadResult::ERROR_IN_READING_FILE; 
     113    } 
     114 
     115    return group; 
    114116} 
    115117 
     
    119121                                                const osgDB::ReaderWriter::Options * options) const 
    120122{ 
    121     osg::Group * group = new osg::Group; 
     123    osg::ref_ptr<osg::Group> group = new osg::Group; 
    122124 
    123125    for (unsigned int i = 0; i < obj.getNumMeshes(); ++i) { 
     
    125127        DX::Mesh & mesh = *obj.getMesh(i); 
    126128        osg::Geode * geode = convertFromDX(mesh, flipTexture, creaseAngle, options); 
    127         if (geode) 
    128             group->addChild(geode); 
    129     } 
    130  
    131     return group; 
     129        if (!geode) { 
     130            return 0; 
     131        } 
     132        group->addChild(geode); 
     133    } 
     134 
     135    return group.release(); 
    132136} 
    133137