Vlad Valica wrote:
>
> I need to load an VRML model which is represented in a wrl format, in my
> Java3D application I don't know how to do it. I don't know if the loader
> which exist is for wrl format or for other format. I need an advice about
> what class i have to use and how I have ti do it.
>
> Thanx a lot in advance

Hi Vlad, take a look at this snippet of code,
it should show you how to use the vrml-loader. The actionlistener of
the button actually does the loading stuff.


Cheers Joerg

Here we go:

import com.sun.j3d.loaders.vrml97.VrmlLoader;
import com.sun.j3d.loaders.vrml97.VrmlScene;
import vrml.BaseNode;

  JButton button3 = new JButton("Add Geometry");
  button3.addActionListener(new ActionListener(){
     public void actionPerformed(ActionEvent e) {
        fc = new JFileChooser("Models/Geometry/");
        fc.setSize(200, 200);
        fc.setLocation(500, 400);
        int returnVal = fc.showOpenDialog(UniverseSwingVrml.this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
          File file = fc.getSelectedFile();
          VrmlScene s = null;
          VrmlLoader loader = new VrmlLoader();
          System.out.println("Parent Pathname: " + file.getParent() + ".");
          try {
               s = (VrmlScene) loader.load(file.getParent()+ "/" +
file.getName());
              } catch (FileNotFoundException fe) {
                 System.err.println(fe);
                 System.exit(1);
                }
                catch (vrml.InvalidVRMLSyntaxException fe) {
                 System.err.println("VRML parse error");
                 fe.printStackTrace(System.err);
                }
        // Transform the geometry
        TransformGroup tg = new TransformGroup();
        Transform3D t = new Transform3D();
        t.set(new Vector3f(0f,1.5f,0f));
        tg.setTransform(t);
        BranchGroup bg = new BranchGroup();
        bg.addChild(tg);
        tg.addChild(s.getSceneGroup());
        cgroot.addChild(bg);
         }
          }
    });


--

  http://w5.cs.uni-sb.de/~baus

  Email : [EMAIL PROTECTED]
  Phone : +49-681-302-2016
  Fax   : +49-681-302-4136

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to