void SceneParser::parseObjects(void) { if(currentToken == Scanner::StreamDone) return; else{ while(errorFlag == false && currentToken != Scanner::StreamDone) { acceptToken(Scanner::Id); string tokenText = scanner.tokenText(); if(tokenText == "sphere") parseSphere(); else if(tokenText == "box") parseBox(); else if(tokenText == "plane") parsePlane(); else if(tokenText == "triangle") parseTriangle(); else if(tokenText == "mesh") parseMesh(); else if(tokenText == "cone") parseCone(); else if(tokenText == "cylinder") parseCylinder(); else if(tokenText == "pointlight") parsePointLight(); else if(tokenText == "directionallight") parseDirectionalLight(); else if(tokenText == "spotlight") parseSpotlight(); else if(tokenText == "arealight") parseAreaLight(); else{ error("undefined command: " + tokenText); } advance(); } } }
Scene* Parser::parseScene(){ /// xml_node scene = root.child("scene"); // optional name Scene* _s; if (scene.attribute("name") != NULL) _s = new Scene(scene.attribute("name").value()); else _s = Scene::New(); // optional settings xml_node op; op = scene.child("background"); float x, y, z; if (op != NULL) { const char* back = op.text().as_string(); sscanf(back, "%f %f %f", &x, &y, &z); _s->backgroundColor = Color(x, y, z); scene.remove_child("background"); } op = scene.child("ambient"); if (op != NULL) { const char* amb = op.text().as_string(); sscanf(amb, "%f %f %f", &x, &y, &z); _s->ambientLight = Color(x, y, z); scene.remove_child("ambient"); } // processing the objets in the scene xml_object_range<xml_node_iterator> objets = scene.children(); Light* light; for (xml_node_iterator sceneElement = objets.begin(); sceneElement != objets.end(); ++sceneElement) { if (strcmp(sceneElement->name(), "mesh") == 0) _s->addActor(parseMesh(sceneElement)); if (strcmp(sceneElement->name(), "sphere") == 0) _s->addActor(parseSphere(sceneElement)); if (strcmp(sceneElement->name(), "box") == 0) _s->addActor(parseBox(sceneElement)); if (strcmp(sceneElement->name(), "cone") == 0) _s->addActor(parseCone(sceneElement)); if (strcmp(sceneElement->name(), "cylinder") == 0) _s->addActor(parseCylinder(sceneElement)); else if (strcmp(sceneElement->name(), "light") == 0){ light = parseLight(sceneElement); _s->addLight(light); } } return _s; }