Example #1
0
void Batch::Save(std::string filename,std::vector< SmartPointer<Batch> > batches)
{
	Clock t1;
	printf("Saving file %s\n",filename.c_str());
	std::set<std::string> light_textures;
	Archive ar;
	ar.Open(filename,true);
	ar.Push("batches");
	int num=(int)batches.size();
	ar.WriteInt("num",num);
	for (int i=0;i<num;i++) 
	{
		ar.Push("batch");
		ar.WriteSmartPointer(batches[i]);
		ar.Pop("batch");

		//save the light maps
		if (batches[i]->texture1 && light_textures.find(batches[i]->texture1->filename)==light_textures.end())
		{
			light_textures.insert(batches[i]->texture1->filename);
			batches[i]->texture1->save();
		}
	}
	ar.Pop("batches");
	ar.Close();
	//printf("done in %d msec\n",t1.msec());
}
Example #2
0
void Batch::Write(Archive& ar)
{
	static int BATCH_VERSION=1;

	ar.WriteInt("version",BATCH_VERSION);
	ar.WriteInt("primitive",primitive);    	

	ar.Push("ambient" );ambient.Write (ar);ar.Pop("ambient");
	ar.Push("diffuse" );diffuse.Write (ar);ar.Pop("diffuse");
	ar.Push("specular");specular.Write(ar);ar.Pop("specular");
	ar.Push("emission");emission.Write(ar);ar.Pop("emission");
	ar.WriteFloat("shininess",shininess);

	ar.Push("matrix"   );matrix.Write(ar);ar.Pop("matrix");

	ar.Push("vertices" );ar.WriteSmartPointer(vertices);ar.Pop("vertices");
	ar.Push("normals"  );ar.WriteSmartPointer(normals );ar.Pop("normals");
	ar.Push("colors"   );ar.WriteSmartPointer(colors  );ar.Pop("colors");
	ar.WriteString("texture0",this->texture0?texture0->filename:"");
	ar.Push("texture0coords");ar.WriteSmartPointer(texture0coords);ar.Pop("texture0coords");
	ar.WriteString("texture1",this->texture1?texture1->filename:"");
	ar.Push("texture1coords");ar.WriteSmartPointer(texture1coords);ar.Pop("texture1coords");

	//important: I do not write the bounding box getBox();
}
Example #3
0
std::vector< SmartPointer<Batch> > Batch::Open(std::string filename)
{
	Clock t1;
	printf("Opening file %s\n",filename.c_str());
	Archive ar;
	ar.Open(filename,false);
	ar.Push("batches");
	int num=ar.ReadInt("num");
	std::vector< SmartPointer<Batch> > batches(num);
	for (int i=0;i<num;i++) 
	{
		ar.Push("batch");
		batches[i]=ar.ReadSmartPointer<Batch>();
		ar.Pop("batch");
	}
	ar.Pop("batches");
	ar.Close();
	//printf("done in %d msec\n",t1.msec());
	return batches;
}
Example #4
0
void Batch::Read(Archive& ar)
{
	int version=ar.ReadInt("version");
	this->primitive=ar.ReadInt("primitive"); 
	ar.Push("ambient" );ambient.Read (ar);ar.Pop("ambient");
	ar.Push("diffuse" );diffuse.Read (ar);ar.Pop("diffuse");
	ar.Push("specular");specular.Read(ar);ar.Pop("specular");
	ar.Push("emission");emission.Read(ar);ar.Pop("emission");
	this->shininess=ar.ReadFloat("shininess");
	ar.Push("matrix"  );matrix.Read(ar);ar.Pop("matrix");
	ar.Push("vertices");vertices=ar.ReadSmartPointer<Vector>();ar.Pop("vertices");
	ar.Push("normals" );normals=ar.ReadSmartPointer<Vector>();ar.Pop("normals");
	ar.Push("colors" ) ;colors=ar.ReadSmartPointer<Vector>();ar.Pop("colors");
	this->texture0.reset();std::string skin_filename=ar.ReadString("texture0");
	if (skin_filename.length()) this->texture0 =Texture::open(skin_filename);
	ar.Push("texture0coords");texture0coords=ar.ReadSmartPointer<Vector>();ar.Pop("texture0coords");
	this->texture1.reset();std::string light_filename=ar.ReadString("texture1");
	if (light_filename.length()) this->texture1 =Texture::open(light_filename);
	ar.Push("texture1coords");texture1coords=ar.ReadSmartPointer<Vector>();ar.Pop("texture1coords");

	//I force a recalculation of bounding box
	this->invalidateBox();
}