Changeset 8003

Show
Ignore:
Timestamp:
03/28/08 13:44:33 (6 years ago)
Author:
robert
Message:

From Paul Martz, "Here's the mods to the OpenFlight? plugin to support FLT export. The ZIP file contains the new .cpp/h files as well as existing files that I modified.


Changes to existing files:

ReaderWriter?.cpp -- to support writeNode() of course.
ReaderWriterATTR.cpp -- to support writeObject -- we write .attr files for textures, if they don't already exist.
AttrData?.cpp/.h -- Minor fixes.
CMakeLists.txt -- to include the new files in the build."


From Robert Osfield, port to non Windows platforms just required fixing of header capitilization errors
that windows lets through the net due to having a case insensitive file system.


Location:
OpenSceneGraph/trunk/src/osgPlugins/OpenFlight
Files:
22 added
10 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/AttrData.cpp

    r7748 r8003  
    2525AttrData::AttrData() : 
    2626    texels_u(0), 
    27     textel_v(0), 
     27    texels_v(0), 
    2828    direction_u(0), 
    2929    direction_v(0), 
  • OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/AttrData.h

    r7748 r8003  
    2323#include <string> 
    2424#include <osg/Object> 
    25 #include "types.h" 
     25#include "Types.h" 
    2626 
    2727namespace flt { 
     
    113113   
    114114        int32   texels_u;               // Number of texels in u direction 
    115         int32   textel_v;               // Number of texels in v direction 
     115        int32   texels_v;               // Number of texels in v direction 
    116116        int32   direction_u;            // Real world size u direction 
    117117        int32   direction_v;            // Real world size v direction 
     
    329329        } 
    330330    #endif 
     331        int32   numSubtextures;             // # of subtextures 
    331332 
    332333}; 
  • OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/CMakeLists.txt

    r7281 r8003  
    77    ControlRecords.cpp 
    88    DataInputStream.cpp 
     9    DataOutputStream.cpp 
    910    Document.cpp 
     11    expAncillaryRecords.cpp 
     12    expControlRecords.cpp 
     13    expGeometryRecords.cpp 
     14    expPrimaryRecords.cpp 
     15    ExportOptions.cpp 
     16    FltExportVisitor.cpp 
    1017    GeometryRecords.cpp 
    1118    LightPointRecords.cpp 
     19    LightSourcePaletteManager.cpp 
     20    MaterialPaletteManager.cpp 
    1221    PaletteRecords.cpp 
    1322    Pools.cpp 
     
    2029    ReservedRecords.cpp 
    2130    RoadRecords.cpp 
     31    TexturePaletteManager.cpp 
    2232    Vertex.cpp 
     33    VertexPaletteManager.cpp 
    2334    VertexRecords.cpp 
    2435) 
     
    2738    AttrData.h 
    2839    DataInputStream.h 
     40    DataOutputStream.h 
     41    ExportOptions.h 
     42    FltExportVisitor.h 
     43    FltWriteResult.h 
    2944    Document.h 
     45    LightSourcePaletteManager.h 
     46    MaterialPaletteManager.h 
    3047    Pools.h 
    3148    Record.h 
    3249    RecordInputStream.h 
    3350    Registry.h 
     51    TexturePaletteManager.h 
    3452    Vertex.h 
    35     opcodes.h 
    36     types.h 
     53    VertexPaletteManager.h 
     54    Opcodes.h 
     55    Types.h 
     56    Utils.h 
    3757) 
    3858 
  • OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/DataInputStream.h

    r7748 r8003  
    2626#include <osg/Vec3d> 
    2727#include <osg/Vec4f> 
    28 #include "types.h"     
     28#include "Types.h"     
    2929 
    3030namespace flt { 
  • OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/Document.h

    r7931 r8003  
    2727#include <osgDB/ReaderWriter> 
    2828 
    29 #include "types.h" 
     29#include "Types.h" 
    3030#include "Record.h" 
    3131#include "Pools.h" 
  • OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/Pools.h

    r7748 r8003  
    2929#include <osg/Light> 
    3030#include <osg/Program> 
    31 #include "types.h" 
     31#include "Types.h" 
    3232 
    3333 
  • OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/ReaderWriterATTR.cpp

    r7919 r8003  
    3030#include "AttrData.h" 
    3131#include "DataInputStream.h" 
     32#include "DataOutputStream.h" 
    3233 
    3334using namespace osg; 
     
    4849 
    4950        virtual ReadResult readObject(const std::string& fileName, const ReaderWriter::Options*) const; 
     51        virtual ReaderWriter::WriteResult writeObject(const osg::Object& object, const std::string& fileName, const Options* options) const; 
    5052}; 
    5153 
     
    7577    { 
    7678        attr->texels_u  = in.readInt32(); 
    77         attr->textel_v  = in.readInt32(); 
     79        attr->texels_v  = in.readInt32(); 
    7880        attr->direction_u  = in.readInt32(); 
    7981        attr->direction_v  = in.readInt32(); 
     
    171173        attr->attrVersion = in.readInt32(); 
    172174        attr->controlPoints = in.readInt32(); 
    173         in.forward(4); 
     175        attr->numSubtextures = in.readInt32(); 
    174176#endif 
    175177    } 
     
    188190 
    189191 
     192ReaderWriter::WriteResult 
     193ReaderWriterATTR::writeObject(const osg::Object& object, const std::string& fileName, const Options* options) const 
     194{ 
     195    using std::ios; 
     196 
     197    std::string ext = osgDB::getLowerCaseFileExtension( fileName ); 
     198    if (!acceptsExtension(ext)) return WriteResult::FILE_NOT_HANDLED; 
     199 
     200    const AttrData* attr = dynamic_cast< const AttrData* >( &object ); 
     201    if (attr == NULL) 
     202    { 
     203        osg::notify( osg::FATAL ) << "AttrWriter: Invalid Object." << std::endl; 
     204        return WriteResult::FILE_NOT_HANDLED; 
     205    } 
     206 
     207    std::ofstream fOut; 
     208    fOut.open( fileName.c_str(), std::ios::out | std::ios::binary ); 
     209 
     210    if ( fOut.fail()) 
     211        return WriteResult::ERROR_IN_WRITING_FILE; 
     212 
     213    flt::DataOutputStream out( fOut.rdbuf() ); 
     214 
     215 
     216    out.writeInt32( attr->texels_u ); 
     217    out.writeInt32( attr->texels_v ); 
     218    out.writeInt32( attr->direction_u ); 
     219    out.writeInt32( attr->direction_v ); 
     220    out.writeInt32( attr->x_up ); 
     221    out.writeInt32( attr->y_up ); 
     222    out.writeInt32( attr->fileFormat ); 
     223    out.writeInt32( attr->minFilterMode ); 
     224    out.writeInt32( attr->magFilterMode ); 
     225    out.writeInt32( attr->wrapMode ); 
     226 
     227    out.writeInt32( attr->wrapMode_u ); 
     228    out.writeInt32( attr->wrapMode_v ); 
     229 
     230    out.writeInt32( attr->modifyFlag ); 
     231    out.writeInt32( attr->pivot_x ); 
     232    out.writeInt32( attr->pivot_y ); 
     233 
     234    out.writeInt32( attr->texEnvMode ); 
     235    out.writeInt32( attr->intensityAsAlpha ); 
     236    out.writeFill( 4*8 ); 
     237    out.writeFloat64( attr->size_u ); 
     238    out.writeFloat64( attr->size_v ); 
     239    out.writeInt32( attr->originCode ); 
     240    out.writeInt32( attr->kernelVersion ); 
     241    out.writeInt32( attr->intFormat ); 
     242    out.writeInt32( attr->extFormat ); 
     243    out.writeInt32( attr->useMips ); 
     244    for (int n=0; n<8; n++) 
     245        out.writeFloat32( attr->of_mips[n] ); 
     246    out.writeInt32( attr->useLodScale ); 
     247    out.writeFloat32( attr->lod0 ); 
     248    out.writeFloat32( attr->scale0 ); 
     249    out.writeFloat32( attr->lod1 ); 
     250    out.writeFloat32( attr->scale1 ); 
     251    out.writeFloat32( attr->lod2 ); 
     252    out.writeFloat32( attr->scale2 ); 
     253    out.writeFloat32( attr->lod3 ); 
     254    out.writeFloat32( attr->scale3 ); 
     255    out.writeFloat32( attr->lod4 ); 
     256    out.writeFloat32( attr->scale4 ); 
     257    out.writeFloat32( attr->lod5 ); 
     258    out.writeFloat32( attr->scale5 ); 
     259    out.writeFloat32( attr->lod6 ); 
     260    out.writeFloat32( attr->scale6 ); 
     261    out.writeFloat32( attr->lod7 ); 
     262    out.writeFloat32( attr->scale7 ); 
     263    out.writeFloat32( attr->clamp ); 
     264    out.writeInt32( attr->magFilterAlpha ); 
     265    out.writeInt32( attr->magFilterColor ); 
     266    out.writeFill( 4 ); 
     267    out.writeFill( 4*8 ); 
     268    out.writeFloat64( attr->lambertMeridian ); 
     269    out.writeFloat64( attr->lambertUpperLat ); 
     270    out.writeFloat64( attr->lambertlowerLat ); 
     271    out.writeFill( 8 ); 
     272    out.writeFill( 4*5 ); 
     273    out.writeInt32( attr->useDetail ); 
     274    out.writeInt32( attr->txDetail_j ); 
     275    out.writeInt32( attr->txDetail_k ); 
     276    out.writeInt32( attr->txDetail_m ); 
     277    out.writeInt32( attr->txDetail_n ); 
     278    out.writeInt32( attr->txDetail_s ); 
     279    out.writeInt32( attr->useTile ); 
     280    out.writeFloat32( attr->txTile_ll_u ); 
     281    out.writeFloat32( attr->txTile_ll_v ); 
     282    out.writeFloat32( attr->txTile_ur_u ); 
     283    out.writeFloat32( attr->txTile_ur_v ); 
     284    out.writeInt32( attr->projection ); 
     285    out.writeInt32( attr->earthModel ); 
     286    out.writeFill( 4 ); 
     287    out.writeInt32( attr->utmZone ); 
     288    out.writeInt32( attr->imageOrigin ); 
     289    out.writeInt32( attr->geoUnits ); 
     290    out.writeFill( 4 ); 
     291    out.writeFill( 4 ); 
     292    out.writeInt32( attr->hemisphere ); 
     293    out.writeFill( 4 ); 
     294    out.writeFill( 4 ); 
     295    out.writeFill( 149*4 ); 
     296    out.writeString( attr->comments, 512 ); 
     297 
     298    out.writeFill( 13*4 ); 
     299    out.writeInt32( attr->attrVersion ); 
     300    out.writeInt32( attr->controlPoints ); 
     301    out.writeInt32( attr->numSubtextures ); 
     302 
     303 
     304    fOut.close(); 
     305 
     306    return WriteResult::FILE_SAVED; 
     307} 
     308 
     309 
    190310 
    191311// now register with Registry to instantiate the above 
    192312// reader/writer. 
    193313REGISTER_OSGPLUGIN(attr, ReaderWriterATTR) 
    194  
    195  
    196  
    197  
    198  
    199  
    200  
    201  
    202  
    203  
    204  
    205  
  • OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp

    r7931 r8003  
    3131#include "Document.h" 
    3232#include "RecordInputStream.h" 
     33#include "DataOutputStream.h" 
     34#include "FltExportVisitor.h" 
     35#include "ExportOptions.h" 
    3336 
    3437#define SERIALIZER() OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_serializerMutex)   
     
    8285 
    8386 
     87/*! 
     88 
     89FLTReaderWriter supports importing and exporting OSG scene grqphs 
     90from/to OpenFlight files. 
     91 
     92<table> 
     93  <tr> 
     94    <th></th> 
     95    <th align="center">Node</th> 
     96    <th align="center">Object</th> 
     97    <th align="center">Image</th> 
     98    <th align="center">HeightField</th> 
     99  </tr> 
     100  <tr> 
     101    <td align="right">Read</td> 
     102    <td align="center"><strong>X</strong></td> 
     103    <td></td> 
     104    <td></td> 
     105    <td></td> 
     106  </tr> 
     107  <tr> 
     108    <td align="right">Write</td> 
     109    <td align="center"><strong>X</strong></td> 
     110    <td></td> 
     111    <td></td> 
     112    <td></td> 
     113  </tr> 
     114</table> 
     115 
     116*/ 
     117 
    84118class FLTReaderWriter : public ReaderWriter 
    85119{ 
    86120    public: 
     121        FLTReaderWriter() 
     122          : _implicitPath( "." ) 
     123        {} 
     124 
    87125        virtual const char* className() const { return "FLT Reader/Writer"; } 
    88126 
     
    348386        } 
    349387 
    350         virtual WriteResult writeNode(const Node& /*node*/,const std::string& /*fileName*/, const osgDB::ReaderWriter::Options* /*options*/) const 
    351         { 
    352             return WriteResult::FILE_NOT_HANDLED; 
    353         } 
    354          
     388        virtual WriteResult writeNode( const osg::Node& node, const std::string& fileName, const Options* options ) const 
     389        { 
     390            if ( fileName.empty() ) 
     391            { 
     392                osg::notify( osg::FATAL ) << "fltexp: writeNode: empty file name" << std::endl; 
     393                return WriteResult::FILE_NOT_HANDLED; 
     394            } 
     395            std::string ext = osgDB::getLowerCaseFileExtension( fileName ); 
     396            if ( !acceptsExtension(ext) ) 
     397                return WriteResult::FILE_NOT_HANDLED; 
     398 
     399            // Get and save the implicit path name (in case a path wasn't specified in Options). 
     400            std::string filePath = osgDB::getFilePath( fileName ); 
     401            if (!filePath.empty()) 
     402                _implicitPath = filePath; 
     403 
     404            std::ofstream fOut; 
     405            fOut.open( fileName.c_str(), std::ios::out | std::ios::binary ); 
     406            if ( fOut.fail()) 
     407            { 
     408                osg::notify( osg::FATAL ) << "fltexp: Failed to open output stream." << std::endl; 
     409                return WriteResult::ERROR_IN_WRITING_FILE; 
     410            } 
     411 
     412            WriteResult wr = WriteResult::FILE_NOT_HANDLED; 
     413            wr = writeNode( node, fOut, options ); 
     414            fOut.close(); 
     415 
     416            return wr; 
     417        } 
     418 
     419 
    355420        virtual WriteResult writeObject(const Object& object,std::ostream& fout, const osgDB::ReaderWriter::Options* options) const 
    356421        { 
     
    360425        } 
    361426 
    362         virtual WriteResult writeNode(const Node& /*node*/,std::ostream& /*fout*/, const osgDB::ReaderWriter::Options* /*options*/) const 
    363         { 
    364             return WriteResult::FILE_NOT_HANDLED; 
     427        virtual WriteResult writeNode( const osg::Node& node, std::ostream& fOut, const Options* options ) const 
     428        { 
     429            // Convert Options to FltOptions. 
     430            ExportOptions* fltOpt = new ExportOptions( options ); 
     431            fltOpt->parseOptionsString(); 
     432 
     433            // If user didn't specify a temp dir, use the output directory 
     434            //   that was implicit in the output file name. 
     435            if (fltOpt->getTempDir().empty()) 
     436                fltOpt->setTempDir( _implicitPath ); 
     437            if (!fltOpt->getTempDir().empty()) 
     438            { 
     439                // If the temp directory doesn't already exist, make it. 
     440                if ( !osgDB::makeDirectory( fltOpt->getTempDir() ) ) 
     441                { 
     442                    osg::notify( osg::FATAL ) << "fltexp: Error creating temp dir: " << fltOpt->getTempDir() << std::endl; 
     443                    return WriteResult::ERROR_IN_WRITING_FILE; 
     444                } 
     445            } 
     446 
     447            flt::DataOutputStream dos( fOut.rdbuf(), fltOpt->getValidateOnly() ); 
     448            flt::FltExportVisitor fnv( &dos, fltOpt ); 
     449 
     450            // Hm. 'node' is const, but in order to write out this scene graph, 
     451            //   must use Node::accept() which requires 'node' to be non-const. 
     452            //   Pretty much requires casting away const. 
     453            osg::Node* nodeNonConst = const_cast<osg::Node*>( &node ); 
     454            nodeNonConst->accept( fnv ); 
     455            fnv.complete( node ); 
     456 
     457            // FIXME: Error-handling? 
     458            return WriteResult::FILE_SAVED; 
    365459        } 
    366460 
    367461    protected: 
     462        mutable std::string _implicitPath; 
    368463 
    369464        mutable OpenThreads::ReentrantMutex _serializerMutex; 
     
    373468// reader/writer. 
    374469REGISTER_OSGPLUGIN(OpenFlight, FLTReaderWriter) 
    375  
    376  
    377  
    378  
    379  
    380  
    381  
    382  
    383  
    384  
    385  
    386  
    387  
  • OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/RecordInputStream.cpp

    r7748 r8003  
    1919 
    2020#include <iostream> 
    21 #include "opcodes.h" 
     21#include "Opcodes.h" 
    2222#include "Registry.h" 
    2323#include "Document.h" 
  • OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/Registry.h

    r7748 r8003  
    2424#include <map> 
    2525#include <osg/ref_ptr> 
    26 #include "opcodes.h" 
     26#include "Opcodes.h" 
    2727#include "Record.h" 
    2828