From 1e10e507d20f7f38e65672ae1a5499b84b805e62 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 10 Apr 2012 16:57:56 +0100 Subject: sequence blending working --- morpher/src/morphmesh.cpp | 79 +++++++++++++++++++++++++++++++++++++---------- morpher/src/morphmesh.h | 7 ++++- morpher/src/testApp.cpp | 67 +++++++++++++++++++++++++++++++++------- morpher/src/testApp.h | 9 ++++++ 4 files changed, 132 insertions(+), 30 deletions(-) (limited to 'morpher/src') diff --git a/morpher/src/morphmesh.cpp b/morpher/src/morphmesh.cpp index 63d58f7..9ab414a 100644 --- a/morpher/src/morphmesh.cpp +++ b/morpher/src/morphmesh.cpp @@ -26,33 +26,73 @@ sequence::sequence(string _name,float _length,float _fadeinTime,float _fadeoutTi { name=_name; length=_length; - startTime=0.0; - stopTime=0.0; + 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::stop(){ +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 seqtime=time-startTime; - float fadeWeight=(seqtimestopTime-fadeoutTime&&stopTime>0&&fadeoutTime>0?(seqtime-fadeoutTime)/(stopTime-fadeoutTime):1.0); - vector weights; - map::iterator i; - for( i = tracks.begin(); i != tracks.end(); i++ ) { - weights.push_back(morphWeight(i->first,(i->second.evaluate(seqtime))*fadeWeight)); - } - return weights; + 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; @@ -96,8 +136,6 @@ void morphmesh::draw(string target){ ofMesh::draw(); } void morphmesh::draw(const vector& weights){ - morphWeight mw[2]; - for (int i=0;i::iterator i; for( i = sequences.begin(); i != sequences.end(); i++ ) { if (i->second.active) { - vector newWeights=i->second.evaluate(fmod(time-i->second.startTime,i->second.length)); - int nnw= newWeights.size(); //test + vector newWeights=i->second.evaluate(time); weights.insert(weights.end(),newWeights.begin(),newWeights.end()); - int nw= weights.size(); //test if (i->second.stopTime>0&&time>i->second.stopTime) i->second.active=false; } } @@ -179,6 +215,15 @@ bool morphmesh::loadSeqs(string filename){ XML.popTag(); } sequences[seqnames[i]]=seq; + + printf("testing sequence: %s\n",seqnames[i].c_str()); + for (int k=0;k tracks; 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; diff --git a/morpher/src/testApp.cpp b/morpher/src/testApp.cpp index 31dffb4..97d57db 100644 --- a/morpher/src/testApp.cpp +++ b/morpher/src/testApp.cpp @@ -3,17 +3,20 @@ //-------------------------------------------------------------- void testApp::setup(){ //mesh.loadfile("Bird-test1.xml"); - if (mesh.loadMesh("Bird-test.xml")) printf("mesh loaded with %i vertices, %i face indices, %i targets\n",mesh.getNumVertices(),mesh.getNumIndices(),mesh.getNumTargets()); + if (mesh.loadMesh("Bird-poses.xml")) printf("mesh loaded with %i vertices, %i face indices, %i targets\n",mesh.getNumVertices(),mesh.getNumIndices(),mesh.getNumTargets()); else printf("mesh XML file not parsed\n"); - if (mesh.loadSeqs("Bird-anim-test.xml")) printf("animation loaded with %i sequences\n",mesh.getNumSequences()); + if (mesh.loadSeqs("Bird-anim.xml")) printf("animation loaded with %i sequences\n",mesh.getNumSequences()); else printf("animation XML file not parsed\n"); - mesh.sequences["flap"].start(); - - texture.loadImage("texture2.jpg"); + mesh.sequences["hover"].start(); + state=HOVER; + currentseq="attack"; + + texture.loadImage("TextureBird.jpg"); - xr=yr=0; + xr=90; + yr=0; xo=yo=0; glEnable(GL_DEPTH_TEST); @@ -43,7 +46,7 @@ void testApp::draw(){ ofRotate(xr,0,1,0); ofRotate(yr,1,0,0); ofRotate(180,1,0,0); - ofScale(2.0,2.0,2.0); + ofScale(1.0,1.0,1.0); //mesh.draw(testweight); mesh.drawAnimated(); ofPopMatrix(); @@ -54,14 +57,54 @@ void testApp::draw(){ } //-------------------------------------------------------------- +/* + void start(); + void stop(); + void startAt(float time); + void fadeout(float time); +*/ void testApp::keyPressed(int key){ - + switch (key){ - case 'a': - //if (movieExporter.isRecording()) movieExporter.stop(); - //else movieExporter.record(); + case '1': + if (currentseq!="hover") { + //mesh.sequences["trans_flaphover"].stopAt(0.3); + //mesh.sequences["trans_flaphover"].start(); + mesh.sequences[currentseq].fadeout(0.5); + mesh.sequences["hover"].fadein(0.5); + currentseq="hover"; + } + break; + case '2': + if (currentseq!="flap") { + //mesh.sequences["trans_hoverflap"].stopAt(0.3); + //mesh.sequences["trans_hoverflap"].start(); + mesh.sequences[currentseq].fadeout(0.5); + mesh.sequences["flap"].fadein(0.5); + currentseq="flap"; + } + break; + case '3': + if (currentseq!="swoop") { + //mesh.sequences["trans_hoverflap"].stopAt(0.3); + //mesh.sequences["trans_hoverflap"].start(); + mesh.sequences[currentseq].fadeout(0.25); + mesh.sequences["swoop_trans"].fadein(0.25); + mesh.sequences["swoop_trans"].stopTime=ofGetElapsedTimef()+1.0; + mesh.sequences["swoop"].startAt(1.0); + currentseq="swoop"; + } break; - case 'z': + case '4': + if (currentseq!="attack") { + //mesh.sequences["trans_hoverflap"].stopAt(0.3); + //mesh.sequences["trans_hoverflap"].start(); + mesh.sequences[currentseq].fadeout(0.2); + mesh.sequences["attack_trans"].fadein(0.2); + mesh.sequences["attack_trans"].stopTime=ofGetElapsedTimef()+0.6; + mesh.sequences["attack"].startAt(0.6); + currentseq="attack"; + } break; } } diff --git a/morpher/src/testApp.h b/morpher/src/testApp.h index c0b665e..0b528ae 100644 --- a/morpher/src/testApp.h +++ b/morpher/src/testApp.h @@ -8,6 +8,11 @@ //#include "ofxMovieExporter.h" +#define HOVER 1 +#define TRANS_HOVERFLY 2 +#define FLAP 3 +#define TRANS_FLYHOVER 4 + class testApp : public ofBaseApp{ public: @@ -33,5 +38,9 @@ class testApp : public ofBaseApp{ int yo,xo; //Apex::ofxMovieExporter movieExporter; + + int state; + + string currentseq; }; -- cgit v1.2.3