Clojure with jME3

I really like Clojure and I keep coming back around to it every few months. I started playing with Clojure just a few months after Rich released it. It was one of the first open source projects I ever donated to. I always dream about working with a game engine that can be coded and updated live from a REPL.

jME3 seemed like a cool engine to start playing with and has good documentation. jMonkeyEngine 3 is a 3D game framework for the JVM. You can use it to create 3D games that run on multiple platforms.

For the past few nights I've been working on getting Clojure to work with jME3. I spent most of the time trying to figure out the right incantations to get leiningen/cake to automagically pick up the Maven jME3 repo that was recently setup. After many failed attempts I found that I needed to provide a correct :repositories value. This was gleaned from the GitHub page that the jME3 repo authors created.

https://github.com/erlend-sh/jme3-maven

After finding a typo in their repository info I was able to come up with the following project.clj.

(defproject HelloJME3 "0.0.1-SNAPSHOT"
  :description "TODO: add summary of your project"
  :repositories {"oss-sonatype" "https://oss.sonatype.org/content/repositories/snapshots/"}
  :dependencies [[clojure "1.2.0"]
                 [com.jme3/jmonkeyengine3 "3.0.0-SNAPSHOT"]
                 [com.jme3/lwjgl "3.0.0-SNAPSHOT"]
                 [com.jme3/lwjgl-natives "3.0.0-SNAPSHOT"]
                 [com.jme3/oggd "3.0.0-SNAPSHOT"]
                 [com.jme3/vorbisd "3.0.0-SNAPSHOT"]]
  :dev-dependencies [[swank-clojure "1.2.1"]]
  :main HelloJME3.core)

This project file will provide everything needed for cake to fetch the dependencies and build a jar. The following test code works with the above project file. It's just a simple rewrite of jME3 first tutorials.

http://jmonkeyengine.org/wiki/doku.php/jme3:beginner:hello_simpleapplica...

(ns HelloJME3.core
  (:import (com.jme3.app SimpleApplication)
           (com.jme3.material Material)
           (com.jme3.math Vector3f)
           (com.jme3.scene Geometry)
           (com.jme3.scene.shape Box)
           (com.jme3.math ColorRGBA))
  (:gen-class
   :extends com.jme3.app.SimpleApplication))

(defn -main [& args]
  (doto (new HelloJME3.core) (.start)))

(defn -simpleInitApp [this]
  (let [b (new Box Vector3f/ZERO 0.1 0.1 0.1)
        geom (new com.jme3.scene.Geometry "Box" b)
        mat (new Material (.getAssetManager this) "Common/MatDefs/Misc/SolidColor.j3md")]
    (.setColor mat "m_Color" ColorRGBA/Blue)
    (.setMaterial geom mat)
    (.attachChild (.getRootNode this) geom)))

Hope this helps someone else out. To compile and run I simply ran "cake uberjar" and then "java -jar path/to/standalone.jar".