CV / 3D Engine - JMonkey

The JMonkey game / 3D engine

JMonkey is an open-source and cross-platform game engine for developing 3D games written in Java. It can be used to write games for Windows, Linux, macOS, Raspberry Pi, Android, and iOS. It uses Lightweight Java Game Library (the original library for Minecraft game) as its default renderer, and also supports another renderer based on Java OpenGL

JMonkey offers top-level features for producing 3D experiences, whether for video games or professional applications. It not only renders complex, realistic 3D scenes, but also enables physics and sound to be integrated into the resulting experiences.

JMonkey is a full-featured game engine, comparable in use and functionality to Unity or the Unreal Engine. The engine's API can be seamlessly integrated into a Java application, enabling it to use the language's features while guaranteeing solid performance thanks to its native bindings. 

Java project integration

JMonkey is easily integrated into a Java project as a Maven dependency. Simply add the following dependencies to the application's pom.xml:

<properties>
	
	<!-- JMonkeyEngine -->
	<jme3_g>org.jmonkeyengine</jme3_g>
	<jme3_v>3.6.1-stable</jme3_v>	
</properties>
	
<dependencies>
  
	<!-- JMonkeyEngine -->   
	<dependency>
		<groupId>${jme3_g}</groupId>
		<artifactId>jme3-core</artifactId>
		<version>${jme3_v}</version>
	</dependency>
	
	<dependency>
		<groupId>${jme3_g}</groupId>
		<artifactId>jme3-desktop</artifactId>
		<version>${jme3_v}</version>
	</dependency>
	
	<dependency>
		<groupId>${jme3_g}</groupId>
		<artifactId>jme3-effects</artifactId>
		<version>${jme3_v}</version>
	</dependency>
	
	<dependency>
		<groupId>${jme3_g}</groupId>
		<artifactId>jme3-jbullet</artifactId>
		<version>${jme3_v}</version>
	</dependency>

	<dependency>
		<groupId>${jme3_g}</groupId>
		<artifactId>jme3-jogg</artifactId>
		<version>${jme3_v}</version>
	</dependency>
		
	<dependency>
		<groupId>${jme3_g}</groupId>
		<artifactId>jme3-lwjgl3</artifactId>
		<version>${jme3_v}</version>
	</dependency>
		
	<dependency>
		<groupId>${jme3_g}</groupId>
		<artifactId>jme3-networking</artifactId>
		<version>${jme3_v}</version>
	</dependency>
		
	<dependency>
		<groupId>${jme3_g}</groupId>
		<artifactId>jme3-niftygui</artifactId>
		<version>${jme3_v}</version>
	</dependency>
	
	<dependency>
		<groupId>${jme3_g}</groupId>
		<artifactId>jme3-plugins</artifactId>
		<version>${jme3_v}</version>
	</dependency>
		
	<dependency>
		<groupId>${jme3_g}</groupId>
		<artifactId>jme3-terrain</artifactId>
		<version>${jme3_v}</version>
	</dependency>
	
	<dependency>
		<groupId>${jme3_g}</groupId>
		<artifactId>jme3-testdata</artifactId>
		<version>${jme3_v}</version>
	</dependency>
		
	<dependency>
		<groupId>${jme3_g}</groupId>
		<artifactId>jme3-vr</artifactId>
		<version>${jme3_v}</version>
	</dependency>	
</dependencies>

Prerequisite

The first step of the practical work aims at configuring a JMonkey Maven project.

Exercise 1.

Download the project archive from http://www.seinturier.fr/teaching/computer_vision/jmonkey-tutorials.zip and extract it.

From the root folder jmonkey-turorial, run the following commands top ensure that the project is compiling:

mvn clean

mvn compile

mvn package

If the compilation and the packaging is successful, run the HelloWorld example by renning the command:

java -cp "target/jmonkey-1.0.0-SNAPSHOT-dist/*" fr.utln.jmonkey.tutorials.beginner.HelloWorld

The JMonkey application is launching and display a blue cube.

Discovering the engine

The JMonkey engine provide a lot of functionnalities. Following exercises illustrates specific features.

Engine mechanics

The first feature of the engine is the SimpleApplication that enable to run an application.

Exercise 2.

From the root of the project, edit the file src/main/java/fr/utln/jmonkey/tutorials/beginner/HelloWorld.java and follow the Simple Application tutorial. The file creation step can be omitted. 

A JMonkey scene is made of a graph that contains all the involved objects. A graph element is represented as a Node, that can represent any displayable or interactive object.

Exercise 3.

From the root of the project, edit the file src/main/java/fr/utln/jmonkey/tutorials/beginner/HelloNode.java and follow the Node tutorial.

Most game engines use a rendering loop for scene display and interaction. To achieve this, the modification of scene objects or the processing of interactions must be synchronized with the rendering loop, otherwise a concurrency error may occur.

Exercice 4.

From the root of the project, edit the file src/main/java/fr/utln/jmonkey/tutorials/beginner/HelloLoop.java and follow the Update loop tutorial.

Displaying objects

Producing a realistic 3D experience means controlling how objects are displayed and how they look. The notion of materials is fundamental to modern game engines. 

Exercise 5.

From the root of the project, edit the file src/main/java/fr/utln/jmonkey/tutorials/beginner/HelloMaterial.java and follow the Material tutorial.

Creating a game or an application requires the use of assets (3D models, textures, ...) that are produced using different ways. The JMonkey engine can deal with a lot a asset types.

Exercise 6.

From the root of the project, edit the file src/main/java/fr/utln/jmonkey/tutorials/beginner/HelloAssets.java and follow the Assets tutorial.

A successful game or application relies on visual effects (smoke, flames, water, reflections, etc.). JMonkey provides a set of visual effects that can be customized and ready to use.

Exercise 7.

From the root of the project, edit the file src/main/java/fr/utln/jmonkey/tutorials/beginner/HelloEffects.java and follow the Effects tutorial.

Interactions

In addition to the 3D display, a game engine or 3D application provides tools for interacting with the user (joystick, mouse, keyboard, VR headset, etc.). With JMonkey, you can set up complex interactions using the peripherals available on the system.

Exercise 8.

From the root of the project, edit the file src/main/java/fr/utln/jmonkey/tutorials/beginner/HelloInput.java and follow the Input system tutorial.

Interactions in games (picking up an object, firing a projectile) or in applications (selecting an object, drag and drop) require the ability to determine whether a user action is targeted at an object. Such interaction is called picking.

Exercise 9.

From the root of the project, edit the file src/main/java/fr/utln/jmonkey/tutorials/beginner/HelloPicking.java and follow the Picking tutorial.

Objects in the scene can interact with users, but they can also interact with each other (two shapes colliding, a projectile hitting its target, etc.). Most of these interactions come down to estimating collisions between objects.

Exercise 10.

From the root of the project, edit the file src/main/java/fr/utln/jmonkey/tutorials/beginner/HelloCollision.java and follow the Collision tutorial. For this exercise, it is not needed to download the town.zip file as it is already embedded within the project.

To be continued...