Esempio n. 1
0
//--------------------------------------------------------------
void ofApp::load(){

	this->splashScreen.init("splashScreen.jpg"); 
	this->splashScreen.begin(); 

	//populate costumesLib map by going through venues directory recursively
	//only works if the names of the files are exactly the same as those inside bonePairs in Costume.cpp
	//will skip over missing files and simply not draw them
	std::string venuesPath = "venues/";
	ofDirectory venues(venuesPath);
	venues.listDir();
	//open venues dir
	for(int i=0; i<venues.numFiles(); i++) {
		ofDirectory venue(venues.getPath(i));
		if(venue.isDirectory()) {
			venue.listDir();
			 //open each venue dir
			for(int j=0;j< venue.numFiles();j++) {
				ofDirectory costume(venue.getPath(j));
				if(costume.isDirectory()) {
					//for each costume:
					//costume.allowExt("dae"); //only look at .dae files (ie ignore texture files)
					costume.listDir();
					std::string cos; //initialize string to name the costume (will get the name late from the absolute path of each file so we have fewer calls to ofSplitString
					std::vector<Segment> segs; //create a vector of segments for each costume that we will populate
					 //open each costume inside each venue
					for(int k=0; k<costume.numFiles();k++) {
						ofDirectory part(costume.getPath(k));
						//initialize model loader for each model
						ofxAssimpModelLoader model; 
						part.allowExt("dae");
						part.listDir();
						//load each .dae file
						model.loadModel(part.getPath(0), true);
						//save the meshes and textures for each file into blocks
						vector<std::pair<ofMesh, ofTexture>> blocks;
						for(int l=0;l<model.getMeshCount();l++) {
							ofMesh mesh = model.getMesh(l); //get each mesh
							ofTexture tex = model.getTextureForMesh(l); //get each texture
							std::pair<ofMesh, ofTexture> block = make_pair(mesh, tex); //associate the two values
							blocks.push_back(block); //add it to blocks vector
						}
						//sort name of each costume out
						vector<std::string> splitString = ofSplitString(costume.getPath(k), "\\"); //split path string on "\" to get venue and costume names
						cos = splitString[2];
						std::vector<std::string> splitPart = ofSplitString(splitString[3], "."); //get the nameof the body part by splitting the string on "." to remove .dae extension
						std::string partName = splitPart[0];
						std::pair<std::string, std::string> pair = std::make_pair(cos, partName);
						//initialize segment with meshes textures and location
						Segment seg;
						seg.init(blocks, partName);
						segs.push_back(seg); //populate segs vector for this costume
						segmentsLib[pair] = seg; // populate segments map for random costumes
					}
					//for each costume create a costume, initialize it with the loaded segments and save it to the costumesLib
					Costume costume;
					costume.init(cos);
					costumesLib[cos] = costume;
					preloadedCostumes.push_back(cos);
				}
			}
		}
	}
	cout<<"List of all "<<costumesLib.size()<<" loaded costumes:"<<endl;
	int i=1;
	map<std::string, Costume>::iterator cos;
	for(cos = costumesLib.begin(); cos != costumesLib.end(); cos++) {
		cout<<i<<": "<<cos->first<<endl;
		i++;
	}
	this->splashScreen.end(); 
	loaded = true;
}