Browse Source

Make it possible to save `GridWarpSurface`

master
Krisjanis Rijnieks 9 years ago
parent
commit
32e5739a3e
  1. 56
      src/Application/SettingsLoader.cpp
  2. 1
      src/Application/SettingsLoader.h
  3. 4
      src/Surfaces/GridWarpSurface.cpp
  4. 1
      src/Surfaces/GridWarpSurface.h

56
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 <ofVec2f> 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 <ofVec2f> 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

1
src/Application/SettingsLoader.h

@ -22,6 +22,7 @@ class SettingsLoader {
BaseSurface * getTriangleSurface(ofxXmlSettings * xmlSettings);
BaseSurface * getQuadSurface(ofxXmlSettings * xmlSettings);
BaseSurface * getGridWarpSurface(ofxXmlSettings * xmlSettings);
};
}

4
src/Surfaces/GridWarpSurface.cpp

@ -129,6 +129,10 @@ vector <ofVec3f> & GridWarpSurface::getVertices(){
return mesh.getVertices();
}
vector <ofVec2f> & GridWarpSurface::getTexCoords(){
return mesh.getTexCoords();
}
void GridWarpSurface::createGridMesh(){
mesh.clear();

1
src/Surfaces/GridWarpSurface.h

@ -25,6 +25,7 @@ class GridWarpSurface : public BaseSurface {
void setVertex(int index, ofVec2f p);
void setVertices(vector<ofVec2f> v);
vector <ofVec3f> & getVertices();
vector <ofVec2f> & getTexCoords();
private:

Loading…
Cancel
Save