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:

Download

mkdir xith
cd xith
svn co https://xith3d.svn.sourceforge.net/svnroot/xith3d/trunk xith3d
svn co https://xith-tk.svn.sourceforge.net/svnroot/xith-tk 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
ant

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="version.build" path="${project.xith3d}"/--]
[property name="version.build" value="1668"]

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

Testing

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

#!/bin/sh
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.

No comments: