diff --git a/src/osgPlugins/OpenFlight/Document.cpp b/src/osgPlugins/OpenFlight/Document.cpp index a36d05c87..3a980250c 100644 --- a/src/osgPlugins/OpenFlight/Document.cpp +++ b/src/osgPlugins/OpenFlight/Document.cpp @@ -28,6 +28,7 @@ Document::Document() : _materialPoolParent(false), _lightSourcePoolParent(false), _lightPointAppearancePoolParent(false), + _lightPointAnimationPoolParent(false), _shaderPoolParent(false) { } diff --git a/src/osgPlugins/OpenFlight/Document.h b/src/osgPlugins/OpenFlight/Document.h index c8409141a..6ef4ca356 100644 --- a/src/osgPlugins/OpenFlight/Document.h +++ b/src/osgPlugins/OpenFlight/Document.h @@ -144,6 +144,11 @@ class Document LightPointAppearancePool* getOrCreateLightPointAppearancePool(); bool getLightPointAppearancePoolParent() const { return _lightPointAppearancePoolParent; } + void setLightPointAnimationPool(LightPointAnimationPool* lpap, bool parent=false) { _lightPointAnimationPool = lpap; _lightPointAnimationPoolParent=parent; } + LightPointAnimationPool* getLightPointAnimationPool() { return _lightPointAnimationPool.get(); } + LightPointAnimationPool* getOrCreateLightPointAnimationPool(); + bool getLightPointAnimationPoolParent() const { return _lightPointAnimationPoolParent; } + void setShaderPool(ShaderPool* cp, bool parent=false) { _shaderPool = cp; _shaderPoolParent=parent; } ShaderPool* getShaderPool() { return _shaderPool.get(); } ShaderPool* getOrCreateShaderPool(); @@ -202,12 +207,14 @@ class Document osg::ref_ptr _materialPool; osg::ref_ptr _lightSourcePool; osg::ref_ptr _lightPointAppearancePool; + osg::ref_ptr _lightPointAnimationPool; osg::ref_ptr _shaderPool; bool _colorPoolParent; bool _texturePoolParent; bool _materialPoolParent; bool _lightSourcePoolParent; bool _lightPointAppearancePoolParent; + bool _lightPointAnimationPoolParent; bool _shaderPoolParent; osg::ref_ptr _currentPrimaryRecord; @@ -252,6 +259,13 @@ inline LightPointAppearancePool* Document::getOrCreateLightPointAppearancePool() return _lightPointAppearancePool.get(); } +inline LightPointAnimationPool* Document::getOrCreateLightPointAnimationPool() +{ + if (!_lightPointAnimationPool.valid()) + _lightPointAnimationPool = new LightPointAnimationPool; + return _lightPointAnimationPool.get(); +} + inline ShaderPool* Document::getOrCreateShaderPool() { diff --git a/src/osgPlugins/OpenFlight/LightPointRecords.cpp b/src/osgPlugins/OpenFlight/LightPointRecords.cpp index 5f8cad6a3..18bb71715 100644 --- a/src/osgPlugins/OpenFlight/LightPointRecords.cpp +++ b/src/osgPlugins/OpenFlight/LightPointRecords.cpp @@ -130,7 +130,7 @@ public: lp._blinkSequence = new osgSim::BlinkSequence(); if (lp._blinkSequence.valid()) { - lp._blinkSequence->setDataVariance(osg::Object::DataVariance::DYNAMIC); + lp._blinkSequence->setDataVariance(osg::Object::DYNAMIC); lp._blinkSequence->setPhaseShift(_animationPhaseDelay); lp._blinkSequence->addPulse(_animationPeriod - _animationPeriodEnable, osg::Vec4f(0.0f, 0.0f, 0.0f, 0.0f)); diff --git a/src/osgPlugins/OpenFlight/PaletteRecords.cpp b/src/osgPlugins/OpenFlight/PaletteRecords.cpp index 21fd78b61..56d0cf896 100644 --- a/src/osgPlugins/OpenFlight/PaletteRecords.cpp +++ b/src/osgPlugins/OpenFlight/PaletteRecords.cpp @@ -636,28 +636,46 @@ protected: virtual ~LightPointAnimationPalette() {} - virtual void readRecord(RecordInputStream& in, Document& /*document*/) + virtual void readRecord(RecordInputStream& in, Document& document) { + if (document.getLightPointAnimationPoolParent()) + // Using parent's light point animation pool -- ignore this record. + return; + + osg::ref_ptr animation = new LPAnimation; + in.forward(4); - std::string name = in.readString(256); - /*int32 index =*/ in.readInt32(-1); - /*float32 animationPeriod =*/ in.readFloat32(); - /*float32 animationPhaseDelay =*/ in.readFloat32(); - /*float32 animationEnabledPeriod =*/ in.readFloat32(); - /*osg::Vec3f axisOfRotation =*/ in.readVec3f(); - /*uint32 flags =*/ in.readUInt32(); - /*int32 animationType =*/ in.readInt32(); - /*int32 morseCodeTiming =*/ in.readInt32(); - /*int32 wordRate =*/ in.readInt32(); - /*int32 characterRate =*/ in.readInt32(); - std::string morseCodeString = in.readString(1024); + animation->name = in.readString(256); + animation->index = in.readInt32(-1); + // Rotating or strobe + animation->animationPeriod = in.readFloat32(); + animation->animationPhaseDelay = in.readFloat32(); + animation->animationEnabledPeriod = in.readFloat32(); + animation->axisOfRotation = in.readVec3f(); + animation->flags = in.readUInt32(); + animation->animationType = in.readInt32(); + + // Morse code + animation->morseCodeTiming = in.readInt32(); + animation->wordRate = in.readInt32(); + animation->characterRate = in.readInt32(); + animation->morseCodeString = in.readString(1024); + + // Flashing sequence int32 numberOfSequences = in.readInt32(); for (int n=0; nsequence.push_back(pulse); } + + // Add to pool + LightPointAnimationPool* lpaPool = document.getOrCreateLightPointAnimationPool(); + (*lpaPool)[animation->index] = animation.get(); } }; diff --git a/src/osgPlugins/OpenFlight/Pools.h b/src/osgPlugins/OpenFlight/Pools.h index 691cdc762..7eaf66e36 100644 --- a/src/osgPlugins/OpenFlight/Pools.h +++ b/src/osgPlugins/OpenFlight/Pools.h @@ -202,6 +202,77 @@ protected: }; +struct LPAnimation : public osg::Referenced +{ + enum AnimationType + { + FLASHING_SEQUENCE = 0, + ROTATING = 1, + STROBE = 2, + MORSE_CODE = 3 + }; + + enum State + { + ON = 0, + OFF = 1, + COLOR_CHANGE = 2 + }; + + struct Pulse + { + uint32 state; + float32 duration; + osg::Vec4 color; + }; + + typedef std::vector PulseArray; + + std::string name; // animation name + int32 index; // animation index + float32 animationPeriod; // animation period, in seconds + float32 animationPhaseDelay; // animation phase delay, in seconds from start of period + float32 animationEnabledPeriod; // animation enabled period (time on), in seconds + osg::Vec3f axisOfRotation; // axis of rotation for rotating animation (i, j, k) + uint32 flags; // flags (bits, from left to right) + // 0 = flashing + // 1 = rotating + // 2 = rotate counter clockwise + // 3-31 = spare + int32 animationType; // animation type + // 0 = flashing sequence + // 1 = rotating + // 2 = strobe + // 3 = morse code + int32 morseCodeTiming; // morse code timing + // 0 = standard timing + // 1 = Farnsworth timing + int32 wordRate; // word rate (for Farnsworth timing) + int32 characterRate; // character rate (for Farnsworth timing) + std::string morseCodeString; // morse code string + PulseArray sequence; +}; + + +class LightPointAnimationPool : public osg::Referenced , public std::map > +{ +public: + + LightPointAnimationPool() {} + + LPAnimation* get(int index) + { + iterator itr = find(index); + if (itr != end()) + return (*itr).second.get(); + return NULL; + } + +protected: + + virtual ~LightPointAnimationPool() {} + +}; class ShaderPool : public osg::Referenced , public std::map > { @@ -250,6 +321,9 @@ public: void setLPAppearancePool(LightPointAppearancePool* pool) { _lpAppearancePool=pool; } LightPointAppearancePool* getLPAppearancePool() const { return _lpAppearancePool.get(); } + void setLPAnimationPool(LightPointAnimationPool* pool) { _lpAnimationPool=pool; } + LightPointAnimationPool* getLPAnimationPool() const { return _lpAnimationPool.get(); } + void setShaderPool(ShaderPool* pool) { _shaderPool=pool; } ShaderPool* getShaderPool() const { return _shaderPool.get(); } @@ -262,6 +336,7 @@ protected: osg::ref_ptr _texturePool; osg::ref_ptr _lightSourcePool; osg::ref_ptr _lpAppearancePool; + osg::ref_ptr _lpAnimationPool; osg::ref_ptr _shaderPool; }; diff --git a/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp b/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp index b922e9c36..99ef39712 100644 --- a/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp +++ b/src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp @@ -222,6 +222,8 @@ class FLTReaderWriter : public ReaderWriter document.setLightSourcePool( pools->getLightSourcePool(), true ); if (pools->getLPAppearancePool()) document.setLightPointAppearancePool( pools->getLPAppearancePool(), true ); + if (pools->getLPAnimationPool()) + document.setLightPointAnimationPool( pools->getLPAnimationPool(), true ); if (pools->getShaderPool()) document.setShaderPool( pools->getShaderPool(), true ); }