Changeset 8286

Show
Ignore:
Timestamp:
05/08/08 15:56:28
Author:
robert
Message:

From Paul Martz, "As I discovered prior to the 2.4 release, the FLT export geometry backend was using some old turn-on code, originally written just to enable other development but not intended for actual release. Sadly, my OSG training commitments prevented me from fixing this prior to 2.4.


In essence, the FLT exporter was emitting a full set of Mesh records each time it encountered a PrimitiveSet?.

Attached is a fix. The code now emits the Mesh set up records, then iterates over all PrimitiveSets? and emits a Mesh Primitive record per PrimitiveSet?.

It also loops over PrimitiveSets? twice, first writing Face records according to the mode, the writing Mesh records (again according to the mode).

The final change included here is support for GL_POINTS as single-vertex Face records.

Billboards are still to come."

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/FltExportVisitor.cpp

    r8018 r8286  
    357357        ScopedStatePushPop drawableGuard( this, geom->getStateSet() ); 
    358358 
    359         // Write vertex array data out to vertex palette manager 
    360         if (!isAllMesh( *geom )) 
     359        // Push and pop subfaces if polygon offset is on. 
     360        SubfaceHelper subface( *this, getCurrentStateSet() ); 
     361 
     362        if (atLeastOneFace( *geom )) 
     363        { 
    361364            // If at least one record will be a Face record, then we 
    362             //   need to write to the vertex pool
     365            //   need to write to the vertex palette
    363366            _vertexPalette->add( *geom ); 
    364367 
    365         unsigned int jdx; 
    366         for (jdx=0; jdx < geom->getNumPrimitiveSets(); jdx++) 
    367         { 
    368             osg::PrimitiveSet* prim = geom->getPrimitiveSet( jdx ); 
    369             if (prim->getType() == osg::PrimitiveSet::DrawArraysPrimitiveType) 
    370                 handleDrawArrays( dynamic_cast<osg::DrawArrays*>( prim ), *geom, node ); 
    371             else if (prim->getType() == osg::PrimitiveSet::DrawArrayLengthsPrimitiveType) 
    372                 handleDrawArrayLengths( dynamic_cast<osg::DrawArrayLengths*>( prim ), *geom, node ); 
    373             else if ( (prim->getType() == osg::PrimitiveSet::DrawElementsUBytePrimitiveType) || 
    374                     (prim->getType() == osg::PrimitiveSet::DrawElementsUShortPrimitiveType) || 
    375                     (prim->getType() == osg::PrimitiveSet::DrawElementsUIntPrimitiveType) ) 
    376                 handleDrawElements( dynamic_cast<osg::DrawElements*>( prim ), *geom, node ); 
    377             else 
     368            // Iterate over all PrimitiveSets and output Face records. 
     369            unsigned int jdx; 
     370            for (jdx=0; jdx < geom->getNumPrimitiveSets(); jdx++) 
    378371            { 
    379                 std::string warning( "fltexp: Unknown PrimitiveSet type." ); 
    380                 osg::notify( osg::WARN ) << warning << std::endl; 
    381                 _fltOpt->getWriteResult().warn( warning ); 
    382                 return; 
     372                osg::PrimitiveSet* prim = geom->getPrimitiveSet( jdx ); 
     373                if ( isMesh( prim->getMode() ) ) 
     374                    continue; 
     375 
     376                if (prim->getType() == osg::PrimitiveSet::DrawArraysPrimitiveType) 
     377                    handleDrawArrays( dynamic_cast<osg::DrawArrays*>( prim ), *geom, node ); 
     378                else if (prim->getType() == osg::PrimitiveSet::DrawArrayLengthsPrimitiveType) 
     379                    handleDrawArrayLengths( dynamic_cast<osg::DrawArrayLengths*>( prim ), *geom, node ); 
     380                else if ( (prim->getType() == osg::PrimitiveSet::DrawElementsUBytePrimitiveType) || 
     381                        (prim->getType() == osg::PrimitiveSet::DrawElementsUShortPrimitiveType) || 
     382                        (prim->getType() == osg::PrimitiveSet::DrawElementsUIntPrimitiveType) ) 
     383                    handleDrawElements( dynamic_cast<osg::DrawElements*>( prim ), *geom, node ); 
     384                else 
     385                { 
     386                    std::string warning( "fltexp: Unknown PrimitiveSet type." ); 
     387                    osg::notify( osg::WARN ) << warning << std::endl; 
     388                    _fltOpt->getWriteResult().warn( warning ); 
     389                    return; 
     390                } 
    383391            } 
     392        } 
     393 
     394        if (atLeastOneMesh( *geom )) 
     395        { 
     396            // If at least one Mesh record, write out preamble mesh records 
     397            //   followed by a Mesh Primitive record per PrimitiveSet. 
     398            writeMesh( node, *geom ); 
     399 
     400            writeMatrix( node.getUserData() ); 
     401            writeComment( node ); 
     402            writeMultitexture( *geom ); 
     403            writeLocalVertexPool( *geom ); 
     404 
     405            writePush(); 
     406 
     407            unsigned int jdx; 
     408            for (jdx=0; jdx < geom->getNumPrimitiveSets(); jdx++) 
     409            { 
     410                osg::PrimitiveSet* prim = geom->getPrimitiveSet( jdx ); 
     411                if ( !isMesh( prim->getMode() ) ) 
     412                    continue; 
     413 
     414                if (prim->getType() == osg::PrimitiveSet::DrawArraysPrimitiveType) 
     415                    handleDrawArrays( dynamic_cast<osg::DrawArrays*>( prim ), *geom, node ); 
     416                else if (prim->getType() == osg::PrimitiveSet::DrawArrayLengthsPrimitiveType) 
     417                    handleDrawArrayLengths( dynamic_cast<osg::DrawArrayLengths*>( prim ), *geom, node ); 
     418                else if ( (prim->getType() == osg::PrimitiveSet::DrawElementsUBytePrimitiveType) || 
     419                        (prim->getType() == osg::PrimitiveSet::DrawElementsUShortPrimitiveType) || 
     420                        (prim->getType() == osg::PrimitiveSet::DrawElementsUIntPrimitiveType) ) 
     421                    handleDrawElements( dynamic_cast<osg::DrawElements*>( prim ), *geom, node ); 
     422                else 
     423                { 
     424                    std::string warning( "fltexp: Unknown PrimitiveSet type." ); 
     425                    osg::notify( osg::WARN ) << warning << std::endl; 
     426                    _fltOpt->getWriteResult().warn( warning ); 
     427                    return; 
     428                } 
     429            } 
     430 
     431            writePop(); 
    384432        } 
    385433    } 
  • OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/FltExportVisitor.h

    r8003 r8286  
    125125    // Geometry records 
    126126    void writeFace( const osg::Geode& geode, const osg::Geometry& geom, GLenum mode ); 
    127     void writeMesh( const osg::Geode& geode, const osg::Geometry& geom, GLenum mode ); 
     127    void writeMesh( const osg::Geode& geode, const osg::Geometry& geom ); 
    128128    int writeVertexList( int first, unsigned int count ); 
    129129    int writeVertexList( const std::vector<unsigned int>& indices, unsigned int count ); 
    130130    void writeMeshPrimitive( const std::vector<unsigned int>& indices, GLenum mode ); 
    131     void writeLocalVertexPool( const osg::Geometry& geom, GLenum mode ); 
     131    void writeLocalVertexPool( const osg::Geometry& geom ); 
    132132    void writeMultitexture( const osg::Geometry& geom ); 
    133133    void writeUVList( int numVerts, const osg::Geometry& geom ); 
     
    159159    bool isLit( const osg::Geometry& geom ) const; 
    160160    bool isTextured( int unit, const osg::Geometry& geom ) const; 
    161     bool isAllMesh( const osg::Geometry& geom ) const; 
     161    bool isMesh( const GLenum mode ) const; 
     162    bool atLeastOneFace( const osg::Geometry& geom ) const; 
     163    bool atLeastOneMesh( const osg::Geometry& geom ) const; 
    162164 
    163165    osg::ref_ptr< ExportOptions > _fltOpt; 
  • OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/expGeometryRecords.cpp

    r8086 r8286  
    6868 
    6969bool 
    70 FltExportVisitor::isAllMesh( const osg::Geometry& geom ) const 
    71 
    72     // Return true if all primitive types will use Mesh records for output. 
     70FltExportVisitor::isMesh( const GLenum mode ) const 
     71
     72    return( (mode == GL_TRIANGLE_STRIP) || 
     73        (mode == GL_TRIANGLE_FAN) || 
     74        (mode == GL_QUAD_STRIP) ); 
     75
     76 
     77bool 
     78FltExportVisitor::atLeastOneFace( const osg::Geometry& geom ) const 
     79
     80    // Return true if at least one PrimitiveSet mode will use a Face record. 
    7381    unsigned int jdx; 
    7482    for (jdx=0; jdx < geom.getNumPrimitiveSets(); jdx++) 
    7583    { 
    7684        const osg::PrimitiveSet* prim = geom.getPrimitiveSet( jdx ); 
    77         if( (prim->getMode() != GL_TRIANGLE_STRIP) && 
    78             (prim->getMode() != GL_TRIANGLE_FAN) && 
    79             (prim->getMode() != GL_QUAD_STRIP) ) 
    80             return false; 
    81     } 
    82     return true; 
     85        if( !isMesh( prim->getMode() ) ) 
     86            return true; 
     87    } 
     88    // All PrimitiveSet modes will use Mesh records. 
     89    return false; 
     90
     91bool 
     92FltExportVisitor::atLeastOneMesh( const osg::Geometry& geom ) const 
     93
     94    // Return true if at least one PrimitiveSet mode will use a Mesh record. 
     95    unsigned int jdx; 
     96    for (jdx=0; jdx < geom.getNumPrimitiveSets(); jdx++) 
     97    { 
     98        const osg::PrimitiveSet* prim = geom.getPrimitiveSet( jdx ); 
     99        if( isMesh( prim->getMode() ) ) 
     100            return true; 
     101    } 
     102    // All PrimitiveSet modes will use Face records. 
     103    return false; 
    83104} 
    84105 
     
    283304 
    284305void 
    285 FltExportVisitor::writeMesh( const osg::Geode& geode, const osg::Geometry& geom, GLenum mode
     306FltExportVisitor::writeMesh( const osg::Geode& geode, const osg::Geometry& geom
    286307{ 
    287308    enum DrawMode 
     
    355376    osg::StateSet const* ss = getCurrentStateSet(); 
    356377 
    357     switch( mode ) 
    358     { 
    359     case GL_POINTS: 
    360     { 
    361         std::string warning( "fltexp: GL_POINTS not supported in FLT export." ); 
    362         osg::notify( osg::WARN ) << warning << std::endl; 
    363         _fltOpt->getWriteResult().warn( warning ); 
    364         return; 
    365         break; 
    366     } 
    367     case GL_LINES: 
    368     case GL_LINE_STRIP: 
    369     case GL_LINE_LOOP: 
    370     case GL_TRIANGLES: 
    371     case GL_QUADS: 
    372     { 
    373         std::string warning( "fltexp: Wrong mode in Mesh record." ); 
    374         osg::notify( osg::WARN ) << warning << std::endl; 
    375         _fltOpt->getWriteResult().warn( warning ); 
    376         return; 
    377         break; 
    378     } 
    379     case GL_TRIANGLE_STRIP: 
    380     case GL_TRIANGLE_FAN: 
    381     case GL_QUAD_STRIP: 
    382     case GL_POLYGON: 
    383378    { 
    384379        // Default to no facet culling 
     
    395390            // Note: OpenFlt can't handle FRONT or FRONT_AND_BACK settings, so ignore these(??) 
    396391        } 
    397         break; 
    398     } 
    399392    } 
    400393 
     
    545538 
    546539void 
    547 FltExportVisitor::writeLocalVertexPool( const osg::Geometry& geom, GLenum mode
     540FltExportVisitor::writeLocalVertexPool( const osg::Geometry& geom
    548541{ 
    549542    // Attribute Mask 
     
    837830        break; 
    838831    case GL_POINTS: 
     832        n = 1; 
     833        break; 
     834    case GL_LINES: 
     835        n = 2; 
     836        break; 
     837    case GL_TRIANGLES: 
     838        n = 3; 
     839        break; 
     840    case GL_QUADS: 
     841        n = 4; 
     842        break; 
    839843    case GL_LINE_STRIP: 
    840844    case GL_LINE_LOOP: 
     
    843847        n = count; 
    844848        break; 
    845     case GL_LINES: 
    846         n = 2; 
    847         break; 
    848     case GL_TRIANGLES: 
    849         n = 3; 
    850         break; 
    851     case GL_QUADS: 
    852         n = 4; 
    853         break; 
    854     } 
    855  
    856     // Push and pop subfaces if polygon offset is on. 
    857     SubfaceHelper subface( *this, getCurrentStateSet() ); 
     849    } 
    858850 
    859851    if (useMesh) 
    860852    { 
    861         writeMesh( geode, geom, mode ); 
    862  
    863         writeMatrix( geode.getUserData() ); 
    864         writeComment( geode ); 
    865         writeMultitexture( geom ); 
    866         writeLocalVertexPool( geom, mode ); 
    867  
    868         writePush(); 
    869  
    870853        std::vector< unsigned int > indices; 
    871854        int jdx; 
     
    873856            indices.push_back( first+jdx ); 
    874857        writeMeshPrimitive( indices, mode ); 
    875  
    876         writePop(); 
    877858    } 
    878859    else 
     
    881862        while ((unsigned int)( first+n ) <= max) 
    882863        { 
    883             // Need: 
    884             // * Geode for record name (but also need to handle 
    885             //   multi Geometry objects and multi PrimitiveSet objects; 
    886             //   all Face records can't have the same name). 
    887             // * Mode 
    888864            writeFace( geode, geom, mode ); 
    889865 
     
    920896        break; 
    921897    case GL_POINTS: 
     898        n = 1; 
     899        break; 
     900    case GL_LINES: 
     901        n = 2; 
     902        break; 
     903    case GL_TRIANGLES: 
     904        n = 3; 
     905        break; 
     906    case GL_QUADS: 
     907        n = 4; 
     908        break; 
    922909    case GL_LINE_STRIP: 
    923910    case GL_LINE_LOOP: 
     
    925912    default: 
    926913        break; 
    927     case GL_LINES: 
    928         n = 2; 
    929         break; 
    930     case GL_TRIANGLES: 
    931         n = 3; 
    932         break; 
    933     case GL_QUADS: 
    934         n = 4; 
    935         break; 
    936914    } 
    937915 
     
    941919    if (useMesh) 
    942920    { 
    943         writeMesh( geode, geom, mode ); 
    944  
    945         writeMatrix( geode.getUserData() ); 
    946         writeComment( geode ); 
    947         writeMultitexture( geom ); 
    948         writeLocalVertexPool( geom, mode ); 
    949  
    950         writePush(); 
    951  
    952921        int idx( 0 ); 
    953922        for( osg::DrawArrayLengths::const_iterator itr=dal->begin(); 
     
    960929            writeMeshPrimitive( indices, mode ); 
    961930        } 
    962  
    963         writePop(); 
    964931    } 
    965932    else 
     
    1017984        break; 
    1018985    case GL_POINTS: 
     986        n = 1; 
     987        break; 
     988    case GL_LINES: 
     989        n = 2; 
     990        break; 
     991    case GL_TRIANGLES: 
     992        n = 3; 
     993        break; 
     994    case GL_QUADS: 
     995        n = 4; 
     996        break; 
    1019997    case GL_LINE_STRIP: 
    1020998    case GL_LINE_LOOP: 
     
    10231001        n = de->getNumIndices(); 
    10241002        break; 
    1025     case GL_LINES: 
    1026         n = 2; 
    1027         break; 
    1028     case GL_TRIANGLES: 
    1029         n = 3; 
    1030         break; 
    1031     case GL_QUADS: 
    1032         n = 4; 
    1033         break; 
    10341003    } 
    10351004 
     
    10391008    if (useMesh) 
    10401009    { 
    1041         writeMesh( geode, geom, mode ); 
    1042  
    1043         writeMatrix( geode.getUserData() ); 
    1044         writeComment( geode ); 
    1045         writeMultitexture( geom ); 
    1046         writeLocalVertexPool( geom, mode ); 
    1047  
    1048         writePush(); 
    1049  
    10501010        std::vector< unsigned int > indices; 
    10511011        int idx; 
     
    10531013            indices.push_back( de->index( idx ) ); 
    10541014        writeMeshPrimitive( indices, mode ); 
    1055  
    1056         writePop(); 
    10571015    } 
    10581016    else