diff --git a/src/osgPlugins/OpenFlight/Document.cpp b/src/osgPlugins/OpenFlight/Document.cpp index 61fdc73c3..0dcb9f038 100644 --- a/src/osgPlugins/OpenFlight/Document.cpp +++ b/src/osgPlugins/OpenFlight/Document.cpp @@ -12,7 +12,7 @@ */ // -// OpenFlight® loader for OpenSceneGraph +// OpenFlight� loader for OpenSceneGraph // // Copyright (C) 2005-2007 Brede Johansen // @@ -32,6 +32,7 @@ Document::Document() : _useBillboardCenter(false), _doUnitsConversion(true), _readObjectRecordData(false), + _preserveNonOsgAttrsAsUserData(false), _desiredUnits(METERS), _done(false), _level(0), diff --git a/src/osgPlugins/OpenFlight/Document.h b/src/osgPlugins/OpenFlight/Document.h index f13837ed4..6fc0ea1a0 100644 --- a/src/osgPlugins/OpenFlight/Document.h +++ b/src/osgPlugins/OpenFlight/Document.h @@ -12,7 +12,7 @@ */ // -// OpenFlight® loader for OpenSceneGraph +// OpenFlight� loader for OpenSceneGraph // // Copyright (C) 2005-2007 Brede Johansen // @@ -202,6 +202,9 @@ class Document void setReadObjectRecordData(bool flag) { _readObjectRecordData = flag; } bool getReadObjectRecordData() const { return _readObjectRecordData; } + void setPreserveNonOsgAttrsAsUserData(bool flag) { _preserveNonOsgAttrsAsUserData = flag; } + bool getPreserveNonOsgAttrsAsUserData() const { return _preserveNonOsgAttrsAsUserData; } + protected: // Options @@ -215,6 +218,7 @@ class Document bool _useBillboardCenter; bool _doUnitsConversion; bool _readObjectRecordData; + bool _preserveNonOsgAttrsAsUserData; CoordUnits _desiredUnits; bool _keepExternalReferences; diff --git a/src/osgPlugins/OpenFlight/GeometryRecords.cpp b/src/osgPlugins/OpenFlight/GeometryRecords.cpp index 6b28110b0..d8fb6fabe 100644 --- a/src/osgPlugins/OpenFlight/GeometryRecords.cpp +++ b/src/osgPlugins/OpenFlight/GeometryRecords.cpp @@ -12,7 +12,7 @@ */ // -// OpenFlight® loader for OpenSceneGraph +// OpenFlight� loader for OpenSceneGraph // // Copyright (C) 2005-2007 Brede Johansen // @@ -29,6 +29,8 @@ #include "Document.h" #include "RecordInputStream.h" +#include + #include namespace flt { @@ -347,7 +349,7 @@ protected: virtual void readRecord(RecordInputStream& in, Document& document) { std::string id = in.readString(8); - /*int32 IRColor =*/ in.readInt32(); + int32 IRColor = in.readInt32(); /*int16 relativePriority =*/ in.readInt16(); _drawFlag = in.readUInt8(SOLID_NO_BACKFACE); uint8 texturedWhite = in.readUInt8(); @@ -358,8 +360,8 @@ protected: /*int detailTexture =*/ in.readInt16(-1); int textureIndex = in.readInt16(-1); int materialIndex = in.readInt16(-1); - /*int16 surface =*/ in.readInt16(); - /*int16 feature =*/ in.readInt16(); + int16 surface = in.readInt16(); + int16 feature = in.readInt16(); /*int32 IRMaterial =*/ in.readInt32(-1); _transparency = in.readUInt16(0); // version > 13 @@ -449,6 +451,24 @@ protected: stateset->setAttribute(material); } + // IRColor (IRC) + if (document.getPreserveNonOsgAttrsAsUserData() && 0 != IRColor) + { + _geometry->setUserValue("", IRColor); + } + + // surface (SMC) + if (document.getPreserveNonOsgAttrsAsUserData() && 0 != surface) + { + _geometry->setUserValue("", surface); + } + + // feature (FID) + if (document.getPreserveNonOsgAttrsAsUserData() && 0 != feature) + { + _geometry->setUserValue("", feature); + } + // Shaders if (shaderIndex >= 0) { @@ -920,7 +940,7 @@ protected: { std::string id = in.readString(8); in.forward(4); - /*int32 IRColor =*/ in.readInt32(); + int32 IRColor = in.readInt32(); /*int16 relativePriority =*/ in.readInt16(); _drawFlag = in.readUInt8(SOLID_NO_BACKFACE); uint8 texturedWhite = in.readUInt8(); @@ -931,8 +951,8 @@ protected: /*int detailTexture =*/ in.readInt16(-1); int textureIndex = in.readInt16(-1); int materialIndex = in.readInt16(-1); - /*int16 surface =*/ in.readInt16(); - /*int16 feature =*/ in.readInt16(); + int16 surface = in.readInt16(); + int16 feature = in.readInt16(); /*int32 IRMaterial =*/ in.readInt32(-1); _transparency = in.readUInt16(0); // version > 13 @@ -1018,6 +1038,24 @@ protected: stateset->setAttribute(material); } + // IRColor (IRC) + if (document.getPreserveNonOsgAttrsAsUserData() && 0 != IRColor) + { + _geode->setUserValue("", IRColor); + } + + // surface (SMC) + if (document.getPreserveNonOsgAttrsAsUserData() && 0 != surface) + { + _geode->setUserValue("", surface); + } + + // feature (FID) + if (document.getPreserveNonOsgAttrsAsUserData() && 0 != feature) + { + _geode->setUserValue("", feature); + } + // Shaders if (shaderIndex >= 0) { diff --git a/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp b/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp index a416b026f..8a76f50a7 100644 --- a/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp +++ b/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp @@ -12,7 +12,7 @@ */ // -// OpenFlight® loader for OpenSceneGraph +// OpenFlight� loader for OpenSceneGraph // // Copyright (C) 2005-2007 Brede Johansen // @@ -236,6 +236,7 @@ class FLTReaderWriter : public ReaderWriter supportsOption("billboardCenter","Import option"); supportsOption("noTextureAlphaForTransparancyBinning","Import option"); supportsOption("readObjectRecordData","Import option"); + supportsOption("preserveNonOsgAttrsAsUserData","Import option: If present in the Options string, following OpenFlight specific attributes will be stored as UserValue: surface: , feature: , IRColor: "); supportsOption("noUnitsConversion","Import option"); supportsOption("convertToFeet","Import option"); supportsOption("convertToInches","Import option"); @@ -376,6 +377,9 @@ class FLTReaderWriter : public ReaderWriter document.setReadObjectRecordData(options->getOptionString().find("readObjectRecordData")==std::string::npos); OSG_DEBUG << readerMsg << "readObjectRecordData=" << !document.getReadObjectRecordData() << std::endl; + document.setPreserveNonOsgAttrsAsUserData((options->getOptionString().find("preserveNonOsgAttrsAsUserData")!=std::string::npos)); + OSG_DEBUG << readerMsg << "preserveNonOsgAttrsAsUserData=" << document.getPreserveNonOsgAttrsAsUserData() << std::endl; + document.setDoUnitsConversion((options->getOptionString().find("noUnitsConversion")==std::string::npos)); // default to true, unless noUnitsConversion is specified. OSG_DEBUG << readerMsg << "noUnitsConversion=" << !document.getDoUnitsConversion() << std::endl;