Ejemplo n.º 1
0
void MotionGraphController::readInMotionSequences(MotionDataSpecification& motion_data_specs)
{
	for (unsigned short i = 0; i<motion_data_specs.size(); i++)
	{
		string current_file = motion_data_specs.getBvhFilename(i);
		cout << "MotionGraphController reading " << current_file << endl;
		logout << "MotionGraphController reading "  << current_file << endl;

		char* BVH_filename = NULL;
		string character_BVH2(current_file);
		try
		{
			BVH_filename = data_manager.findFile(character_BVH2.c_str());
			if (BVH_filename == NULL)
			{
				stringstream ss;
				ss << "MotionGraphController::readInMotionSequences: Unable to find character BVH file <" << character_BVH2 << ">. Aborting load.";
				logout << ss.str() << endl;
				throw AppException(ss.str().c_str());
			}
			pair<Skeleton*, MotionSequence*> read_result;
			try
			{
				read_result = data_manager.readBVH(BVH_filename);
			}
			catch (const DataManagementException& dme)
			{
				stringstream ss;
				ss << "MotionGraphController::readInMotionSequences: Aborting due to DataManager expection: " << dme.msg;
				logout << ss.str();
				throw AppException(ss.str().c_str());
			}

			// throw away the skeleton
			delete read_result.first;
			MotionSequence * ms = read_result.second;

			string seqID = motion_data_specs.getSeqID(i);
			char* tmp = new char[strlen(seqID.c_str())+1];
			strcpy(tmp, seqID.c_str());
			ms->setId(tmp);
			delete [] tmp;

			//scale the character position in the motion sequence
			ms->scaleChannel(CHANNEL_ID(0, CT_TX), character_size_scale);
			ms->scaleChannel(CHANNEL_ID(0, CT_TY), character_size_scale);
			ms->scaleChannel(CHANNEL_ID(0, CT_TZ), character_size_scale);

			motion_sequence_map.insert(pair<string, MotionSequence*>(seqID, ms));
		}
		catch (BasicException& e)
		{
			stringstream ss;
			ss << "MotionGraphController::readInMotionSequences: Aborting due to BasicException: " << e.msg;
			logout << ss.str();
			throw AppException(ss.str().c_str());
		}
	}
	logout << "the number of motion sequences is : " << motion_sequence_map.size() << endl;
	logout << "... MotionGraphController::readInMotionSequences finished" << endl;
}
Ejemplo n.º 2
0
void MotionGraphController::readInMotionSequences()
{
	cout << "reading motion Sequences" << endl;
	namespace fs = ::boost::filesystem;

	fs::path p(BVH_MOTION_FILE_PATHMOTIONS);
	if (!exists(p))    // does p actually exist?
		cout << "doesn't exist" << endl;
	fs::directory_iterator end_itr;

	// cycle through the directory
	for (fs::directory_iterator itr(p); itr != end_itr; ++itr)
	{
		// If it's not a directory, list it. If you want to list directories too, just remove this check.
		if (is_regular_file(itr->path())) {
			// assign current file name to current_file and echo it out to the console.
			string current_file = itr->path().string();
			current_file = itr->path().filename().string();

			cout << current_file << endl;

			DataManager dataman;
			dataman.addFileSearchPath(BVH_MOTION_FILE_PATHMOTIONS);
			char* BVH_filename = NULL;
			string character_BVH2(current_file);
			try
			{
				BVH_filename = dataman.findFile(character_BVH2.c_str());
				if (BVH_filename == NULL)
				{
					logout << "AnimationControl::loadCharacters: Unable to find character BVH file <" << character_BVH2 << ">. Aborting load." << endl;
					throw BasicException("ABORT");
				}
				pair<Skeleton*, MotionSequence*> read_result;
				try
				{
					read_result = data_manager.readBVH(BVH_filename);
				}
				catch (const DataManagementException& dme)
				{
					logout << "AnimationControl::loadCharacters: Unable to load character data files. Aborting load." << endl;
					logout << "   Failure due to " << dme.msg << endl;
					throw BasicException("ABORT");
				}

				Skeleton* skel = read_result.first;
				MotionSequence * ms = read_result.second;
				
				std::string x = current_file;
				char *y = new char[x.length() + 1];
				std::strcpy(y, x.c_str());
				//set the ID aka filename
				ms->setId(y);
				delete[] y;

				//scale each motion sequence once
				ms->scaleChannel(CHANNEL_ID(0, CT_TX), character_size_scale);
				ms->scaleChannel(CHANNEL_ID(0, CT_TY), character_size_scale);
				ms->scaleChannel(CHANNEL_ID(0, CT_TZ), character_size_scale);

				MotionSequenceContainer test;
				test.MS = ms;
				test.SeqID = current_file;
				MsVector.push_back(test);
				cout << "done loading:  "<<current_file << MsVector.size() << endl;
			}
			catch (BasicException& e) { cout << e.msg << endl; }
		}
	}
	cout << "the size of the vector is : " << MsVector.size() << endl;
}