Hi, I have the following code to read in values from �cube.obj� and output a
cube from this.

import com.sun.j3d.loaders.*;
import com.sun.j3d.loaders.objectfile.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.*;
import java.awt.event.*;

public class ObjectLoader extends Frame implements ActionListener {
        protected Canvas3D myCanvas3D = new Canvas3D(null);
        protected Button myButton = new Button("Exit");
        protected String filename = null;
//      String[] InputFile = new String[cube.obj];

        protected BranchGroup buildViewBranch(Canvas3D c) {
                BranchGroup viewBranch = new BranchGroup();
                Transform3D viewXfm = new Transform3D();
                viewXfm.set(new Vector3f(0.0f,0.0f,10.0f));
                TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
                ViewPlatform myViewPlatform = new ViewPlatform();
                PhysicalBody myBody = new PhysicalBody();
                PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
                viewXfmGroup.addChild(myViewPlatform);
                viewBranch.addChild(viewXfmGroup);
                View myView = new View();
                myView.addCanvas3D(c);
                myView.attachViewPlatform(myViewPlatform);
                myView.setPhysicalEnvironment(myEnvironment);
                return viewBranch;
        }

        protected void addLights(BranchGroup b) {
                BoundingSphere bounds = new
                        BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
                        Color3f ambientColour = new Color3f(1.0f, 1.0f, 1.0f);
                        AmbientLight ambLight = new AmbientLight(ambientColour);
                        ambLight.setInfluencingBounds(bounds);
                        b.addChild(ambLight);
        }

        protected BranchGroup buildContentBranch (Node shape) {
                BranchGroup contentBranch = new BranchGroup();
                Transform3D rotateCube = new Transform3D();
                rotateCube.set(new AxisAngle4d(1.0,1.0,0.0,Math.PI/4.0));
                TransformGroup rotationGroup = new TransformGroup(rotateCube);
                contentBranch.addChild(rotationGroup);
                rotationGroup.addChild(shape);
                addLights(contentBranch);
                return contentBranch;
        }

        protected Node buildCube() {
                ObjectFile f = new ObjectFile();
                Scene s = null;
                try {
                        s = f.load(filename);
                }catch(Exception e) {
                        System.exit(1);
                }
                return s.getSceneGroup();
        }

        public void actionPerformed(ActionEvent e) {
                dispose();
                System.exit(0);
        }

        public ObjectLoader(String args[]) {

                if (args.length > 0) {
                        filename = args[0];
                        VirtualUniverse myUniverse = new VirtualUniverse();
                        Locale myLocale = new Locale(myUniverse);
                        myLocale.addBranchGraph(
                                                                                       
                                 buildViewBranch(myCanvas3D));
                        myLocale.addBranchGraph(
                                                                                       
                                 buildContentBranch(buildCube()));
                        setTitle("ObjectLoader");
                        setSize(400,400);
                        setLayout(new BorderLayout());
                        add("Center", myCanvas3D);
                        myButton.addActionListener(this);
                        add("South", myButton);
                        setVisible(true);
                }
        }

                public static void main (String[] args) {
                        String[] InputFile = {"cube.obj"};

                        ObjectLoader sw = new ObjectLoader(InputFile);
                }
        }

The input file is a normal txt file called �cube.obj�, it contains the
following
v 1.0 1.0 1.0
v -1.0 1.0 1.0
v -1.0 -1.0 1.0
v 1.0 -1.0 1.0
v 1.0 1.0 -1.0
v -1.0 1.0 -1.0
v -1.0 -1.0 -1.0
v 1.0 -1.0 -1.0

f 1 2 3 4
f 8 7 6 5
f 1 4 8 5
f 6 7 3 2
f 1 5 6 2
f 7 8 4 3

But when I try to run the program I get the following error

java.lang.IllegalStateException: PhysicalBody is null
at javax.media.j3d.View.checkView(View.java:2782)
at
javax.media.j3d.ViewPlatformRetained.setLive(ViewPlatformRetained.java:280)
at javax.media.j3d.GroupRetained.childDoSetLive(GroupRetained.java:2083)
etc

When I compile the code I do not get an error.  Do you know what could be
the reason for this, is it because of the format of the file I am reading
in.  Also do you know how I could read colour values from the file and then
set the cube equal to this colour.

Any help would be appreciated.
Thanks.



_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx

===========================================================================
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