From 02783e1dfd6a8962a7cce3dcbe0a71eb5ccd32eb Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 2 Oct 2006 15:09:49 +0000 Subject: [PATCH] From Paul Martz, Bug fix for sequence node direction, It examines the number of children in the Group record destructor, so that the total duration of the sequence matches the specified loopDuration field. --- src/osgPlugins/OpenFlight/PrimaryRecords.cpp | 22 ++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/osgPlugins/OpenFlight/PrimaryRecords.cpp b/src/osgPlugins/OpenFlight/PrimaryRecords.cpp index 3495f1d0f..eefe2a4b2 100644 --- a/src/osgPlugins/OpenFlight/PrimaryRecords.cpp +++ b/src/osgPlugins/OpenFlight/PrimaryRecords.cpp @@ -137,6 +137,7 @@ class Group : public PrimaryRecord osg::ref_ptr _group; bool _forwardAnim; bool _backwardAnim; + float32 _loopDuration; public: @@ -157,7 +158,22 @@ public: protected: - virtual ~Group() {} + virtual ~Group() + { + if (!_group.valid()) + return; + + if ( (_group->getNumChildren() > 0) && + (_forwardAnim || _backwardAnim) ) + { + // Now that we know the number of children, set the loop duration + // to the best of our ability (currently, osg::Sequence doesn't + // support the OpenFlight last frame duration concept). + osg::Sequence* sequence = dynamic_cast( _group.get() ); + assert( sequence != NULL ); + sequence->setDuration( _loopDuration / (float)(_group->getNumChildren()) ); + } + } void readRecord(RecordInputStream& in, Document& document) { @@ -173,7 +189,7 @@ protected: /*int8 layer =*/ in.readInt8(); in.forward(5); /*uint32 loopCount =*/ in.readUInt32(); - /*float32 loopDuration =*/ in.readFloat32(); + _loopDuration = in.readFloat32(); /*float32 lastFrameDuration =*/ in.readFloat32(); // Check for forward animation (sequence) @@ -201,6 +217,8 @@ protected: else sequence->setInterval(loopMode, -1, 0); + // Set the duration, temporarily. We'll set the correct value + // in the destructor, when we know the number of children. float speed=0.1f; sequence->setDuration(speed); sequence->setMode(osg::Sequence::START);