usage of OBJLoader2

i’m trying to use OBJLoader2 but I’m getting just a blank window even though the model seems to have loaded fine and if i substitute a xith primitive geometry it works fine and i can see it… so i’m wondering what i’m doing wrong…


VirtualUniverse universe = new VirtualUniverse();
universe.addView(view);
Locale locale = new Locale();
universe.addLocale(locale);

File modelFile = new File(MODEL_OBJ_FILENAME); 
Scene model = null;
try {
	model = (new OBJLoader2().load(modelFile.getAbsolutePath()));
	System.out.println("scene model successfully loaded");
} catch (Exception e) {
	System.out.println("Nope");
}

BranchGroup modelBG = model.getSceneGroup();
locale.addBranchGraph(modelBG);

modelBG.compile();

// create a canvas for our graphics
RenderPeer rp = new RenderPeerImpl();
CanvasPeer cp = rp.makeCanvas(null, 640, 480, 32, false);
Canvas3D canvas = new Canvas3D();
canvas.set3DPeer(cp);

// modify our view so we can see the cube
view.addCanvas3D(canvas);
view.getTransform().lookAt(
new Vector3f(0, 0, 2f),    // location of eye
new Vector3f( 0, 0, 0),    // center of view
new Vector3f( 0, 1, 0));    // vector pointing up
view.startView();

Try that :


VirtualUniverse universe = new VirtualUniverse();
universe.addView(view);
Locale locale = new Locale();
universe.addLocale(locale);

File modelFile = new File(); 
Scene model = null;
try {
	model = (new OBJLoader2().load(MODEL_OBJ_FILENAME));
	System.out.println("scene model successfully loaded");
} catch (Exception e) {
	System.out.println("Nope");
}

BranchGroup modelBG = model.getSceneGroup();
locale.addBranchGraph(modelBG);

modelBG.compile();

// create a canvas for our graphics
RenderPeer rp = new RenderPeerImpl();
CanvasPeer cp = rp.makeCanvas(null, 640, 480, 32, false);
Canvas3D canvas = new Canvas3D();
canvas.set3DPeer(cp);

// modify our view so we can see the cube
view.addCanvas3D(canvas);
view.getTransform().lookAt(
new Vector3f(0, 0, 2f),    // location of eye
new Vector3f( 0, 0, 0),    // center of view
new Vector3f( 0, 1, 0));    // vector pointing up
view.startView();

(No File is created, just pass the model obj filename to the load() method : it handles classpath automatically)

thanks for the suggestion… i couldn’t tell it didn’t need a File object from the api…i’m assuming it just constructs one internally…overloaded constructors? the xith-tk source i have only has the code for ObjLoader, the corresponding whoola directory where I’m guessing objLoader2 would be is empty except for cvs file.

so i tried that, but i’m still getting a blank screen. i’ve got the model succesfully loading in java3d, though, and tried using the scaling factor calculated by that code, but the model still doesn’t show up…just a blank gray screen. i do get a lot of warnings though about smoothing groups and i’m wondering whether that would have any bearing:
org.xith3d.loaders.obj.OBJLoader2: smoothing groups not currently supported: “s 1”
org.xith3d.loaders.obj.OBJLoader2: smoothing groups not currently supported: “s 2”
org.xith3d.loaders.obj.OBJLoader2: smoothing groups not currently supported: “s 3”
etc.

That’s not a problem. Smoothing groups aren’t that important.
Try to add a PointLight to your scene, color (1f, 1f, 1f), position something like (0f, 0f, 50f) and attenuation something like (0.001f, 0.001f, 0.001f)