From 88e823ddc098020e10a575dad8de30f9aa3f2417 Mon Sep 17 00:00:00 2001
From: "nor..67"
com.jme3.animation.AnimControl
object in your JME3 appli
playerControl.addListener(this); // add listener
control.clearChannels();
AnimControl Property | Usage | Adds or removes an animation from this Control. | getAnimationLength("anim")Returns the length of the given named animation in seconds |
---|
AnimControl Property | Usage | Adds or removes an animation from this Control. | getAttachmentsNode("bone")Returns the attachment node of a bone. Attach models and effects to this node to make them follow this bone's motions. |
---|
The following information is available for a channel. @@ -244,7 +244,7 @@ The following information is available for a channel.
Use the following methods to add or remove individual bones to an AnimChannel. This is useful when you play two animations in parallel on two channels, and each controls a subset of the bones (e.g. one the arms, and the other the legs). @@ -270,9 +270,9 @@ addToRootBone(bone1)
Tip: Use the AnimEventLister below to react at the end or start of an animation cycle.
- +com.jme3.app.state.AppState
class is a customizable jME3 interf
-
+
setEnable
MyAppState.class
.
The AppStateManager's render(), postRender(), cleanUp()
methods are internal, ignore them, users never call them directly.
this.app.getStateManager().getState(MyAppState.class).doSomeCustomStuffInThisState();
package chapter04.appstatedemo; @@ -72,7 +72,7 @@ public class Main extends SimpleApplication { inputManager.addListener(actionListener, new String[]{"Toggle Settings"}); } - private ActionListener() { + private ActionListener actionListener = new ActionListener() { public void onAction(String name, boolean isPressed, float tpf) { System.out.println("key" + name); if (name.equals("Game Pause Unpause") && !isPressed) { @@ -108,7 +108,7 @@ public class Main extends SimpleApplication {
package chapter04.appstatedemo; @@ -156,7 +156,7 @@ public class GameRunningState extends AbstractAppState { /** Load this scene */ viewPort.setBackgroundColor(backgroundColor); - Box(Vector3f.ZERO, 1, 1, 1); + Box mesh = new Box(Vector3f.ZERO, 1, 1, 1); Geometry geom = new Geometry("Box", mesh); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); @@ -200,7 +200,7 @@ public class GameRunningState extends AbstractAppState { }
package chapter04.appstatedemo; @@ -248,7 +248,7 @@ public class SettingsScreenState extends AbstractAppState { /** Load this scene */ viewPort.setBackgroundColor(backgroundColor); - Box(new Vector3f(-1, -1, 0), .5f, .5f, .5f); + Box mesh = new Box(new Vector3f(-1, -1, 0), .5f, .5f, .5f); Geometry geom = new Geometry("Box", mesh); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); @@ -289,7 +289,7 @@ public class SettingsScreenState extends AbstractAppState { }
package chapter04.appstatedemo; @@ -337,7 +337,7 @@ public StartScreenState(SimpleApplication app){ /** Init this scene */ viewPort.setBackgroundColor(backgroundColor); - Box(new Vector3f(-1,1,0), .5f,.5f,.5f); + Box mesh = new Box(new Vector3f(-1,1,0), .5f,.5f,.5f); Geometry geom = new Geometry("Box", mesh); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); @@ -378,4 +378,5 @@ public StartScreenState(SimpleApplication app){ }
assets/Models/
assets/Sound/
directory of your project. j
-
+
com.jme3.audio.AudioNode
.
getPitch() | Returns the pitch. |
There are other obvious getters to poll the status of corresponding setters below.
setPitch(1) | Makes the sound play in a higher or lower pitch. Default is 1. 2 is twice as high, .5f is half as high. |
AudioNode Method | Usage | All 3D effects switched off. This sound is global | setMaxDistance(100f) | Maximum distance the sound can be heard, in world units. Default is 20. |
---|
AudioNode Method | Usage | Activates 3D audio: The sound appears to come f | setReverbEnabled(true) | A 3D echo effect that only makes sense to use with positional AudioNodes. The reverb effect is influenced by the environment that the audio renderer is in. See "Setting Environment Properties" below. |
---|
AudioNode Method | Usage | Activates 3D audio: This sound can only be heard from setOuterAngle() | Set the angle in degrees for the directional audio. The angle is relative to the direction. Note: By default, both angles are 360° and the sound can be heard from all directions! |
---|
myAudioNode.playInstance();
c
Closet 1.00f 1.0f 1.0f 1.00f 0.15f 1.0f 0.600f 0.0025f 0.500f 0.0006f
Activate the preset with setEnvironment(). E.g. in a dungeon environment:
-audioRenderer.setEnvironment(new Environment.Dungeon));+
audioRenderer.setEnvironment(new Environment(Environment.Dungeon));
A sound engineer can create a custom com.jme3.audio.Environment
object and specify custom environment factors. You can find many examples of audio environment presets here. Activate your custom environment settings in the Environment constructor:
@@ -209,4 +209,5 @@ You can find more info about OpenAL and its advanced features here:
setBloomIntensity(float)
You'll probably need to adjust those parameters depending on your scene.
- +
Tip: After you change view port, frustum, or frame, call cam.update();
The jMonkey team can add more types of tracks, just ask in the forum.
- +MotionTrack.Direction.Rotation
or MotionTrack.Direction.PathAndRotation
.
Tip: Most likely you remote-control more than one object in your scene. Give the tracks and paths useful names such as dragon_track
, dragon_path
, hero_track
, hero_path
, etc.
ComboMoveExecution fireballExec = new ComboMoveExecution(fireball);
The press()
and notPress()
methods accept sets of Input Triggers, e.g. fireball.press("A","B","C").done()
.
@@ -153,9 +153,9 @@ The following getters give you more information about the game state:
currentMove.getMoveName()
and proceed to call methods that imp
mesh
by this
public class MyMesh extends Mesh { }
physicsSpace.enableDebug(assetManager);
private ActionListener() { +
private ActionListener actionListener = new ActionListener() { @Override public void onAction(String name, boolean pressed, float tpf) { // toggle wireframe @@ -189,7 +189,7 @@ TIP :: To set the line width of wireframe display, use mesh.setLineWidth(lineWid
fade.setDuration()
.
Using the GUI Node is the default approach in jme3 to create simple HUDs. If you just quickly want to display a line of text, or a simple icon on the screen, use the no-frills GUI Node, it's easier.
guiFont
is a default font provided by SimpleA
hudText = new BitmapText(myFont, false);
In your IDE, use code completion to quickly look up Trigger literals. In the jMonkeyEngine SDK for example, press ctrl-space or ctrl-/ after KeyInput.|
to choose from the list of all keys.
inputManager.deleteMapping( SimpleApplication.INPUT_MAPPING_MEMORY );@@ -153,9 +153,9 @@ In your IDE, use code completion to quickly look up Trigger literals. In the jMo
stop();
. Typically you do not remove this, unless you replace it by another way of quitting gracefully.private ActionListener() { +private ActionListener actionListener = new ActionListener() { public void onAction(String name, boolean keyPressed, float tpf) { /** TODO: test for mapping names and implement actions */ } };
if
and else if
in
if
and else if
in
In the most common case, you want an action to be triggered once, in the moment when the button or key trigger is released. For example, when the player presses a key to open a door, or clicks to pick up an item. For these cases, use an ActionListener and test for && !keyPressed
, like shown in the following example.
-private ActionListener() { +private ActionListener actionListener = new ActionListener() { public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("Pause Game") && !keyPressed) { // test? @@ -333,7 +333,7 @@ In the most common case, you want an action to be triggered once, in the moment };
Spatial signpost = (Spatial) assetManager.loadAsset( @@ -282,7 +282,7 @@ The JPG files are i
Material mat = assetManager.loadMaterial( @@ -307,7 +307,7 @@ The PNG files are in the sa
getWorldLig
mylight.setColor(ColorRGBA.White.mult(1.3f));
ResourceBundle.getBundle("Bundle").getString("greeting")); +
System.out.print(ResourceBundle.getBundle("Bundle").getString("greeting")); UiText.setText(ResourceBundle.getBundle("Bundle").getString("score.display")+score);
Locale.getISOLanguages()));+
System.out.println(Arrays.toString(Locale.getISOLanguages()));
Logger.getLogger(””).setLevel(Level.FINE);
Code sample: @@ -87,7 +87,7 @@ The camera's transformation is copied over the spatial's transformatio - +
Code sample: @@ -148,7 +148,7 @@ new KeyTrigger(KeyInput.KEY_SPACE))
You can test these examples within the following code snippet. It creates a box and applies the material:
-Box(Vector3f.ZERO, 1, 1, 1); +Box b = new Box(Vector3f.ZERO, 1, 1, 1); Geometry geom = new Geometry("Box", b); // ... insert Material definition... geom.setMaterial(mat); @@ -135,7 +135,7 @@ rootNode.attachChild(geom);
Other useful, but less commonly used material definitions:
@@ -143,9 +143,9 @@ setColor("GlowColor", ColorRGBA.White);
setBoolean("PointSprite",true);
-
+
-
+
Special Illuminated Material Definitions | Usage | Material Parameters |
---|
Common/MatDefs/Misc/ShowNormals.j3md | A color gradient calculated from the model's surface normals. You can use this built-in material to debug the generation of normals in meshes, to preview models that have no material and no lights, or as fall-back default material. This built-in material has no parameters. |
getAdditionalRenderState().setBlendMode(BlendMode.PremultAlpha); | Pre-multiplied alpha blending. E.g. if the color of the object has already been multiplied by its alpha, this is used instead of "Alpha" blend mode. | For use with Premult Alpha textures. |
If the DiffuseMap has an alpha channel, use: @@ -332,7 +332,7 @@ Later, put the Geometry (not the Material!) in the appropriate render queue
getAdditionalRenderState().setFaceCullMode(FaceCullMode.FrontAndBack) | Cull both backfaces and frontfaces. | Use this as an efficient way to make an object temporarily invisible, while keeping all its other in-game properties (node attachment, collision shapes, interactions, etc) active. |
getAdditionalRenderState().setPolyOffset(); | Enable polygon offset. | Use this when you have meshes that have triangles really close to each over (e.g. |
You can register several types of listeners to be notified of changes. @@ -56,12 +56,12 @@ You can register several types of listeners to be notified of changes. - +
Your game can define its own game data based on whatever criteria you want, typically these include player ID and state. If the server needs to look up player/client-specific information, you can store this information directly on the HostedConnection object. The following examples read and write a custom Java object MyState
in the HostedConnection object conn
:
@@ -175,14 +175,14 @@ Your game can define its own game data based on whatever criteria you want, typi
Serializer.registerClass(HelloMessage.class);
myServer.addMessageListener(new ServerListener(), HelloMessage.class);
conn.close("We kick cheaters.");
First implement the ClientStateListener interface in the Client class. Then register it to myClient in MyGameClient's simeplInitApp() method: @@ -422,7 +422,7 @@ First implement the ClientStateListener interface in the Client class. Then regi
myClient.addClientStateListener(this);- +
First implement the ConnectionListener interface in the Server class. Then register it to myServer in MyGameServer's simpleInitApp() method. @@ -451,7 +451,7 @@ First implement the ConnectionListener interface in the Server class. Then regis
myServer.addConnectionListener(this);- +
MyStartScreen
and this
app
<inte
<interact onClick="doNothing()"/>
assets/Interfaces/
directory of y
Example: @@ -616,7 +616,7 @@ Example:
nifty.registerMouseCursor("hand", "Interface/mouse-cursor-hand.png", 5, 4);
MySettingsScreen
class is a custom de.lessvoid.nifty.screen.Scr
${PROP.key} | looks up key in the Nifty properties. Use Nifty.setGlobalproperties(properties) and Nifty.getGlobalproperties("key"). Or SystemGetProperties(key); |
See also:
MyHudScreen.java
for the hud
scr
playSound
effect
</label>
clicked
) what ever you like, as long
assets/Interfaces/
directory
setShape(new EmitterSphereShape( Vector3f.ZERO, 2f));
Build up you effect by specifying one parameter after the other. If you change several parameters at the same time, it's difficult to tell which of the values caused which outcome.
- +test-data.jar<
Effects/Smoke/Smoke.png 1*15
Tip: Use the setStartColor()
/setEndColor()
settings described above to colorize the white and gray parts of textures.
ParticleEmitter fire = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30); @@ -237,4 +237,5 @@ See also:
physicsSpace
object:
com.jme3.app.SimpleApplication
.com.jme3.app.SimpleApplication
.private BulletAppState bulletAppState;
All non-mesh CollisionShapes can be used for dynamic, kinematic, as well as static Spatials. (Code samples see below) @@ -200,7 +200,7 @@ All non-mesh CollisionShapes can be used for dynamic, kinematic, as well as stat Limitations: Requires heightmap data. Collisions between two mesh-accurate shapes cannot be detected, only non-mesh shapes can collide with this shape.
The mesh-accurate shapes can use a CollisionShapeFactory as constructor (code samples see below). @@ -217,7 +217,7 @@ The mesh-accurate shapes can use a CollisionShapeFactory as constructor (code sa
- +Special PhysicsControls | Usage | Examples | Special Control used for collapsing, flailing, or falling characters | Falling persons, animals, robots, "Rag dolls" |
---|
Click the links for details on the special PhysicsControls. This article is about RigidBodyControl.
- +The following creates a box Geometry with the correct default BoxCollisionShape:
-Box(1,1,1); +Box b = new Box(1,1,1); Geometry box_geo = new Geometry("Box", b); box_geo.addControl(new RigidBodyControl( 1.0f )); // explicit non-zero mass, implicit BoxCollisionShape@@ -330,7 +330,7 @@ gameLevel.addControl(new RigidBodyControl(0.0f)); // explicit ze
On a RigidBodyControl, you can apply the following physical forces: @@ -459,9 +459,9 @@ On a RigidBodyControl, you can apply the following physical forces: (See detailed explanation below.) - + - +
setApplyPhysicsLocal(true)
for an object to make it move relatively to its local physics space. You would do that if you need a physics space that moves with a node (e.g. a spaceship with artificial gravity surrounded by zero-g space). By default, it's set to false, and all movement is relative to the world.
@@ -620,7 +620,7 @@ removeCollideWithGroup(COLLISION_GROUP_01)Note that after the collision method has been called the object is not valid anymore so you should copy any data you want to keep into local variables.
- +Water method example | Effects: Color | Default | water.setColorExtinction(new Vector3f(10f,20f,30f)); | Sets At what depth the refraction color extincts. The three values are RGB (red, green, blue) in this order. Play with these parameters to "muddy" the water. | Vector3f(5f,20f,30f) |
---|
Water method example | Effects: Shore | Default | water.setUseHQShoreline(false); | Renders shoreline with better quality ? | true |
---|
Water method example | Effects: Foam | Default | This foam texture will be used with WrapMode.Repeat | "Common/MatDefs/Water/Textures/foam.jpg" |
---|
Water method example | Effects: Light | Default | This foam texture w | water.setReflectionMapSize(256) | Sets the size of the reflection map. The higher, the better the quality, but the slower the effect. | 512 |
---|
flyCam.setEnabled(false); @@ -40,7 +40,7 @@ camNodeSide.setControlDir(ControlDirection.CameraToSpatial); camNodeSide.getControl(0).setEnabled(false);
destroy()
to save the rootNode to a
/* This is called when the user quits the app. */ @Override public void destroy() { - System.getProperty("user.home"); + String userHome = System.getProperty("user.home"); BinaryExporter exporter = BinaryExporter.getInstance(); - File(userHome+"/MySuperGame/"+"LastSavedGame.j3o"); + File file = new File(userHome+"/MySuperGame/"+"LastSavedGame.j3o"); try { exporter.save(rootNode, file); } catch (IOException ex) { @@ -53,7 +53,7 @@ The following example overridesdestroy()
to save the rootNode to aYou can add a timestamp to your saved files:- +long timestamp = System.currentTimeMillis()/1000; -File(userHome+"/MySuperGame/"+"/SavedGame-"+timestamp+".j3o");+File file = new File(userHome+"/MySuperGame/"+"/SavedGame-"+timestamp+".j3o");@@ -61,7 +61,7 @@ File(userHome+"/MySuperGame/"+"/SavedGame-"+timestamp+&q
Loading a Node
@@ -71,10 +71,10 @@ The following example uses simpleInitApp() to load the last saved game when the- +@Override public void simpleInitApp() { - System.getProperty("user.home"); + String userHome = System.getProperty("user.home"); BinaryImporter importer = BinaryImporter.getInstance(); importer.setAssetManager(assetManager); - File(userHome+"/MySuperGame/"+"LastSavedGame.j3o"); + File file = new File(userHome+"/MySuperGame/"+"LastSavedGame.j3o"); if(file.exists()){ try { Node loadedNode = (Node)importer.load(file); @@ -94,7 +94,7 @@ The following example uses simpleInitApp() to load the last saved game when theCustom Savable Class
@@ -184,4 +184,5 @@ To make a custom class savable:+ \ No newline at end of file diff --git a/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/advanced/shape.html b/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/advanced/shape.html index ea35260a1..01d992918 100644 --- a/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/advanced/shape.html +++ b/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/advanced/shape.html @@ -7,7 +7,7 @@ The simplest type of Meshes are the built-in JME Shapes. You can create Shapes w
Spatial s = new Spatial();
! A Spatial is an abstract concept, like a mammal (there is no actual creature called "mammal" walking around here). You either create a Node or a Geometry object. Some methods however require a Spatial argument: This is because they are able to accept both Nodes and Geometries as arguments. In this case, you must cast a Node or Geometry to Spatial.
@@ -64,7 +64,7 @@ no mesh, no material.
house
is the loaded model. The s
Geometry submesh = (Geometry) houseScene.getChild("door 12");
main()
method. W
public static void main(String[] args) { - java.awt.Runnable() { + java.awt.EventQueue.invokeLater(new Runnable() { public void run() { // ... see below ... } @@ -78,7 +78,7 @@ In the SwingCanvasTest's main() method, create a queued runnable(). It will }
@@ -113,7 +113,7 @@ Note that we have not called start() on the application, as we would usually do
window
.
-JFrame("Swing Application"); +JFrame window = new JFrame("Swing Application"); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);@@ -133,7 +133,7 @@ We create a standard JPanel inside the JFrame. Give it any Layout you wish – h The important step is to add() the canvas component into the panel, like all the other Swing components.
-FlowLayout()); // a panel +JPanel panel = new JPanel(new FlowLayout()); // a panel // add all your Swing components ... panel.add(new JButton("Some Swing Component")); ... @@ -163,7 +163,7 @@ Clean, build, and run!
heightmap = new HillHeightMap(1025, 1000, 50, 100, (byte) 3);
package jme3test.helloworld; @@ -214,12 +214,12 @@ Compile and run the code. You should see a terrain. You can use the WASD keys an
terrain
and the first-person player
to
bulletAppState.getPhysicsSpace().add(player);
vehicleNode
with a visible "car" geome
mat
.
setWalkDirection(Vector3f.ZERO)
to stop a directional motion.
For best practices on how to use setWalkDirection()
, see the Navigation Inputs example below.
public class WalkingCharacterDemo extends SimpleApplication
@@ -135,7 +135,7 @@ For best practices on how to use setWalkDirection()
, see the Naviga
public void onAnimChange(AnimControl control, AnimChannel channel, String animName) { }
private BulletAppState bulletAppState; @@ -178,7 +178,7 @@ public void simpleInitApp() { }
private ChaseCamera chaseCam; @@ -305,7 +305,7 @@ public void simpleInitApp() { ...
Commo
Commo
package jme3test.helloworld; @@ -80,7 +80,7 @@ public class HelloAnimation extends SimpleApplication inputManager.addMapping("Walk", new KeyTrigger(KeyInput.KEY_SPACE)); inputManager.addListener(actionListener, "Walk"); } - private ActionListener() { + private ActionListener actionListener = new ActionListener() { public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("Walk") && !keyPressed) { if (!channel.getAnimationName().equals("Walk")) { @@ -93,7 +93,7 @@ public class HelloAnimation extends SimpleApplication }
implements AnimEventListener
to the class declaration. This int
}
private ActionListener() { +private ActionListener actionListener = new ActionListener() { public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("Walk") && !keyPressed) { if (!channel.getAnimationName().equals("Walk")){ @@ -233,7 +233,7 @@ Test for each action by name, and set the channel to the corresponding animation };
for (System.out.println(anim); }+
for (String anim : control.getAnimationNames()) { System.out.println(anim); }
package jme3test.helloworld; @@ -55,7 +55,7 @@ public class HelloAssets extends SimpleApplication { rootNode.attachChild(teapot); // Create a wall with a simple texture from test_data - Box(Vector3f.ZERO, 2.5f,2.5f,1.0f); + Box box = new Box(Vector3f.ZERO, 2.5f,2.5f,1.0f); Spatial wall = new Geometry("Box", box ); Material mat_brick = new Material( assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); @@ -93,7 +93,7 @@ Build and run the code sample. You should see a green Ninja with a colorful teap
assets/Textures/
. Load the texture into the material before you set the Material. The following code sample is from the simpleInitApp()
method and loads a simple wall model:
// Create a wall with a simple texture from test_data -Box(Vector3f.ZERO, 2.5f,2.5f,1.0f); +Box box = new Box(Vector3f.ZERO, 2.5f,2.5f,1.0f); Spatial wall = new Geometry("Box", box ); Material mat_brick = new Material( assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); @@ -156,7 +156,7 @@ In this case, youLoading Text and Fonts
@@ -179,7 +179,7 @@ guiNode.attachChild(helloText);- +Loading a Model
@@ -203,7 +203,7 @@ Note that you do no need to create a Material if you exported the model with a m- +Loading Assets From Custom Paths
@@ -233,7 +233,7 @@ JME3 offers ClasspathLocator, ZipLocator, FileLocator, HttpZipLocator, and UrlLo- +Creating Models and Scenes
@@ -272,7 +272,7 @@ If you use Blender, export your models as Ogre- +Model File Formats
@@ -317,7 +317,7 @@ If your executable gets a runtime exception, make sure you have converted all mo- +Loading Models and Scenes
- +- +@@ -346,9 +346,9 @@ rootNode.attachChild(scene);
Excercise - How to Load Assets
@@ -453,7 +453,7 @@ Again, you should see the Ninja+wall+teapot standing in a town.Conclusion
@@ -497,4 +497,5 @@ Let's add some action to the scene and continue with the \ No newline at end of file diff --git a/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/beginner/hello_audio.html b/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/beginner/hello_audio.html index cadc76217..cc10a73fe 100644 --- a/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/beginner/hello_audio.html +++ b/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/beginner/hello_audio.html @@ -11,7 +11,7 @@ This tutorial explains how to add 3D sound to a game, and how make sounds play t- +Sample Code
- +package jme3test.helloworld; @@ -43,7 +43,7 @@ public class HelloAudio extends SimpleApplication { flyCam.setMoveSpeed(40); /** just a blue box floating in space */ - Box(Vector3f.ZERO, 1, 1, 1); + Box box1 = new Box(Vector3f.ZERO, 1, 1, 1); player = new Geometry("Player", box1); Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); @@ -81,7 +81,7 @@ public class HelloAudio extends SimpleApplication { } /** Defining the "Shoot" action: Play a gun sound. */ - private ActionListener() { + private ActionListener actionListener = new ActionListener() { @Override public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("Shoot") && !keyPressed) { @@ -104,7 +104,7 @@ When you run the sample, you should see a blue cube. You should hear a nature-liUnderstanding the Code Sample
@@ -122,7 +122,7 @@ Let's have a closer look at- +initAudio()
to learn how to useAudioNodes
@@ -178,7 +178,7 @@ Here you make audio_nature a positional sound that comes from a certain place. F- +Triggering Sound
@@ -196,7 +196,7 @@ Let's have a closer look at- +initKeys()
: As you learned in prev Setting up the ActionListener should also be familiar from previous tutorials. You declare that, when the trigger (the mouse button) is pressed and released, you want to play a gun sound./** Defining the "Shoot" action: Play a gun sound. */ - private ActionListener() { + private ActionListener actionListener = new ActionListener() { @Override public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("Shoot") && !keyPressed) { @@ -210,7 +210,7 @@ Since you want to be able to shoot fast repeatedly, so you do not want to wait fAmbient or Situational?
@@ -246,7 +246,7 @@ Apart from the looping boolean, another difference is whereplay()
The gunshot sound, however, is triggered situationally, once, only as part of the- +Shoot
input action that you defined in the ActionListener./** Defining the "Shoot" action: Play a gun sound. */ - private ActionListener() { + private ActionListener actionListener = new ActionListener() { @Override public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("Shoot") && !keyPressed) { @@ -259,7 +259,7 @@ Apart from the looping boolean, another difference is whereplay()
Buffered or Streaming?
@@ -277,7 +277,7 @@ Typically, you stream long sounds, and buffer short sounds.- +Play() or PlayInstance()?
- +- +@@ -294,9 +294,9 @@ Typically, you stream long sounds, and buffer short sounds.
The same sound cannot play twice at the same time. The same sounds can play multiple times and overlap. Your Ear in the Scene
@@ -318,7 +318,7 @@ If you don't do that, the results of 3D audio will be quite random.- +Global, Directional, Positional?
@@ -345,7 +345,7 @@ In short, you must choose in every situation whether it makes sense for a sound- +Conclusion
@@ -380,4 +380,5 @@ See also:
simpleInitApp()
method.
sceneModel
setupKeys()
package jme3test.helloworld; @@ -116,7 +116,7 @@ You should see an explosion that sends debris flying, and a fire.
test-data.jar
. You can
Copy them into you assets/Effects
directory to use them.
assets
setGravity()
You can find details about effect parameters here. @@ -331,7 +331,7 @@ Add and modify one parameter at a time, and try different values until you get t
- +package jme3test.helloworld; @@ -47,7 +47,7 @@ public class HelloInput extends SimpleApplication { @Override public void simpleInitApp() { - Box(Vector3f.ZERO, 1, 1, 1); + Box b = new Box(Vector3f.ZERO, 1, 1, 1); player = new Geometry("Player", b); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.Blue); @@ -70,7 +70,7 @@ public class HelloInput extends SimpleApplication { } - private ActionListener() { + private ActionListener actionListener = new ActionListener() { public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("Pause") && !keyPressed) { isRunning = !isRunning; @@ -112,7 +112,7 @@ Build and run the example.
simpleInitApp()
method. But since we will l
isRunning
before any action (other than unpausing) is executed.private ActionListener() { +private ActionListener actionListener = new ActionListener() { public void onAction(String name, boolean keyPressed, float tpf) { if (name.equals("Pause") && !keyPressed) { isRunning = !isRunning; @@ -267,7 +267,7 @@ It's okay to use only one of the two Listeners, and not implement the other
src/core/com/jme3/in
KeyTrigger(KeyInput.KEY_LEFT), KeyTrigger(KeyInput.KEY_RIGHT)
Tip: If you don't recall an input constant during development, you benefit from an IDE's code completion functionality: Place the caret after e.g. KeyInput.|
and trigger code completion to select possible input identifiers.
package jme3test.helloworld; @@ -39,7 +39,7 @@ public class HelloLoop extends SimpleApplication { @Override public void simpleInitApp() { - Box(Vector3f.ZERO, 1, 1, 1); + Box b = new Box(Vector3f.ZERO, 1, 1, 1); player = new Geometry("blue cube", b); Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); @@ -61,7 +61,7 @@ Build and run the file: You see a constantly rotating cube.
simpleUpdate()
method – this is the
package jme3test.helloworld; @@ -45,7 +45,7 @@ public class HelloMaterial extends SimpleApplication { @Override public void simpleInitApp() { /** A simple textured cube -- in good MIP map quality. */ - Box(new Vector3f(-3f,1.1f,0f), 1f,1f,1f); + Box boxshape1 = new Box(new Vector3f(-3f,1.1f,0f), 1f,1f,1f); Geometry cube = new Geometry("My Textured Box", boxshape1); Material mat_stl = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); Texture tex_ml = assetManager.loadTexture("Interface/Logo/Monkey.jpg"); @@ -54,7 +54,7 @@ public class HelloMaterial extends SimpleApplication { rootNode.attachChild(cube); /** A translucent/transparent texture, similar to a window frame. */ - Box(new Vector3f(0f,0f,0f), 1f,1f,0.01f); + Box boxshape3 = new Box(new Vector3f(0f,0f,0f), 1f,1f,0.01f); Geometry window_frame = new Geometry("window frame", boxshape3); Material mat_tt = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat_tt.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png")); @@ -66,7 +66,7 @@ public class HelloMaterial extends SimpleApplication { rootNode.attachChild(window_frame); /** A cube with base color "leaking" through a partially transparent texture */ - Box(new Vector3f(3f,-1f,0f), 1f,1f,1f); + Box boxshape4 = new Box(new Vector3f(3f,-1f,0f), 1f,1f,1f); Geometry cube_leak = new Geometry("Leak-through color cube", boxshape4); Material mat_tl = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat_tl.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png")); @@ -116,7 +116,7 @@ Move around with the WASD keys to have a closer look at the translucency, and th
/** A simple textured cube. */ - Box(new Vector3f(-3f,1.1f,0f), 1f,1f,1f); + Box boxshape1 = new Box(new Vector3f(-3f,1.1f,0f), 1f,1f,1f); Geometry cube = new Geometry("My Textured Box", boxshape1); Material mat_stl = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); @@ -150,7 +150,7 @@ The ColorMap is the typical material layer where textures go.
/** A translucent/transparent texture. */ - Box(new Vector3f(0f,0f,0f), 1f,1f,0.01f); + Box boxshape3 = new Box(new Vector3f(0f,0f,0f), 1f,1f,0.01f); Geometry seethrough = new Geometry("see-through box", boxshape3); Material mat_tt = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat_tt.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png")); @@ -207,7 +207,7 @@ The ColorMap is the material layer where textures go. ThisShininess and Bumpiness
@@ -274,7 +274,7 @@ Remember that any Lighting.j3md-based material requires a light source, as shown- +Default Material Definitions
@@ -299,19 +299,19 @@ DiffuseMap, NormalMap, SpecularMap : Texture2D- +
Shininess : FloatFor a game, you create custom Materials based on these existing MaterialDefintions – as you have just seen in the example with the shiny rock's material.
LeakThrough.j3m
only takes one line.
package jme3test.helloworld; @@ -64,7 +64,7 @@ public class HelloNode extends SimpleApplication { public void simpleInitApp() { /** create a blue box at coordinates (1,-1,1) */ - Box( new Vector3f(1,-1,1), 1,1,1); + Box box1 = new Box( new Vector3f(1,-1,1), 1,1,1); Geometry blue = new Geometry("Box", box1); Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); @@ -72,7 +72,7 @@ public class HelloNode extends SimpleApplication { blue.setMaterial(mat1); /** create a red box straight above the blue one at (1,3,1) */ - Box( new Vector3f(1,3,1), 1,1,1); + Box box2 = new Box( new Vector3f(1,3,1), 1,1,1); Geometry red = new Geometry("Box", box2); Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); @@ -96,7 +96,7 @@ Build and run the code sample. You should see two colored boxes tilted at the sa
Every JME3 application has a rootNode: Your game automatically inherits the
You define the actual action of shooting a new cannon ball as follows:
If you are unfamiliar with the vocabulary, read more about the Scene Graph here.
Learn details about the Multi-Media Asset Pipeline here.
Which ever method you choose, a Java-Application works on the main operating systems: Windows, Mac OS, Linux, Android.
@@ -510,4 +510,5 @@ The distribution appears in a newly generated rootNode
object from SimpleApplication. Everything attached to the rootNode is part of the scene graph. The elements of the scene graph are Spatials.
@@ -152,9 +152,9 @@ Every JME3 application has a rootNode: Your game automatically inherits the A box, a sphere, a player, a building, a piece of terrain, a vehicle, missiles, NPCs, etc… The
-
+
-
+
rootNode
, a floor node grouping several terrains, a custom vehicle-with-passengers node, a player-with-weapon node, an audio node, etc… Understanding the Code
simpleInitApp()
metho
Box( new Vector3f(1,-1,1), 1,1,1);
+
Box box1 = new Box( new Vector3f(1,-1,1), 1,1,1);
Geometry blue = new Geometry("Box", box1);
Material mat1 = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
@@ -194,7 +194,7 @@ What happens in the code snippet? You use the
simpleInitApp()
metho
Box( new Vector3f(1,3,1), 1,1,1);
+
Box box2 = new Box( new Vector3f(1,3,1), 1,1,1);
Geometry red = new Geometry("Box", box2);
Material mat2 = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md");
@@ -240,7 +240,7 @@ If you run the app with only the code up to here, you see two cubes: A red cube
What is a Pivot Node?
How do I Populate the Scenegraph?
@@ -267,7 +267,7 @@ You can transform (e.g. rotate) Geometries around their own center, or around a
Task…? Solution!
-
Create a Spatial Create a shape, wrap it into a Geometry, and give it a Material. For example: Box(Vector3f.ZERO, 1, 1, 1);
+
Create a Spatial Create a shape, wrap it into a Geometry, and give it a Material. For example: Box mesh = new Box(Vector3f.ZERO, 1, 1, 1);
Geometry thing = new Geometry("thing", mesh);
Material mat = new Material(assetManager,
"Common/MatDefs/Misc/ShowNormals.j3md");
@@ -293,9 +293,9 @@ thing.setMaterial(mat);
Specify what should be loaded at the start Everything you initialize and attach to the
rootNode
in the simpleInitApp()
method is part of the scene at the start of the game. How do I Transform Spatials?
+right -left +up -down +forward -backward
+
@@ -331,7 +331,7 @@ To scale a Spatial 10 times longer, one tenth the height, and keep the same widt
Scaling resizes Spatials X-axis Y-axis Z-axis
length height width
+
@@ -347,9 +347,9 @@ To roll an object 180° around the z axis: Rotation turns Spatials X-axis Y-axis Z-axis
thing.rotate( 0f , 0f , 180*
pitch = nodding your head yaw = shaking your head roll = cocking your head
How do I Troubleshoot Spatials?
A Geometry has an unexpected Color or Material. Did you reuse a Material from another Geometry and have inadvertently changed its properties? (If so, consider cloning it: mat2 = mat.clone(); )
How do I Add Custom Data to Spatials?
pivot id
), you can
Conclusion
Sample Code
A Basic Physics Application
Creating Bricks and Cannon Balls
Geometries
RigidBodyControl: Brick
RigidBodyControl: Cannonball
RigidBodyControl: Floor
Creating the Scene
simpleInitApp()
method
The Cannon Ball Shooting Action
initInputs()
method, you add an input mapping that triggers
private ActionListener() {
+
private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("shoot") && !keyPressed) {
makeCannonBall();
@@ -543,7 +543,7 @@ In the moment the cannonball appears in the scene, it flies off with the velocit
Moving a Physical Spatial
Excercises
Exercise 1: Debug Shapes
Exercise 2: No Mo' Static
Exercise 3: Behind the Curtain
Conclusion
Sample Code
package jme3test.helloworld;
@@ -86,7 +86,7 @@ public class HelloPicking extends SimpleApplication {
inputManager.addListener(actionListener, "Shoot");
}
/** Defining the "Shoot" action: Determine what was hit and how to respond. */
- private ActionListener() {
+ private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("Shoot") && !keyPressed) {
@@ -123,7 +123,7 @@ public class HelloPicking extends SimpleApplication {
/** A cube object for target practice */
protected Geometry makeCube(String name, float x, float y, float z) {
- Box(new Vector3f(x, y, z), 1, 1, 1);
+ Box box = new Box(new Vector3f(x, y, z), 1, 1, 1);
Geometry cube = new Geometry(name, box);
Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.randomColor());
@@ -133,7 +133,7 @@ public class HelloPicking extends SimpleApplication {
/** A floor to show that the "shot" can go through several objects. */
protected Geometry makeFloor() {
- Box(new Vector3f(0, -4, -5), 15, .2f, 15);
+ Box box = new Box(new Vector3f(0, -4, -5), 15, .2f, 15);
Geometry floor = new Geometry("the Floor", box);
Material mat1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat1.setColor("Color", ColorRGBA.Gray);
@@ -186,7 +186,7 @@ Keep an eye on the application's output stream, it will give you more detai
Understanding the Helper Methods
Understanding Ray Casting for Hit Testing
Implementing Hit Testing
Loading the scene
Setting Up the Input Listener
Picking Action Using Crosshairs
/** Defining the "Shoot" action: Determine what was hit and how to respond. */
- private ActionListener() {
+ private ActionListener actionListener = new ActionListener() {
@Override
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("Shoot") && !keyPressed) {
@@ -369,7 +369,7 @@ Note how it prints a lot of output to show you which hits were registered.
Picking Action Using Mouse Pointer
Exercises
Exercise 1: Magic Spell
Exercise 2: Shoot a Character
Exercise 3: Pick up into Inventory
Conclusion
Create a Project
Write a SimpleApplication
Sample Code
Understanding the Code
Start the SimpleApplication
Understanding the Terminology
@@ -211,14 +211,14 @@ This code opens your application window. Let's learn how you put something
You want the cube to appear in the center. I create the Box at the origin = at
Vector3f.ZERO
.Initialize the Scene
simpleInitApp()
method is auto
The initialization code of a blue cube looks as follows:
public void simpleInitApp() {
- Box(Vector3f.ZERO, 1, 1, 1); // create a 1x1x1 box shape at the origin
+ Box b = new Box(Vector3f.ZERO, 1, 1, 1); // create a 1x1x1 box shape at the origin
Geometry geom = new Geometry("Box", b); // create a cube geometry from the box shape
Material mat = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material
@@ -288,7 +288,7 @@ A typical JME3 game has the following initialization process:
Conclusion
Sample Code
package jme3test.helloworld;
@@ -117,7 +117,7 @@ When you run this sample you should see a landscape with dirt mountains, grass p
What is a Heightmap?
Looking at the Heightmap Code
What is Texture Splatting?
Looking at the Texturing Code
setWrap(WrapMode.Repeat)
to make the small texture fill the wid
What is a Terrain?
Looking at the Terrain Code
What is LOD (Level of Detail)?
Exercises
Exercise 1: Texture Layers
Exercise 2: Randomized Terrains
Exercise 3: Solid Terrains
Conclusion
Downloading the Sources
Build and Run
Optional: Javadoc Popups and Source Navigation in NetBeans
Asset Management
Creation Process
I want to create and configure a jME3 Application
How do I start with a preconfigured game?
How do I change the background color?
viewPort.setBackgroundColor(ColorRGBA.Blue);
Can I customize the SimpleApplication class?
How can I switch between screens or states?
How do I pause/unpause a game?
How do I disable logger output to the console?
Why does the executable crash with "Cannot locate resource"?
I want to load my scene
How do I make objects appear / disappear in the 3D scene?
Why do I get AssetNotFoundException when loading X ?
How do I Create 3-D models, textures, sounds?
How do I load a 3-D model into the scene?
How do initialize the scene?
I want to transform objects in the scene
How do I move or turn or resize a spatial?
How do I make a spatial move by itself?
How do I access a named sub-mesh in Model?
Geometry result = spatial.getName().startsWith(name);
@@ -245,7 +245,7 @@ Change the geometry's translation (position) live in the update loop using
How do I make procedural or custom shapes?
I want to change the surface of objects in the scene
Why is my UV wrapping / texture appearance all wrong?
material.setTexture("ColorMap", this.assetManager.loadTexture(new TextureKey("myTexture.jpg", false)));
How do I scale, mirror, or wrap a texture?
com.jme3.texture.Texture.WrapMode
s for
material.getTextureParam("DiffuseMap").getTextureValue().setWrap(WrapMode.Repeat);
How do I change color or shininess of an material?
How do I make a surface wood, stone, metal, etc?
Why are materials too bright, too dark, or flickering?
How do I make geometries cast a shadow?
How do I make materials transparent?
How do I force or disable backface culling?
material.getAdditionalRenderState().setFaceCullMode(FaceCullMode.FrontAndBack);
Can I draw only an outline of the scene?
I want to control the camera
How do I switch between third-person and first-person view ?
How do I increase camera speed?
flyCam.setMoveSpeed(50f);
Actions, Interactions, Physics
How do I implement game logic / game mechanics?
How do I let players interact via keyboard?
How do I let players interact by clicking?
How do I animate characters?
How do I keep players from falling through walls and floors?
How do I make balls/wheels/etc bounce and roll?
How do I debug weird Physics behaviour?
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
How do I make a walking character?
How do I steer vehicles?
Can objects swing like a pendulums, chains, ropebridges?
Default GUI Display
What are these FPS/Objects/Vertices/Triangles statistics?
How do I get rid of the FPS/Objects statistics?
How do I display score, health, mini-maps, status icons?
guiNode
to create a head
How do I display buttons and UI controls?
How do i display a loading screen?
Nifty GUI
I get NoSuchElementException when adding controls (buttons etc)!
Where can I find example code of Nifty GUI's XML and Java classes?
Is there Java Doc for Nifty GUI?
I want to create an environment with sounds, effects, and landscapes
How do I play sounds and noises?
How do I make fire, smoke, explosions, swarms, magic spells?
How do I make water, waves, reflections?
How do I make fog, bloom, blur, light scrattering?
How do I generate a terrain?
How do I make a sky?
I want to access to back-end properties
How do I read out graphic card capabilities?
How do I optimize the heck out of the Scene Graph?
How do I prevent users from unzipping my JAR?
I want to do maths
What does addLocal() / multLocal() etc mean?
What is the difference between World and Local coordinates?
How do I convert Degrees to Radians?
Code Sample
public static void main(String[] args) {
@@ -35,7 +35,7 @@ Set the boolean in the AppSettings contructor to true if you want to keep the de
Properties
@@ -75,7 +75,7 @@ Set VSync to false to deactivate vertical syncing (faster, but possible page tea
60 fps
+
@@ -86,7 +86,7 @@ Set VSync to false to deactivate vertical syncing (faster, but possible page tea
Settings Property (Input) Description Default
setUseJoysticks(true) Activate optional joystick support false
+
@@ -97,7 +97,7 @@ Set VSync to false to deactivate vertical syncing (faster, but possible page tea
Settings Property (Audio) Description Default
setStereo3D(true) Enable 3D stereo. This feature requires hardware support from the GPU driver. See false
+
@@ -112,9 +112,9 @@ ImageIO.read(new File("")), …});Settings Property (Branding) Description Default
This specifies the little a
setSettingsDialogImage("/path/to/splash.png") A custom splashscreen image in the assets directory which is displayed when the settings dialog is shown. "/com/jme3/app/Monkey.png"
Saving and Loading Settings
Requirements and Planning
Requirements Gathering
Planning Development Milestones
Use File Version Control
Multi-Media Asset Pipeline
@@ -182,14 +182,14 @@ If you don't know which to choose, Subversion is a good choice for starters
Convert Models to j3o format. Move j3o files into assets/Models
. Don't reference Blender/Ogre/OBJ files in your load() code, because these unoptimized files are not packaged into the JAR.
Development Phase
Extend SimpleApplication
Where to Start?
The Smart Way to Add Custom Methods and Fields
Nodes
and Geometry
s) often carry custom
The Smart Way to Access Game Features
The Smart Way to Implement Game Logic
Optimize Application Performance
@@ -363,7 +363,7 @@ Read all about
Don't Mess With Geometric State
Maintain Internal Documentation
Debugging and Test Phase
Release Phase
Pre-Release To-Do List
@@ -460,7 +460,7 @@ Treat javadoc as messages to your future self. "genNextVal() generates the
Distributing the Executables
Game runs on Android devices. Android devices do not support post-procesor effects.
dist
directory inside
jMonkeyEngine3 File Formats
@@ -27,9 +27,9 @@ Each custom .j3m Material is based on a material definition. Advanced users can
Effects Overview
Supported External File Types
@@ -73,6 +73,7 @@ Each custom .j3m Material is based on a material definition. Advanced users can
.OGG audio OGG Vorbis music and sounds