Intro03

From JReality Wiki
Jump to: navigation, search

Set material properties with appearances

Source file: Intro03

JavaDoc: Appearance


Run as Java webstart


In order to simulate the appearance changes carried out in the user tutorial, we can work directly with the underlying Appearance instances. Here's the code that needs to be added to the main() method of the example in Load a geometry into JRViewer to get the results seen in the User Tutorial


import java.awt.Color;
import static de.jreality.shader.CommonAttributes.*;
import de.jreality.scene.Appearance;
 
...
 
Appearance ap = sgc.getAppearance();
// change the color and size of the tubes and spheres
// do so without using shader interfaces
ap.setAttribute(LINE_SHADER+"."+DIFFUSE_COLOR, Color.yellow);
ap.setAttribute(LINE_SHADER+"."+TUBE_RADIUS, .05);
ap.setAttribute(POINT_SHADER+"."+DIFFUSE_COLOR, Color.red);
ap.setAttribute(POINT_SHADER+"."+POINT_RADIUS, .1);
ap.setAttribute(POLYGON_SHADER+"."+SMOOTH_SHADING, false);
// turn on transparency for faces but keep tubes and spheres opaque
ap.setAttribute(TRANSPARENCY_ENABLED, true);
ap.setAttribute(OPAQUE_TUBES_AND_SPHERES, true);
ap.setAttribute(POLYGON_SHADER+"."+TRANSPARENCY, .4);


The resulting code should pop up a window looking like the one below (taken from the User Tutorial). The navigator may also appear on the right. If the navigator is not there, open it via Window->"Left Slot" or Window->"Right Slot".


After loading a dodecahedron


In case you do not want to load a geometry but just display a given one replace the line"Appearance ap = sgc.getAppearance();" by the following code


SceneGraphComponent sgc = new SceneGraphComponent("Intro3");
sgc.setGeometry(Primitives.icosahedron());
Appearance ap = new Appearance();
sgc.setAppearance(ap);


To see all the possible Attributes have a look at the Attributes in the navigator and the source of de.jreality.shader.CommonAttributes.


Previous: Intro02 Developer Tutorial: Contents Next: Intro04