From 6ddd691156f1a3a24be9045056db39e78041b8d8 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 10 Apr 2012 22:22:02 +0100 Subject: integrating --- gaunt01/bin/data/Bird-test.xml | 39 -------- gaunt01/src/bird.cpp | 66 +++++++------ gaunt01/src/bird.h | 2 + gaunt01/src/morphmesh.cpp | 186 ++++++++++++++++++++++++++++++++---- gaunt01/src/morphmesh.h | 29 ++++-- morpher/bin/data/Bird-anim-test.xml | Bin 495 -> 0 bytes morpher/bin/data/Bird-test.xml | 39 -------- morpher/morpher.layout | 12 +-- morpher/src/testApp.cpp | 2 +- 9 files changed, 233 insertions(+), 142 deletions(-) delete mode 100644 gaunt01/bin/data/Bird-test.xml delete mode 100644 morpher/bin/data/Bird-anim-test.xml delete mode 100644 morpher/bin/data/Bird-test.xml diff --git a/gaunt01/bin/data/Bird-test.xml b/gaunt01/bin/data/Bird-test.xml deleted file mode 100644 index ebcdc00..0000000 --- a/gaunt01/bin/data/Bird-test.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/gaunt01/src/bird.cpp b/gaunt01/src/bird.cpp index 9418b65..0a17563 100644 --- a/gaunt01/src/bird.cpp +++ b/gaunt01/src/bird.cpp @@ -11,19 +11,27 @@ finally drawAnimated() bird::bird() { - model.loadMesh("Bird-test.xml"); - texture.loadImage("TextureBird.jpg"); - - //starting pos - position=ofVec3f(ofGetWidth()/2,ofGetHeight()/3,ofGetHeight()/2); - heading=ofVec3f(-1,0,0); - direction=ofVec3f(-1,0,0); - velocity=ofGetWidth()/100; - - turnAngle=0; - diveAngle=0; - - lastTime=ofGetElapsedTimef(); + if (model.loadMesh("Bird-poses.xml")) printf("mesh loaded with %i vertices, %i face indices, %i targets\n",model.getNumVertices(),model.getNumIndices(),model.getNumTargets()); + else printf("mesh XML file not parsed\n"); + + if (model.loadSeqs("Bird-anim.xml")) printf("animation loaded with %i sequences\n",model.getNumSequences()); + else printf("animation XML file not parsed\n"); + + model.sequences["flap"].start(); + currentseq="hover"; + + texture.loadImage("TextureBird.jpg"); + + //starting pos + position=ofVec3f(ofGetWidth()/2,ofGetHeight(),-100); //ofGetHeight()/4); + heading=ofVec3f(-1,0,0); + direction=ofVec3f(-1,0,0); + velocity=ofGetWidth()/50; + + turnAngle=-1; + diveAngle=0; + + lastTime=ofGetElapsedTimef(); } bird::~bird() @@ -32,23 +40,23 @@ bird::~bird() } void bird::update(const vector& players){ - float time=ofGetElapsedTimef(); - float timeSeg=time-lastTime; - lastTime=time; - position+=direction*velocity*timeSeg; + float time=ofGetElapsedTimef(); + float timeSeg=time-lastTime; + lastTime=time; + position+=direction*velocity*timeSeg; } void bird::draw(){ - glEnable(GL_DEPTH_TEST); - ofPushMatrix(); - ofTranslate(position); - //ofRotate(direction); - ofRotate(90,0,0,1); - ofRotate(90,-1,0,0); - //ofRotate(180,1,0,0); - bindTexture(texture); - model.draw(); - unbindTexture(texture); - ofPopMatrix(); - glDisable(GL_DEPTH_TEST); + glEnable(GL_DEPTH_TEST); + ofPushMatrix(); + ofTranslate(position); + //ofRotate(direction); + ofRotate(90,0,0,1); + ofRotate(90,-1,0,0); + ofScale(.15,.15,.15); + bindTexture(texture); + model.drawAnimated(); + unbindTexture(texture); + ofPopMatrix(); + glDisable(GL_DEPTH_TEST); } diff --git a/gaunt01/src/bird.h b/gaunt01/src/bird.h index 4114ad3..e4b7f65 100644 --- a/gaunt01/src/bird.h +++ b/gaunt01/src/bird.h @@ -52,6 +52,8 @@ class bird morphmesh model; ofImage texture; + + string currentseq; }; #endif // BIRD_H diff --git a/gaunt01/src/morphmesh.cpp b/gaunt01/src/morphmesh.cpp index e68e526..a126002 100644 --- a/gaunt01/src/morphmesh.cpp +++ b/gaunt01/src/morphmesh.cpp @@ -1,9 +1,5 @@ #include "morphmesh.h" -sequence::sequence() -{ -} - track::track() { } @@ -19,17 +15,89 @@ float track::evaluate(float time) { //interpolate key track if (time<=keys.begin()->first) return keys.begin()->second; - if (time>keys.rbegin()->first) return keys.rbegin()->second; - multimap< float,float >::iterator key2=keys.upper_bound( time ); - multimap< float,float >::iterator key1=key2--; + if (time>=keys.rbegin()->first) return keys.rbegin()->second; + map< float,float >::iterator key2=keys.upper_bound( time ); + map< float,float >::iterator key1=key2--; float interval=key2->first-key1->first; return (((1.0-((key2->first-time)/interval))*key2->second)+((1.0-((time-key1->first)/interval))*key1->second)); } +sequence::sequence(string _name,float _length,float _fadeinTime,float _fadeoutTime) +{ + name=_name; + length=_length; + startTime=0; + stopTime=0; + fadeinTime=_fadeinTime; + fadeoutTime=_fadeoutTime; + active=false; +} + +//----------------------------------------------------- +// stopTime & startTime are absolute +// +// all other time markers are relative to the sequence +// +// +void sequence::reset(){ + active=false; + fadeinTime=-1; + fadeoutTime=-1; + startTime=0; + stopTime=0; +} +void sequence::start(){ + reset(); + active=true; + startTime=ofGetElapsedTimef(); +} +void sequence::startAt(float time){ + reset(); + active=true; + startTime=ofGetElapsedTimef()+time; +} +void sequence::stopAt(float time){ + reset(); + active=true; + stopTime=ofGetElapsedTimef()+time; +} +void sequence::fadeout(float time){ + if(active==true) { + reset(); + active=true; + startTime=ofGetElapsedTimef(); + fadeoutTime=0; + stopTime=ofGetElapsedTimef()+time; + } +} +void sequence::fadein(float time){ + reset(); + active=true; + fadeinTime=time; + startTime=ofGetElapsedTimef(); +} +void sequence::stop(){ + reset(); +} + +vector sequence::evaluate(float time){ + float now=ofGetElapsedTimef(); + float seqtime=time-startTime; + float looptime=fmod(seqtime,length); + float fadeWeight=(seqtimefadeoutTime&&fadeoutTime>-1?1.0-(seqtime/(stopTime-startTime)):1.0); + vector weights; + map::iterator i; + for( i = tracks.begin(); i != tracks.end(); i++ ) { + weights.push_back(morphWeight(i->first,(i->second.evaluate(looptime))*fadeWeight)); + } + return weights; +} + morphmesh::morphmesh() { loaded=false; - /* + + /* //testing track function track testrack; testrack.keys.insert( pair(0.0,2.0) ); @@ -38,7 +106,7 @@ morphmesh::morphmesh() for (float f=-0.4;f<1.4;f+=0.1) { printf("%f : %f\n",f,testrack.evaluate(f)); } - */ + */ } morphmesh::morphmesh(string filename) @@ -51,6 +119,9 @@ morphmesh::morphmesh(string filename) int morphmesh::getNumTargets(){ return morphs.size(); } +int morphmesh::getNumSequences(){ + return sequences.size(); +} void morphmesh::draw() { draw(0); } @@ -64,26 +135,106 @@ void morphmesh::draw(string target){ addVertices(morphs[target]); ofMesh::draw(); } -void morphmesh::draw(const vector& targets, const vector& weights){ +void morphmesh::draw(const vector& weights){ clearVertices(); //normalise weights - int targetsNum=min(targets.size(),morphs.size()); float totalWeights=0; - for (int i=0;isecond.size();j++) { bx=by=bz=0; - for (int i=0;i weights; + map::iterator i; + for( i = sequences.begin(); i != sequences.end(); i++ ) { + if (i->second.active) { + vector newWeights=i->second.evaluate(time); + weights.insert(weights.end(),newWeights.begin(),newWeights.end()); + if (i->second.stopTime>0&&time>i->second.stopTime) i->second.active=false; + } + } + draw(weights); +} + + +bool morphmesh::loadSeqs(string filename){ + loaded=false; + ofxXmlSettings XML; + if( !XML.loadFile(filename) ){ + printf("unable to load %s check data/ folder\n",filename.c_str()); + }else{ + if(XML.pushTag("Gauntletanim")) { + int numSeqs=XML.getNumTags("Sequence"); + vector seqnames; + for (int i=0;i targnames; + for (int j=0;j times; + string keystring=XML.getAttribute("Keys","Times","none",0); + stringstream ks(keystring); + istream_iterator kbegin(ks); + istream_iterator kend; + vector kstrings(kbegin, kend); + + vector values; + string valstring=XML.getAttribute("Keys","Values","none",0); + stringstream vs(valstring); + istream_iterator vbegin(vs); + istream_iterator vend; + vector vstrings(vbegin, vend); + + track tr; + + for (int k=0;k verts; - string vertstring=XML.getAttribute("Attribute","Data","none",0); stringstream ss(vertstring); istream_iterator begin(ss); diff --git a/gaunt01/src/morphmesh.h b/gaunt01/src/morphmesh.h index 18463a8..bc22c3d 100644 --- a/gaunt01/src/morphmesh.h +++ b/gaunt01/src/morphmesh.h @@ -36,8 +36,9 @@ These could be parameterised on top of the rest? */ struct morphWeight { - string name; - float weight; + morphWeight(string _name="",float _weight=1.0) {name=_name;weight=_weight;} + string name; + float weight; }; struct key @@ -52,8 +53,7 @@ class track //a single morph channel. keys a single morph target within a single sequence public: track(); - string target; - multimap keys; + map keys; float evaluate(float time); }; @@ -67,15 +67,23 @@ class sequence //sequencer keeps track of playback time and start/stop of sequences //tracks is a map of time,value pairs - built in interpolation via multimap public: - sequence(); + sequence(string _name="",float _length=1.0,float _fadeinTime=-2.0,float _fadeoutTime=-2.0); + string name; map tracks; - vector evaluate(); - private: + vector evaluate(float time); + void reset(); + void start(); + void stop(); + void startAt(float time); + void stopAt(float time); + void fadein(float time); + void fadeout(float time); float length; float startTime; + float stopTime; float fadeinTime; float fadeoutTime; - bool loop,active; + bool active; }; @@ -90,10 +98,11 @@ class morphmesh : public ofMesh void draw(); void draw(int target); void draw(string target); - void draw(const vector& targets, const vector& weights); + void draw(const vector& weights); void drawAnimated(); //evaluates all active sequences via iterator and builds a collection of targets and weights for above int getNumTargets(); - map< string,sequence > sequences; //public for direct access + int getNumSequences(); + map sequences; //public for direct access protected: private: map< string,vector > morphs; diff --git a/morpher/bin/data/Bird-anim-test.xml b/morpher/bin/data/Bird-anim-test.xml deleted file mode 100644 index 245164e..0000000 Binary files a/morpher/bin/data/Bird-anim-test.xml and /dev/null differ diff --git a/morpher/bin/data/Bird-test.xml b/morpher/bin/data/Bird-test.xml deleted file mode 100644 index ebcdc00..0000000 --- a/morpher/bin/data/Bird-test.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/morpher/morpher.layout b/morpher/morpher.layout index 19ecc35..e0122f5 100644 --- a/morpher/morpher.layout +++ b/morpher/morpher.layout @@ -7,22 +7,22 @@ - + - + - + - + - + - + diff --git a/morpher/src/testApp.cpp b/morpher/src/testApp.cpp index 97d57db..e2163f5 100644 --- a/morpher/src/testApp.cpp +++ b/morpher/src/testApp.cpp @@ -11,7 +11,7 @@ void testApp::setup(){ mesh.sequences["hover"].start(); state=HOVER; - currentseq="attack"; + currentseq="hover"; texture.loadImage("TextureBird.jpg"); -- cgit v1.2.3