From Wee See, Support for importing OpenFlight Surface Material Codes using osg::Object::UserValue. Notes from Wee See:

See attached my ported code, which fulfills:

- using of setUserValue()/getUserValue()
- user-value will be attached to Geode or Drawable
- actually 3 values will be added: SMC (surface), FID (feature) and IRC (IRcolor). Its UserValue-names are < UA:SMC >, < UA:FID > and < UA:IRC > (without spaces!)
- user-value will be attached to Geode or Drawable
- has an option (named preserveNonOsgAttrsAsUserData) for control whether the UserValues should be attached (Default: no UserValues will be attached)

Reading out this values is very simple. Here is an example (uservalue-name without spaces!):

signed short smc;
if (myGeode.getUserValue("< UA:SMC >", smc))
{
  doSomethingWithTheGeodeAndItsSmc(myGeode, smc);
}
else
{
  // geode has no SMC
}
This commit is contained in:
Robert Osfield
2013-02-06 16:04:13 +00:00
parent 00c7e5e552
commit 0e9d969c84
4 changed files with 57 additions and 10 deletions

View File

@@ -12,7 +12,7 @@
*/
//
// OpenFlight<68> loader for OpenSceneGraph
// OpenFlight<68> 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),

View File

@@ -12,7 +12,7 @@
*/
//
// OpenFlight<68> loader for OpenSceneGraph
// OpenFlight<68> 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;

View File

@@ -12,7 +12,7 @@
*/
//
// OpenFlight<68> loader for OpenSceneGraph
// OpenFlight<68> loader for OpenSceneGraph
//
// Copyright (C) 2005-2007 Brede Johansen
//
@@ -29,6 +29,8 @@
#include "Document.h"
#include "RecordInputStream.h"
#include <osg/ValueObject>
#include <algorithm>
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("<UA:IRC>", IRColor);
}
// surface (SMC)
if (document.getPreserveNonOsgAttrsAsUserData() && 0 != surface)
{
_geometry->setUserValue("<UA:SMC>", surface);
}
// feature (FID)
if (document.getPreserveNonOsgAttrsAsUserData() && 0 != feature)
{
_geometry->setUserValue("<UA:FID>", 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("<UA:IRC>", IRColor);
}
// surface (SMC)
if (document.getPreserveNonOsgAttrsAsUserData() && 0 != surface)
{
_geode->setUserValue("<UA:SMC>", surface);
}
// feature (FID)
if (document.getPreserveNonOsgAttrsAsUserData() && 0 != feature)
{
_geode->setUserValue("<UA:FID>", feature);
}
// Shaders
if (shaderIndex >= 0)
{

View File

@@ -12,7 +12,7 @@
*/
//
// OpenFlight<68> loader for OpenSceneGraph
// OpenFlight<68> 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: <UA:SMC>, feature: <UA:FID>, IRColor: <UA:IRC>");
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;