I know this is bad organization, but this is only for a quick-and-dirty prototype of our game. I just have all our art resources (models, textures) in the working directory, and I just want to load everything from there (it’s the easiest thing to do for now). However, a problem I’m running into is that what I’m doing doesn’t seem to work on PCs - only OSX. Here’s basically my code:
String pwd = System.getProperty(“user.dir”).replace(’’, ‘/’).replaceAll(" “, “%20”);
System.out.println(“Pwd = " + pwd);
RelativeResourceLocator locator = new RelativeResourceLocator(new URI(“file”, “//”+pwd+”/”, null));
ResourceLocatorTool.addResourceLocator( ResourceLocatorTool.TYPE_MODEL, locator );
ResourceLocatorTool.addResourceLocator( ResourceLocatorTool.TYPE_TEXTURE, locator );
That doesn’t seem to work. I either get a URI formatting exception, which is why I added the replace’s, and even then it still doesn’t find my resources. I get resources with this code:
OgreLoader loader = new OgreLoader();
MaterialLoader matLoader = new MaterialLoader();
URL matURL = ResourceLocatorTool.locateResource(
ResourceLocatorTool.TYPE_TEXTURE, material_url);
URL meshURL = ResourceLocatorTool.locateResource(
ResourceLocatorTool.TYPE_MODEL, meshxml_url);
So am I using URI’s correctly, or am I forgetting something? Thanks.
Heres some code to add a ResourceLocator to find any kind of resource:
http://hub.jmonkeyengine.org/groups/general-2/snippets/single/11/
Just do
return new File("."+File.separator+string).toURI().toURL();
to get the file from the current working dir.
Cheers,
Normen
Awesome. Just what i was looking for! Thanks.