 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
KF Guest
|
Posted: Fri Mar 10, 2006 2:12 am Post subject: Problem to Display wrl file in applet embeded in browser |
|
|
Hi,
Urgent, can anybody help me, please.
i can display the wrl file in applet itself but i can't display in the
browser.is it any problem with the coding? pls correct me. Thanks.
here is the sample coding :
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.behaviors.mouse.MouseZoom;
import com.sun.j3d.utils.behaviors.mouse.MouseTranslate;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.net.URL;
import java.net.MalformedURLException;
import org.web3d.j3d.loaders.VRML97Loader;
import com.sun.j3d.loaders.Scene;
public class SimpleVrml extends Applet implements ActionListener {
String location;
String initLocation;
Canvas3D canvas;
SimpleUniverse universe;
TransformGroup vpTransGroup;
VRML97Loader loader;
View view;
Panel panel;
Label label;
BranchGroup sceneRoot;
TransformGroup examineGroup;
BranchGroup sceneGroup;
BoundingSphere sceneBounds;
DirectionalLight headLight;
AmbientLight ambLight;
TextField textField;
Cursor waitCursor;
Cursor handCursor;
public SimpleVrml() {
initLocation="cylinder.wrl";
setLayout(new BorderLayout());
GraphicsConfiguration config
=SimpleUniverse.getPreferredConfiguration();
setLayout(new BorderLayout());
canvas = new Canvas3D(config);
add("Center",canvas);
panel = new Panel();
panel.setLayout(new FlowLayout(FlowLayout.LEFT));
textField = new TextField(initLocation,60);
textField.addActionListener(this);
label = new Label("Location:");
panel.add(label);
panel.add(textField);
add("North",panel);
waitCursor = new Cursor(Cursor.WAIT_CURSOR);
handCursor = new Cursor(Cursor.HAND_CURSOR);
universe = new SimpleUniverse(canvas);
ViewingPlatform viewingPlatform = universe.getViewingPlatform();
vpTransGroup = viewingPlatform.getViewPlatformTransform();
Viewer viewer = universe.getViewer();
view = viewer.getView();
setupBehavior();
loader = new VRML97Loader();
gotoLocation(initLocation);
}
public void actionPerformed(ActionEvent ae) {
gotoLocation(textField.getText());
}
void gotoLocation(String location) {
canvas.setCursor(waitCursor);
if (sceneGroup != null) {
sceneGroup.detach();
}
Scene scene = null;
try {
URL loadUrl = new URL(location);
try {
// load the scene
scene = loader.load(new URL(location));
} catch (Exception e) {
System.out.println("Exception loading URL:" + e);
}
} catch (MalformedURLException badUrl) {
// location may be a path name
try {
// load the scene
scene = loader.load(location);
} catch (Exception e) {
System.out.println("Exception loading file from path:" + e);
}
}
if (scene != null) {
// get the scene group
sceneGroup = scene.getSceneGroup();
sceneGroup.setCapability(BranchGroup.ALLOW_DETACH);
sceneGroup.setCapability(BranchGroup.ALLOW_BOUNDS_READ);
// add the scene group to the scene
examineGroup.addChild(sceneGroup);
// now that the scene group is "live" we can inquire the bounds
sceneBounds = (BoundingSphere)sceneGroup.getBounds();
// set up a viewpoint to include the bounds
setViewpoint();
}
canvas.setCursor(handCursor);
}
void setViewpoint() {
Transform3D viewTrans = new Transform3D();
Transform3D eyeTrans = new Transform3D();
// point the view at the center of the object
Point3d center = new Point3d();
sceneBounds.getCenter(center);
double radius = sceneBounds.getRadius();
Vector3d temp = new Vector3d(center);
viewTrans.set(temp);
// pull the eye back far enough to see the whole object
double eyeDist = 1.4*radius / Math.tan(view.getFieldOfView() / 2.0);
temp.x = 0.0;
temp.y = 0.0;
temp.z = eyeDist;
eyeTrans.set(temp);
viewTrans.mul(eyeTrans);
// set the view transform
vpTransGroup.setTransform(viewTrans);
}
private void setupBehavior() {
sceneRoot = new BranchGroup();
examineGroup = new TransformGroup();
examineGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
examineGroup.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
examineGroup.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
examineGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
examineGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
sceneRoot.addChild(examineGroup);
BoundingSphere behaviorBounds = new BoundingSphere(new Point3d(),
Double.MAX_VALUE);
MouseRotate mr = new MouseRotate();
mr.setTransformGroup(examineGroup);
mr.setSchedulingBounds(behaviorBounds);
sceneRoot.addChild(mr);
MouseTranslate mt = new MouseTranslate();
mt.setTransformGroup(examineGroup);
mt.setSchedulingBounds(behaviorBounds);
sceneRoot.addChild(mt);
MouseZoom mz = new MouseZoom();
mz.setTransformGroup(examineGroup);
mz.setSchedulingBounds(behaviorBounds);
sceneRoot.addChild(mz);
BoundingSphere lightBounds =
new BoundingSphere(new Point3d(), Double.MAX_VALUE);
ambLight = new AmbientLight(true, new Color3f(1.0f, 1.0f,
1.0f));
ambLight.setInfluencingBounds(lightBounds);
ambLight.setCapability(Light.ALLOW_STATE_WRITE);
sceneRoot.addChild(ambLight);
headLight = new DirectionalLight();
headLight.setCapability(Light.ALLOW_STATE_WRITE);
headLight.setInfluencingBounds(lightBounds);
sceneRoot.addChild(headLight);
universe.addBranchGraph(sceneRoot);
}
public static void main(String[] args) {
new MainFrame(new SimpleVrml(), 780, 780);
}
}
cylinder.wrl :
#VRML V2.0 utf8
# A cylinder
Shape {
appearance Appearance {
material Material { }
}
geometry Cylinder {
height 2.0
radius 1.5
}
}
view.html:
<html>
<applet code="SimpleVrml.class" width=600 height=600>
</applet>
</html>
error msg that i get :
Exception loading file from path:java.security.AccessControlException:
access denied (java.util.PropertyPermission user.dir read) |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|