diff options
Diffstat (limited to 'morpher')
| -rw-r--r-- | morpher/morpher.layout | 24 | ||||
| -rw-r--r-- | morpher/src/morphmesh.cpp | 48 | ||||
| -rw-r--r-- | morpher/src/morphmesh.h | 36 | ||||
| -rw-r--r-- | morpher/src/testApp.cpp | 18 |
4 files changed, 85 insertions, 41 deletions
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 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <CodeBlocks_layout_file> <ActiveTarget name="Debug" /> - <File name="addons.make" open="1" top="0" tabpos="8"> + <File name="addons.make" open="0" top="0" tabpos="8"> <Cursor position="14" topLine="0" /> </File> - <File name="config.make" open="1" top="0" tabpos="9"> + <File name="config.make" open="0" top="0" tabpos="9"> <Cursor position="478" topLine="0" /> </File> - <File name="src/morphmesh.cpp" open="1" top="0" tabpos="5"> - <Cursor position="245" topLine="0" /> + <File name="src/morphmesh.cpp" open="1" top="1" tabpos="6"> + <Cursor position="815" topLine="23" /> </File> - <File name="src/morphmesh.h" open="1" top="1" tabpos="4"> - <Cursor position="333" topLine="4" /> + <File name="src/morphmesh.h" open="1" top="0" tabpos="5"> + <Cursor position="1187" topLine="35" /> </File> - <File name="src/testApp.cpp" open="1" top="0" tabpos="6"> - <Cursor position="460" topLine="0" /> + <File name="src/normBindTexture.cpp" open="1" top="0" tabpos="2"> + <Cursor position="0" topLine="3" /> </File> - <File name="src/testApp.h" open="1" top="0" tabpos="7"> + <File name="src/normBindTexture.h" open="1" top="0" tabpos="1"> + <Cursor position="0" topLine="0" /> + </File> + <File name="src/testApp.cpp" open="1" top="0" tabpos="4"> + <Cursor position="1167" topLine="25" /> + </File> + <File name="src/testApp.h" open="1" top="0" tabpos="3"> <Cursor position="597" topLine="0" /> </File> </CodeBlocks_layout_file> 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<string,vector<ofVec3f> >::iterator it=morphs.begin(); + for ( int i=0;i<target;i++ ) it++; + addVertices(it->second); ofMesh::draw(); } -void morphmesh::draw(const vector<int>& targets, const vector<float>& weights){ +void morphmesh::draw(const vector<string>& targets, const vector<float>& weights){ clearVertices(); //normalise weights int targetsNum=min(targets.size(),morphs.size()); @@ -30,7 +37,7 @@ void morphmesh::draw(const vector<int>& targets, const vector<float>& weights){ for (int i=0;i<targetsNum;i++) totalWeights+=weights[i]; float weightFactor=1.0/totalWeights; float bx,by,bz; - for (int j=0;j<morphs[0].size();j++) { + for (int j=0;j<morphs[targets[0]].size();j++) { bx=by=bz=0; for (int i=0;i<targetsNum;i++) { bx+=morphs[targets[i]][j].x*weights[i]; @@ -42,8 +49,8 @@ void morphmesh::draw(const vector<int>& targets, const vector<float>& 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<string> meshnames; + for (int i=0;i<numMeshes;i++) meshnames.push_back(XML.getAttribute("Mesh","Name","none",i)); for (int i=0;i<numMeshes;i++) { XML.pushTag("Mesh",i); if (XML.pushTag("AttributeList")) { vector<ofVec3f> verts; - + string vertstring=XML.getAttribute("Attribute","Data","none",0); stringstream ss(vertstring); istream_iterator<string> begin(ss); @@ -64,11 +73,11 @@ bool morphmesh::loadfile(string filename){ for (int j=0;j<vstrings.size();j+=3) { verts.push_back(ofVec3f(ofToFloat(vstrings[j]),ofToFloat(vstrings[j+1]),ofToFloat(vstrings[j+2]))); } - morphs.push_back(verts); - + morphs[meshnames[i]]=verts; + if (i==0) { addVertices(verts); - + vector<ofVec3f> 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<ofVec2f> 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<ofIndexType> 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<int> targets, vector<float> 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<int>& targets, const vector<float>& weights); + void draw(const vector<string>& targets, const vector<float>& weights); int getNumTargets(); protected: private: - //vector < <vector <ofVec3f> >targets; - vector< vector<ofVec3f> > morphs; + map< string,vector<ofVec3f> > 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<int> targets; + vector<string> targets; vector<float> 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); } |
