From adc1fe0182495151eba174f7ab5b99a900e10b5e Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Fri, 6 Apr 2012 00:00:16 +0100 Subject: changed morphmesh to use associative keys for targets --- morpher/morpher.layout | 24 +++++++++++++++--------- morpher/src/morphmesh.cpp | 48 ++++++++++++++++++++++++++++++----------------- morpher/src/morphmesh.h | 36 +++++++++++++++++++++++++++++------ morpher/src/testApp.cpp | 18 +++++++++--------- 4 files changed, 85 insertions(+), 41 deletions(-) (limited to 'morpher') diff --git a/morpher/morpher.layout b/morpher/morpher.layout index e0a0550..d273f51 100644 --- a/morpher/morpher.layout +++ b/morpher/morpher.layout @@ -1,22 +1,28 @@ - + - + - - + + - - + + - - + + - + + + + + + + diff --git a/morpher/src/morphmesh.cpp b/morpher/src/morphmesh.cpp index 77cc8c9..5fc7182 100644 --- a/morpher/src/morphmesh.cpp +++ b/morpher/src/morphmesh.cpp @@ -1,11 +1,14 @@ #include "morphmesh.h" morphmesh::morphmesh() -{} - +{ + loaded=false; +} + morphmesh::morphmesh(string filename) { - loadfile(filename); + morphmesh(); + loadMesh(filename); } morphmesh::~morphmesh() @@ -16,13 +19,17 @@ morphmesh::~morphmesh() int morphmesh::getNumTargets(){ return morphs.size(); } - +void morphmesh::draw() { + draw(0); +} void morphmesh::draw(int target){ clearVertices(); - addVertices(morphs[target]); + map >::iterator it=morphs.begin(); + for ( int i=0;isecond); ofMesh::draw(); } -void morphmesh::draw(const vector& targets, const vector& weights){ +void morphmesh::draw(const vector& targets, const vector& weights){ clearVertices(); //normalise weights int targetsNum=min(targets.size(),morphs.size()); @@ -30,7 +37,7 @@ void morphmesh::draw(const vector& targets, const vector& weights){ for (int i=0;i& targets, const vector& weights){ ofMesh::draw(); } -bool morphmesh::loadfile(string filename){ - bool loaded=false; +bool morphmesh::loadMesh(string filename){ + loaded=false; ofxXmlSettings XML; if( !XML.loadFile(filename) ){ printf("unable to load %s check data/ folder\n",filename.c_str()); @@ -51,11 +58,13 @@ bool morphmesh::loadfile(string filename){ if(XML.pushTag("Oak3DModelDocument")) { if(XML.pushTag("MeshList")) { int numMeshes=XML.getNumTags("Mesh"); + vector meshnames; + for (int i=0;i verts; - + string vertstring=XML.getAttribute("Attribute","Data","none",0); stringstream ss(vertstring); istream_iterator begin(ss); @@ -64,11 +73,11 @@ bool morphmesh::loadfile(string filename){ for (int j=0;j norms; string normstring=XML.getAttribute("Attribute","Data","none",1); stringstream ns(normstring); @@ -79,7 +88,7 @@ bool morphmesh::loadfile(string filename){ norms.push_back(ofVec3f(ofToFloat(nstrings[j]),ofToFloat(nstrings[j+1]),ofToFloat(nstrings[j+2]))); } addNormals(norms); - + vector texcords; string texstring=XML.getAttribute("Attribute","Data","none",2); stringstream ts(texstring); @@ -90,9 +99,9 @@ bool morphmesh::loadfile(string filename){ texcords.push_back(ofVec2f(ofToFloat(tstrings[j]),ofToFloat(tstrings[j+1]))); } addTexCoords(texcords); - + XML.popTag(); - + if (XML.pushTag("IndexList")) { vector faces; string facestring=XML.getAttribute("Index","Data","none",0); @@ -120,4 +129,9 @@ bool morphmesh::loadfile(string filename){ XML.popTag(); } return loaded; -} \ No newline at end of file +} + +bool morphmesh::isLoaded() +{ + return loaded; +} diff --git a/morpher/src/morphmesh.h b/morpher/src/morphmesh.h index 7e3cb0b..ca1231c 100644 --- a/morpher/src/morphmesh.h +++ b/morpher/src/morphmesh.h @@ -18,26 +18,50 @@ Multiple meshes are loaded as morph targets Coords are absolute -TODO -draw(vector targets, vector weights); - m + +--managing movement sequences +--cycles can refer to targets by name +--high level controller objects can refer to animation sequences by name +--this makes it impossible for a re-odering to banjax everything + +cycles have a start time, and they either loop or act as a transition + +Working out the morphs is a question of: +-working out which cycles are active based on behaviours +-adding their morph targets into the current vector of targets + +behaviours are triggered by things like spotting people or avoiding the wall. +These could be parameterised on top of the rest? */ +class sequence +{ + //stores a morph sequence: an animation cycle or transition + public: + sequence(); + virtual ~sequence(); + + +}; + class morphmesh : public ofMesh { public: morphmesh(); morphmesh(string filename); virtual ~morphmesh(); - bool loadfile(string filename); + bool loadMesh(string filename); + bool isLoaded(); + void draw(); void draw(int target); - void draw(const vector& targets, const vector& weights); + void draw(const vector& targets, const vector& weights); int getNumTargets(); protected: private: - //vector < >targets; - vector< vector > morphs; + map< string,vector > morphs; + bool loaded; }; #endif // MORPHMESH_H diff --git a/morpher/src/testApp.cpp b/morpher/src/testApp.cpp index 3b5779e..a55ee13 100644 --- a/morpher/src/testApp.cpp +++ b/morpher/src/testApp.cpp @@ -4,16 +4,16 @@ void testApp::setup(){ mesh=morphmesh(); //mesh.loadfile("Bird-test1.xml"); - if (mesh.loadfile("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-test.xml")) printf("mesh loaded with %i vertices, %i face indices, %i targets\n",mesh.getNumVertices(),mesh.getNumIndices(),mesh.getNumTargets()); else printf("XML not parsed\n"); texture.loadImage("texture2.jpg"); - + xr=yr=0; xo=yo=0; - + glEnable(GL_DEPTH_TEST); - + //movieExporter.setup(); } @@ -28,14 +28,14 @@ void testApp::update(){ void testApp::draw(){ //calculate morph targets float segment=(sin(ofGetElapsedTimef())*0.5)+0.5; - vector targets; + vector targets; vector weights; - targets.push_back(0); + targets.push_back("bird 2"); weights.push_back(segment); - targets.push_back(1); + targets.push_back("bird"); weights.push_back(1.0-segment); //printf("drawing %f %f\n",segment,1.0-segment); - + ofBackground(0,0,0); bindTexture(texture); ofPushMatrix(); @@ -47,7 +47,7 @@ void testApp::draw(){ mesh.draw(targets,weights); ofPopMatrix(); unbindTexture(texture); - + ofSetHexColor(0xFFFFFF); ofDrawBitmapString("fps: "+ofToString(ofGetFrameRate(), 2), 10, 15); } -- cgit v1.2.3