ref_ptr<Light> LightResource::createResource( SceneParser *parser, SceneInputNode &input) { Light::Type lightType = input.getValue<Light::Type>("type", Light::SPOT); ref_ptr<Light> light = ref_ptr<Light>::alloc(lightType); light->set_isAttenuated( input.getValue<bool>("is-attenuated", lightType!=Light::DIRECTIONAL)); light->position()->setVertex(0, input.getValue<Vec3f>("position", Vec3f(0.0f))); light->direction()->setVertex(0, input.getValue<Vec3f>("direction", Vec3f(0.0f,0.0f,1.0f))); light->diffuse()->setVertex(0, input.getValue<Vec3f>("diffuse", Vec3f(1.0f))); light->specular()->setVertex(0, input.getValue<Vec3f>("specular", Vec3f(1.0f))); light->radius()->setVertex(0, input.getValue<Vec2f>("radius", Vec2f(999999.9f))); Vec2f angles = input.getValue<Vec2f>("cone-angles", Vec2f(50.0f,55.0f)); light->set_innerConeAngle(angles.x); light->set_outerConeAngle(angles.y); parser->putState(input.getName(),light); return light; }
// Override void processInput( SceneParser *parser, SceneInputNode &input, const ref_ptr<StateNode> &parent) { ref_ptr<State> state = ref_ptr<State>::alloc(); ref_ptr<StateNode> newNode = ref_ptr<StateNode>::alloc(state); newNode->set_name(input.getName()); newNode->set_isHidden(GL_TRUE); parent->addChild(newNode); parser->putNode(input.getName(), newNode); handleChildren(parser,input,newNode); ViewNode viewNode; viewNode.name = input.getName(); viewNode.node = newNode; viewNodes_->push_back(viewNode); REGEN_INFO("View: " << viewNode.name); }
ref_ptr<Camera> CameraResource::createResource( SceneParser *parser, SceneInputNode &input) { if(input.hasAttribute("reflector") || input.hasAttribute("reflector-normal") || input.hasAttribute("reflector-point")) { ref_ptr<Camera> userCamera = parser->getResources()->getCamera(parser, input.getValue("camera")); if(userCamera.get()==NULL) { REGEN_WARN("Unable to find Camera for '" << input.getDescription() << "'."); return ref_ptr<Camera>(); } ref_ptr<ReflectionCamera> cam; bool hasBackFace = input.getValue<bool>("has-back-face", false); if(input.hasAttribute("reflector")) { ref_ptr<MeshVector> mesh = parser->getResources()->getMesh(parser, input.getValue("reflector")); if(mesh.get()==NULL || mesh->empty()) { REGEN_WARN("Unable to find Mesh for '" << input.getDescription() << "'."); return ref_ptr<Camera>(); } const vector< ref_ptr<Mesh> > &vec = *mesh.get(); cam = ref_ptr<ReflectionCamera>::alloc( userCamera,vec[0],input.getValue<GLuint>("vertex-index",0u), hasBackFace); } else if(input.hasAttribute("reflector-normal")) { Vec3f normal = input.getValue<Vec3f>("reflector-normal", Vec3f(0.0f,1.0f,0.0f)); Vec3f position = input.getValue<Vec3f>("reflector-point", Vec3f(0.0f,0.0f,0.0f)); cam = ref_ptr<ReflectionCamera>::alloc(userCamera,normal,position,hasBackFace); } if(cam.get()==NULL) { REGEN_WARN("Unable to create Camera for '" << input.getDescription() << "'."); return ref_ptr<Camera>(); } parser->putState(input.getName(),cam); return cam; } else if(input.hasAttribute("light")) { ref_ptr<Camera> userCamera = parser->getResources()->getCamera(parser, input.getValue("camera")); if(userCamera.get()==NULL) { REGEN_WARN("Unable to find Camera for '" << input.getDescription() << "'."); return ref_ptr<Camera>(); } ref_ptr<Light> light = parser->getResources()->getLight(parser, input.getValue("light")); if(light.get()==NULL) { REGEN_WARN("Unable to find Light for '" << input.getDescription() << "'."); return ref_ptr<Camera>(); } GLuint numLayer = input.getValue<GLuint>("num-layer", 1u); GLdouble splitWeight = input.getValue<GLdouble>("split-weight", 0.9); GLdouble near = input.getValue<GLdouble>("near", 0.1); GLdouble far = input.getValue<GLdouble>("far", 200.0); ref_ptr<LightCamera> cam = ref_ptr<LightCamera>::alloc( light,userCamera,Vec2f(near,far),numLayer,splitWeight); parser->putState(input.getName(),cam); // Hide cube shadow map faces. if(input.hasAttribute("hide-faces")) { const string val = input.getValue<string>("hide-faces",""); vector<string> faces; boost::split(faces,val,boost::is_any_of(",")); for(vector<string>::iterator it=faces.begin(); it!=faces.end(); ++it) { int faceIndex = atoi(it->c_str()); cam->set_isCubeFaceVisible( GL_TEXTURE_CUBE_MAP_POSITIVE_X+faceIndex, GL_FALSE); } } return cam; } else if(input.hasAttribute("cube-mesh")) { ref_ptr<Camera> userCamera = parser->getResources()->getCamera(parser, input.getValue("camera")); if(userCamera.get()==NULL) { REGEN_WARN("Unable to find Camera for '" << input.getDescription() << "'."); return ref_ptr<Camera>(); } ref_ptr<MeshVector> mesh = parser->getResources()->getMesh(parser, input.getValue("cube-mesh")); if(mesh.get()==NULL || mesh->empty()) { REGEN_WARN("Unable to find Mesh for '" << input.getDescription() << "'."); return ref_ptr<Camera>(); } ref_ptr<CubeCamera> cam = ref_ptr<CubeCamera>::alloc((*mesh.get())[0],userCamera); parser->putState(input.getName(),cam); // Hide cube shadow map faces. if(input.hasAttribute("hide-faces")) { const string val = input.getValue<string>("hide-faces",""); vector<string> faces; boost::split(faces,val,boost::is_any_of(",")); for(vector<string>::iterator it=faces.begin(); it!=faces.end(); ++it) { int faceIndex = atoi(it->c_str()); cam->set_isCubeFaceVisible( GL_TEXTURE_CUBE_MAP_POSITIVE_X+faceIndex, GL_FALSE); } } return cam; } else if(input.hasAttribute("paraboloid-mesh")) { ref_ptr<Camera> userCamera = parser->getResources()->getCamera(parser, input.getValue("camera")); if(userCamera.get()==NULL) { REGEN_WARN("Unable to find Camera for '" << input.getDescription() << "'."); return ref_ptr<Camera>(); } ref_ptr<MeshVector> mesh = parser->getResources()->getMesh(parser, input.getValue("paraboloid-mesh")); if(mesh.get()==NULL || mesh->empty()) { REGEN_WARN("Unable to find Mesh for '" << input.getDescription() << "'."); return ref_ptr<Camera>(); } bool hasBackFace = input.getValue<bool>("has-back-face",false); ref_ptr<ParaboloidCamera> cam = ref_ptr<ParaboloidCamera>::alloc( (*mesh.get())[0],userCamera,hasBackFace); parser->putState(input.getName(),cam); return cam; } else { ref_ptr<Camera> cam = ref_ptr<Camera>::alloc(); cam->set_isAudioListener( input.getValue<bool>("audio-listener", false)); cam->position()->setVertex(0, input.getValue<Vec3f>("position", Vec3f(0.0f,2.0f,-2.0f))); Vec3f dir = input.getValue<Vec3f>("direction", Vec3f(0.0f,0.0f,1.0f)); dir.normalize(); cam->direction()->setVertex(0, dir); cam->updateFrustum( (GLfloat)parser->getViewport()->getVertex(0).x/ (GLfloat)parser->getViewport()->getVertex(0).y, input.getValue<GLfloat>("fov", 45.0f), input.getValue<GLfloat>("near", 0.1f), input.getValue<GLfloat>("far", 200.0f)); // Update frustum when window size changes parser->addEventHandler(Application::RESIZE_EVENT, ref_ptr<ProjectionUpdater>::alloc(cam, parser->getViewport())); parser->putState(input.getName(),cam); return cam; } }