I want to understand how exactly locating resources work in Jme.
Let’s say I am trying to read an xml file for nifty or something else
why compiling this code:
[java]nifty.fromXml(“C:\Users\garnaout\Desktop\Accurev_workspace\JSLDriveModel\Interface\Nifty\CinematicTest.xml”, “start”);
[/java]
will result in a resource not found (although it is there) and compiling this code below works:
[java]nifty.fromXml(“all/intro.xml”, “start”); // this works[/java]
where is this being read from?
Also if I compile this:
[java]nifty.fromXml(“Interface/Nifty/CinematicTest.xml”, “start”);[/java]
I will get the following trace in my console but still nothing appears:
[java]INFO:
Nifty Data:
no children styles
no children useStyles
no children useControls
no children registerSounds
no children registeredMusic
no children registeredEffect
no children popups
no children controlDefinitions
children screens: 1
<screen> (controller => de.lessvoid.nifty.examples.helloworld.HelloWorldStartScreen, id => start)
children layers: 1
<layer> [element] (backgroundColor => #0000, childLayout => center, id => layer)
<interact> ()
<effects> ()
children elements: 1
<panel> [element] (backgroundColor => #0000, width => 100%, childLayout => center, visibleToMouse => true, id => panel)
<interact> ()
<effects> ()
children elements: 1
<text> [element] (color => #000f, font => aurulent-sans-16.fnt, valign => bottom, text => , align => center, id => text)
<interact> ()
<effects> ()
no children elements[/java]
Hi!
The all/intro.xml file is located in the libs of jme: lib/nifty-examples-1.3.jar
You should try to add 2x backslash in “c:Usersg…” (If you did not)
I had the same problem by loading models outside of the project-folder.
So I created my own “SimpleFileLocator” to load such models.
This FileLocator I had to register with: getAssetManager().registerLocator("/",“starcom.jme3d.io.SimpleFileLocator”);
[java]
package starcom.jme3d.io;
import com.jme3.asset.AssetInfo;
import com.jme3.asset.AssetKey;
import com.jme3.asset.AssetLocator;
import com.jme3.asset.AssetManager;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
public class SimpleFileLocator implements AssetLocator
{
public void setRootPath(String rootPath) {}
public AssetInfo locate(AssetManager manager, AssetKey key)
{
String name = key.getName();
File file = new File("", name); // Relativ
if (file.exists() && file.isFile())
{
return new AssetInfoFile(manager, key, file);
}
file = new File(name);
if (file.exists() && file.isFile())
{
return new AssetInfoFile(manager, key, file);
}
else
{
return null;
}
}
private static class AssetInfoFile extends AssetInfo
{
private File file;
public AssetInfoFile(AssetManager manager, AssetKey key, File file)
{
super(manager, key);
this.file = file;
}
@Override
public InputStream openStream()
{
try
{
return new FileInputStream(file);
}catch (FileNotFoundException e){ System.out.println("Error in SimpleFileLocator.java: "+e); return null; }
}
}
}
[/java]
Hope, this can help!
bye.