diff --git a/src/Application/SettingsLoader.cpp b/src/Application/SettingsLoader.cpp index af56a7a..13bbcaa 100644 --- a/src/Application/SettingsLoader.cpp +++ b/src/Application/SettingsLoader.cpp @@ -89,6 +89,12 @@ bool SettingsLoader::load(SurfaceStack & surfaces, MediaServer & mediaServer, st quadSurface->setSource(source); } surfaces.push_back(quadSurface); + }else if(vertexCount > 4){ + BaseSurface * gridWarpSurface = getGridWarpSurface(xmlSettings); + if(sourceName != "none" && source != 0){ + gridWarpSurface->setSource(source); + } + surfaces.push_back(gridWarpSurface); } xmlSettings->popTag(); // surface @@ -331,5 +337,55 @@ BaseSurface * SettingsLoader::getQuadSurface(ofxXmlSettings * xmlSettings){ return quadSurface; } +BaseSurface * SettingsLoader::getGridWarpSurface(ofxXmlSettings * xmlSettings){ + vector vertices; + + if(xmlSettings->tagExists("vertices")){ + xmlSettings->pushTag("vertices"); + + int iv = 0; + + while(xmlSettings->tagExists("vertex", iv)){ + xmlSettings->pushTag("vertex", iv); + vertices.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), + xmlSettings->getValue("y", 0.0f))); + xmlSettings->popTag(); + ++iv; + } + + xmlSettings->popTag(); // vertices + } + + vector texCoords; + + if(xmlSettings->tagExists("texCoords")){ + xmlSettings->pushTag("texCoords"); + + int it = 0; + + while(xmlSettings->tagExists("texCoord", it)){ + xmlSettings->pushTag("texCoord", it); + texCoords.push_back(ofVec2f(xmlSettings->getValue("x", 0.0f), + xmlSettings->getValue("y", 0.0f))); + xmlSettings->popTag(); + ++it; + } + + xmlSettings->popTag(); // texCoords + } + + // Create and add quad surface + BaseSurface * gridWarpSurface = + SurfaceFactory::instance()->createSurface( + SurfaceType::GRID_WARP_SURFACE); + gridWarpSurface->setVertices(vertices); + gridWarpSurface->setTexCoords(texCoords); + + return gridWarpSurface; +} + + + + } // namespace piMapper } // namespace ofx \ No newline at end of file diff --git a/src/Application/SettingsLoader.h b/src/Application/SettingsLoader.h index ed51461..1738c90 100644 --- a/src/Application/SettingsLoader.h +++ b/src/Application/SettingsLoader.h @@ -22,6 +22,7 @@ class SettingsLoader { BaseSurface * getTriangleSurface(ofxXmlSettings * xmlSettings); BaseSurface * getQuadSurface(ofxXmlSettings * xmlSettings); + BaseSurface * getGridWarpSurface(ofxXmlSettings * xmlSettings); }; } diff --git a/src/Surfaces/GridWarpSurface.cpp b/src/Surfaces/GridWarpSurface.cpp index 33eb1fe..c08f6ea 100644 --- a/src/Surfaces/GridWarpSurface.cpp +++ b/src/Surfaces/GridWarpSurface.cpp @@ -129,6 +129,10 @@ vector & GridWarpSurface::getVertices(){ return mesh.getVertices(); } +vector & GridWarpSurface::getTexCoords(){ + return mesh.getTexCoords(); +} + void GridWarpSurface::createGridMesh(){ mesh.clear(); diff --git a/src/Surfaces/GridWarpSurface.h b/src/Surfaces/GridWarpSurface.h index 15db21b..f0ac613 100644 --- a/src/Surfaces/GridWarpSurface.h +++ b/src/Surfaces/GridWarpSurface.h @@ -25,6 +25,7 @@ class GridWarpSurface : public BaseSurface { void setVertex(int index, ofVec2f p); void setVertices(vector v); vector & getVertices(); + vector & getTexCoords(); private: