void ObjectAnimations::Load( BaseIO& str )
{
	unsigned int id = 0;
	str.Read(id, 0, true);
	obj.SetConnectionID(id);
	unsigned int sz = 0;
	str.Read(sz, 0, true);

	for(unsigned int i = 0; i<sz; i++)
	{
		int k = 0;
		str.Read(k, 0, true);

		unsigned int sz2 = 0;
		str.Read(sz2, 0, true);
		for(unsigned int i2 = 0; i2<sz2; i2++)
		{
			AnimationKey key;
			key.Load(str);
			animations[k].insert(key);
		}
	}
}
void World::LoadScene(const char * scene_path)
{
	// Using case-insensitive strings and streams for easier parsing
	ci_ifstream input;
	input.open(scene_path, ios::in);

	// Invalid file
	if (input.fail())
	{
		fprintf(stderr, "Error loading file: %s\n", scene_path);
		getchar();
		exit(-1);
	}

	ci_string item;
	while (std::getline(input, item, '['))
	{
		ci_istringstream iss(item);

		ci_string result;
		if (std::getline(iss, result, ']'))
		{
			if (result == "player")
			{
				// Box attributes
				PlayerModel* player = new PlayerModel();
				player->Load(iss);
				mModel.push_back(player);

				mPlayerModel = player;
			}
			else if (result == "discoball")
			{
				// Box attributes
				Discoball* discoBallz = new Discoball();
				discoBallz->Load(iss);
				mModel.push_back(discoBallz);
			}
			else if (result == "bunnny")
			{
				// Box attributes
				BunnyModel* bunny = new BunnyModel();
				bunny->Load(iss);
				mModel.push_back(bunny);
			}
			else if (result == "barrel")
			{
				// Box attributes
				BarrelModel* barrel = new BarrelModel();
				barrel->Load(iss);
				mModel.push_back(barrel);
			}
			else if (result == "cube")
			{
				// Box attributes
				CubeModel* cube = new CubeModel();
				cube->Load(iss);
				mModel.push_back(cube);
			}
			else if (result == "sphere")
			{
				SphereModel* sphere = new SphereModel();
				sphere->Load(iss);
				mModel.push_back(sphere);
			}
			else if (result == "animationkey")
			{
				AnimationKey* key = new AnimationKey();
				key->Load(iss);
				mAnimationKey.push_back(key);
			}
			else if (result == "animation")
			{
				Animation* anim = new Animation();
				anim->Load(iss);
				mAnimation.push_back(anim);
			}
			else if (result.empty() == false && result[0] == '#')
			{
				// this is a comment line
			}
			else
			{
				fprintf(stderr, "Error loading scene file... !");
				getchar();
				exit(-1);
			}
		}
	}
	input.close();

	if (DRAW_ANIM_PATH) {
		for (vector<Animation*>::iterator it = mAnimation.begin(); it < mAnimation.end(); ++it)
		{
			(*it)->CreateVertexBuffer();
		}
	}
}
void World::LoadScene(const char * scene_path)
{
	// Using case-insensitive strings and streams for easier parsing
	ci_ifstream input;
	input.open(scene_path, ios::in);

	// Invalid file
	if (input.fail())
	{
		fprintf(stderr, "Error loading file: %s\n", scene_path);
		getchar();
		exit(-1);
	}

	ci_string item;
	while (std::getline(input, item, '['))
	{
		ci_istringstream iss(item);

		ci_string result;
		if (std::getline(iss, result, ']'))
		{
			if (result == "cube")
			{
				CubeModel* cube = new CubeModel();
				cube->Load(iss);
				mModel.push_back(cube);
			}
			else if (result == "sphere")
			{
#if defined(PLATFORM_OSX)
				int sphereTextureID = TextureLoader::LoadTexture("Textures/moonTexture.jpg");
#else
				int sphereTextureID = TextureLoader::LoadTexture("../Assets/Textures/moonTexture.jpg");
#endif

				SphereModel* moon = new SphereModel(sphereTextureID, vec3(10.0f, 10.0f, 10.0f));
				moon->Load(iss);
				mModel.push_back(moon);
			}
			else if (result == "animationkey")
			{
				AnimationKey* key = new AnimationKey();
				key->Load(iss);
				mAnimationKey.push_back(key);
			}
			else if (result == "animation")
			{
				Animation* anim = new Animation();
				anim->Load(iss);
				mAnimation.push_back(anim);
			}
			else if (result.empty() == false && result[0] == '#')
			{
				// this is a comment line
			}
			else
			{
				fprintf(stderr, "Error loading scene file... !");
				getchar();
				exit(-1);
			}
		}
	}
	input.close();

	// Set Animation vertex buffers
	for (vector<Animation*>::iterator it = mAnimation.begin(); it < mAnimation.end(); ++it)
	{
		// Draw model
		(*it)->CreateVertexBuffer();
	}
}
Exemple #4
0
void World::LoadScene(const char * scene_path){
	// Using case-insensitive strings and streams for easier parsing
	ci_ifstream input;
	input.open(scene_path, ios::in);

	// Invalid file
	if(input.fail() ){	 
		fprintf(stderr, "Error loading file: %s\n", scene_path);
		getchar();
		exit(-1);
	}

	ci_string item;
	while( std::getline( input, item, '[' ) ){
        ci_istringstream iss( item );

		ci_string result;
		if( std::getline( iss, result, ']') ){
			if( result == "cube" ){
				// Box attributes
				//CubeModel* cube = new CubeModel();
				ourGuy->Load(iss);
				mModel.push_back(ourGuy);
			}
			else if( result == "ground" ){
				// Box attributes
				CubeModel* cube = new CubeModel();
				cube->Load(iss);
				mModel.push_back(cube);
			}
            else if( result == "sphere" ){
                //SphereModel* sphere = new SphereModel();
                ourSphere->Load(iss);
                mModel.push_back(ourSphere);
            }
			else if ( result == "animationkey" ){
				AnimationKey* key = new AnimationKey();
				key->Load(iss);
				mAnimationKey.push_back(key);
			}
			else if (result == "animation"){
				Animation* anim = new Animation();
				anim->Load(iss);
				mAnimation.push_back(anim);
			}//*/
			else if (result == "bspline"){
				BSpline* spline = new BSpline();
				spline->Load(iss);
				mBSpline.push_back(spline);
			}//*/
			else if ( result.empty() == false && result[0] == '#'){
				// this is a comment line
			}
			else{
				fprintf(stderr, "Error loading scene file... !");
				getchar();
				exit(-1);
			}
	    }
	}
	input.close();

	// Set Animation vertex buffers
	for (vector<Animation*>::iterator it = mAnimation.begin(); it < mAnimation.end(); ++it)
		// Draw model
		(*it)->CreateVertexBuffer();
}