Saving TextureToPolygon Verts to a file?

Topics: Developer Forum, User Forum
Jan 9, 2010 at 8:18 PM
Edited Jan 9, 2010 at 8:22 PM

Is there a way to take the list of data of TextureToPolygon verts and other info about a polygonal object and then save it to a file, so as to not have to calculate the position of all the verts upon every startup?

As in, load a text file with the verts data, rather than work it out upon start up. Would this be quicker? Can anyone give any examples?

Any help is much appreciated.

 

Jan 9, 2010 at 11:28 PM

If you're using XNA, you can use the IntermediateSerializer, e.g.


 // construct xml writer settings
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;

 using (XmlWriter writer = XmlWriter.Create(targetDirectory + textureName + ".xml", settings))
 {
     IntermediateSerializer.Serialize<Vector2[]>(writer, verts.ToArray(), textureName);
 }

 

Jan 10, 2010 at 7:03 PM

That's awesome. Thanks.

From that, how would I go about loading the xml file, extracting the verts data and applying it to an object without using the geometryFactory to create the polygon?

I would like to just load the verts data, rather than have the geometryFactory work them out upon each startup. Unless it is better for performance to do so.

Jan 10, 2010 at 7:08 PM

Add the generated XML to your content project, with importer type XML Content, and no processing required. Then you can load it through your content manager, the same as anything else.