Intro02

From JReality Wiki
Revision as of 11:32, 18 December 2009 by Paulpeters (Talk | contribs) (moved loading to the end)

(diff) ←Older revision | view current revision (diff) | Newer revision→ (diff)
Jump to: navigation, search

Loading and displaying a geometry

Display a geometry in JRViewer

Source file: Icosahedron

Run as Java webstart


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());


Primitives.icosahedron()


Display a geometry in JRViewerVR

Source file: IcosahedronVR

Run as Java webstart


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.


icosahedron in ViewerVR

Load a geometry into JRViewer

Source file: Intro02

Run as Java webstart


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):

After loading a dodecahedron


Previous: Intro01 Developer Tutorial: Contents Next: Intro03