# Frequently Asked Questions

## I want to create and configure a jME3 Application

### How do I start with a preconfigured game?

Extend com.jme3.app.SimpleApplication.
Learn more: Hello SimpleApplication,
.

### How do I change the background color?

    viewPort.setBackgroundColor(ColorRGBA.Blue);

### Can I customize the SimpleApplication class?

Yes! For your own games, you should create a custom base class that extends
class, configure application settings, and customize away.
Learn more: SimpleApplication, AppSettings.

### How do I disable logger output to the console?

During development, you can switch the severity level of the default logger to no longer print FINE warnings, but only WARNINGs.

    java.util.logging.Logger.getLogger("").setLevel(Level.WARNING);

For the release, switch the severity level of the default logger to print only SEVERE errors.

    java.util.logging.Logger.getLogger("").setLevel(Level.SEVERE);

Learn more: Logging.

## I want to load my scene

### How do I make objects appear / disappear in the 3D scene?

To make a spatial appear in the scene, you attach it to the rootNode, To remove a spatial, you detach it.

    rootNode.attachChild(spatial); // appear

    rootNode.detachChild(spatial); // remove

Optionally, you can control whether the engine culls an object always or never.

    spatial.setCullHint(CullHint.Never); // always drawn

    spatial.setCullHint(CullHint.Always); // never drawn

Learn more: The Scene Graph, Hello Node, Hello Asset, Spatial,
and
.

### Why do I get AssetNotFoundException when loading X ?

First check whether the file path of the asset is correct. By default it is relative to your project's assets directory:

    // To load .../jMonkeyProjects/MyGame/assets/Models/Ninja/Ninja.mesh.xml
    Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");

If you are not using the default `assets` directory, verify that you have registered a locator to the AssetManager.
are available.

    this.assetManager.registerLocator("assets/", FileLocator.class); // default
    this.assetManager.registerLocator("c:/jme3User/JMEisSoCool/myAwesomeFolder", FileLocator.class);
    this.assetManager.registerLocator("town.zip", ZipLocator.class.getName());

Learn more: Asset Manager

### How do I Create 3-D models?

You create 3-D models in a 3-D mesh editor, for example Blender, and export it in Ogre Mesh XML or Wavefront OBJ format.
Learn more: 3D Models,
,
,
.

### How do I load a 3-D model into the scene?

Use the jMonkeyEngine SDK to convert models from Ogre XML or Wavefront OBJ formats to .j3o binary format. Load the .j3o file using the AssetManager.

    // To load .../jMonkeyProjects/MyGame/assets/Models/Ninja/Ninja.mesh.xml
    Spatial ninja = assetManager.loadModel("Models/Ninja/Ninja.mesh.xml");

Learn more: Hello Asset, Asset Manager,
,
, jMonkeyEngine SDK j3o converter,
Code sample:
,
.

### How do initialize the scene?

Use the simpleInitApp() method in SimpleApplication (or initApp() in Application).
Learn more: Hello SimpleApplication,
.

## I want to transform objects in the scene

### How do I move or turn or resize a spatial?

To move or turn or resize a spatial you use transformations. You can concatenate transformations (e.g. perform rotations around several axes in one step using a Quaternion with `slerp()` or a com.jme3.math.Transform with interpolateTransforms().

    spatial.setLocalTranslation(1,-3,2.5f); spatial.rotate(0,3.14f,0); spatial.scale(2,2,2);

Learn more: Hello Node, Spatial, rotate, rotate_about_a_point, quaternion, math_for_dummies.

### How do I make a spatial move by itself?

Change the geometry's translation (position) live in the update loop using setLocalTranslation() for non-physical and setWalkDirection() for physical objects. You can also define and remote-control a spatial's motion using Cinematics, e.g. to record cut scenes.
Learn more: Hello Loop, Update Loop, Custom Controls, Cinematics
Code sample:
,

### How do I access a named sub-mesh in Model?

    Geometry result = spatial.getName().startsWith(name);

Learn more: Spatial

### How do I make procedural or custom shapes?

You can programmatically create com.jme3.scene.Mesh'es.
Learn more: Custom Meshes

## I want to change the surface of objects in the scene

### Why is my UV wrapping / texture appearance all wrong?

The most likely reason is the flipping of textures. You may be using the following default method:

      material.setTexture("ColorMap", assetManager.loadTexture("myTexture.jpg"));

You can set the boolean value in the constructor of TextureKey to flipped or not flipped. Toggle the boolean to see if it fixes your UV wrapping/texture problem:

      material.setTexture("ColorMap", this.assetManager.loadTexture(new TextureKey("myTexture.jpg", false)));

### How do I scale, mirror, or wrap a texture?

You cannot scale a texture, but you scale the texture coordinates of the mesh the texture is applied to:

    mesh.scaleTextureCoordinates(new Vector2f(2,2));

You can choose among various `com.jme3.texture.Texture.WrapMode`s for individual texture maps of a material: BorderClamp, EdgeClamp, Clamp; MirrorBorderClamp, MirrorEdgeClamp, MirrorClamp; Repeat, MirroredRepeat.

    material.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);

### How do I change color or shininess of an material?

Use the AssetManager to load Materials, and change material settings.
Learn more: Hello Material, Materials Overview, Asset Manager
Code sample:
,
.

### How do I make a surface wood, stone, metal, etc?

Create Textures as image files. Use the AssetManager to load a Material and set the material's texture maps.
Learn more: Hello Material, Materials Overview, Asset Manager,
,
Code sample:

### Why are materials too bright, too dark, or flickering?

If you use a lit material (based on Lighting.j3md) then you must attach a light source to the rootNode, otherwise you see nothing. If you use lit material colors, make sure you have specified an Ambient color (can be the same as the Diffuse color) if you use an AmbientLight. If you see objects, but they are gray or too dark, set the light color to white, or make it brighter (you can multiply the color value with a scalar), or add a global light source (AmbientLight). Similarly, if everything is white, tune down the lights. If materials flicker under a directional light, change the light direction vector. Change the background color (which is independent of light sources) to get a better contrast while debugging a light problem.

### How do I make geometries cast a shadow?

Use com.jme3.shadow.BasicShadowRenderer together with com.jme3.light.DirectionalLight, and setShadowMode().
Learn more: Light and Shadow
Code sample:
,

### How do I make materials transparent?

Assign a texture with an alpha channel to a Material and set the Material's blend mode to alpha. Use this to create transparent or translucent materials such as glass, window panes, water, tree leaves, etc.

    material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);

Learn more: Hello Material, Materials Overview

### How do I force or disable backface culling?

You can switch the com.jme3.material.RenderState.FaceCullMode to Back, Front, FrontAndBack, or Off. This influences whether the front or backside of an object is being drawn. By default, backsides are culled (not drawn) because they are usually not visible anyway.

    material.getAdditionalRenderState().setFaceCullMode(FaceCullMode.FrontAndBack);

### Can I draw only an outline of the scene?

Create a material and switch its renders state to wireframe.

    material.getAdditionalRenderState().setWireframe(true);

Learn more: Debugging.

## I want to control the camera

### How do I switch between third-person and first-person view ?

The default camera is the `cam` object. Learn more:

- You can activate the FlyBy Cam as a first-person camera.
  Learn more: Hello Collision.
  Code sample:

      flyCam.setEnabled(true);

- You can also create a third-person chase cam.
  Learn more:
  Code sample:
  .

      flyCam.setEnabled(false);
      chaseCam = new ChaseCamera(cam, spatial, inputManager);

### How do I increase camera speed?

    flyCam.setMoveSpeed(50f);

## Actions, Interactions, Physics

### How do I implement game logic / game mechanics?

Use Controls to define the behaviour of types of Spatials. Use Application States to implement global behaviour. Use the `simpleUpdate()` loop for the remaining tests and interactions. Use Cinematics to remote-control objects in scenes.
Learn more: Hello Loop, Update Loop, Custom Controls, Application States, Cinematics

### How do I let players interact via keyboard?

Use com.jme3.input.KeyInput and a Input Listener.
Learn more: Hello Input, Input Handling

### How do I let players interact by clicking?

Players use the mouse to pick up objects, to open doors, to shoot a weapon, etc. Use an Input Listener to respond to mouse clicks, then cast a ray from the player; if it intersect with the bounding volume of a spatial, this is the selected target. The links below contain code samples for both "fixed crosshair" picking and "free mouse pointer" picking.
Learn more: Hello Picking, Mouse Picking, Collision and Intersection, Input Handling, com.jme3.bounding.*, com.jme3.math.Ray, com.jme3.collision.CollisionResults.
Code sample:

### How do I animate characters?

Create an animated OgreMesh model with bones in a 3-D mesh editor (e.g. Blender).
Learn more: com.jme3.animation.*, Hello Animation, Animation,
Code sample:

### How do I keep players from falling through walls and floors?

Use collision detection. The most common solution is to use jme's physics integration.
Learn more: Hello Collision, Physics, com.jme3.bullet.*, CapsuleCollisionShape versus CompoundCollisionShape, CharacterControl versus RigidBodyControl.

### How do I make balls/wheels/etc bounce and roll?

Add physics controls to Spatials and give them spherical or cylindrical bounding volumes.
Learn more: Hello Physics, Physics, com.jme3.bounding.*, com.jme3.bullet.collisions, com.jme3.bullet.controls.RigidBodyControl,
Code sample:
,

### How do I debug weird Physics behaviour?

Maybe your collision shapes overlap – or they are not where you think they are. Make the collision shapes visible by adding the following line after the bulletAppState initialization:

    bulletAppState.getPhysicsSpace().enableDebug(assetManager);

### How do I make a walking character?

Use a CharacterControl that locks the physical object upright, so it does not tip over when moving/walking (as tall physical objects are wont to do).
Learn more: CharacterControl
Code samples:
(first-person),
(third-person)

### How do I steer vehicles?

Use a VehicleControl that supports suspension behavior.
Learn more: Vehicles, com.jme3.bullet.*, VehicleControl
Code samples:
, (Press HUJK keys to steer, spacebar to jump.)

### Can objects swing like a pendulums, chains, ropebridges?

Use PhysicsControl's joints.
Learn more: Hinges and Joints, com.jme3.bullet.joints.PhysicsHingeJoint,
(Press HK keys to turn, spacebar to swing.)

## Default GUI Display

### What are these FPS/Objects/Vertices/Triangles statistics?

At the bottom left of every default SimpleGame, you see the StatsView and the FPS (frames per seconds) view. It provides you with extra information during the development phase. For example, if the object count is increasing and the FPS slows down, then you now that your code attaches too many and does not detach enough objects.

### How do I get rid of the FPS/Objects statistics?

In the application's simpleInitApp() method, call:

    setDisplayFps(false); // to hide the FPS
    setDisplayStatView(false); // to hide the statistics

### How do I display score, health, mini-maps, status icons?

Attach text and pictures to the orthogonal `guiNode` to create a heads-up display (
).
Learn more: HUD, com.jme3.font.*, com.jme3.ui.Picture, guiNode.attachChild()
Code sample:
,
|

### How do I display buttons and UI controls?

You may want to display buttons to let the player switch between the game, settings screen, and score screens. For buttons and other more advanced UI controls, jME supports the Nifty GUI library.
Learn more: Nifty GUI
Sample Code:

### How do i display a loading screen?

Instead of having a frozen frame while your games loads, you can have a loading screen while it loads.
Learn more: Loading screen

## Nifty GUI

### I get NoSuchElementException when adding controls (buttons etc)!

Verify that you include a controls definition file link in your XML: This is the default:

    <useControls filename="nifty-default-controls.xml"/>

### Where can I find example code of Nifty GUI's XML and Java classes?

### Is there Java Doc for Nifty GUI?

Nifty GUI 1.3 Java docs

## I want to create an environment with sounds, effects, and landscapes

### How do I play sounds and noises?

Use AudioRenderer, Listener, and AudioNode from com.jme3.audio.*.
Learn more: Hello Audio, Audio
Code sample:

### How do I make fire, smoke, explosions, swarms, magic spells?

For swarm like effects you use particle emitters.
Learn more: Hello Effects, Particle Emitters, Bloom and Glow, Effects Overview, com.jme3.effect.EmitterSphereShape, com.jme3.effect.ParticleEmitter
Code sample:
,

### How do I make water, waves, reflections?

Use a special post-processor renderer from com.jme3.water.*.
Learn more: Water, Post-Processor Water
Code sample:
,
,
,

### How do I make fog, bloom, blur, light scrattering?

Use special post-processor renderers from com.jme3.post.*.
Learn more: effects_overview

### How do I generate a terrain?

Use com.jme3.terrain.*. The JMonkeyEngine also provides you with a Terrain Editor plugin.
Learn more: Hello Terrain, Terrain, Terrain Editor
Code sample:

### How do I make a sky?

Code sample:

    rootNode.attachChild(SkyFactory.createSky( assetManager,
           "Textures/Sky/Bright/BrightSky.dds", false));
    skyGeo.setQueueBucket(Bucket.Sky)

Learn more: Sky

## I want to access to back-end properties

### How do I read out graphic card capabilities?

If your game is heavily using features that older cards do not support, you can add a check of the JME3 Renderer Caps.

    Collection<com.jme3.renderer.Caps> caps = renderer.getCaps();
    Logger.getLogger(HelloJME3.class.getName()).log(Level.INFO, "Capabilities: {0}" + caps.toString());

The following shortened example shows the capabilities of an older graphic card. In this case you decide whether to branch to a low-quality rendering of the unsupported features (if you still want to support this card), or print an error message explaining the user what capabilities the card is missing to play the game.

Here is an example of the capabilities of an older graphic card:

    INFO: Running on jMonkey Engine 3
    INFO: Using LWJGL 2.7.1
    INFO: Selected display mode: 1024 x 768 x 0 @0Hz
    INFO: Adapter: null
    INFO: Driver Version: null
    INFO: Vendor: ATI Technologies Inc.
    INFO: OpenGL Version: 2.0 ATI-1.6.36
    INFO: Renderer: ATI Radeon X1600 OpenGL Engine
    INFO: GLSL Ver: 1.20
    INFO: Timer resolution: 1.000 ticks per second
    INFO: Capabilities: [FrameBuffer, FrameBufferMRT, FrameBufferMultisample,
    OpenGL20, ARBprogram, GLSL100, GLSL110, GLSL120,
    VertexTextureFetch, FloatTexture,
    TextureCompressionLATC, NonPowerOfTwoTextures]

A newer graphic card has better capabilities, for example:

    INFO: Running on jMonkeyEngine 3.0.0
    INFO: Using LWJGL 2.8.2
    INFO: Selected display mode: 1280 x 720 x 0 @0Hz
    INFO: Adapter: null
    INFO: Driver Version: null
    INFO: Vendor: ATI Technologies Inc.
    INFO: OpenGL Version: 2.1 ATI-7.14.5
    INFO: Renderer: AMD Radeon HD 6770M OpenGL Engine
    INFO: GLSL Ver: 1.20
    INFO: Timer resolution: 1.000 ticks per second
    INFO: Capabilities: [FrameBuffer, FrameBufferMRT, FrameBufferMultisample,
    OpenGL20, OpenGL21, ARBprogram, GLSL100, GLSL110, GLSL120,
    VertexTextureFetch, TextureArray, FloatTexture,
    FloatColorBuffer, FloatDepthBuffer, PackedFloatTexture, SharedExponentTexture, PackedFloatColorBuffer,
    TextureCompressionLATC, NonPowerOfTwoTextures, MeshInstancing]

### How do I optimize the heck out of the Scene Graph?

You can batch all Geometries in a scene (or a subnode) that remains static.

    jme3tools.optimize.GeometryBatchFactory.optimize(rootNode);

Batching means that all Geometries with the same Material are combined into one mesh. This optimization only has an effect if you use only few (roughly up to 32) Materials total. The pay-off is that batching takes extra time when the game is initialized.

## I want to do maths

### What does addLocal() / multLocal() etc mean?

Many maths functions (mult(), add(), subtract(), etc) come as local and a non-local variant (multLocal(), addLocal(), subtractLocal(), etc).

1. Non-local means a new independent object is created (similar to clone()) as a return value. Use non-local methods if you want to keep using the old value of the object calling the method.
   - Example 1: `Quaternion q1 = q2.mult(q3);`
     - Returns the result as a new Quaternion q1.
     - The involved objects q2 and q3 stay as they are and can be reused.
   - Example 2: `v.mult(b).add(b);`
     - Watch out: This calculates the expected result, but unless you actually use the return value, it is discarded!
2. Local means that no new objects are created, instead, the calling object is modified. Use this if you are sure you no longer need the old value of the calling object.
   - Example 1: `q2.multLocal(q3)`
     - Calculates q2*q3 without creating temp objects.
     - The result is stored in the calling object q2. The old value of q2 is gone.
     - Object q3 stays as it was.
   - Example 2:`v.multLocal(a).addLocal(b);`
     - Calculates the expected result without creating temp objects.
     - The result is stored in the calling object v. The old value of v is gone.
     - The objects a and b stay as they were.

### What is the difference between World and Local coordinates?

World coordinates of a Spatial are its absolute coordinates in the 3D scene (this is like giving GPS coordinates). Local coordinates are relative to the Spatial's parent Spatial (this is like saying, "I'm ten meters left of the entrance").

### How do I convert Degrees to Radians?

Multiply degree value by FastMath.DEG_TO_RAD to convert it to radians.

view online version