void Render::loadXML(ofXml &xml) { if (xml.exists("[@vsync]")) { string str = ofToString( xml.getAttribute("[@vsync]") ); if (str == "on") vsync = true; else vsync = false; } if (xml.exists("[@framerate]")) framerate = ofToInt( xml.getAttribute("[@framerate]") ); setup(); }
void Socket::loadXML(ofXml &xml) { if (xml.exists("socket[@enabled]")) { string str = ofToString(xml.getAttribute("socket[@enabled]")); if (str == "on") enabled = true; else enabled = false; } if (xml.exists("socket[@host]")) host = ofToString( xml.getAttribute("socket[@host]") ); if (xml.exists("socket[@send]")) send = ofToInt( xml.getAttribute("socket[@send]") ); if (xml.exists("socket[@receive]")) receive = ofToInt( xml.getAttribute("socket[@receive]") ); if (enabled) setup(); }
void Projector::loadXML(ofXml &xml) { string str; if (xml.exists("[@resolution]")) { str = xml.getAttribute("[@resolution]"); width = ofToFloat(ofSplitString(str, ",")[0]); height = ofToFloat(ofSplitString(str, ",")[1]); } }
void Projector::loadXML2(ofXml &xml) { string str; float val; // color if (xml.exists("[@brightness]")) { brightness = ofToFloat( xml.getAttribute("[@brightness]")); } if (xml.exists("[@contrast]")) { contrast = ofToFloat( xml.getAttribute("[@contrast]") ); } if (xml.exists("[@saturation]")) { saturation = ofToFloat( xml.getAttribute("[@saturation]") ); } // plane warp plane.width = width; plane.height = height; plane.load(xml, projectorStartingIndex); // camera position if (xml.exists("[@position]")) { str = xml.getAttribute("[@position]"); float azi = ofToFloat(ofSplitString(str, ",")[0]); float ele = ofToFloat(ofSplitString(str, ",")[1]); float dis = ofToFloat(ofSplitString(str, ",")[2]); setCameraPosition(azi, ele, dis); } // camera orientation if (xml.exists("[@orientation]")) { str = xml.getAttribute("[@orientation]"); float roll = ofToFloat(ofSplitString(str, ",")[0]); float tilt = ofToFloat(ofSplitString(str, ",")[1]); float pan = ofToFloat(ofSplitString(str, ",")[2]); setCameraOrientation(roll, tilt, pan); } // camera lens fov if (xml.exists("[@fov]")) { val = ofToFloat( xml.getAttribute("[@fov]") ); setCameraFov(val); } //camera lens offset if (xml.exists("[@offset]")) { str = xml.getAttribute("[@offset]"); float offX = ofToFloat(ofSplitString(str, ",")[0]); float offY = ofToFloat(ofSplitString(str, ",")[1]); setCameraOffset(offX, offY); } curves.load(projectorStartingIndex); mask.width = width; mask.height = height; mask.load(projectorStartingIndex); }
void ofxShaderGraph::buildFromXml(ofXml x){ unordered_set<string> root_names; x.reset(); unsigned long n = x.getNumChildren(); params.setName(x.getName()); //first pass, create all nodes and set defaults for(unsigned long i=0; i<n; i++){ x.reset(); x.setToChild(i); if(x.getName()!="node") continue; string name = x.getAttribute("name"); if(name==""){ cout<<"ofxShaderGraph warning: anonymous node in XML"<<endl; continue; } ofxBaseShaderNode *node; ofFbo::Settings node_fbo_settings = fbo_settings; //check for modifications to fbo_settings if(x.setTo("scale")){ float scale = x.getFloatValue(); node_fbo_settings.width*=scale; node_fbo_settings.height*=scale; x.setToParent(); } string format = x.getAttribute("format"); if(format!=""){ if(format=="rgba8") node_fbo_settings.internalformat = GL_RGBA8; else if(format=="rgba16") node_fbo_settings.internalformat = GL_RGBA16; else if(format=="rgba32f") node_fbo_settings.internalformat = GL_RGBA32F; else if(format=="rgba16f") node_fbo_settings.internalformat = GL_RGBA16F; else if(format=="rgb8") node_fbo_settings.internalformat = GL_RGB8; else if(format=="rgb16") node_fbo_settings.internalformat = GL_RGB16; else if(format=="rgb32f") node_fbo_settings.internalformat = GL_RGB32F; else if(format=="rgb16f") node_fbo_settings.internalformat = GL_RGB16F; } //check for node to swap buffers with string swap_name = x.getAttribute("swap"); if(swap_name != ""){ //don't duplicate pairs if(swap.count(swap_name)==0){ cout<<"ofxShaderGraph: "<<name<<" swaps with "<<swap_name<<endl; swap.insert(pair<string, string>(name, swap_name)); }else{ cout<<"ofxShaderGraph warning: ignoring duplicate swap of"<<name<<" with "<<swap_name<<endl; } } //check for color to init buffer to if(x.setTo("init")){ float val = x.getFloatValue(); init.insert(pair<string, float>(name, val)); x.setToParent(); } //check for shader path string shader_name = x.getAttribute("shader"); if(shader_name == ""){ //shaderless node node = new ofxConstantShaderNode(allocator, node_fbo_settings, name); } else{ ofShader *shader = new ofShader(); stringstream shader_path; shader_path<<ofToDataPath("../../src/shader/")<<shader_name; shader->load(shader_path.str()); if(!shader->isLoaded()){ cout<<"ofxShaderGraph warning: shader "<<shader_name<<" failed to load from path "<<shader_path.str()<<endl; } else{ cout<<"ofxShaderGraph: loaded shader "<<shader_name<<endl; } node = new ofxBaseShaderNode(allocator, node_fbo_settings, name, shader); } //grab all of the new node's parameters params.add(node->getParameterGroup()); //put it in the map from names to nodes nodes.insert(pair<string, ofxBaseShaderNode*>(name, node)); //everything goes in root_names, to be removed when is appears as an input root_names.insert(name); cout<<"ofxShaderGraph: inserted node "<<name<<endl; //set defaults if(x.setTo("defaults") && x.setToChild(0)){ do{ string param_type = x.getName(); string param_name = x.getAttribute("name"); if(param_type=="float"){ float v = x.getFloatValue(); node->setParameter(param_name, v); }else if(param_type=="int"){ int v = x.getIntValue(); node->setParameter(param_name, v); }else{ cout<<"ofxShaderGraph warning: parameter type "<<param_type<<" unsupported"<<endl; } }while(x.setToSibling()); x.setToParent(); x.setToParent(); } //set aliases /*if(x.setTo("aliases") && x.setToChild(0)){ do{ string param_type = x.getName(); string param_name = x.getAttribute("name"); string alias_name = x.getValue(); if(param_type=="float"){ auto alias_param = aliases.getFloat(alias_name); node->setParameterAlias(param_name, alias_param); }else if(param_type=="int"){ auto alias_param = aliases.getInt(alias_name); node->setParameterAlias(param_name, alias_param); }else{ cout<<"ofxShaderGraph warning: aliased parameter type "<<param_type<<" unsupported"<<endl; } }while(x.setToSibling()); x.setToParent(); x.setToParent(); }*/ } //second pass, fill in inputs for each node and remove all referenced nodes from root_names for(unsigned long i=0; i<n; i++){ x.reset(); x.setToChild(i); if(x.getName()!="node") continue; string name = x.getAttribute("name"); if(name=="") continue; ofxBaseShaderNode *node = nodes[name]; //set inputs if(!x.setTo("inputs")) continue; if(!x.setToChild(0)) continue; do{ string input_name = x.getValue(); if(nodes.find(input_name) == nodes.end()){ cout << "ofxShaderGraph error: node "<<name<<" lists input "<<input_name<<" which does not exist"<<endl; } else{ ofxBaseShaderNode *input = nodes.at(input_name); node->inputs.push_back(input); input->num_dependents++; root_names.erase(input_name); cout<<"ofxShaderGraph: connected node "<<input_name<<" to node "<<name<<endl; } }while(x.setToSibling()); } //populate roots for(string root_name:root_names){ ofxBaseShaderNode *root_node = nodes.at(root_name); roots.insert(root_node); cout<<"ofxShaderGraph: node "<<root_name<<" is a root"<<endl; } }