// parses material in materialNode and stores it in the scene bool SceneParser::addGlobalMaterial(struct basicxmlnode * materialNode, Scene * scene){ if (!materialNode) { std::cout << "SceneParser::addGlobalMaterial: empty node \n"; return false; } std::string materialName = materialNode->tag; // create Material Material* new_material = new Material(); Vector4 vectorValue; double shininess; // read user specified values char * attributeValue; if (attributeValue = getattributevaluebyname(materialNode, "emission")) { if (!stringToVector4<double>(vectorValue, attributeValue)) { delete(new_material); return false; } new_material->emission = vectorValue; } if (attributeValue = getattributevaluebyname(materialNode, "ambient")) { if (!stringToVector4<double>(vectorValue, attributeValue)) { delete(new_material); return false; } new_material->ambient = vectorValue; } if (attributeValue = getattributevaluebyname(materialNode, "diffuse")) { if (!stringToVector4<double>(vectorValue, attributeValue)) { delete(new_material); return false; } new_material->diffuse = vectorValue; } if (attributeValue = getattributevaluebyname(materialNode, "specular")) { if (!stringToVector4<double>(vectorValue, attributeValue)) { delete(new_material); return false; } new_material->specular = vectorValue; } if (attributeValue = getattributevaluebyname(materialNode, "shininess")) { if (!stringToNumber<double>(shininess, attributeValue)) { delete(new_material); return false; } new_material->shininess = shininess; } // add pointer to materiallist of the scene scene->addMaterial(materialName, new_material); std::cout << "SceneParser::addGlobalMaterial: added global material " << materialName <<"\n"; return true; }
bool ConfigParser::addRendererProperties(struct basicxmlnode * rendererNode, Renderer * renderer) { if (!rendererNode) { std::cout << "ConfigParser::addRendererProperties: empty renderer node\n"; return false; } if (std::string(rendererNode->tag) != "Renderer") { std::cout << "ConfigParser::addRendererProperties: config file has to have toplevel Renderer node\n"; return false; } // read renderer properties unsigned int recursionDepth; char * attributeValue; if (attributeValue = getattributevaluebyname(rendererNode, "recursionDepth")) { if (!stringToNumber<unsigned int>(recursionDepth, attributeValue)) { return false; } renderer->setRecursiondepth(recursionDepth); } return true; }
// reads the reference of the material and returns a pointer. If no valid reference // is found it returns a pointer to the default material Material* SceneParser::getMaterialReference(struct basicxmlnode * materialNode, Scene* scene){ Material* material = scene->getDefaultMaterial(); if (!materialNode) { std::cout << "SceneParser::addElementMaterial: empty node \n"; return material; } char * attributeValue; // see if it is a reference to a global material if (attributeValue = getattributevaluebyname(materialNode, "ref")) { if (scene->getMaterial(attributeValue)) { material = scene->getMaterial(attributeValue); std::cout << "SceneParser::getMaterialReference: added global material " << attributeValue << " to element\n"; return material; } else { std::cout << "SceneParser::getMaterialReference: reffered material not defined\n"; return material; } } // material ref not found. Use default std::cout << "SceneParser::addElementMaterial: material ref not found. Using default.\n"; return material; }
bool ConfigParser::addShader(struct basicxmlnode * shaderNode, WhittedIntegrator* whittedIntegrator ){ if (!shaderNode) { std::cout << "ConfigParser::addShader: empty shader node\n"; return false; } if (std::string(shaderNode->tag) != "Shader") { std::cout << "ConfigParser::addShader: wrong shader tag name\n"; return false; } // read shader type std::string type = getattributevaluebyname(shaderNode, "type"); if (type == "ConstantShader") { whittedIntegrator->setShader(WhittedIntegrator::CONSTANT ); } else if (type == "DiffuseLightingShader") { whittedIntegrator->setShader(WhittedIntegrator::DIFFUSE); } else if (type == "PhongLightingShader") { whittedIntegrator->setShader(WhittedIntegrator::PHONG); } #ifdef READ_BUMPMAP_FLAG else if (type == "PhongBumpShader") { whittedIntegrator->setShader(WhittedIntegrator::PHONGBUMP); } #endif else { std::cout << "ConfigParser::addShader: unknown shader specified\n"; return false; } return true; }
// reads the reference of the texture and returns a pointer. If no valid reference // is found it returns NULL ITexture* SceneParser::getTextureReference(struct basicxmlnode* textureNode, Scene* scene) { if (!textureNode) { std::cout << "SceneParser::addElementMaterial: empty node \n"; return 0; } char * attributeValue; // see if it is a reference to a global texture if (attributeValue = getattributevaluebyname(textureNode, "ref")) { if (scene->getTexture(attributeValue)) { std::cout << "SceneParser::getTextureReference: added global texture " << attributeValue << " to element\n"; return scene->getTexture(attributeValue);; } else { std::cout << "SceneParser::getTextureReference: reffered texture not defined\n"; return 0; } } // texture ref not found. std::cout << "SceneParser::addElementMaterial: material ref not found. Using default.\n"; return 0; }
bool ConfigParser::addShader(struct basicxmlnode * shaderNode, Renderer * renderer){ if (!shaderNode) { std::cout << "ConfigParser::addShader: empty shader node\n"; return false; } if (std::string(shaderNode->tag) != "Shader") { std::cout << "ConfigParser::addShader: wrong shader tag name\n"; return false; } // read shader type std::string type = getattributevaluebyname(shaderNode, "type"); if (type == "ConstantShader") { renderer->setShader(new ConstantShader()); } else if (type == "DiffuseLightingShader") { renderer->setShader(new DiffuseLightingShader()); } else if (type == "PhongLightingShader") { renderer->setShader(new PhongLightingShader()); } #ifdef READ_BUMPMAP_FLAG else if (type == "PhongBumpShader") { renderer->setShader(new PhongBumpShader()); } #endif else { std::cout << "ConfigParser::addShader: unknown shader specified\n"; return false; } return true; }
bool ConfigParser::addSampler(struct basicxmlnode * samplerNode, Renderer * renderer){ if (!samplerNode) { std::cout << "ConfigParser::addSampler: empty sampler node\n"; return false; } if (std::string(samplerNode->tag) != "Sampler") { std::cout << "ConfigParser::addSampler: wrong sampler tag name\n"; return false; } // read sampler type std::string type = getattributevaluebyname(samplerNode, "type"); if (type == "ScanlineSampler") { renderer->setSampler(new ScanlineSampler()); } #ifdef READ_SUPERSAMPLER_FLAG else if (type == "SuperSampler") { double sample_pixel=1; char* attributeValue; if (attributeValue = getattributevaluebyname(samplerNode, "mSubsamples")) { if (!stringToNumber<double>(sample_pixel, attributeValue)) { return false; } } bool jitter = false; if (attributeValue = getattributevaluebyname(samplerNode, "jitter")) { std::string jittervalue = getattributevaluebyname(samplerNode, "jitter"); jitter = (jittervalue == "yes") ? true : false; } ISampler* s = new SuperSampler((int)sample_pixel, jitter); renderer->setSampler(s); } #endif else if (type == "ProgressiveSampler") { renderer->setSampler(new ProgressiveSampler()); } else { std::cout << "ConfigParser::addSampler: unknown sampler specified\n"; return false; } return true; }
bool SceneParser::addLight(struct basicxmlnode * lightNode, Scene * scene){ if (!lightNode) { std::cout << "SceneParser::addLight: empty light node \n"; return false; } if (std::string(lightNode->tag) != "Light") { return false; } // create light PointLight * light = new PointLight(); Vector3 position; Vector4 color; // read user specified values char * attributeValue; if (attributeValue = getattributevaluebyname(lightNode, "position")) { if (!stringToVector3<double>(position, attributeValue)) { delete(light); return false; } light->setPosition(position); } if (attributeValue = getattributevaluebyname(lightNode, "color")) { if (!stringToVector4<double>(color, attributeValue)) { delete(light); return false; } light->setColor(color); } // add light to scene scene->addLight(light); std::cout << "SceneParser::addLight: added Light\n"; return true; }
bool SceneParser::addSceneProperties(struct basicxmlnode * sceneNode, Scene * scene){ if (!sceneNode) { std::cout << "SceneParser::addSceneProperties: empty scene node\n"; return false; } if (std::string(sceneNode->tag) != "Scene") { std::cout << "SceneParser::addSceneProperties: scene description file has to have toplevel Scene node\n"; return false; } // read scene properties Vector4 color; double refractionIndex; char * attributeValue; if (attributeValue = getattributevaluebyname(sceneNode, "background")) { if (!stringToVector4<double>(color, attributeValue)) { return false; } scene->setBackground(color); } if (attributeValue = getattributevaluebyname(sceneNode, "ambient")) { if (!stringToVector4<double>(color, attributeValue)) { return false; } scene->setAmbient(color); } if (attributeValue = getattributevaluebyname(sceneNode, "refractionIndex")) { if (!stringToNumber<double>(refractionIndex, attributeValue)) { return false; } scene->setRefractionIndex(refractionIndex); } return true; }
// tries to load the texture referenced by textureNode and stores it in the scene bool SceneParser::addGlobalTexture(struct basicxmlnode * textureNode, Scene * scene) { if (!textureNode) { std::cout << "SceneParser::addGlobalTexture: empty node \n"; return false; } std::string textureName = textureNode->tag; char* filename; if (filename = getattributevaluebyname(textureNode, "file")) { #ifdef READ_TEXTURES_FLAG // create Texture std::string path = directory; #ifdef READ_CHECKERBOARD_FLAG if (path=="CheckerBoard") { scene->addTexture(textureName, new CheckerBoardTexture()); std::cout << "SceneParser::addGlobalTexture: added checkerboard texture \n"; return true; } #endif Image* i = Image::LoadTGA(path.append(filename).c_str()); if (i) { scene->addTexture(textureName, new ImageTexture(i)); std::cout << "SceneParser::addGlobalTexture: added texture " << textureName <<"\n"; return true; } else { std::cout << "SceneParser::addGlobalTexture: couldnt open file " << textureName <<"\n"; return false; } #else return true; #endif } else { std::cout << "SceneParser::addGlobalTexture: no 'file' field found in " << textureName <<"\n"; return false; } }
bool SceneParser::addTorus(struct basicxmlnode * elementNode, Scene * scene) { if (!elementNode) { std::cout << "SceneParser::addQuadric: empty node \n"; return false; } if (std::string(elementNode->tag) != "Torus") { return false; } // create torus Torus * torus = new Torus(scene->getDefaultMaterial()); Vector3 center; double R, r; double reflectionPercentage; double refractionIndex; double refractionPercentage; Vector4 color; // read user specified values char * attributeValue; if (attributeValue = getattributevaluebyname(elementNode, "center")) { if (!stringToVector3<double>(center, attributeValue)) { delete(torus); return false; } torus->setCenter(center); } if ( (attributeValue = getattributevaluebyname(elementNode, "R")) ) { if (!stringToNumber<double>(R, attributeValue)) { delete(torus); return false; } torus->setR(R); } if ( (attributeValue = getattributevaluebyname(elementNode, "r")) ) { if (!stringToNumber<double>(r, attributeValue)) { delete(torus); return false; } torus->setr(r); } if (attributeValue = getattributevaluebyname(elementNode, "color")) { if (!stringToVector4<double>(color, attributeValue)) { delete(torus); return false; } torus->setColor(color); } if (attributeValue = getattributevaluebyname(elementNode, "reflectionPercentage")) { if (!stringToNumber<double>(reflectionPercentage, attributeValue)) { delete(torus); return false; } torus->setReflectionPercentage(reflectionPercentage); } if ( attributeValue = getattributevaluebyname(elementNode, "refractionIndex") ) { if ( !stringToNumber<double>(refractionIndex, attributeValue) ) { delete(torus); return false; } torus->setRefractionIndex(refractionIndex); } if ( attributeValue = getattributevaluebyname(elementNode, "refractionPercentage") ) { if ( !stringToNumber<double>(refractionPercentage, attributeValue) ) { delete(torus); return false; } torus->setRefractionPercentage(refractionPercentage); } // read material struct basicxmlnode * materialNode = getchildnodebyname(elementNode, "Material"); Material* material = getMaterialReference(materialNode, scene); torus->setMaterial(material); // add it to scene scene->addElement(torus); std::cout << "SceneParser::addTorus: added Torus\n"; return true; }
bool SceneParser::addQuadric(struct basicxmlnode * elementNode, Scene * scene) { if (!elementNode) { std::cout << "SceneParser::addQuadric: empty node \n"; return false; } if (std::string(elementNode->tag) != "Quadric") { return false; } // create quadric Quadric * quadric = new Quadric(scene->getDefaultMaterial()); Vector3 center; double a_real, a_img, b_real, b_img, c_real, c_img; double reflectionPercentage; double refractionIndex; double refractionPercentage; Vector4 color; // read user specified values char * attributeValue1, * attributeValue2; if (attributeValue1 = getattributevaluebyname(elementNode, "center")) { if (!stringToVector3<double>(center, attributeValue1)) { delete(quadric); return false; } quadric->setCenter(center); } if ( (attributeValue1 = getattributevaluebyname(elementNode, "aReal")) && (attributeValue2 = getattributevaluebyname(elementNode, "aImg")) ) { if (!stringToNumber<double>(a_real, attributeValue1) || !stringToNumber<double>(a_img, attributeValue2)) { delete(quadric); return false; } quadric->setA(ComplexNumber(a_real,a_img)); } if ( (attributeValue1 = getattributevaluebyname(elementNode, "bReal")) && (attributeValue2 = getattributevaluebyname(elementNode, "bImg")) ) { if (!stringToNumber<double>(b_real, attributeValue1) || !stringToNumber<double>(b_img, attributeValue2)) { delete(quadric); return false; } quadric->setB(ComplexNumber(b_real,b_img)); } if ( (attributeValue1 = getattributevaluebyname(elementNode, "cReal")) && (attributeValue2 = getattributevaluebyname(elementNode, "cImg")) ) { if (!stringToNumber<double>(c_real, attributeValue1) || !stringToNumber<double>(c_img, attributeValue2)) { delete(quadric); return false; } quadric->setC(ComplexNumber(c_real,c_img)); } if (attributeValue1 = getattributevaluebyname(elementNode, "color")) { if (!stringToVector4<double>(color, attributeValue1)) { delete(quadric); return false; } quadric->setColor(color); } if (attributeValue1 = getattributevaluebyname(elementNode, "reflectionPercentage")) { if (!stringToNumber<double>(reflectionPercentage, attributeValue1)) { delete(quadric); return false; } quadric->setReflectionPercentage(reflectionPercentage); } if ( attributeValue1 = getattributevaluebyname(elementNode, "refractionIndex") ) { if ( !stringToNumber<double>(refractionIndex, attributeValue1) ) { delete(quadric); return false; } quadric->setRefractionIndex(refractionIndex); } if ( attributeValue1 = getattributevaluebyname(elementNode, "refractionPercentage") ) { if ( !stringToNumber<double>(refractionPercentage, attributeValue1) ) { delete(quadric); return false; } quadric->setRefractionPercentage(refractionPercentage); } // read material struct basicxmlnode * materialNode = getchildnodebyname(elementNode, "Material"); Material* material = getMaterialReference(materialNode, scene); quadric->setMaterial(material); // add it to scene scene->addElement(quadric); std::cout << "SceneParser::addQuadric: added Quadric\n"; return true; }
bool SceneParser::addTriangle(struct basicxmlnode * elementNode, Scene * scene){ if (!elementNode) { std::cout << "SceneParser::addTriangle: empty node \n"; return false; } if (std::string(elementNode->tag) != "Triangle") { return false; } // create triangle Triangle * triangle = new Triangle(scene->getMaterial("material_default")); Vector3 point1; Vector3 point2; Vector3 point3; Vector3 normal1; Vector3 normal2; Vector3 normal3; Vector4 color; double reflectionPercentage; double refractionIndex; double refractionPercentage; // read user specified values char * attributeValue; if (attributeValue = getattributevaluebyname(elementNode, "point1")) { if (!stringToVector3<double>(point1, attributeValue)) { delete(triangle); return false; } triangle->setPoint1(point1); } if (attributeValue = getattributevaluebyname(elementNode, "point2")) { if (!stringToVector3<double>(point2, attributeValue)) { delete(triangle); return false; } triangle->setPoint2(point2); } if (attributeValue = getattributevaluebyname(elementNode, "point3")) { if (!stringToVector3<double>(point3, attributeValue)) { delete(triangle); return false; } triangle->setPoint3(point3); } if (attributeValue = getattributevaluebyname(elementNode, "normal1")) { if (!stringToVector3<double>(normal1, attributeValue)) { delete(triangle); return false; } triangle->setNormal1(normal1); } if (attributeValue = getattributevaluebyname(elementNode, "normal2")) { if (!stringToVector3<double>(normal2, attributeValue)) { delete(triangle); return false; } triangle->setNormal2(normal2); } if (attributeValue = getattributevaluebyname(elementNode, "normal3")) { if (!stringToVector3<double>(normal3, attributeValue)) { delete(triangle); return false; } triangle->setNormal3(normal3); } if (attributeValue = getattributevaluebyname(elementNode, "color")) { if (!stringToVector4<double>(color, attributeValue)) { delete(triangle); return false; } triangle->setColor(color); } if (attributeValue = getattributevaluebyname(elementNode, "reflectionPercentage")) { if (!stringToNumber<double>(reflectionPercentage, attributeValue)) { delete(triangle); return false; } triangle->setReflectionPercentage(reflectionPercentage); } if ( attributeValue = getattributevaluebyname(elementNode, "refractionIndex") ) { if ( !stringToNumber<double>(refractionIndex, attributeValue) ) { delete(triangle); return false; } triangle->setRefractionIndex(refractionIndex); } if ( attributeValue = getattributevaluebyname(elementNode, "refractionPercentage") ) { if ( !stringToNumber<double>(refractionPercentage, attributeValue) ) { delete(triangle); return false; } triangle->setRefractionPercentage(refractionPercentage); } // read material struct basicxmlnode * materialNode = getchildnodebyname(elementNode, "Material"); Material* material = getMaterialReference(materialNode, scene); triangle->setMaterial(material); // and add it to scene scene->addElement(triangle); std::cout << "SceneParser::addTriangle: added Triangle\n"; return true; }
bool SceneParser::addCirclePlane(struct basicxmlnode * elementNode, Scene * scene){ if (!elementNode) { std::cout << "SceneParser::addCirclePlane: empty node \n"; return false; } if (std::string(elementNode->tag) != "CirclePlane") { return false; } // create plane CirclePlane* circleplane = new CirclePlane(scene->getMaterial("default material")); Vector3 point; Vector3 normal; Vector4 color; double reflectionPercentage; double refractionIndex; double refractionPercentage; // read user specified values char * attributeValue; if (attributeValue = getattributevaluebyname(elementNode, "point")) { if (!stringToVector3<double>(point, attributeValue)) { delete(circleplane); return false; } circleplane->setPoint(point); } if (attributeValue = getattributevaluebyname(elementNode, "normal")) { if (!stringToVector3<double>(normal, attributeValue)) { delete(circleplane); return false; } circleplane->setNormal(normal); } if (attributeValue = getattributevaluebyname(elementNode, "color")) { if (!stringToVector4<double>(color, attributeValue)) { delete(circleplane); return false; } circleplane->setColor(color); } if (attributeValue = getattributevaluebyname(elementNode, "reflectionPercentage")) { if (!stringToNumber<double>(reflectionPercentage, attributeValue)) { delete(circleplane); return false; } circleplane->setReflectionPercentage(reflectionPercentage); } if ( attributeValue = getattributevaluebyname(elementNode, "refractionIndex") ) { if ( !stringToNumber<double>(refractionIndex, attributeValue) ) { delete(circleplane); return false; } circleplane->setRefractionIndex(refractionIndex); } if ( attributeValue = getattributevaluebyname(elementNode, "refractionPercentage") ) { if ( !stringToNumber<double>(refractionPercentage, attributeValue) ) { delete(circleplane); return false; } circleplane->setRefractionPercentage(refractionPercentage); } // read material struct basicxmlnode * materialNode = getchildnodebyname(elementNode, "Material"); Material* material = getMaterialReference(materialNode, scene); circleplane->setMaterial(material); // add it to scene scene->addElement(circleplane); std::cout << "SceneParser::addCirclePlane: added CirclePlane\n"; return true; }
bool SceneParser::addCamera(struct basicxmlnode * cameraNode, Scene * scene){ if (!cameraNode) { std::cout << "SceneParser::addCamera: empty camera node\n"; return false; } if (std::string(cameraNode->tag) != "Camera") { return false; } // read resolution (mandatory attributes!) int resolutionX; int resolutionY; char * attributeValue; if (attributeValue = getattributevaluebyname(cameraNode, "resolutionX")) { if (!stringToNumber<int>(resolutionX, attributeValue)) { return false; } } else { std::cerr << "SceneParser::addCamera: no resolution provided!" << "\n"; return false; } if (attributeValue = getattributevaluebyname(cameraNode, "resolutionY")) { if (!stringToNumber<int>(resolutionY, attributeValue)) { return false; } } else { std::cerr << "SceneParser::addCamera: no resolution provided!" << "\n"; return false; } // instanciate camera SimpleCamera* camera = new SimpleCamera(resolutionX, resolutionY); Vector3 position; Vector3 direction; Vector3 up; float angle = 70; // read user specified values if (attributeValue = getattributevaluebyname(cameraNode, "position")) { if (!stringToVector3<double>(position, attributeValue)) { delete(camera); return false; } camera->setPosition(position); } if (attributeValue = getattributevaluebyname(cameraNode, "direction")) { if (!stringToVector3<double>(direction, attributeValue)) { delete(camera); return false; } else if (attributeValue = getattributevaluebyname(cameraNode, "up")) { if (!stringToVector3<double>(up, attributeValue)) { delete(camera); return false; } camera->setOrientation(direction, up); } else { std::cout << "SceneParser::addCamera: direction specified without up\n"; delete(camera); return false; } } else if (attributeValue = getattributevaluebyname(cameraNode, "up")) { std::cout << "SceneParser::addCamera: up specified without direction\n"; delete(camera); return false; } if (attributeValue = getattributevaluebyname(cameraNode, "angle")) { if (!stringToNumber<float>(angle, attributeValue)) { delete(camera); return false; } camera->setOpeningAngle(angle); } // add camera to scene scene->setCamera(camera); std::cout << "SceneParser::addCamera: added camera\n"; return true; }
bool SceneParser::addTriangleMesh(struct basicxmlnode * elementNode, Scene * scene){ if (!elementNode) { std::cout << "SceneParser::addTriangleMesh: empty node \n"; return false; } if (std::string(elementNode->tag) != "TriangleMesh") { return false; } // read filename char * cobjFileName; if (!(cobjFileName = getattributevaluebyname(elementNode, "OBJFileName"))) { std::cerr << "SceneParser::addTriangleMesh: no file specified!" << "\n"; return false; } // build obj object std::string objFileName(cobjFileName); char * attributeValue; Vector3 translate; translate[0]=0.0;translate[1]=0.0;translate[2]=0.0; if (attributeValue = getattributevaluebyname(elementNode, "translateFromOrigin")) { if (!stringToVector3<double>(translate, attributeValue)) { return false; } } double newRadius=1.0; if (attributeValue = getattributevaluebyname(elementNode, "radius")) { if (!stringToNumber<double>(newRadius, attributeValue)) { return false; } } Material* material; struct basicxmlnode * materialNode = getchildnodebyname(elementNode, "Material"); if(materialNode) { material = getMaterialReference(materialNode, scene); } // set Texture struct basicxmlnode * textureNode = getchildnodebyname(elementNode, "Texture"); ITexture* textureImage = getTextureReference(textureNode, scene); // set Bumpmap struct basicxmlnode * bumpmapNode = getchildnodebyname(elementNode, "Bumpmap"); ITexture* bumpmap = getTextureReference(bumpmapNode, scene); Vector4 color = Vector4(1,0,0,1); double reflectionPercentage = 0; if (attributeValue = getattributevaluebyname(elementNode, "color")) { if (!stringToVector4<double>(color, attributeValue)) { return false; } } if (attributeValue = getattributevaluebyname(elementNode, "reflectionPercentage")) { if (!stringToNumber<double>(reflectionPercentage, attributeValue)) { return false; } } double refractionPercentage = 0; double refractionIndex = 1; if (attributeValue = getattributevaluebyname(elementNode, "refractionPercentage")) { if (!stringToNumber<double>(refractionPercentage, attributeValue)) { return false; } } if (attributeValue = getattributevaluebyname(elementNode, "refractionIndex")) { if (!stringToNumber<double>(refractionIndex, attributeValue)) { return false; } } Mesh *m = new Mesh(scene,0,0); scene->addMesh(m); bool readSuccess = Mesh3DReader::read(objFileName,*m); if (!readSuccess) { std::cerr << "SceneParser::addTriangleMesh: Error while importing from Obj file: "<< objFileName << "\n"; return false; } /* bool readVertexNormals = false; bool readTexture = false; readOBJFile(objFileName,m,scene,readVertexNormals,readTexture); if(!readVertexNormals) { calcVertexNormals(m); } */ preprocessing(m,newRadius,translate); for(unsigned int i=0;i<m->numberOfFaces();i++) { m->getFace(i)->setTexture(textureImage); m->getFace(i)->setBumpmap(bumpmap); m->getFace(i)->setColor(color); m->getFace(i)->setMaterial(material); m->getFace(i)->setReflectionPercentage(reflectionPercentage); m->getFace(i)->setRefractionPercentage(refractionPercentage); m->getFace(i)->setRefractionIndex(refractionIndex); } return true; }
bool SceneParser::addSphere(struct basicxmlnode * elementNode, Scene * scene){ if (!elementNode) { std::cout << "SceneParser::addSphere: empty node \n"; return false; } if (std::string(elementNode->tag) != "Sphere") { return false; } // create sphere Sphere * sphere = new Sphere(scene->getDefaultMaterial()); Vector3 center; double radius; double reflectionPercentage; double refractionIndex; double refractionPercentage; Vector4 color; // read user specified values char * attributeValue; if (attributeValue = getattributevaluebyname(elementNode, "center")) { if (!stringToVector3<double>(center, attributeValue)) { delete(sphere); return false; } sphere->setCenter(center); } if (attributeValue = getattributevaluebyname(elementNode, "radius")) { if (!stringToNumber<double>(radius, attributeValue)) { delete(sphere); return false; } sphere->setRadius(radius); } if (attributeValue = getattributevaluebyname(elementNode, "color")) { if (!stringToVector4<double>(color, attributeValue)) { delete(sphere); return false; } sphere->setColor(color); } if (attributeValue = getattributevaluebyname(elementNode, "reflectionPercentage")) { if (!stringToNumber<double>(reflectionPercentage, attributeValue)) { delete(sphere); return false; } sphere->setReflectionPercentage(reflectionPercentage); } if ( attributeValue = getattributevaluebyname(elementNode, "refractionIndex") ) { if ( !stringToNumber<double>(refractionIndex, attributeValue) ) { delete(sphere); return false; } sphere->setRefractionIndex(refractionIndex); } if ( attributeValue = getattributevaluebyname(elementNode, "refractionPercentage") ) { if ( !stringToNumber<double>(refractionPercentage, attributeValue) ) { delete(sphere); return false; } sphere->setRefractionPercentage(refractionPercentage); } // read material struct basicxmlnode * materialNode = getchildnodebyname(elementNode, "Material"); Material* material = getMaterialReference(materialNode, scene); sphere->setMaterial(material); // add it to scene scene->addElement(sphere); std::cout << "SceneParser::addSphere: added Sphere\n"; return true; }
bool ConfigParser::addIntegrator( struct basicxmlnode * integratorNode, Renderer * renderer ) { if (!integratorNode) { std::cout << "ConfigParser::addIntegrator: empty integrator node\n"; return false; } if (std::string(integratorNode->tag) != "Integrator") { std::cout << "ConfigParser::addIntegrator: wrong integrator tag name\n"; return false; } std::string type = getattributevaluebyname(integratorNode, "type"); if (type == "WhittedIntegrator") { struct basicxmlnode * shaderNode = getchildnodebyname(integratorNode, "Shader"); WhittedIntegrator* integrator = new WhittedIntegrator(); if(addShader(shaderNode,integrator)){ renderer->setIntegrator( integrator ); }else{ return false; } //read recursion depth unsigned int recursionDepth; char * attributeValue; if (attributeValue = getattributevaluebyname(integratorNode, "recursionDepth")) { if (!stringToNumber<unsigned int>(recursionDepth, attributeValue)) { return false; } integrator->setRecursionDepth(recursionDepth); } }else if (type == "DirectLighting") { DirectLighting* integrator = new DirectLighting(); renderer->setIntegrator(integrator); //read number of samples unsigned int nSamples; char * attributeValue; if (attributeValue = getattributevaluebyname(integratorNode, "nSamples")) { if (!stringToNumber<unsigned int>(nSamples, attributeValue)) { return false; } integrator->setNSamples(nSamples); } }else if (type == "PathTracer") { PathTracer* integrator = new PathTracer(); renderer->setIntegrator(integrator); //read number of samples unsigned int nSamples; char * attributeValue; if (attributeValue = getattributevaluebyname(integratorNode, "nSamples")) { if (!stringToNumber<unsigned int>(nSamples, attributeValue)) { return false; } integrator->setNSamples(nSamples); } //read max. depth unsigned int maxDepth; if (attributeValue = getattributevaluebyname(integratorNode, "maxDepth")) { if (!stringToNumber<unsigned int>(maxDepth, attributeValue)) { return false; } integrator->setMaxDepth(maxDepth); } //read sample depth unsigned int sampleDepth; if (attributeValue = getattributevaluebyname(integratorNode, "sampleDepth")) { if (!stringToNumber<unsigned int>(sampleDepth, attributeValue)) { return false; } integrator->setSampleDepth(sampleDepth); } //read continue probabilty double p; if (attributeValue = getattributevaluebyname(integratorNode, "pContinue")) { if (!stringToNumber<double>(p, attributeValue)) { return false; } integrator->setContinueProbabilty(p); } } //Add loading of other integrator types here return true; }