Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

VIEWING VRML FILES IN JAVA3D. URGENT!!!

 
prashantpotnis
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dear friends,
i want to load vrml files into java 3d so that i can have some control on the VRML code.
But following program doesn't load the vrml file.
Can anyone help me with this problem.
IT IS REALLY URGENT.
Thanks in Advance.
Regards,
Prashant.
import java.awt.*;
import java.applet.*;
import java.util.*;
import javax.vecmath.*;
import javax.media.j3d.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.loaders.vrml97.VrmlLoader;
import com.sun.j3d.loaders.Scene;
public class VView extends Applet
{
SimpleUniverse universe;
Scene scene = null;
public VView(String avatar)
{
setLayout(new BorderLayout());
Canvas3D canvas = new Canvas3D(null);
add("Center",canvas);

universe = new SimpleUniverse(canvas);
ViewingPlatform viewingPlatform = universe.getViewingPlatform();
View view = (universe.getViewer()).getView();

VrmlLoader loader = new VrmlLoader();
try
{
scene = loader.load(avatar);
}
catch(Exception e)
{
System.out.println("exception in loading the file");
System.exit(1);
}
BranchGroup sceneGroup = scene.getSceneGroup();
sceneGroup.setCapability(BranchGroup.ALLOW_DETACH);
sceneGroup.setCapability(BranchGroup.ALLOW_BOUNDS_READ);

universe.addBranchGraph(sceneGroup);
BoundingSphere sceneBounds = (BoundingSphere)sceneGroup.getBounds();
double radius = sceneBounds.getRadius();
Point3d center = new Point3d();
sceneBounds.getCenter(center);
Vector3d temp = new Vector3d(center);
temp.z=1.4*radius/Math.tan(view.getFieldOfView()/2.0);

Transform3D viewTransform = new Transform3D();
viewTransform.set(temp);
TransformGroup.setTransform(viewTransform);
}
public static void main(String p[])
{
new MainFrame(new VView(p[0]),400,400);
}
}
 
Rob Ross
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi "prashantpotnis", Welcome to JavaRanch!
Please change your name to comply with the naming policy to which you agreed when you registered here..

For your publicly displayed name,
use a first name, a space, and a last name.

You can change your name:
here

You can also find the naming policy:
here
Thank You!
Also, please note that people on JavaRanch are generally friendly and helpful, and will try to answer your questions as best they can, when they can. Marking your message as "URGENT" will NOT make anyone answer any faster, in fact, it will probably make people ignore you. If you like, you can edit your message to change your subject by clicking the little paper & pencil icon above your message.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic