diff --git a/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/intermediate/api_feature_mapping.html b/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/intermediate/api_feature_mapping.html deleted file mode 100644 index 1be0e20be..000000000 --- a/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/intermediate/api_feature_mapping.html +++ /dev/null @@ -1,334 +0,0 @@ -
This page provides a quick answer to the questions "I want my game to do X, where do I find that in jME 3 ??"
Knowing exactly what you are looking for allows you to search more efficiently, find documentation more quickly, and ask clearer questions on the support forum. This intermediate page assumes that you already went through the beginner tutorials. Feel free to add APIs, tutorials and javadoc links that helped you understand and use a feature!
How do I…? | Use this JME 3 Feature! | Learn more here… |
---|---|---|
Start with a preconfigured game | com.jme3.app.SimpleApplication | Hello SimpleApplication |
Make an object appear in the scene | Attach nodes and geometries to the rootNode: rootNode.attachChild(geo); com.jme3.scene.Node, com.jme3.scene.Geometry node.setCullHint(CullHint.Never); | The Scene Graph Hello Asset Hello Node |
Make an object disappear from the scene | Detach nodes and geometries from the rootNode: rootNode.detachChild(geo); node.setCullHint(CullHint.Always); | The Scene Graph Hello Asset Hello Node |
Use third-person view | Use default camera cam com.jme3.renderer.Camera | ChaseCam WIP |
Use first-person view | Use camera flyCam com.jme3.input.FlyByCamera | Hello Collision |
Increase camera speed | flyCam.setMoveSpeed(50f); | – |
Only draw outline of the scene | Use a wireframe material, e.g. for debugging. | Debugging |
Change the background color | Call viewPort.setBackgroundColor(ColorRGBA.Blue); | N/A |
Customize the applicaton class | Extend com.jme3.app.SimpleApplication (or com.jme3.app.Application) and set Application Settings | SimpleApplication AppSettings |
Disable the logger output | Logger.getLogger("").setLevel(Level.SEVERE); java.util.logging.* | Logging |
How do I…? | Use this JME 3 Feature! | Learn more here… |
---|---|---|
Make simple shapes like cubes, spheres | com.jme3.scene.Geometry, com.jme3.scene.shape.* | Hello Node, Shape TestCylinder.java, TestBox.java, TestSphere.java |
Create a 3-D model | Create the model in a 3-D mesh editor (for example Blender) and export it as Ogre XML mesh. | Download Blender, Blender tutorial, Blender-to-Ogre plugin 3D Models |
Load a 3-D model | Import asset as Ogre XML mesh. jMonkeyPlatform: Converting Ogre to j3o binary format speeds up model loading. AssetManager, com.jme3.scene.plugins.ogre.*, com.jme3.scene.Geometry | Hello Asset jMonkeyPlatform j3o converter TestOgreLoading.java, TestOgreConvert.java |
Move or turn or resize an object | Use transformations: geo.setLocalTranslation(), geo.rotate(), geo.scale() geo.updateGeometricState(); | Hello Node Spatial |
Concatenate transformations (e.g. rotations around several axes in one step) | com.jme3.math.Quaternion, slerp() com.jme3.math.Transform, interpolateTransforms() | rotate, rotate_about_a_point, quaternion, math_for_dummies |
Make an object move by itself | Change the geo's translation in the update phase of the main loop. Or remote-control the motion using cinematics. com.jme3.scene.Geometry, setLocalTranslation(), setWalkDirection() for physical objects. | Hello Loop Update Loop Custom Controls Cinematics TestBumpModel.java, TestOgreLoading.java |
Manipulate the color or shininess of an object | Materials, AssetManager | Hello Material Materials Overview TestNormalMapping.java, TestSphere.java |
Manipulate the surface of an object (wood vs stone vs metal etc) | Textures, AssetManager. | Hello Material Materials Overview TestSimpleBumps.java Blender: Creating Bump Maps and Normal maps |
Make objects cast a shadow | com.jme3.shadow.BasicShadowRenderer, com.jme3.light.DirectionalLight setShadowMode() | Light and Shadow TestEverything.java, TestShadow.java |
Render transparent objects (glass, window panes, water, tree leaves) | Assign a transparent texture to the Material and set material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); | Hello Material Materials Overview |
Force or disable Backface culling | com.jme3.material.RenderState.FaceCullMode: Back, Front, FrontAndBack, Off e.g. material.getAdditionalRenderState(). setFaceCullMode(FaceCullMode.FrontAndBack); | N/A |
Make procedural or custom shapes | com.jme3.scene.Mesh | Custom Meshes |
Keep my models, textures, sound files in order | Put all assets in subdirectories of a project directory named assets and use the assetManager to load them. | Hello Asset, Asset Manager |
Identify Named Sub-Mesh in Model | Geometry result = spatial.getName().startsWith(name); | Spatial |
How do I…? | Use this JME 3 Feature! | Learn more here… |
---|---|---|
Implement the game logic and game mechanics | Use Controls to define behaviours of types of Spatials. Use Application States to implement global behaviours. Use the simpleUpdate() loop for the remaining tests and interactions. Use Cinematics to remote-control objects in scenes. | Hello Loop Update Loop Custom Controls Application States Cinematics |
Let players interact by pressing keyboard keys | com.jme3.input.KeyInput, com.jme3.input.binding.BindingListener | Hello Input Input Handling |
Let players interact by clicking, e.g. picking up objects, opening doors, shooting | Intersect a Ray from the player with the Bounding Volume of the target: com.jme3.bounding.*, com.jme3.math.Ray, com.jme3.collision.CollisionResults. | Hello Picking Collision and Intersection TestRayCollision.java |
Animate objects and characters | Create an animated OgreMesh model with Bones in a 3-D editor (e.g. Blender). com.jme3.animation.* | Hello Animation Animation animation, Blender animation tutorial |
Keep players walking on floors of scenes | Collision detection – raycasting or physics. | Hello Collision Physics |
Prevent players from walking through walls in scenes | Collision detection using physics and bounding volumes. com.jme3.bullet.*, CapsuleCollisionShape / CompoundCollisionShape, PhysicsCharacterNode / PhysicsNode geo.setModelBound(); geo.updateModelBound(); | Hello Collision Physics |
Let balls, cars, etc bounce off obstacles and roll on floors | Use physics nodes and bounding volumes: com.jme3.bounding.*, com.jme3.bullet.collisions, com.jme3.bullet.nodes.PhysicsNode etc geo.setModelBound(); geo.updateModelBound(); | Hello Physics Physics TestSimplePhysics.java, more samples |
Steer cars, motorcycles, etc | Use physics characters and vehicles: com.jme3.bullet.*, PhysicsCharacterNode, PhysicsVehicleNode | Vehicles TestFancyCar.java, TestPhysicsCharacter.java (Press HUJK keys to steer, spacebar to jump.) |
Let an object swing like a pendulum or chain links | Use physics joints: com.jme3.bullet.joints.PhysicsHingeJoint | Hinges and Joints TestPhysicsHingeJoint.java (Press HK keys to turn, spacebar to swing.) |
How do I…? | Use this JME 3 Feature! | Learn more here… |
---|---|---|
Get rid of default debug display (fps, stats etc) in SimpleApplication | app.setDisplayFps(false); app.setDisplayStatView(false); | N/A |
Display text (score, health), flat mini-maps or status icons | Attach a picture to the orthogonal guiNode to create a heads-up display (HUD). com.jme3.font.*, com.jme3.ui.Picture. guiNode.attachChild() | HUD TestOrtho.java, TestBitmapFont.java |
Display buttons to let the player switch between the game/settings/score screens | Nifty GUI | Nifty GUI TestNiftyGui.java |
How do I…? | Use this JME 3 Feature! | Learn more here… |
---|---|---|
Play sounds and noises | AudioRenderer, Listener, and AudioNode from com.jme3.audio.* | Hello Audio Audio audio |
Simulate fire, flames, smoke, explosions, swarms, dust, magic spells | Use particle emitters: com.jme3.effect.EmitterSphereShape, com.jme3.effect.ParticleEmitter | Hello Effects Particle Emitters Bloom and Glow Effects Overview TestExplosionEffect.java, TestParticleEmitter.java |
Simulate water, waves, reflections | com.jme3.water.* | Water Post-Processor Water TestSceneWater.java |
Generate a terrain | com.jme3.terrain.* | Hello Terrain Terrain TestTerrain.java |
Simulate a sky | rootNode.attachChild(SkyFactory.createSky( assetManager, - "Textures/Sky/Bright/BrightSky.dds", false)); -skyGeo.setQueueBucket(Bucket.Sky) | Sky TestCubeMap.java |
How do I…? | Use this JME 3 Feature! | Learn more here… |
---|---|---|
Check graphic card capabilities | com.jme3.renderer.Caps Collection<Caps> caps = renderer.getCaps(); Logger.getLogger(HelloJME3.class.getName()).log(Level.INFO, "Caps: {0}" + caps.toString()); | N/A |
Optimize the heck out of the scenegraph | jme3tools.optimize.GeometryBatchFactory GeometryBatchFactory.optimize(rootNode); | N/A |
When adding multiplayer to your game, you may find that your server needs to know about game state (e.g. where are players, objects? Was that a direct hit? etc.) You can code all this up yourself, but there's an easier way.
It's very easy to change your current (client) game to function as a server as well.
First, let's take a look at the default way of creating a new game (in its simplest form):
public static void main(String[] args) { - Application app = new Main(); - app.start(); -}
Now, with a simple change you can start your game in Headless mode. This means that all input and audio/visual output will be ignored. That's a good thing for a server.
import com.jme3.system.JmeContext; -import com.jme3.system.JmeContext.Type; - -public static void main(String[] args) { - Application app = new Main(); - app.start(JmeContext.Type.Headless); -}
simpleUpdate()
as expected.Okay, so you can now start your game in a headless 'server mode', where to go from here?
String[] args
from the main
-method to enable server mode on demand (e.g. start your server like java -jar mygame.jar –server
.if (servermode)
-block) (or if (!servermode)
for the client).*Work in progress*
This page will extend (not the Java keyword!) the Hello_Terrain tutorial in a few small ways in order to show you a quick way to create a Collision Shape out of the map we have generated. A Collision Shape allows a player (who is also a Collision Shape in this tutorial) to collide with the map, i.e. clip, walk on, stand on, etc. in order to create the type of world and interactivity most gamers are familiar with in FPS or MMOs.
package mygame;
-
-import jme3tools.converters.ImageToAwt;
-import com.jme3.app.SimpleBulletApplication;
-import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
-import com.jme3.bullet.collision.shapes.HeightfieldCollisionShape;
-import com.jme3.bullet.nodes.PhysicsCharacterNode;
-import com.jme3.bullet.nodes.PhysicsNode;
-import com.jme3.input.KeyInput;
-import com.jme3.input.controls.ActionListener;
-import com.jme3.input.controls.KeyTrigger;
-import com.jme3.material.Material;
-import com.jme3.math.Vector3f;
-import com.jme3.renderer.Camera;
-import com.jme3.terrain.geomipmap.TerrainLodControl;
-import com.jme3.terrain.heightmap.AbstractHeightMap;
-import com.jme3.terrain.heightmap.ImageBasedHeightMap;
-import com.jme3.terrain.geomipmap.TerrainQuad;
-import com.jme3.texture.Texture;
-import com.jme3.texture.Texture.WrapMode;
-import java.util.ArrayList;
-import java.util.List;
-
-public class Main extends SimpleBulletApplication {
-
- private TerrainQuad terrain;
- PhysicsCharacterNode player;
- Boolean left = false, right = false, up = false, down = false;
- private Vector3f walkDirection = new Vector3f();
-
- public static void main(String[] args) {
- Main app = new Main();
- app.start();
- }
-
- @Override
- public void simpleInitApp() {
- setupKeys();
- setupPlayer();
-
- Material terrain_mat;
- PhysicsNode landscape;
-
- /** 1. Create terrain material and load four textures into it. */
- terrain_mat = new Material(assetManager, "Common/MatDefs/Terrain/Terrain.j3md");
-
- /** 1.1) Add ALPHA map (for red-blue-green coded splat textures) */
- terrain_mat.setTexture("m_Alpha", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
-
- /** 1.2) Add GRASS texture into the red layer (m_Tex1). */
- Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
- grass.setWrap(WrapMode.Repeat);
- terrain_mat.setTexture("m_Tex1", grass);
- terrain_mat.setFloat("m_Tex1Scale", 64f);
-
- /** 1.3) Add DIRT texture into the green layer (m_Tex2) */
- Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
- dirt.setWrap(WrapMode.Repeat);
- terrain_mat.setTexture("m_Tex2", dirt);
- terrain_mat.setFloat("m_Tex2Scale", 32f);
-
- /** 1.4) Add ROAD texture into the blue layer (m_Tex3) */
- Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
- rock.setWrap(WrapMode.Repeat);
- terrain_mat.setTexture("m_Tex3", rock);
- terrain_mat.setFloat("m_Tex3Scale", 128f);
-
- /** 2. Create the height map */
- AbstractHeightMap heightmap = null;
- Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
- heightmap = new ImageBasedHeightMap(
- ImageToAwt.convert(heightMapImage.getImage(), false, true, 0));
- heightmap.load();
-
- /** 3. We have prepared material and heightmap. Now we create the actual terrain:
- * 3.1) We create a TerrainQuad and name it "my terrain".
- * 3.2) A good value for terrain tiles is 64x64 -- so we supply 64+1=65.
- * 3.3) We prepared a heightmap of size 512x512 -- so we supply 512+1=513.
- * 3.4) At last, we supply the prepared heightmap itself.*/
- terrain = new TerrainQuad("my terrain", 65, 513, heightmap.getHeightMap());
-
- HeightfieldCollisionShape sceneShape = new HeightfieldCollisionShape(heightmap.getHeightMap());
- landscape = new PhysicsNode(terrain, sceneShape, 0);
-
-
- /** 4. The LOD (level of detail) depends on were the camera is: */
- List<Camera> cameras = new ArrayList<Camera>();
- cameras.add(getCamera());
- TerrainLodControl control = new TerrainLodControl(terrain, cameras);
- terrain.addControl(control);
-
- /** 5. We give the terrain its material, position & scale it, and attach it. */
- terrain.setMaterial(terrain_mat);
- landscape.setLocalTranslation(0, -100, 0);
- rootNode.attachChild(landscape);
- getPhysicsSpace().add(landscape);
- }
-
- @Override
- public void simpleUpdate(float tpf) {
- Vector3f camDir = cam.getDirection().clone().multLocal(0.2f);
- Vector3f camLeft = cam.getLeft().clone().multLocal(0.1f);
- walkDirection.set(0, 0, 0);
- if (left) {
- walkDirection.addLocal(camLeft);
- }
- if (right) {
- walkDirection.addLocal(camLeft.negate());
- }
- if (up) {
- walkDirection.addLocal(camDir);
- walkDirection.y = 0;
- }
- if (down) {
- walkDirection.addLocal(camDir.negate());
- walkDirection.y = 0;
- }
- player.setWalkDirection(walkDirection);
- cam.setLocation(player.getLocalTranslation());
- }
-
- public void setupPlayer() {
- player = new PhysicsCharacterNode(new CapsuleCollisionShape(1.2f, 3f, 1), .05f);
- player.setJumpSpeed(20); //10 default
- player.setFallSpeed(30); //30 default
- player.setGravity(30); //30 default
- player.setLocalTranslation(new Vector3f(0f, 250f, 150f));
- rootNode.attachChild(player);
- getPhysicsSpace().add(player);
- }
-
- private void setupKeys() {
- inputManager.addMapping("Lefts", new KeyTrigger(KeyInput.KEY_A));
- inputManager.addMapping("Rights", new KeyTrigger(KeyInput.KEY_D));
- inputManager.addMapping("Ups", new KeyTrigger(KeyInput.KEY_W));
- inputManager.addMapping("Downs", new KeyTrigger(KeyInput.KEY_S));
- inputManager.addMapping("Jumps", new KeyTrigger(KeyInput.KEY_SPACE));
- inputManager.addListener(actionListener, new String[]{"Lefts", "Rights", "Ups",
- "Downs", "Jumps"});
- }
- private ActionListener() {
-
- public void onAction(String binding, boolean value, float tpf) {
- if (binding.equals("Lefts")) {
- if (value && player.onGround()) {
- left = true;
- } else {
- left = false;
- }
- } else if (binding.equals("Rights")) {
- if (value && player.onGround()) {
- right = true;
- } else {
- right = false;
- }
- } else if (binding.equals("Ups")) {
- if (value && player.onGround()) {
- up = true;
- } else {
- up = false;
- }
- } else if (binding.equals("Downs")) {
- if (value && player.onGround()) {
- down = true;
- } else {
- down = false;
- }
- } else if (binding.equals("Jumps") && player.onGround()) {
- player.jump();
- }
- }
- };
-}
To try this code, go into a New Project → JME3 → BasicGame using the default settings (if you haven't already made a default project before) the name should be BasicGame and the package would be called myGame, then just paste this over the entire preconstructed main.java text. Then Add the jme3-test-data library which is available through your library list. This should compile and run from there.
I will only briefly describe the sections that are covered in the original Hello_Terrain. Most detail will be given to the additives.
Imports are to bring in the appropriate class definitions.
private TerrainQuad terrain;
Holds our map.
PhysicsCharacterNode player;
Creates our character in the style of FPS that many gamers are familiar with.
Boolean left = false, right = false, up = false, down = false;
Variables for creating fluid movement.
private Vector3f walkDirection = new Vector3f();
The direction we determine from combinations of the booleans.
The main function is standard. -In simpleInit we run setupKeys() first and create the common WASD and SPACEBAR to jump.
inputManager.addListener(actionListener, new String[]{"Lefts", "Rights", "Ups", "Downs", "Jumps"})
This line indicates our actionListener function and what to do when each command (the string names) is sent.
The onAction function basically sets the booleans true based on which directions we're pressing or makes us jump. -The simpleUpdate function constants changed our direction based on the boolean (ie the directions) we're pressing.
The real collisioning happens in these parts;
player = new PhysicsCharacterNode(new CapsuleCollisionShape(1.2f, 3f, 1), .05f); -rootNode.attachChild(player); -getPhysicsSpace().add(player); -HeightfieldCollisionShape sceneShape = new HeightfieldCollisionShape(heightmap.getHeightMap()); -landscape = new PhysicsNode(terrain, sceneShape, 0); -landscape.setLocalTranslation(0, -100, 0); -rootNode.attachChild(landscape); -getPhysicsSpace().add(landscape);
The first chunk makes our player into a collision shape that's a capsule, kinda like a human right? And then attaches it to the rootNode and gets it's physics (important!). -The second chunk feeds the heightmap we made into a heightfield collision shape generator to create the collidable shape of the land mass. -The third chunk sets our land and it's collision down some, attaches em to root, and gets the physics.
You should spawn high up in the area and fall down to the map, giving you a few seconds to survey the domain. Then walk around and see how you like the lay of the land.
See also: