"Saveable" - how to use?

I have NavMesh class that @normanh wrote, and I see it implements Saveable, and the read and write methods. The issue I am having is that generating the navmesh (specifically, linking the cells together) takes a long time. I figured I could generate it once, and save it somehow, and instead of generating it just load it again later.

It looks like I could use jmonkeyengine saveable to save the NavMesh - but I just cannot work out how!

https://bitbucket.org/jakebriggs/modeltest/src/c998fe62e8384e71ec5aca5f94a192d3a0a050a3/src/com/jme3/ai/navmesh/NavMesh.java?at=ai-smaller&fileviewer=file-view-default

https://jmonkeyengine.github.io/wiki/jme3/advanced/save_and_load.html

Easy Approach:

Node n = new Node("NavMesh");
n.attachChild(navMesh);
rootNode.addChild(n);
```

Then it's in your j3o and will stay there. For loading you just need `rootNode.getChild("NavMesh")`.
Note: If you use the Generator in the SDK, it does all that for you (but I guess it's still 3.0 only)

NavMsh isn’t a spatial, so, this won’t work…

When I do this:

BinaryExporter exporter = BinaryExporter.getInstance();
File file = new File("/tmp/MyModel.j3o");
try {
    exporter.save(navMesh, file);
} catch (IOException ex) {
    System.out.println("opps " + ex);
}

I get this:

Jun 18, 2016 7:20:55 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
java.lang.StackOverflowError
	at com.jme3.export.binary.BinaryOutputCapsule.writeAlias(BinaryOutputCapsule.java:392)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:121)
	at com.jme3.math.Vector3f.write(Vector3f.java:1001)
	at com.jme3.export.binary.BinaryExporter.processBinarySavable(BinaryExporter.java:401)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:720)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:733)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:281)
	at com.jme3.ai.navmesh.Cell.write(Cell.java:724)
	at com.jme3.export.binary.BinaryExporter.processBinarySavable(BinaryExporter.java:401)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:720)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:733)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:281)
	at com.jme3.ai.navmesh.Cell.write(Cell.java:727)
	at com.jme3.export.binary.BinaryExporter.processBinarySavable(BinaryExporter.java:401)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:720)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:733)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:281)



	at com.jme3.export.binary.BinaryExporter.processBinarySavable(BinaryExporter.java:401)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:720)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:733)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:281)
	at com.jme3.ai.navmesh.Cell.write(Cell.java:727)
	at com.jme3.export.binary.BinaryExporter.processBinarySavable(BinaryExporter.java:401)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:720)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:733)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:281)
	at com.jme3.ai.navmesh.Cell.write(Cell.java:727)
	at com.jme3.export.binary.BinaryExporter.processBinarySavable(BinaryExporter.java:401)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:720)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:733)
	at com.jme3.export.binary.BinaryOutputCapsule.write(BinaryOutputCapsule.java:281)
	at com.jme3.ai.navmesh.Cell.write(Cell.java:727)
	at com.jme3.export.binary.BinaryExporter.processBinarySavable(BinaryExporter.java:401)

BUILD SUCCESSFUL (total time: 55 seconds)

NavMesh is a Mesh so you can wrap it into a Geometry.
For some reason the savable of navmesh.Cell (which you use) calls itself recursively which then leads to a stack overflow.

That’s something you can’t actually change and would have with the Geometry aswell (though you should prefer saving them along with the according level)

Are you sure NavMesh is a Mesh? Its not working for me.

Anyway, even if I did attach it to a node and saved the node, wouldn’t the node save the navmesh, which in turn would save the cell, which would save itself over and over and we would end up with the same issue?

Okay I think my navmesh is too damn big. If I make a terain from a 2px by 2px png, it seems to save fine.