Timer t = new NanoTimer();
float time = 0f;
// new loader each time, yes
try {
Geometry g;
// need to load vial loadModel, JME does not see obj, etc as
// Assets..
t.reset();
Spatial n = (Spatial) assetMan.loadModel(from.getAbsolutePath());
time = t.getTimeInSeconds();
System.out.println("File " + from.getAbsolutePath() + " loaded in "
+ time + " seconds");
if (n instanceof Geometry) {
g = (Geometry) n;
n = new Node(g.getName());
((Node)n).attachChild(g);
} else if (n instanceof Node) {
if (((Node) n).getChildren().size() > 1)
throw new Throwable(
"Mesh with more children detected than one on "
+ from.getName());
g = (Geometry) ((Node) n).getChild(0);
} else
throw new Throwable("Spatial loaded was unexpected type "
+ n.getClass());
// jme fucked up the model names, and ignores any object name
// entries so we fix a bit
String fName = from.getName().substring(0,
from.getName().length() - fileEnding.length());// without .nav
g.setName(fName.toLowerCase());
TiledNavMesh navMesh = new TiledNavMesh();
{
String[] xy = from.getParentFile().getName().split("_");
// l2j's center is in x between region 19 (-32768) and 20 (+32768)
// and in y between region 18 (+32768) and 17 (-32768)
// minus 20*2048, 20 because region count starts with 0_0,
// 2048 because one region consists of 8x8 tiles (each 256x256 long)
int xd = (Integer.parseInt(xy[0]) * 256) - (20 * 2048);
// minus 18*2048
int yd = (Integer.parseInt(xy[1])) * 256 - (18 * 2048);
// center is in top left corner for nav mesh to be consistent with
// this for borders move x right, move y up by half size
Vector3f offset = new Vector3f(xd + 128, 0, yd - 128);
System.out.println("Offset for "+from.getParentFile().getName()+"/nav2.obj should be at:"+offset);
}
navMesh.loadFromMesh(g.getMesh(), Vector3f.ZERO, isMeshRelative);
time = t.getTimeInSeconds();
System.out.println("File " + from.getAbsolutePath()
+ " converted in " + time + " seconds");
String path = from.getAbsolutePath();