Monday, February 2, 2009

Xith3D with Clojure

I've been working a bit with 3D graphics with Clojure, and I have now tested various libraries. jME was a bit awkward to set up in Clojure, and Java3D is dying, so my current efforts are concentrated on Xith3D. I had some problems installing Xith3D in Ubuntu 8.10, so here is how to get started:


mkdir xith
cd xith
svn co xith3d
svn co xith-tk

Compiling problems and how to solve them

xith3d only compiles with java-6-sun, not openjdk-6, so
remove all other java implementations (see /usr/lib/jvm) first.

cd xith

Another problem is that ant is too old, and svnrevget fails. To fix
this, go to xith and do "svn log". Note the latest revision number,
and go to xith-tk. Edit build.xml, and find the svnrevget line.
Comment it out and hard-code the version number:

[!-- svnrevget property="" path="${project.xith3d}"/--]
[property name="" value="1668"]

Now you can do "ant" in the xith-tk folder.


Here is a basic test file (put it in the xith folder, call it test.clj)

(import '(org.xith3d.loop RenderLoop)
'(org.xith3d.render Canvas3D Canvas3DFactory)
'(org.xith3d.base Xith3DEnvironment))

(let [env (Xith3DEnvironment.)
canvas (.createWindowed Canvas3DFactory 800 600 "My empty scene")
rl (RenderLoop.)]
(.addCanvas env canvas)
(.setMaxFPS rl 120.0)
(.setXith3DEnvironment rl env)
(.begin rl))

And a script to start it with

export LD_LIBRARY_PATH=xith3d/third-party/gluegen/linux-i586:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=xith3d/third-party/jogl/linux-i586:$LD_LIBRARY_PATH
java -cp ~/.clojure/clojure.jar:xith3d/dist/xith3d.jar:xith3d/third-party/jagatoo.jar:xith3d/third-party/math/openmali.jar:xith3d/third-party/jogl/jogl.jar:xith3d/third-party/gluegen/gluegen-rt.jar clojure.lang.Script test.clj

and an empty window appears on the screen.