Changeset 8003
- Timestamp:
- 03/28/08 13:44:33 (5 years ago)
- Location:
- OpenSceneGraph/trunk/src/osgPlugins/OpenFlight
- Files:
-
- 22 added
- 10 modified
-
AttrData.cpp (modified) (1 diff)
-
AttrData.h (modified) (3 diffs)
-
CMakeLists.txt (modified) (3 diffs)
-
DataInputStream.h (modified) (1 diff)
-
DataOutputStream.cpp (added)
-
DataOutputStream.h (added)
-
Document.h (modified) (1 diff)
-
ExportOptions.cpp (added)
-
ExportOptions.h (added)
-
FltExportVisitor.cpp (added)
-
FltExportVisitor.h (added)
-
FltWriteResult.h (added)
-
LightSourcePaletteManager.cpp (added)
-
LightSourcePaletteManager.h (added)
-
MaterialPaletteManager.cpp (added)
-
MaterialPaletteManager.h (added)
-
Opcodes.h (added)
-
Pools.h (modified) (1 diff)
-
ReaderWriterATTR.cpp (modified) (5 diffs)
-
ReaderWriterFLT.cpp (modified) (5 diffs)
-
RecordInputStream.cpp (modified) (1 diff)
-
Registry.h (modified) (1 diff)
-
TexturePaletteManager.cpp (added)
-
TexturePaletteManager.h (added)
-
Types.h (added)
-
Utils.h (added)
-
VertexPaletteManager.cpp (added)
-
VertexPaletteManager.h (added)
-
expAncillaryRecords.cpp (added)
-
expControlRecords.cpp (added)
-
expGeometryRecords.cpp (added)
-
expPrimaryRecords.cpp (added)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/AttrData.cpp
r7748 r8003 25 25 AttrData::AttrData() : 26 26 texels_u(0), 27 tex tel_v(0),27 texels_v(0), 28 28 direction_u(0), 29 29 direction_v(0), -
OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/AttrData.h
r7748 r8003 23 23 #include <string> 24 24 #include <osg/Object> 25 #include " types.h"25 #include "Types.h" 26 26 27 27 namespace flt { … … 113 113 114 114 int32 texels_u; // Number of texels in u direction 115 int32 tex tel_v; // Number of texels in v direction115 int32 texels_v; // Number of texels in v direction 116 116 int32 direction_u; // Real world size u direction 117 117 int32 direction_v; // Real world size v direction … … 329 329 } 330 330 #endif 331 int32 numSubtextures; // # of subtextures 331 332 332 333 }; -
OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/CMakeLists.txt
r7281 r8003 7 7 ControlRecords.cpp 8 8 DataInputStream.cpp 9 DataOutputStream.cpp 9 10 Document.cpp 11 expAncillaryRecords.cpp 12 expControlRecords.cpp 13 expGeometryRecords.cpp 14 expPrimaryRecords.cpp 15 ExportOptions.cpp 16 FltExportVisitor.cpp 10 17 GeometryRecords.cpp 11 18 LightPointRecords.cpp 19 LightSourcePaletteManager.cpp 20 MaterialPaletteManager.cpp 12 21 PaletteRecords.cpp 13 22 Pools.cpp … … 20 29 ReservedRecords.cpp 21 30 RoadRecords.cpp 31 TexturePaletteManager.cpp 22 32 Vertex.cpp 33 VertexPaletteManager.cpp 23 34 VertexRecords.cpp 24 35 ) … … 27 38 AttrData.h 28 39 DataInputStream.h 40 DataOutputStream.h 41 ExportOptions.h 42 FltExportVisitor.h 43 FltWriteResult.h 29 44 Document.h 45 LightSourcePaletteManager.h 46 MaterialPaletteManager.h 30 47 Pools.h 31 48 Record.h 32 49 RecordInputStream.h 33 50 Registry.h 51 TexturePaletteManager.h 34 52 Vertex.h 35 opcodes.h 36 types.h 53 VertexPaletteManager.h 54 Opcodes.h 55 Types.h 56 Utils.h 37 57 ) 38 58 -
OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/DataInputStream.h
r7748 r8003 26 26 #include <osg/Vec3d> 27 27 #include <osg/Vec4f> 28 #include " types.h"28 #include "Types.h" 29 29 30 30 namespace flt { -
OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/Document.h
r7931 r8003 27 27 #include <osgDB/ReaderWriter> 28 28 29 #include " types.h"29 #include "Types.h" 30 30 #include "Record.h" 31 31 #include "Pools.h" -
OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/Pools.h
r7748 r8003 29 29 #include <osg/Light> 30 30 #include <osg/Program> 31 #include " types.h"31 #include "Types.h" 32 32 33 33 -
OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/ReaderWriterATTR.cpp
r7919 r8003 30 30 #include "AttrData.h" 31 31 #include "DataInputStream.h" 32 #include "DataOutputStream.h" 32 33 33 34 using namespace osg; … … 48 49 49 50 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; 50 52 }; 51 53 … … 75 77 { 76 78 attr->texels_u = in.readInt32(); 77 attr->tex tel_v = in.readInt32();79 attr->texels_v = in.readInt32(); 78 80 attr->direction_u = in.readInt32(); 79 81 attr->direction_v = in.readInt32(); … … 171 173 attr->attrVersion = in.readInt32(); 172 174 attr->controlPoints = in.readInt32(); 173 in.forward(4);175 attr->numSubtextures = in.readInt32(); 174 176 #endif 175 177 } … … 188 190 189 191 192 ReaderWriter::WriteResult 193 ReaderWriterATTR::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 190 310 191 311 // now register with Registry to instantiate the above 192 312 // reader/writer. 193 313 REGISTER_OSGPLUGIN(attr, ReaderWriterATTR) 194 195 196 197 198 199 200 201 202 203 204 205 -
OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp
r7931 r8003 31 31 #include "Document.h" 32 32 #include "RecordInputStream.h" 33 #include "DataOutputStream.h" 34 #include "FltExportVisitor.h" 35 #include "ExportOptions.h" 33 36 34 37 #define SERIALIZER() OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(_serializerMutex) … … 82 85 83 86 87 /*! 88 89 FLTReaderWriter supports importing and exporting OSG scene grqphs 90 from/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 84 118 class FLTReaderWriter : public ReaderWriter 85 119 { 86 120 public: 121 FLTReaderWriter() 122 : _implicitPath( "." ) 123 {} 124 87 125 virtual const char* className() const { return "FLT Reader/Writer"; } 88 126 … … 348 386 } 349 387 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 355 420 virtual WriteResult writeObject(const Object& object,std::ostream& fout, const osgDB::ReaderWriter::Options* options) const 356 421 { … … 360 425 } 361 426 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; 365 459 } 366 460 367 461 protected: 462 mutable std::string _implicitPath; 368 463 369 464 mutable OpenThreads::ReentrantMutex _serializerMutex; … … 373 468 // reader/writer. 374 469 REGISTER_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 19 19 20 20 #include <iostream> 21 #include " opcodes.h"21 #include "Opcodes.h" 22 22 #include "Registry.h" 23 23 #include "Document.h" -
OpenSceneGraph/trunk/src/osgPlugins/OpenFlight/Registry.h
r7748 r8003 24 24 #include <map> 25 25 #include <osg/ref_ptr> 26 #include " opcodes.h"26 #include "Opcodes.h" 27 27 #include "Record.h" 28 28
