It's clearly a permission error but I cannot solve it
SEVERE: Exception in game loop
java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
at java.lang.System.getProperty(Unknown Source)
at java.io.Win32FileSystem.getUserPath(Unknown Source)
at java.io.Win32FileSystem.resolve(Unknown Source)
at java.io.File.getAbsolutePath(Unknown Source)
at java.io.File.getAbsoluteFile(Unknown Source)
at java.io.File.toURI(Unknown Source)
at it.F1Viewer3D.ModelLoader.load3ds(ModelLoader.java:65)
at it.F1Viewer3D.ModelLoader.load3ds(ModelLoader.java:37)
at it.F1Viewer3D.Car.build(Car.java:94)
at it.F1Viewer3D.Car.<init>(Car.java:88)
at it.F1Viewer3D.Applet.buildCar(Applet.java:469)
at it.F1Viewer3D.Applet.initGame(Applet.java:366)
at com.jmex.awt.applet.BetterBaseJMEApplet.gameLoop(BetterBaseJMEApplet.java:125)
at com.jmex.awt.applet.BetterBaseJMEApplet$1.run(BetterBaseJMEApplet.java:97)
27-giu-2009 14.00.46 com.jmex.awt.applet.BetterBaseJMEApplet$1 run
INFO: Application ending.
you've got multiple certificates there, they don't really work too well with applets, best to delete all the certificates in the jars and sign everything again with a single certificate.
you've got multiple certificates there, they don't really work too well with applets, best to delete all the certificates in the jars and sign everything again with a single certificate.
but the problem happens when I try to read a file out of the jar (a 3ds file)
are you sure?
static final FormatConverter CONVERTER_3DS = new MaxToJme();
/**
* Imports a .3ds model from file system. Like the 2-argument method
* with a null textureDir. The texture file(s) are assumed to be in the
* same directory as the model file.
* @param modelPath the path to the model file.
* Can be relative to the project directory.
* @return a Spatial containing the model geometry
* (with provided texture, if any) that can be attached to
* the scenegraph, or null instead if unable to load geometry.
*/
public static Spatial load3ds(String modelPath) {
return load3ds(modelPath, null);
}
/**
* Imports a .3ds model from file system.
* @param modelPath the path to the model file.
* Can be relative to the project directory.
* @param textureDir the path to the directory with the model's
* textures. If null, this will attempt to infer textureDir from
* modelPath, which assumes that the texture file(s) are in the same
* directory as the model file.
* @return a Spatial containing the model geometry
* (with provided texture, if any) that can be attached to
* the scenegraph, or null instead if unable to load geometry.
*/
public static Spatial load3ds(String modelPath, String textureDir) {
Spatial output = null; // the geometry will go here.
final ByteArrayOutputStream outStream =
new ByteArrayOutputStream(); // byte array streams don't have to be closed
try {
final File textures;
if(textureDir != null) { // set textureDir location
textures = new File( textureDir );
} else {// try to infer textureDir from modelPath.
textures = new File(
modelPath.substring(0, modelPath.lastIndexOf('/')) );
} // Add texture URL to auto-locator
final SimpleResourceLocator location =
new SimpleResourceLocator(textures.toURI().toURL());
ResourceLocatorTool.addResourceLocator(
ResourceLocatorTool.TYPE_TEXTURE, location );
// read .3ds file into memory & convert it to a jME usable format.
final FileInputStream rawIn = new FileInputStream(modelPath);
CONVERTER_3DS.convert(rawIn, outStream);
rawIn.close(); // FileInputStream s must be explicitly closed.
// prepare outStream for loading.
final ByteArrayInputStream convertedIn =
new ByteArrayInputStream(outStream.toByteArray());
// import the converted stream to jME as a Spatial
output = (Spatial) BinaryImporter.getInstance().load(convertedIn);
} catch (FileNotFoundException e) {
e.printStackTrace();
System.err.println("File not found at: " + modelPath);
} catch (IOException e) {
e.printStackTrace();
System.err.println("Unable read model at: " + modelPath);
} catch (URISyntaxException e) {
e.printStackTrace();
System.err.println("Invalid texture location at:" + textureDir);
} /*
* The bounding box is an important optimization.
* There is no point in rendering geometry outside of the camera's
* field of view. However, testing whether each individual triangle
* is visible is nearly as expensive as actually rendering it. So you
* don't test every triangle. Instead, you just test the bounding box.
* If the box isn't in view, don't bother looking for triangles inside.
*/
output.setModelBound(new BoundingBox());
output.updateModelBound();
return output;
}
}
how can I say to it to look for textures in my jar?
thanks bye
Set up the ResourceLocator correctly.
It needs to point to the Folder containing the textures (don't forget the trailing slash)
new SimpleResourceLocator(your/package/data/textures/);
I need an url
I wrote
location = new SimpleResourceLocator(getClass().getResource( "./media/" ) );
but I get
java.lang.NullPointerException: baseDir can not be null.
at com.jme.util.resource.SimpleResourceLocator.<init>(SimpleResourceLocator.java:61)
at it.F1Viewer3D.ModelLoader.load3ds(ModelLoader.java:77)