java3d调用了VRML文件在eclipse上能运行,但在浏览器上运行出错,WHY?
我用java3d写了一个applet程序,程序中调用了VRML文件。在eclipse中能运行,放在网页中就运行不了。我写的代码如下:
import java.applet.Applet;
import java.awt.BorderLayout;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import org.jdesktop.j3d.loaders.vrml97.VrmlLoader;
import com.sun.j3d.loaders.Scene;
import java.awt.GraphicsConfiguration;
import java.io.*;
public class Vrml1 extends Applet {
public void init() {
//filename = args[0];
setLayout(new BorderLayout());
Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
add("Center", c);
BranchGroup scene = createSceneGraph();
SimpleUniverse u = new SimpleUniverse(c);
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}
/**
*
*/
private static final long serialVersionUID = -6019133668952244907L;
//private String filename = "SKXC.wrl";
public BranchGroup createSceneGraph() {
BranchGroup objRoot = new BranchGroup();
TransformGroup objScale = new TransformGroup();
Transform3D t3d = new Transform3D();
t3d.setScale(0.3);
objScale.setTransform(t3d);
objRoot.addChild(objScale);
Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
BoundingSphere bounds =
new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
light1.setInfluencingBounds(bounds);
objRoot.addChild(light1);
TransformGroup objTrans = new TransformGroup();
objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objScale.addChild(objTrans);
VrmlLoader loader = new VrmlLoader();
Scene s = null;
try {
s = loader.load("SKXC.wrl");
} catch (Exception e) {
System.err.println(e);
System.exit(1);
}
objTrans.addChild(s.getSceneGroup());
Transform3D yAxis = new Transform3D();
Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE,
0, 0,
4000, 0, 0,
0, 0, 0);
RotationInterpolator rotator =
new RotationInterpolator(rotationAlpha, objTrans, yAxis,
0.0f, (float) Math.PI*2.0f);
rotator.setSchedulingBounds(bounds);
objTrans.addChild(rotator);
objRoot.compile();
return objRoot;
}
public Vrml1() {
//filename = args[0];
setLayout(new BorderLayout());
Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
add("Center", c);
BranchGroup scene = createSceneGraph();
SimpleUniverse u = new SimpleUniverse(c);
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}
}
然后html代码如下:<applet code="Vrml1" ARCHIVE="Vrml1.jar" width=600 height=400>
</applet>
在网页中运行出错为:
java.security.AccessControlException:
access denied (java.lang.RuntimePermission exitVM.1)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)