Пример #1
0
XMLScene::XMLScene(char *filename, GlobalData &globals, Graph &graphScene)
{

	// Read XML from file

	doc=new TiXmlDocument( filename );
	bool loadOkay = doc->LoadFile();

	if ( !loadOkay )
	{
		printf( "Could not load file '%s'. Error='%s'. Exiting.\n", filename, doc->ErrorDesc() );
		exit( 1 );
	}

	TiXmlElement* anfElement= doc->FirstChildElement( "anf" );

	if (anfElement == NULL)
	{
		printf("Main anf block element not found! Exiting!\n");
		exit(1);
	}

	globalsElement = anfElement->FirstChildElement( "globals" );
	cameraElement = anfElement->FirstChildElement("cameras");
	lightElement = anfElement->FirstChildElement("lights");
	textureElement = anfElement->FirstChildElement("textures");
	appearanceElement = anfElement->FirstChildElement("appearances");
	graphElement = anfElement->FirstChildElement("graph");
	animsElement = anfElement->FirstChildElement("animations");

	parseGlobals(globals);
	parseCameras(graphScene);
	parseLights(graphScene);
	parseTextures(graphScene);
	parseAppearances(graphScene);
	parseAnimations(graphScene);
	parseGraph(graphScene);
}
Пример #2
0
void Spritesheet::load(const std::string& path)
{
   // Load the image itself into a texture using GraphicsUtil
   std::string imgPath(path);
   imgPath += IMG_EXTENSION;

   DEBUG("Loading spritesheet image \"%s\"...", imgPath.c_str());
   texture = new Texture(imgPath);
   size = texture->getSize();

   // Load in the spritesheet data file, which tells the engine where
   // each frame is in the image
   std::string dataPath(path);
   dataPath += DATA_EXTENSION;
   DEBUG("Loading spritesheet data \"%s\"...", dataPath.c_str());

   std::ifstream input(dataPath.c_str());
   if(!input.is_open())
   {
      T_T(std::string("Error opening file: ") + dataPath);
   }
   
   // Read in the JSON data in the file
   Json::Value jsonRoot;
   input >> jsonRoot;
   
   if(jsonRoot.isNull())
   {
      DEBUG("Unexpected root element name.");
      T_T("Failed to parse spritesheet data.");
   }
   
   parseFrames(jsonRoot);
   parseAnimations(jsonRoot);

   DEBUG("Spritesheet constructed!");
}
Пример #3
0
bool ANFparser::parse(Scene * scene,const char* filename){
	this->scene = scene;

	try{
		TiXmlDocument * doc = new TiXmlDocument(filename);

		//First things first, reading the XML/ANF file
		if (!doc->LoadFile()){
			issue("Could not load file '%"+str(filename)+"'. Error='" + str(doc->ErrorDesc()) + "'.", ERROR);
		}

		//Must exist anf root block
		TiXmlElement* anfRoot = doc->FirstChildElement("anf");
		if (!anfRoot){
			issue("Main block 'anf' block not found!",ERROR);
		}

		//Lets process the global variables
		TiXmlElement* anfGlobals = anfRoot->FirstChildElement("globals");
		if(!anfGlobals){
			issue("Block 'globals' not found!",WARNING);
		}else{
			parseGlobals(anfGlobals);
		}
		
		//Lets process the cameras
		TiXmlElement* anfCameras = anfRoot->FirstChildElement("cameras");
		if(!anfCameras){
			issue("Block 'cameras' not found!",ERROR);
		}else{
			std::string firstCameraId = str(anfCameras->Attribute("initial"));
			if(firstCameraId == "" ){
				issue("Cameras block must declare the first camera.. ", WARNING);
			}
			parseCameras(anfCameras,firstCameraId);
		}

		//Lets process the lights
		TiXmlElement* anfLights = anfRoot->FirstChildElement("lights");
		if(!anfLights){
			issue("Block 'lights' not found!",WARNING);
		}else{
			parseLights(anfLights);
		}

		//If textures extist, we process it
		TiXmlElement* anfTextures = anfRoot->FirstChildElement("textures");
		map<std::string,Texture *> textures;
		if(!anfTextures){
			issue("Block 'textures' not found!",WARNING);
		}else{
			parseTextures(anfTextures,textures);
		}


		//If appearances block exist, we call its parser
		TiXmlElement* anfAppearances = anfRoot->FirstChildElement("appearances");
		map<std::string,Appearance *> appearances;
		if(!anfAppearances){
			issue("Block 'appearances' not found!",WARNING);
		}else{
			parseAppearances(anfAppearances,appearances,textures);
		}
		
		//If animations extist, we process it
		TiXmlElement* anfAnimations = anfRoot->FirstChildElement("animations");
		map<std::string,Animation *> animations;
		if(!anfAnimations){
			issue("Block 'animations' not found!",WARNING);
		}else{
			parseAnimations(anfAnimations,animations);
		}


		//If graph block exist, we call its parser
		TiXmlElement* anfGraph = anfRoot->FirstChildElement("graph");
		if(!anfGraph){
			issue("Block 'graph' not found!",ERROR);
		}else{
			this->scene->setRoot(parseGraph(anfGraph,appearances,animations));
		}

		return true; 
	}catch(...){
		return false;
	}
}