From cb213d0ff40a57997bdd5836d06a7d959895cf3f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 7 Apr 2004 08:57:15 +0000 Subject: [PATCH] From Paul Martz, changes to better support OpenFlight 15.8 --- src/osgPlugins/flt/GroupRecord.h | 11 +++---- .../flt/TextureMappingPaletteRecord.h | 11 +++++-- src/osgPlugins/flt/flt2osg.cpp | 30 ++++++++++++------- 3 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/osgPlugins/flt/GroupRecord.h b/src/osgPlugins/flt/GroupRecord.h index 5d2725b13..8936284eb 100644 --- a/src/osgPlugins/flt/GroupRecord.h +++ b/src/osgPlugins/flt/GroupRecord.h @@ -42,11 +42,12 @@ class GroupRecord : public PrimNodeRecord public: enum FlagBit { - FORWARD_ANIM = 0x40000000, - SWING_ANIM = 0x20000000, - BOUND_BOX_FOLLOW = 0x10000000, - FREEZE_BOUND_BOX = 0x08000000, - DEFAULT_PARENT = 0x04000000 + FORWARD_ANIM = 0x40000000, + SWING_ANIM = 0x20000000, + BOUND_BOX_FOLLOW = 0x10000000, + FREEZE_BOUND_BOX = 0x08000000, + DEFAULT_PARENT = 0x04000000, + BACKWARD_ANIM = 0x02000000 }; GroupRecord(); diff --git a/src/osgPlugins/flt/TextureMappingPaletteRecord.h b/src/osgPlugins/flt/TextureMappingPaletteRecord.h index 4074bd504..555984fb9 100644 --- a/src/osgPlugins/flt/TextureMappingPaletteRecord.h +++ b/src/osgPlugins/flt/TextureMappingPaletteRecord.h @@ -57,7 +57,9 @@ struct SPutTextureMapping // 1 = Origin point // 2 = Alignment point // 3 = Shear point - int32 Reserved; // should always be set to 1 + int32 uvDisplayType; // v15.8 (1580) UV display type + // 1 = XY + // 2 = UV }; @@ -92,9 +94,14 @@ struct SPointPutTextureMapping // 2 = Alignment point // 3 = Shear point // 4 = Perspective point - int32 Reserved; // should always be set to 1 + int32 uvDisplayType; // v15.8 (1580) UV display type + // 1 = XY + // 2 = UV float32 sfScale; // Depth scale factor + int32 reserved_0; // New for 15.8 float64 dfMat[4][4]; // Transformation matrix for the 4 point projection plane + float32 sfURep; // U repetition + float32 sfVRep; // V repetition }; diff --git a/src/osgPlugins/flt/flt2osg.cpp b/src/osgPlugins/flt/flt2osg.cpp index 84661afc3..1c3a2b079 100644 --- a/src/osgPlugins/flt/flt2osg.cpp +++ b/src/osgPlugins/flt/flt2osg.cpp @@ -814,27 +814,38 @@ osg::Group* ConvertFromFLT::visitBSP(osg::Group& osgParent, BSPRecord* rec) osg::Group* ConvertFromFLT::visitGroup(osg::Group& osgParent, GroupRecord* rec) { + const int fltVer = rec->getFltFile()->getFlightVersion(); SGroup* currentGroup = (SGroup*) rec->getData(); - // OpenFlight 15.7 has two animation flags, forward and swing - bool forwardAnim = (currentGroup->dwFlags & GroupRecord::FORWARD_ANIM)!=0; - bool swingAnim = (currentGroup->dwFlags & GroupRecord::SWING_ANIM)!=0; + const bool forwardAnim = (currentGroup->dwFlags & GroupRecord::FORWARD_ANIM)!=0; + // OpenFlight 15.8 adds backwards animations + const bool backwardAnim = ( (fltVer >= 1580) && + ((currentGroup->dwFlags & GroupRecord::BACKWARD_ANIM) != 0) ); + // Regardless of forwards or backwards, animation could have swing bit set + const osg::Sequence::LoopMode loopMode = ( (currentGroup->dwFlags & GroupRecord::SWING_ANIM) == 0 ) ? + osg::Sequence::LOOP : osg::Sequence::SWING; - if( forwardAnim || swingAnim ) + if( forwardAnim || backwardAnim) { osg::Sequence* animSeq = new osg::Sequence; visitAncillary(osgParent, *animSeq, rec)->addChild( animSeq ); visitPrimaryNode(*animSeq, rec); - animSeq->setDuration(0.0,1000000); + const int numReps = (fltVer >= 1580) ? + currentGroup->iLoopCount : 1000000; + const float frameDuration = (fltVer >= 1580) ? + currentGroup->fLoopDuration / (float)animSeq->getNumChildren() : 0.f; + animSeq->setDuration( frameDuration, numReps ); if ( forwardAnim ) - animSeq->setInterval(osg::Sequence::LOOP, 0, -1); - else - animSeq->setInterval(osg::Sequence::SWING, 0, -1); - + animSeq->setInterval( loopMode, 0, -1 ); + else // Backwards animation + animSeq->setInterval( loopMode, -1, 0 ); + + animSeq->setMode( osg::Sequence::START ); + // Only set the name from the normal record ID if the visitAncillary() // call didn't find a Long ID record on this group if (animSeq->getName().length() == 0) @@ -2347,7 +2358,6 @@ void ConvertFromFLT::visitLightPointIndex(osg::Group& osgParent, LightPointIndex } - void ConvertFromFLT::visitMesh ( osg::Group &parent, GeoSetBuilder *pBuilder, MeshRecord *rec ) { DynGeoSet* dgset = pBuilder->getDynGeoSet();