I’m about to go crazy with this code. I load the mesh/model from a 3ds file with a proper loader and I put it to render but nothing appears. Here is the code:
package teste;
import com.sun.j3d.loaders.*;
import com.sun.j3d.loaders.objectfile.ObjectFile;
import com.sun.j3d.utils.geometry.Text2D;
import javax.swing.*;
import javax.media.j3d.*;
import com.sun.j3d.utils.universe.*;
import java.awt.*;
import java.io.*;
import javax.vecmath.*;
import ncsa.j3d.*;
import ncsa.j3d.loaders.*;
/**
*
* @author ramon
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception{
JFrame frame = new JFrame("Teste Java3D");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(640, 480);
frame.setResizable(false);
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas = new Canvas3D(config);
SimpleUniverse universe = new SimpleUniverse(canvas);
BranchGroup group = new BranchGroup();
final int BOUNDSIZE = 100;
BoundingSphere bounds = new BoundingSphere(new Point3d(0,0,0), BOUNDSIZE);
Scene s = null;
ModelLoader map = new ModelLoader();
try {
s = map.load("/home/ramon/data/models/Coolrobo.3ds");
}
catch(Exception e) {
e.printStackTrace();
}
BranchGroup gr = s.getSceneGroup();
gr.setBounds(bounds);
TransformGroup tg = new TransformGroup();
tg.addChild(gr);
Switch sw = new Switch();
sw.addChild(tg);
sw.setCapability(Switch.ALLOW_SWITCH_WRITE);
sw.setWhichChild( Switch.CHILD_ALL );
group.addChild(sw);
group.compile();
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(group);
frame.add(canvas);
frame.setVisible(true);
}
}
Text3D works finely, Text2D also, the primitives as well, my only problem is with the mesh/model.
Please someone give me some help!!
P.S.: My problem is that I can’t see the mesh rendered! It’s not the API, other program(not written by me) works finely with the very same mesh. It’s not the lib. I don’t know what is!