コード例 #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
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;
	}
}