ARMonkeyKit

Building an ARMonkeyKit application

Posted by: ajclarkson on: March 3, 2010

It’s as easy as 123..4

First things first, we are going to use the ARTeapotTorus as example code here, it’s in the framework sourcecode (armonkeykit.core.examples.patternmarkers)

1. The basics of the application, defining the class and the main method:

public class ARTeapotTorus extends ARMonkeyKitApp {

You can see here that we are extending ARMonkeyKitApp, this is the entry point to the framework, all applications which are using the framework must make use of this abstract class. It enforces the basic methods which allow you to build functionality. After including a super() call in the constructor it’s on to the main method so we can run this code:

public static void main (String[] args) {
ARTeapotTorus app = new ARTeapotTorus();
app.setConfigShowMode(ConfigShowMode.AlwaysShow);
app.start();
}
The two lines following the application creation come straight from the jMonkeyEngine which handles our 3D content, setConfigShowMode simply tells the application whether or not to show configuration dialogue (for screen resolution) at startup or not, and then app.start() runs the application.
2. The simpleInitARSystem method
The framework has support for two different types of fiducial marker at present. The type which we will use in our example applications is a Pattern Marker. This is a pattern which is known to the computer using ARToolkit’s pattern generator, the example ones which are included are pattHiro and pattKanji (in the ardata folder). It also supports the NyIDmarker model 2 system, which will be covered at a later date as this area of the framework is still in development.
With this in mind we initialise the marker processor which will be used:
markerProcessor = initPatternProcessor();
Now the system knows that we are dealing with the pattern based markers. In order to tell the system what to do when it detects a marker, we need to specify an event listener. The default listener which is included with the framework at the time of writing is a NodeTranslateListener. The function of this is to calculate the transformation of the marker, and apply it to any 3D content which is associated with it. This is the basic functionality of many AR applications.
rtl = new NodeRotateTranslateListener();
markerProcessor.registerEventListener(rtl);
Now the system knows what type of markers we want to use and what we want to use them for. The AR system is now initialised. Easy right?
3. addMarkers method
The other method which we will use from the ARMonkeyKitApp class is addMarkers. Here we specify what markers the system should look for, and set up relationships between those markers and 3D content. The framework does most of the heavy lifting here, so it is a few API calls on the developers behalf:
PatternMarker kanji = markerProcessor.createMarkerObject(“kanji”, 16,                               “ardata/patt.kanji”);
markerProcessor.registerMarker(kanji);
Here we have created a marker object and registered it with the system. The three parameters which are used are as follows:
  • String uniqueID – a unique identifier for the marker object
  • int Segments – the resolution of the pattern file. This is determined at pattern creation, for the example patterns it should always be 16 (the highest possible is 64)
  • String path – this is the filepath to the pattern file (not the pdf) where the system finds a representation of the pattern file. Again this is taken care of by the pattern generator, you just need to give the path.
Now that we have that taken care of, let’s create some content. jME makes this quite easy, let’s register a teapot to our marker. First we create a node for the teapot. This is very important. The node is what the eventlistener acts upon.
Node teapotAffectedNode = new Node(“Affected Teapot Node”);
Now we create a teapot:
Teapot tp = new Teapot(“ShinyTeapot”);
tp.setLocalScale(10f);
// rotate our teapot so its base sits on the marker
Quaternion q = new Quaternion();
q = q.fromAngleAxis(-FastMath.PI/2,new Vector3f(1f,0f,0f));
tp.setLocalRotation(q);
We then attach the teapot to our affected node, and then that to the root node of the scene:
teapotAffectedNode.attachChild(tp);
rootNode.attachChild(teapotAffectedNode);
Then we must make two final api calls, the second is vital.
rtl.associate(kanji, teapotAffectedNode);
markerProcessor.finaliseMarkers();
The first uses the EventListener to make an association between marker and content. The second call tells the system that we have added new markers. If this is not called then you will get an exception as the list of markers will not have been finalised and therefore cannot be used by the system.
That really is all there is to building a simple application which associates a 3D model to a marker and then allows you to manipulate the model by rotating the marker. The ARMonkeyKit framework is very powerful in removing code from the developer and just allowing them to concentrate on the content of the application.
Oh yeah… number 4
You may notice that the ARMonkeyKitApp mandates that you have a callUpdates() method in your code. For applications such as this, that method can stay empty as it adds complex functionality which isn’t required here.
Hopefully that helps with understanding the example code a bit more. The next development of the framework is to add a content manager which will allow easy loading of .obj 3D model files. Watch this space as always.
Advertisement

2 Responses to "Building an ARMonkeyKit application"

Hi. I’d like to try your AR framework, it looks pretty good to me and very easy to setup. Unlikely I don’t find a binary version to download, and in the sources there isn’t a build file like an ANT’s build.xml or a maven .pom file. Could you explain how to import your sources under NetBeans, or provide a binary version with a list of dependencies to install (I work under Linux and Mac). Thank you very much and thanks for your nice job.

Hi,
The sources shouldn’t need a build file as you should just be able to include them as a project on your build path. I am not a netbeans user so I can’t give you any help on that front I am afraid, I won’t be providing binaries for the foreseeable future as this framework is the backbone of a research project and as such is constantly changing. If I manage to start a formal release schedule when the project is more mature then I will consider binary releases.

As for dependancies, you will certainly need the Java Media Framework, and Quick Time for Java (this should be included with the latest version of quicktime as QTJava.zip) I’m sorry I can’t be of more help at the minute but I only just have time to do the development necessary for the project, and not to provide support for other build environments at present.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.