Code: Select all

```
package throwaway;
import static de.jreality.shader.CommonAttributes.POLYGON_SHADER;
import static java.awt.Color.white;
import static java.lang.Math.PI;
import java.io.IOException;
import de.jreality.geometry.Primitives;
import de.jreality.math.Matrix;
import de.jreality.plugin.JRViewer;
import de.jreality.scene.Appearance;
import de.jreality.scene.SceneGraphComponent;
import de.jreality.shader.DefaultGeometryShader;
import de.jreality.shader.DefaultPolygonShader;
import de.jreality.shader.ImageData;
import de.jreality.shader.RenderingHintsShader;
import de.jreality.shader.ShaderUtility;
import de.jreality.shader.Texture2D;
import de.jreality.shader.TextureUtility;
import de.jreality.util.Input;
public class CylTexApp {
public static void main(String[]unused) {
Appearance ap = new Appearance();
DefaultGeometryShader dgs = (DefaultGeometryShader) ShaderUtility.createDefaultGeometryShader(ap, true);
dgs.setShowLines(false);
dgs.setShowPoints(false);
dgs.setShowFaces(true);
RenderingHintsShader rhs = ShaderUtility.createDefaultRenderingHintsShader(ap, true);
rhs.setSeparateSpecularColor(true);
DefaultPolygonShader dps = (DefaultPolygonShader) dgs.createPolygonShader("default");
dps.setTransparency(0.);
dps.setSmoothShading(true);
dps.setAmbientCoefficient(.2);
dps.setAmbientColor(white);
dps.setDiffuseCoefficient(.7);
dps.setDiffuseColor(white);
dps.setSpecularCoefficient(.5);
dps.setSpecularColor(white);
dps.setSpecularExponent(15.);
ImageData imgDat = null;
try {
imgDat = ImageData.load(Input.getInput("GALVANIZED_HEAVY.png"));
} catch (IOException ex) {
System.err.println("ERROR: Couldn't load "+"GALVANIZED_HEAVY.png");
}
int n = 36;
double r = 1;
double zmin = 0;
double zmax = 2*PI;
double thetamax = 2*PI;
SceneGraphComponent cyl = Primitives.closedCylinder(n, r, zmin, zmax, thetamax );
Texture2D tex = TextureUtility.createTexture(ap, POLYGON_SHADER,imgDat);
tex.setTextureMatrix(new Matrix());
cyl.setAppearance(ap);
JRViewer.display(cyl);
}
}
```