From 6468905e42ee370fe60dea99e4e2f3217f9a8544 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 15 May 2007 14:55:02 +0000 Subject: [PATCH] From John Kelso, Added support for new Sequence options. From Robert Osfield, updated the above changes to the .ive loader so that the new addition were tested against the IVE version number --- src/osgPlugins/ive/IveVersion.h | 3 +- src/osgPlugins/ive/Sequence.cpp | 34 +++++++--- src/osgPlugins/osg/Sequence.cpp | 109 ++++++++++++++++++++++++++++---- 3 files changed, 124 insertions(+), 22 deletions(-) diff --git a/src/osgPlugins/ive/IveVersion.h b/src/osgPlugins/ive/IveVersion.h index 6fdabbe35..621ad7bfa 100644 --- a/src/osgPlugins/ive/IveVersion.h +++ b/src/osgPlugins/ive/IveVersion.h @@ -29,8 +29,9 @@ #define VERSION_0018 18 #define VERSION_0019 19 #define VERSION_0020 20 +#define VERSION_0021 21 -#define VERSION VERSION_0020 +#define VERSION VERSION_0021 /* The BYTE_SEX tag is used to check the endian of the IVE file being read in. The IVE format diff --git a/src/osgPlugins/ive/Sequence.cpp b/src/osgPlugins/ive/Sequence.cpp index 2c1cf91a2..c11cd7779 100644 --- a/src/osgPlugins/ive/Sequence.cpp +++ b/src/osgPlugins/ive/Sequence.cpp @@ -18,22 +18,28 @@ using namespace ive; -void Sequence::write(DataOutputStream* out){ +void Sequence::write(DataOutputStream* out) +{ // Write Sequence's identification. out->writeInt(IVESEQUENCE); // If the osg class is inherited by any other class we should also write this to file. osg::Group* group = dynamic_cast(this); - if(group){ + if(group) + { ((ive::Group*)(group))->write(out); } else + { throw Exception("Sequence::write(): Could not cast this osg::Sequence to an osg::Group."); + } + // Write Sequence's properties. // Write frame times. int size = getNumChildren(); out->writeInt(size); - for(int i=0;iwriteFloat(getTime(i)); } // Write loop mode & interval @@ -43,34 +49,43 @@ void Sequence::write(DataOutputStream* out){ out->writeInt(mode); out->writeInt(begin); out->writeInt(end); + // Write duration float speed; int nreps; getDuration(speed, nreps); out->writeFloat(speed); out->writeInt(nreps); + // Write sequence mode out->writeInt(getMode()); } -void Sequence::read(DataInputStream* in){ +void Sequence::read(DataInputStream* in) +{ // Peek on Sequence's identification. int id = in->peekInt(); - if(id == IVESEQUENCE){ + if(id == IVESEQUENCE) + { // Read Sequence's identification. id = in->readInt(); // If the osg class is inherited by any other class we should also read this from file. osg::Group* group = dynamic_cast(this); - if(group){ + if(group) + { ((ive::Group*)(group))->read(in); } else + { throw Exception("Sequence::read(): Could not cast this osg::Sequence to an osg::Group."); + } + // Read Sequence's properties // Read frame times. int size = in->readInt(); - for(int i=0;ireadFloat()); } // Read loop mode & interval @@ -78,14 +93,17 @@ void Sequence::read(DataInputStream* in){ int begin = in->readInt(); int end = in->readInt(); setInterval((osg::Sequence::LoopMode)mode, begin, end); + // Read duration float speed = in->readFloat(); int nreps = in->readInt(); setDuration(speed, nreps); + // Read sequence mode setMode((osg::Sequence::SequenceMode)in->readInt()); } - else{ + else + { throw Exception("Sequence::read(): Expected Sequence identification."); } } diff --git a/src/osgPlugins/osg/Sequence.cpp b/src/osgPlugins/osg/Sequence.cpp index 7a999cfe8..1ad747cc7 100644 --- a/src/osgPlugins/osg/Sequence.cpp +++ b/src/osgPlugins/osg/Sequence.cpp @@ -25,11 +25,17 @@ static bool Sequence_matchLoopMode(const char* str, Sequence::LoopMode& mode) { if (strcmp(str, "LOOP") == 0) + { mode = Sequence::LOOP; + } else if (strcmp(str, "SWING") == 0) + { mode = Sequence::SWING; + } else + { return false; + } return true; } @@ -50,11 +56,17 @@ static bool Sequence_matchSeqMode(const char* str, Sequence::SequenceMode& mode) { if (strcmp(str, "START") == 0) + { mode = Sequence::START; + } else if (strcmp(str, "STOP") == 0) + { mode = Sequence::STOP; + } else + { return false; + } return true; } @@ -75,35 +87,64 @@ bool Sequence_readLocalData(Object& obj, Input& fr) Sequence& sw = static_cast(obj); - if (fr.matchSequence("frameTime {")) { + if (fr.matchSequence("defaultTime")) + { + if (fr[1].isFloat()) + { + float t; + fr[1].getFloat(t) ; + sw.setDefaultTime(t) ; + iteratorAdvanced = true; + fr += 2; + } + } + else if (fr.matchSequence("frameTime {")) + { int entry = fr[0].getNoNestedBrackets(); fr += 2; - + int i = 0; - while (!fr.eof() && fr[0].getNoNestedBrackets() > entry) { + while (!fr.eof() && fr[0].getNoNestedBrackets() > entry) + { float t; - if (fr[0].getFloat(t)) { + if (fr[0].getFloat(t)) + { sw.setTime(i, t); ++fr; i++; } } - + iteratorAdvanced = true; ++fr; } - else if (fr.matchSequence("interval")) { + else if (fr.matchSequence("lastFrameTime")) + { + if (fr[1].isFloat()) + { + float t; + fr[1].getFloat(t) ; + sw.setLastFrameTime(t) ; + iteratorAdvanced = true; + fr += 2; + } + } + else if (fr.matchSequence("interval")) + { Sequence::LoopMode mode; int begin, end; if (Sequence_matchLoopMode(fr[1].getStr(), mode) && - fr[2].getInt(begin) && fr[3].getInt(end)) { + fr[2].getInt(begin) && fr[3].getInt(end)) + { sw.setInterval(mode, begin, end); iteratorAdvanced = true; fr += 4; } } - else if (fr.matchSequence("duration")) { - if (fr[1].isFloat() && fr[2].isInt()) { + else if (fr.matchSequence("duration")) + { + if (fr[1].isFloat() && fr[2].isInt()) + { float speed; int nreps; fr[1].getFloat(speed); @@ -113,15 +154,39 @@ bool Sequence_readLocalData(Object& obj, Input& fr) fr += 3; } } - else if (fr.matchSequence("mode")) { + else if (fr.matchSequence("mode")) + { Sequence::SequenceMode mode; - if (Sequence_matchSeqMode(fr[1].getStr(), mode)) { + if (Sequence_matchSeqMode(fr[1].getStr(), mode)) + { sw.setMode(mode); iteratorAdvanced = true; fr += 2; } } - + else if (fr.matchSequence("sync")) + { + if (fr[1].isInt()) + { + int sync ; + fr[1].getInt(sync) ; + sw.setSync((bool)sync) ; + iteratorAdvanced = true; + fr += 2; + } + } + else if (fr.matchSequence("clearOnStop")) + { + if (fr[1].isInt()) + { + int clearOnStop ; + fr[1].getInt(clearOnStop) ; + sw.setClearOnStop((bool)clearOnStop) ; + iteratorAdvanced = true; + fr += 2; + } + } + return iteratorAdvanced; } @@ -129,15 +194,23 @@ bool Sequence_writeLocalData(const Object& obj, Output& fw) { const Sequence& sw = static_cast(obj); + // default frame time + fw.indent() << "defaultTime " << sw.getDefaultTime() << std::endl; + // frame times fw.indent() << "frameTime {" << std::endl; fw.moveIn(); - for (unsigned int i = 0; i < sw.getNumChildren(); i++) { + for (unsigned int i = 0; i < sw.getNumChildren(); i++) + { fw.indent() << sw.getTime(i) << std::endl; } + fw.moveOut(); fw.indent() << "}" << std::endl; + // last frame time + fw.indent() << "lastFrameTime " << sw.getLastFrameTime() << std::endl; + // loop mode & interval Sequence::LoopMode mode; int begin, end; @@ -153,5 +226,15 @@ bool Sequence_writeLocalData(const Object& obj, Output& fw) // sequence mode fw.indent() << "mode " << Sequence_getSeqMode(sw.getMode()) << std::endl; + // sync + bool sync ; + sw.getSync(sync); + fw.indent() << "sync " << (int) sync << std::endl; + + // clearOnStop + bool clearOnStop ; + sw.getClearOnStop(clearOnStop); + fw.indent() << "clearOnStop " << (int) clearOnStop << std::endl; + return true; }