Intro02
Loading and displaying a geometry
Contents
Display a geometry in JRViewer
Source file: Icosahedron
Calling JRViewer.display(SceneGraphNode n) opens the jReality viewer and displays the Geometry or a SceneGraphComponent passed in as argument.
Some simple geometries are implemented in class de.jreality.geometry.Primitives, find an example below.
... JRViewer.display(Primitives.icosahedron());
Display a geometry in JRViewerVR
Source file: IcosahedronVR
If you like to look at a geometry in a virtual reality environment then add
the following plugins to the JRViewer:
JRViewer v = new JRViewer(); v.addBasicUI(); v.addVRSupport(); v.addContentSupport(ContentType.TerrainAligned); v.registerPlugin(new ContentAppearance()); v.registerPlugin(new ContentTools()); v.setContent(Primitives.icosahedron()); v.startup();
We call this collection of plugins ViewerVR or JRViewerVR, see also the ViewerVR_User_Manual.
Load a geometry into JRViewer
Source file: Intro02
Calling JRViewer.display(SceneGraphNode node) opens a jReality JRViewer and displays the node node. The node should be an instance of Geometry or SceneGraphComponent if you want to see anything!
The following method reads in the file dodec.off which we used in the User Tutorial. Notice that it's expected that you have a copy of this file in the directory where you are running these examples (see the getResource()
method call). If you're using the jReality src-tutorial folder itself, then the file is already present there. Otherwise, you'll need to copy it to wherever you're running these examples.
private static SceneGraphComponent readDodec() { URL url = Intro02.class.getResource("dodec.off"); SceneGraphComponent sgc = null; try { sgc = Readers.read(Input.getInput(url)); sgc.setName("Dodecahedron"); } catch (IOException e) { e.printStackTrace(); } }
If you prefer to access the file as a URL, replace the method call shown with
sgc = Readers.read(Input.getInput( "http://www3.math.tu-berlin.de/jreality/download/data/dodec.off"));
Pass the component returned from this method to the JRViewer.display() method. Customize the resulting JRViewer to display the navigator panel. And finally, encompass the scene with the 'e' key.
The resulting code should pop up a window looking like this (taken from the User Tutorial):
|