Use jReality with groovy

From JReality Wiki
Jump to: navigation, search

Source file: testJRViewer.groovy

Source file: mygroovy

This file testJRViewer.groovy is an example to show how to use jReality with groovy, a popular scripting language written in groovy.

To run this example with the JOGL backend enabled:

  • Download and install groovy.
  • Edit the executable script mygroovy to reflect the configuration of your filesystem
  • Run "mygroovy testJRViewer.groovy"

If successful, you should see a colored icosahedron displayed in a JRViewer application.

Warning: when specifying double values as Appearance attributes in groovy, be sure the specify the number with a following capital D, e.g.,

ap.setAttribute(TRANSPARENCY, 0.5D);

This is necessary since the Groovy interpreter uses BigDecimals by default, but these don't get passed correctly to the set method.

More advanced example

Source file: MatrixMultiplication.groovy

This example (contributed by Michael Pacchioli of City College, NY) is a more advanced groovy script using jReality.

  • It demonstrates how matrix multiplication works using a 3D model.
  • Each time you invoke it, you get different random matrices!

You'll need at least version 1..5.4 of groovy for this script to work properly.

Previous: Use jReality with jython Developer Tutorial: Contents Next: Developer Tutorial