Skip to content
Alexander Scheurer edited this page Feb 14, 2014 · 6 revisions

Protobuf

... is a way to serialize structured data, developed by Google. > Wikipedia

Protobuf can serialize almost anything, in this tutorial we will only use it to load our 3D models, because it yields a massive performance increase. Until now we loaded cubes with only 8 vertices, but this lesson has the FUSEE rocket with 14.5k vertices attached. Using protobuf we easiely have 10x faster load times for the rocket. Try switching between them in this lessons code and have a stopwatch ready.

So what we are actually doing? We have a class linked in called MySerializer, and we just give it spot in our GameEntity class private MySerializer _ser;. The only other thing to do is a function to decide if the incoming data is protobufed or not.

if (meshPath.Contains("protobuf"))
{
   _ser = new MySerializer();
   using (var file = File.OpenRead(meshPath))
   {
      _mesh = _ser.Deserialize(file, null, typeof(Mesh)) as Mesh;
   }
}
else
{
   _mesh = MeshReader.LoadMesh(meshPath);
}

If the meshPath contains "protobuf" deserialize it, otherwise handel it like a regular mesh file. That is all there is to do for this lesson, really.

The MySerializer class we use here is specialized for protobufing Wavefront OBJ files. If you want to serialize other data, check out this tutorial: HowTo: [Serialization] Saving and loading objects from to disk in Fusee

[> Lesson 12 - More of everything](Lesson 12)