Entropy's picture

Serialising (Serializing) the Vector3 struct?

Hi, there.

For my current project (which is *almost* at the point where I could confidently post it on the "Personal Projects" board - give it a few more weeks) I'm rendering geodesic spheres as planetoids (sort of). I've got a decent algorithm for building the spheres as an array of raw vertices, then optimising that array into one Vector3 array of unique vertices and one integer array of elements, to be drawn as a VBO.

Once it's optimised, it renders nice and smoothe, but the optimisation process takes quite a bit of time for the higher levels of resolution. I'd use a display list, but as the terrain changes shape, it's not an option.

Anyway, my solution is to optimise the data once, then serialise it to disk by defining some preprocessor variables in my sphere class. Then I can redefine the preprocessor variables and just load the pre-optimised data directly into memory, so I can have relatively higher-res spheres without the long optimisation times.

So now I pass a vertex data struct to my file-handling class for serialisation, but as the OpenTK Vector3 struct is not marked as [Serializable] (SP?), I can't currently serialise the data.

I tried all this at home this morning before setting off to work, but when I get home I'm going try one of two things:

a) Recompiling the OpenTK source after marking Vector3 with the [Serializable] attribute, or
b) Modifying my vertex data struct to convert the inputted Vector3 array to a float array - this seems pretty inefficient to me.

Is there any reason I shouldn't just tag the Vector3 struct as [Serializable]? Or does anyone think I'm just looking at this in entirely the wrong way?

Any feedback would be greatly appreciated.

And once I've coded in the rough "Look'n'Feel" of the game a little more, I'll post screenies and an overview on the Personal Projects pages.

Also, if anyone wants to see my sphere building/optimisation algorithms, let me know and I'll post them here. I didn't come up with the sphere method myself (I just ported it to C#/.NET/OpenTK), but it's so deceptively simple and clever, I was kicking myself when I stumbled across it.

Quick aside: Being from the UK, It's kind of strange to me that I have to use US English spellings of words like "Colour/Color" and "Serialise/Serialize" while coding. It also leaves me confused sometimes as to whether I should stick to US-English conventions or use the (for me, preferred) UK spellings when creating fields. Generally, I go with US English to avoid later confusion, but it still feels a little odd.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
objarni's picture

US English - yeah being from sweden it might just be simpler - it is a whole other language instead of some "odd spellings" of common words hehe.

Entropy's picture

US English - yeah being from sweden it might just be simpler - it is a whole other language instead of some "odd spellings" of common words hehe.

Heh - fair point, objarni. Guess I don't really have much to complain about do I? :-D

Entropy's picture

Well, in case anyone out there is interested, I rebuilt the OpenTK library with a [Serializeable] Vector3 class and everything seems to work just fine.

the Fiddler's picture

This is already added to SVN and will come to 0.9.2.

Entropy's picture

Awesome! Thanks, Fiddler.