Recently I have a small problem to display an 3D object from VRML file with Java 3D.
I load the data of VRML file with CyberVRML97's package and so I obtain an object "BranchGroup", usable with Java 3D classic. But when I try to display it in a classic frame, nothing appears. Here is my source code :
public class Viewer3 {
public static void main( String[] args ) { Frame frame = new Frame(); frame.setSize(640, 480); frame.setLayout(new BorderLayout());
Canvas3D canvas = new Canvas3D(null); frame.add("Center", canvas); SimpleUniverse u = new SimpleUniverse(canvas); u.getViewingPlatform().setNominalViewingTransform(); // Loading of source file VRML97Loader loader = new VRML97Loader(); loader.load("test2.wrl"); BranchGroup b = loader.getBranchGroup(); b.compile(); u.addBranchGraph(b);
frame.show(); } }
I don't know if the error comes from the display or comes from the loading of VRML file. This last presents an object of the Shape3D class with an appearance and a Geometry ; the Geometry object is an IndexedTriangleArray.
If somebody has an idea about my problem, I am taker. Ciao and thank you in advance !
Ps : if somebody has the source code of an example which use Java3D and CyberVRML97 to display an IndexedTriangleArray, I am taker also.
The line: Canvas3D canvas = new Canvas3D(null); is probably the problem. It probably should be like:
//Find the preferred GraphicsConfiguration object for the system.
GraphicsConfiguration graphicsConfiguration = SimpleUniverse.getPreferredConfiguration();
//Create a Canvas3D using the preferred GraphicsConfiguration
Canvas3D canvas3d = new Canvas3D(graphicsConfiguration);