Saving and loading .scene files

burns

21-02-2008 16:05:47

Is there a way to save and load .scene files in MOGRE?

I have seen others in the forums say that oFusion can load them, but not save them. I was wondering if any functionality had been built from the C# side of things.

I've also seen others suggest that I should just read and write binary files, which makes sense. Has anything of that sort been implemented? Thanks!

dodongoxp

21-02-2008 23:44:43

.scene files are just xml files.. try to use methods of handling with xml files included in the .net framework

if you want an example.. there are a scene loader in the mogre wiki.. just look around abit ... :wink:

burns

22-02-2008 14:14:18

Okay, I guess I was hoping for something that automated an entire scene graph dump and retrieval.

If nothing like that exists, that's good to know. I can try to roll my own, but I just figured it didn't make sense to expend that effort if something already existed.

I figured something probably did exist since I would imagine a lot of people want to save and load scene graphs. But I guess people want to do that in slightly different ways, so maybe a general solution would be too difficult.

Beauty

28-02-2009 02:21:02

In my application I have an exporter/importer class.
There I store all needed/wanted parameters of the scene.
For example Position, NodeName, ParentNode etc.
Then I use .NET fuctions to serialize it.
It creates a type of XML file, which I can edit by hand. Also adding new objects.
Also it's easy to load this file again, attach all objects to the scene again.
This is not the dotScene format, but for me it's enough and I'm happy.

With C# you can serialize most parts of a class to a file.
For this you must add a line with [Serializable] above the class (or struct).

Here you see how you can serialize a class.

Save Scene:
MyScene exportScene = new MyScene();
// write information to exportScene

XmlSerializer ser = new XmlSerializer(typeof(MyScene));
StreamWriter myWriter = new StreamWriter(filename);
ser.Serialize(myWriter, exportScene);
myWriter.Close();



Load Scene:
XmlSerializer ser = new XmlSerializer(typeof(MyScene));
myReader = new StreamReader(filename);
MyScene importScene;
try
{
importScene = (MyScene)ser.Deserialize(myReader);
}
catch (System.InvalidOperationException e)
{
Console.WriteLine("Problems at deserializing: " + e.Message);
}
finally
{
myReader.Close();
}
// restore from importScene