void Scenario::loadFromXml(ofxBulletWorldRigid &world){
    ofxXmlSettings ScenarioXml;
    
    if(ScenarioXml.loadFile(PinballChinoManager::projectName+"/scenario.xml")){
        
        ScenarioXml.pushTag("scenario");
        
        int numberOfSavedObjects = ScenarioXml.getNumTags("object");
        
        for(int i = 0; i < numberOfSavedObjects; i++){
            
            ScenarioXml.pushTag("object", i);
            SimpleObject::shapeType Type = (SimpleObject::shapeType)ScenarioXml.getValue("type", 0);
            int objId = ScenarioXml.getValue("id", 0);
            
            
            ofVec3f pos, scale;
			
            pos.x = ScenarioXml.getValue("positionX",0.0, 0);
            pos.y = ScenarioXml.getValue("positionY",0.0, 0);
            pos.z = ScenarioXml.getValue("positionZ",0.0, 0);
            
            scale.x = ScenarioXml.getValue("scaleX",0.0, 0);
            scale.y = ScenarioXml.getValue("scaleY",0.0, 0);
            scale.z = ScenarioXml.getValue("scaleZ",0.0, 0);
			
			ofQuaternion rotation;
            ofVec4f rot;
			
			rot.x = ScenarioXml.getValue("rotationX",0.0,0);
			rot.y = ScenarioXml.getValue("rotationY",0.0,0);
			rot.z = ScenarioXml.getValue("rotationZ",0.0,0);
            rot.w = ScenarioXml.getValue("rotationW",0.0,0);
			rotation.set(rot);
			
            string path;
            path = ScenarioXml.getValue("path","", 0);
            
            //TODO uncomment the line below when the xml is properly configured
            //string strcolor = ScenarioXml.getValue("color", "0xFFFFFF", 0);
			int color = ScenarioXml.getValue("color", 0xFFFFFF, 0);
			
			int pointsCollision = ScenarioXml.getValue("pointsCollision", 0, 0);

			int invisible = 0; // Visible by default event if this value is not implemented in the Xml editor
			invisible = ScenarioXml.getValue("invisible", 0, 0);
			
            switch(Type){
                case SimpleObject::ShapeTypeBall:{
                    Ball *oBall = new Ball(currentMissions);
                    float mass = ScenarioXml.getValue("mass", 0.0);
                    float radius = ScenarioXml.getValue("radius", 0.0);
                    float restitution = ScenarioXml.getValue("restitution", 0.0);
                    float friction = ScenarioXml.getValue("friction", 0.0);
                    oBall->setup(world, pos, mass, radius, restitution, friction);
                    oBall->SetObjectId(objId);
					oBall->setRotation(rotation);
                    oBall->color = color;
					oBall->setVisibility(invisible);
					
                    ScenarioObjects.push_back(oBall);
                }
                break;
                    
                case SimpleObject::ShapeTypeHammer:{
                    Hammer *oHammer = new Hammer(currentMissions);
                    oHammer->setup(world, pos);
                    oHammer->SetObjectId(objId);
					oHammer->setRotation(rotation);
                    oHammer->color = color;
					oHammer->setVisibility(invisible);
                    ScenarioObjects.push_back(oHammer);
					
					oHammer->setupRot();
                }
                break;
                    
                case SimpleObject::ShapeTypeLever:{
                    Lever *oLever = new Lever(currentMissions);
                    int dir = ScenarioXml.getValue("LeverType", 0);
                    oLever->setup(world, pos, path, scale, dir);
                    oLever->SetObjectId(objId);
					oLever->setRotation(rotation);
                    oLever->color = color;
					oLever->setVisibility(invisible);
                    ScenarioObjects.push_back(oLever);

                }
                break;
                    
                case SimpleObject::ShapeTypeObstacle:{
                    Obstacle *oObstable = new Obstacle(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oObstable->setup(world, pos, path, scale);
                    oObstable->SetObjectId(objId);
					oObstable->setRotation(rotation);
                    oObstable->color = color;
					oObstable->setVisibility(invisible);
                    ScenarioObjects.push_back(oObstable);
					oObstable->setPointsCollision(pointsCollision);
					oObstable->setupRot();

                }
                break;
                
                case SimpleObject::ShapeTypeGravity:{
                    Gravity *oGravity = new Gravity(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oGravity->setup(world, pos, path, scale);
                    oGravity->SetObjectId(objId);
					oGravity->setRotation(rotation);
                    oGravity->color = color;
					oGravity->setVisibility(invisible);
                    ScenarioObjects.push_back(oGravity);
					oGravity->setPointsCollision(pointsCollision);
					oGravity->setupRot();
                    
                }
                break;
                   
                case SimpleObject::ShapeTypeTeleporter:{
                    Teleporter *oTeleporter = new Teleporter(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oTeleporter->setup(world, pos, path, scale);
                    oTeleporter->SetObjectId(objId);
					oTeleporter->setRotation(rotation);
                    oTeleporter->color = color;
					oTeleporter->setVisibility(invisible);
                    ScenarioObjects.push_back(oTeleporter);
					oTeleporter->setPointsCollision(pointsCollision);
					oTeleporter->setupRot();
                    
                }
                break;
					
				case SimpleObject::ShapeTypeRamp:{
					Ramp *oRamp = new Ramp(currentMissions);
					//oObstable->setup(world, pos, "3DModels/chino_6.dae");
					oRamp->setup(world, pos, path, scale);
					oRamp->SetObjectId(objId);
					oRamp->setRotation(rotation);
					oRamp->color = color;
					oRamp->setVisibility(invisible);
					ScenarioObjects.push_back(oRamp);
					oRamp->setPointsCollision(pointsCollision);
					oRamp->setupRot();
				}
					break;
					
				case SimpleObject::ShapeTypeObstacleTriShapeMesh:{
					ObstacleTriShapeMesh *oObstacleTriShapeMesh= new ObstacleTriShapeMesh(currentMissions);
					
					oObstacleTriShapeMesh->setup(world, pos, path, scale);
					oObstacleTriShapeMesh->SetObjectId(objId);
					oObstacleTriShapeMesh->setRotation(rotation);
					oObstacleTriShapeMesh->color = color;
					oObstacleTriShapeMesh->setVisibility(invisible);
					ScenarioObjects.push_back(oObstacleTriShapeMesh);
					oObstacleTriShapeMesh->setPointsCollision(pointsCollision);
					oObstacleTriShapeMesh->setupRot();
				}
					break;
					
                case SimpleObject::ShapeTypeAnimatedObject:{
                    AnimatedObject *oAnimatedObject = new AnimatedObject(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oAnimatedObject->setup(world, pos, path, scale);
                    oAnimatedObject->SetObjectId(objId);
					oAnimatedObject->setRotation(rotation);
                    oAnimatedObject->color = color;
					oAnimatedObject->setVisibility(invisible);
                    ScenarioObjects.push_back(oAnimatedObject);
					oAnimatedObject->setPointsCollision(pointsCollision);
					oAnimatedObject->setupRot();
                    
                }
                break;
                
                case SimpleObject::ShapeTypeAnimatedMotionPath:{
                    string pathMotionModel;
                    pathMotionModel = ScenarioXml.getValue("pathMotionModel","", 0);
                    AnimatedMotionPath *oAnimatedMotionPath = new AnimatedMotionPath(currentMissions);
                    oAnimatedMotionPath->setup(world, pos, path, pathMotionModel, scale);
                    oAnimatedMotionPath->SetObjectId(objId);
					oAnimatedMotionPath->setRotation(rotation);
                    oAnimatedMotionPath->color = color;
					oAnimatedMotionPath->setVisibility(invisible);
                    ScenarioObjects.push_back(oAnimatedMotionPath);
					oAnimatedMotionPath->setPointsCollision(pointsCollision);
					oAnimatedMotionPath->setupRot();
                    
                }
                break;
                    
                case SimpleObject::ShapeTypeAnimatedMesh:{
                    AnimatedMesh *oAnimatedMesh = new AnimatedMesh(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oAnimatedMesh->setup(world, pos, path, scale);
                    oAnimatedMesh->SetObjectId(objId);
					oAnimatedMesh->setRotation(rotation);
                    oAnimatedMesh->color = color;
					oAnimatedMesh->setVisibility(invisible);
                    ScenarioObjects.push_back(oAnimatedMesh);
					oAnimatedMesh->setPointsCollision(pointsCollision);
					oAnimatedMesh->setupRot();
                    
                }
                break;
                case SimpleObject::ShapeTypeGeneratedMesh:{
                    GeneratedMesh *oGeneratedMesh = new GeneratedMesh(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oGeneratedMesh->setup(world, pos, path, scale);
                    oGeneratedMesh->SetObjectId(objId);
					oGeneratedMesh->setRotation(rotation);
                    oGeneratedMesh->color = color;
					oGeneratedMesh->setVisibility(invisible);
                    ScenarioObjects.push_back(oGeneratedMesh);
					oGeneratedMesh->setPointsCollision(pointsCollision);
					oGeneratedMesh->setupRot();
                    
                }
                break;
                    
                case SimpleObject::ShapeTypeBounds:{
                    Bounds *oBounds = new Bounds(currentMissions);
                    oBounds->setup(world, pos, path, scale);
                    oBounds->SetObjectId(objId);
					oBounds->setRotation(rotation);
                    oBounds->color = color;
					oBounds->setVisibility(invisible);
                    ScenarioObjects.push_back(oBounds);
					
					oBounds->setupRot();
                }
                break;

            }
            ScenarioXml.popTag();
        }
        
        ScenarioXml.popTag(); //pop position
    }
    
    else{
        
        ofLogError("Scenario file did not load!");
        
    }
    
}