Making Obj2TriMesh

Code working here:

import java.io.FileNotFoundException;
import com.jme.math.Vector3f;
import com.jme.scene.TriMesh;
import com.jme.util.geom.BufferUtils;
import java.io.File;
import java.net.URI;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 * <code>Obj2TriMesh</code> provides an extension of <code>TriMesh</code>. A
 * <code>Obj2TriMesh</code> is defined by a file URI.
 *
 * @author Andreas Endruweit
 * @version $Id: Obj2TriMesh.java,v 0.9 2008/06/11 18:19:17 nca Exp $
 */
public class Obj2TriMesh extends TriMesh {

    private static final long serialVersionUID = 1L;

    private static Scanner scan;

    public Obj2TriMesh() {
        this("Model");
    }
   
    /**
     * Creates a new TriMesh from file URI
     *
     * @param name
     *            The name of this Object.
     */
    public Obj2TriMesh(String name, URI f) {

        super(name);
        URI f = null;
        File file = null;

        try {
            scan = new Scanner(new File(f));
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Obj2TriMesh.class.getName()).log(Level.SEVERE, null, ex);
        }

        setGeometryData();
    }
   
    private static void setGeometryData() {
        int vnum = 0, vnnum = 0, inum = 0;
       
        for (int i = 0; scan.hasNext(); i++) {
            if ((scan.findInLine("v ") + "www").equals("v www")) {
                vnum++;
                scan.nextLine();
            } else if ((scan.findInLine("vn ") + "www").equals("vn www")) {
                vnnum++;
                scan.nextLine();
            } else if ((scan.findInLine("f ") + "www").equals("f www")) {
                inum++;
                scan.nextLine();
            } else {
                scan.nextLine();
            }

        }
        inum *= 3;
       
        int[] indexes = new int[inum];
        Vector3f[] vertex = new Vector3f[vnum], vectorn = new Vector3f[vnnum];
        for (int i = 0; scan.hasNext(); i++) {
            if (scan.findInLine("v ").equals("v")) {
                vertex[i] = new Vector3f(scan.nextFloat(), scan.nextFloat(), scan.nextFloat());
            } else if (scan.findInLine("vn ").equals("vn")) {
                vectorn[i] = new Vector3f(scan.nextFloat(), scan.nextFloat(), scan.nextFloat());
            } else if (scan.findInLine("f ").equals("f")) {
                for (int k = 0; k < 3; k++)  {
                    indexes[i+k] = scan.nextInt();
                    if (scan.hasNextInt(indexes[i+k])) {
                        scan.nextInt();
                    }
                }
            } else {
                if (scan.hasNextLine()) {
                    scan.nextLine();
                }
            }

        }
       
        TriMesh Obj = new TriMesh("Obj", BufferUtils.createFloatBuffer(vertex), BufferUtils.createFloatBuffer(vectorn), null,
                    null, BufferUtils.createIntBuffer(indexes));
    }
}



How i can make this little thing work like this:


Obj2TriMesh myObj = new Obj2TriMesh("obj model", "c:\test.obj")
rootNode.attachChild(myObj);

  XD
Like a Box, Sphere...  :D