The term collision can be used to refer to physical interactions (where physical objects collide and bump off one another), and also to non-physical intersections. This article is about non-physical (mathematical) collisions.
The term collision can be used to refer to <ahref="/com/jme3/gde/core/docs/jme3/advanced/physics_listeners.html">physical interactions</a> (where <ahref="/com/jme3/gde/core/docs/jme3/advanced/physics.html">physical objects</a> collide, push and bump off one another), and also to non-physical <em>intersections</em> in 3D space. This article is about the non-physical (mathematical) collisions.
</p>
<p>
Non-physical collision detection is interesting because they use less computing resources than physical collision detection. You can optimize your game if you find a way to simulate a certain effect in a non-physical way, using mathematical techniques such as ray casting.
Non-physical collision detection is interesting because it uses less computing resources than physical collision detection. The non-physical calculations are faster because they do not have any side effects such as pushing other objects or bumping off of them. Tasks such as <ahref="/com/jme3/gde/core/docs/jme3/advanced/mouse_picking.html">mouse picking</a> are easily implemented using using mathematical techniques such as ray casting and intersections. Experienced developers optimize their games by finding ways to simulate certain (otherwise expensive physical) interactions in a non-physical way.
</p>
<p>
One example for an optimization is a physical vehicle's wheels. You could make the wheels fully physical disks, and have jME calculate every tiny force – sounds very accurate, but is total overkill. A more performant solution is to cast four invisible rays down from the vehicle and calculate the intersections with the floor and other obstacles. These non-physical wheels require (in the simplest case) only four calculations to achieve an effect that players can hardly distinguish from the real thing.
<strong>Example:</strong>One example for an optimization is a physical vehicle's wheels. You could make the wheels fully physical disks, and have jME calculate every tiny force – sounds very accurate? It's total overkill and too slow for a racing game. A more performant solution is to cast four invisible rays down from the vehicle and calculate the intersections with the floor. These non-physical wheels require (in the simplest case) only four calculations per tick to achieve an effect that players can hardly distinguish from the real thing.
</p>
</div>
<h2><a>Bounding Volumes</a></h2>
<div>
<p>
A com.jme3.bounding.BoundingVolume is an interface for dealing with containment of a collection of points. All BoundingVolumes are Collidable and are used as optimization to calculate non-physical collisions more quickly: It's faster to calculate an intersection between simple shapes like spheres and boxes than between complex shapes. In cases where precision is not relevant, you wrap a complex model in a simpler shape to speed up collision detection.
</p>
<ul>
<li><div> Type.Sphere: com.jme3.bounding.BoundingSphere is a sphere used as a container for a group of vertices of a piece of geometry. A BoundingSphere has a center and a radius.</div>
</li>
<li><div> Type.AABB = Axis-aligned bounding box. A com.jme3.bounding.BoundingBox is an axis-aligned cuboid used as a container for a group of vertices of a piece of geometry. A BoundingBox has a center and extents from that center along the x, y and z axis.</div>
</li>
<li><div> Type.OBB = Oriented bounding box. (not in use)</div>
</li>
<li><div> Type.Capsule = Cylinder with rounded ends. Often used for mobile characters.</div>
</li>
</ul>
<p>
<strong>Note:</strong> Physical objects have their own "bounding volumes" called CollisionShapes.
</p>
</div>
<h2><a>Collisions</a></h2>
<h2><a>Collidable</a></h2>
<div>
<p>
@ -73,7 +48,7 @@ Note that jME counts <em>all</em> collisions, this means a ray intersecting a bo
<td>getCollision(i) </td><td>Returns the CollisionResult at index i.</td>
</tr>
</table></div>
<!-- EDIT1 TABLE [2825-3153] -->
<!-- EDIT1 TABLE [2081-2409] -->
<p>
A CollisionResult object contains information about the second party of the collision event.
</p>
@ -100,7 +75,7 @@ A CollisionResult object contains information about the second party of the coll
<td>getTriangleIndex()</td><td>Returns the index of the triangle on the second party's mesh that was hit. (?)</td>
</tr>
</table></div>
<!-- EDIT2 TABLE [3247-3784] -->
<!-- EDIT2 TABLE [2503-3040] -->
</div>
<h3><a>Code Sample</a></h3>
@ -158,54 +133,94 @@ Knowing the distance of the collisions is useful for example when you intersect
</div>
<h2><a>Intersection</a></h2>
<h2><a>Bounding Volumes</a></h2>
<div>
<p>
A com.jme3.math.Ray is an infinite line with a beginning, a direction, and no end; whereas a com.jme3.math.Line is an infinite line with only a direction (no beginning, no end).
A com.jme3.bounding.BoundingVolume is an interface for dealing with containment of a collection of points. All BoundingVolumes are <code>Collidable</code> and are used as optimization to calculate non-physical collisions more quickly: It's always faster to calculate an intersection between simple shapes like spheres and boxes than between complex shapes like models.
</p>
<p>
Rays are used to detect where the user or a player is "looking" when performing an action:
All fast-paced action and shooter games use BoundingVolumes as an optimization. Wrap all complex models into simpler shapes – in the end, you get equally useful collision detection results, but faster. <objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://en.wikipedia.org/wiki/Bounding_volume"><paramname="text"value="<html><u>More about bounding volumes...</u></html>"><paramname="textColor"value="blue"></object>
</p>
<p>
Supported types:
<imgsrc="/wiki/lib/exe/fetch.php">
</p>
<ul>
<li><div><strong>Click to select:</strong> You can determine what a user has clicked by casting a ray from the camera in the direction of the camera. Now identify the closest collision of the ray with the rootNode.</div>
<li><div> Type.Sphere: com.jme3.bounding.BoundingSphere is a sphere used as a container for a group of vertices of a piece of geometry. A BoundingSphere has a center and a radius.</div>
</li>
<li><div> Type.AABB = Axis-aligned bounding box, that means it doesn't rotatewhich makes it less precise. A com.jme3.bounding.BoundingBox is an axis-aligned cuboid used as a container for a group of vertices of a piece of geometry. A BoundingBox has a center and extents from that center along the x, y and z axis.</div>
</li>
<li><div><strong>Line of sight:</strong> Cast a ray from a player in the direction of another player. Then you detect all collisions of this ray with other entities (walls, foliage, window panes) and use this to calculate whether one can see the other.</div>
<li><div> Type.OBB = Oriented bounding box. This bounding box is more precise because it can rotate with its content, but is computationally more expensive. (Currently not supported.)</div>
</li>
<li><div> Type.Capsule = Cylinder with rounded ends, also called "swept sphere". Typically used for mobile characters.</div>
</li>
</ul>
<p>
These simple ray-surface intersection tests are called Ray Casting. As opposed to the more advanced Ray Tracing, Ray Casting does not follow a ray's reflection after the first hit, the ray just goes straight on.
<p><div>Note: If you are looking for BoundingVolumes for physical objects, use <ahref="/com/jme3/gde/core/docs/jme3/advanced/physics.html">CollisionShapes</a>.
</div></p>
</p>
</div>
<h3><a>Usage</a></h3>
<div>
<p>
Learn how to implement <ahref="/com/jme3/gde/core/docs/jme3/advanced/mouse_picking.html">Mouse Picking</a> here.
For example you can use Bounding Volumes on custom meshes, or complex non-physical shapes.
A com.jme3.math.Ray is an infinite line with a beginning, a direction, and no end; whereas a com.jme3.math.Line is an infinite line with only a direction (no beginning, no end).
</p>
</div>
<p>
Rays are used to perform line-of-sight calculations. This means you can detect what users were "aiming at" when they clicked or pressed a key. You can also use this to detect whether game characters can see something (or someone) or not.
</p>
<ul>
<li><div><strong>Click to select:</strong> You can determine what a user has clicked by casting a ray from the camera forward in the direction of the camera. Now identify the closest collision of the ray with the rootNode, and you have the clicked object.</div>
</li>
<li><div><strong>Line of sight:</strong> Cast a ray from a player in the direction of another player. Then you detect all collisions of this ray with other entities (walls versus foliage versus window panes) and use this to calculate how likely it is that one can see the other.</div>
</li>
</ul>
<h2><a>SweepSphere</a></h2>
<div>
<p>
<p><div>These simple but powerful ray-surface intersection tests are called Ray Casting. As opposed to the more advanced Ray Tracing technique, Ray Casting does not follow the ray's reflection after the first hit – the ray just goes straight on.
</div></p>
</p>
<p>
Learn the details of how to implement <ahref="/com/jme3/gde/core/docs/jme3/advanced/mouse_picking.html">Mouse Picking</a> here.
</p>
<hr/>
A com.jme3.collision.SweepSphere implements a collidable "stretched" sphere that is shaped like a capsule (an upright cylinder with half a sphere on top and the second half at the bottom).
This shape is usually used to simulate simple non-physcial collisions for character entities in games. The sweep sphere can be used to check collision against a triangle or another sweep sphere.
<li><div> A com.jme3.collision.SweepSphere implements a collidable "stretched" sphere that is shaped like a capsule (an upright cylinder with half a sphere on top and the second half at the bottom). This shape is usually used to simulate simple non-physcial collisions for character entities in games. The sweep sphere can be used to check collision against a triangle or another sweep sphere.</div>
@ -34,7 +34,14 @@ Okay, we want to create a Quad. A quad has four vertices, and is made up of two
The base class for creating meshes is <code>com.jme3.scene.Mesh</code>.
</p>
<pre>Mesh m = new Mesh();</pre>
<pre>Mesh mesh = new Mesh();</pre>
<p>
If you create your own Mesh-based class, replace <code>mesh</code> by <code>this</code> in the following examples:
</p>
<pre>public class MyMesh extends Mesh {}</pre>
</div>
@ -110,13 +117,13 @@ The Mesh data is stored in a buffer.
</li>
<li><div> The third parameter describes the number of components of the values. Vertex postions are 3 float values, texture coordinates are 2 float values, and the indices are single ints.</div>
</li>
<li><div> In order for JMonkey to correctly show the mesh in the scene, it needs to know the bounds of our new mesh. This can easily be achieved by calling the updateBound() method on it.</div>
<li><div> In order for jMonkey to correctly show the mesh in the scene, it needs to know the bounds of our new mesh. This can easily be achieved by calling the updateBound() method on it.</div>
@ -161,21 +168,20 @@ There are more vertex buffers in a Mesh than the three shown above. For an overv
<div>
<p>
Vertex coloring is a simple way of coloring meshes. Instead of just assigning one solid color, each vertex (corner) has a color assigned. The faces between the vertices are then colored with a gradient.
We will use the same mesh <code>m</code> as defined above, but with a special VertexColor material.
Vertex coloring is a simple way of coloring meshes. Instead of just assigning one solid color, each vertex (corner) has a color assigned. The faces between the vertices are then colored with a gradient. You can use the same mesh <code>mesh</code> object that you defined above.
</p>
<pre>Geometry coloredMesh = new Geometry ("ColoredMesh", m);
Material matVC = new Material(assetManager, "Common/MatDefs/Misc/VertexColor.j3md");</pre>
<pre>Geometry geo = new Geometry ("ColoredMesh", mesh);
Material matVC = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");</pre>
<p>
We create a float array color buffer.
You create a float array color buffer:
</p>
<ul>
<li><div>We assign 4 color values, RGBA, to each vertex.</div>
<li><div>Assign 4 color values, RGBA, to each vertex.</div>
<ul>
<li><div> To loop over the 4 color values, we use a color index <pre>int colorIndex = 0;</pre>
<li><div> To loop over the 4 color values, use a color index <pre>int colorIndex = 0;</pre>
</div>
</li>
</ul>
@ -193,7 +199,7 @@ We create a float array color buffer.
</ul>
<p>
We loop over the colorArray buffer to quickly set some RGBA value for each vertex. As usual, RGBA color values range from 0.0f to 1.0f. Note that the values we use here are arbitrarily chosen! It's just a quick loop to give every vertex a different RGBA value (a purplish gray, purple, a greenish gray, green, see screenshot), without writing too much code. For your own mesh, you'd assign values for the color buffer depending on which color you want your mesh to have.
Loop over the colorArray buffer to quickly set some RGBA value for each vertex. As usual, RGBA color values range from 0.0f to 1.0f. <strong>Note that the color values in this example are arbitrarily chosen.</strong> It's just a quick loop to give every vertex a different RGBA value (a purplish gray, purple, a greenish gray, green, see screenshot), without writing too much code. For your own mesh, you'd assign meaningful values for the color buffer depending on which color you want your mesh to have.
</p>
<pre>for(int i = 0; i < 4; i++){
@ -212,8 +218,8 @@ We loop over the colorArray buffer to quickly set some RGBA value for each verte
Next, set the color buffer. An RGBA color value contains four float components, thus the parameter <code>4</code>.
@ -223,6 +229,24 @@ Now you see a gradient color extending from each vertex.
</div>
<h3><a>Example: Shaded Mesh with Normals</a></h3>
<div>
<p>
The examples used the mesh together with the Unshaded.j3md material. If you want to use the Mesh with a Phong illuminated material (such as Lighting.j3md), the mesh needs to include information about its normals. (The Normals encode in which direction a mesh polygon is facing, which is important for calculating light and shadow.)
</p>
<pre>float[] normals = new float[12];
normals = new float[]{0,0,1, 0,0,1, 0,0,1, 0,0,1};
You need as many normals as the polygon has vertices. For a flat quad, they point all in the same direction. In this case, the direction is the Z unit vector (Vector3f.UNIT_Z), this means the quad is facing the camera.
</p>
</div>
<h3><a>Example: Point Mode</a></h3>
<div>
@ -232,14 +256,14 @@ Alternatively, you can show the vertices as colored points instead of coloring t
</p>
<pre>Geometry coloredMesh = new Geometry ("ColoredMesh", cMesh);
...
m.setMode(Mesh.Mode.Points);
m.setPointSize(10f);
m.updateBound();
m.setStatic();
Geometry points = new Geometry("Points", m);
mesh.setMode(Mesh.Mode.Points);
mesh.setPointSize(10f);
mesh.updateBound();
mesh.setStatic();
Geometry points = new Geometry("Points", mesh);
Geometries have Materials (.j3m), Materials are based on material definitions (.j3md). You can <ahref="/com/jme3/gde/core/docs/jme3/advanced/j3m_material_files.html">write .j3m files in a text editor</a>, or <ahref="/com/jme3/gde/core/docs/sdk/material_editing.html">use the jMonkeyEngine SDK to generate</a> them for you.
A Geometry (mesh) is just the shape of the object. jMonkeyEngine cannot render a shape without knowing anything about its surface properties. You need to apply a color or texture to the surface of your Geometries to make them visible. In jMonkeyEngine, colors and textures are represented as Material objects.
</p>
<p>
This table shows you the material definitions that jMonkeyEngine supplies by default. You want to make the most of your models by using the right material parameters. The developers should be in contact with the graphic designer regarding which of the available jMonkeyEngine features individual Materials and Textures require. You must have an understanding what <ahref="/com/jme3/gde/core/docs/jme3/terminology#materialstextures.html">texture maps</a> are to be able to use textured materials.
All Geometries have Materials: You either use the setters described here to specifiy the Material's properties in your Java code, or you load a custom .j3m file that lists the properties. To improve performance, reuse Materials for similar models, don't create a new Material object for every Geometry. (E.g. use one bark Material for many tree models.)
</p>
<p>
You can <ahref="/com/jme3/gde/core/docs/jme3/advanced/j3m_material_files.html">write .j3m files in a text editor</a>, or <ahref="/com/jme3/gde/core/docs/sdk/material_editing.html">use the jMonkeyEngine SDK to create .j3m files</a> for you. (Advanced users can also create custom Material Definitions.)
</p>
<p>
Each Material is based on one of the default material definitions (.j3md files) that are included in the engine. The Materials table shows you the material definitions that jMonkeyEngine supports by default. You want to make the most of your models by setting good looking material parameters: The developers should be in contact with the graphic designer regarding which of the available jMonkeyEngine features (listed here) are intended to be used in individual Models' Materials. You must have an understanding what <ahref="/com/jme3/gde/core/docs/jme3/terminology#materialstextures.html">texture maps</a> are to be able to use textured materials.
</p>
</div>
<h2><a>Usage</a></h2>
<h2><a>Code Sample</a></h2>
<div>
<p>
There are two types of material definitions below, illuminated and unshaded. Illuminated materials look more naturalistic, unshaded ones look more abstract.
The following samples assume that you loaded a Geometry, e.g. <code>Spatial myGeometry = assetManager.loadModel("Models/Teapot/Teapot.j3o");</code>
</p>
<pre>Material mat = new Material(assetManager, // Create new material and
mat.setColor("Color", ColorRGBA.Blue); // Set one or more parameters.
myGeometry.setMaterial(mat); // Use material on Geometry.</pre>
<p>
Most parameters are not mandatory, even if they are not explicitly marked optional. For example, it is okay to specify solely the <code>DiffuseMap</code> and <code>NormalMap</code> when using <code>Lighting.j3md</code>, and leave the rest empty. You are only using a subset of the available features, but that's fully acceptable if it already results in the material you want. You can always add more texture maps later.
<p><div>1) Looks confusing? Start with <code>Unshaded.j3md</code>, and then <code>Lighting.j3md</code>. <br/>
Most Material parameters are not mandatory. For example, it is normal to specify solely the <code>DiffuseMap</code> and <code>NormalMap</code> when using <code>Lighting.j3md</code>, and leave the rest empty. You are only using a subset of the advanced features, but that's acceptable if it results in the material looking the way you want. You can always add more texture maps later.
</p>
<p>
<p><div>1) Looks confusing? Start with <code>Unshaded.j3md</code>, then look into <code>Lighting.j3md</code>. <br/>
2) The jMonkeyEngine <ahref="/com/jme3/gde/core/docs/sdk.html">SDK</a> offers a visual editor where you can set properties and preview the outcome. The <acronymtitle="Software Development Kit">SDK</acronym> Palette contains code snippets to load materials. <br/>
3) If you don't know what an optional setting means, you're likely not using it.
3) If you don't know what an obscure parameter means, you're likely not using it.
</div></p>
</p>
<p>
jMonkeyEngine supports illuminated and unshaded Material Definitions.
</p>
<ul>
<li><div> Phong Illuminated materials look more naturalistic.</div>
</li>
<li><div> Unshaded materials look more abstract.</div>
</li>
</ul>
</div>
<h2><a>Standard Coloring and Textures</a></h2>
<h2><a>Unshaded Coloring and Textures</a></h2>
<div>
<p>
Standard materials look slightly abstract because they ignore light sources. They work even if the scene does not include a light source. They are single-colored or textured and have no shadows.
"Unshaded" materials look somewhat abstract because they ignore lighting and shading. Unshaded Materials work even if the scene does not include a light source. These Materials can be single-colored or textured. For example, they are used for cards and tiles, for the sky, billboards and UI elements, for toon-style games, or for testing.
</p>
<div><table>
<tr>
<th> Basic Material Definition </th><th> Usage </th><th> Parameter : Type </th>
<th> Basic Material Definition </th><th> Usage </th><th> Parameter </th>
</tr>
<tr>
<td> Common/MatDefs/Misc/Unshaded.j3md </td><td> Standard, non-illuminated Materials. Use this for simple coloring, simple texturing, simple glow, simple transparency. <br/>
See also: <ahref="/com/jme3/gde/core/docs/jme3/beginner/hello_material.html">Hello Material</a></td><td> ColorMap : Texture <br/>
Other useful, but less commonly used material definitions:
@ -65,23 +96,23 @@ Other useful, but less commonly used material definitions:
</p>
<div><table>
<tr>
<th> Special Material Definitions </th><th> Usage </th><th>Parameter : Type </th>
<th> Special Material Definitions </th><th> Usage </th><th>Setter, Parameter, Type </th>
</tr>
<tr>
<td> Common/MatDefs/Misc/Sky.j3md </td><td> A solid skyblue, or use with a custom SkyDome texture. <br/>
See also: <ahref="/com/jme3/gde/core/docs/jme3/advanced/sky.html">Sky</a></td><td>Texture : TextureCubeMap<br/>
SphereMap : Boolean<br/>
NormalScale : Vector3</td>
See also: <ahref="/com/jme3/gde/core/docs/jme3/advanced/sky.html">Sky</a></td><td>setTexture("TextureCubeMap", assetManager.loadTexture(""));<br/>
setBoolean("SphereMap",true);<br/>
setVector3("NormalScale", new Vector3f(0,0,0));</td>
</tr>
<tr>
<td> Common/MatDefs/Terrain/Terrain.j3md </td><td> Splat textures for e.g. terrains. <br/>
See also: <ahref="/com/jme3/gde/core/docs/jme3/beginner/hello_terrain.html">Hello Terrain</a></td><td>Texture1 : Texture (red) <br/>
Texture1Scale : Float<br/>
Texture2 : Texture (green) <br/>
Texture2Scale : Float<br/>
Texture3 : Texture (blue) <br/>
Texture3Scale : Float<br/>
Alpha : Texture</td>
See also: <ahref="/com/jme3/gde/core/docs/jme3/beginner/hello_terrain.html">Hello Terrain</a></td><td>setTexture("Texture1", assetManager.loadTexture("")); (red) <br/>
<td> Common/MatDefs/Misc/Particle.j3md </td><td> Used with texture masks for particle effects, or for point sprites. <br/>
The Quadratic value scales the particle for perspective view (<objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/core/com/jme3/effect/ParticleEmitter.java"><paramname="text"value="<html><u>formula</u></html>"><paramname="textColor"value="blue"></object>). <br/>
Does support an optional colored glow effect. <br/>
See also: <ahref="/com/jme3/gde/core/docs/jme3/beginner/hello_effects.html">Hello Effects</a></td><td>Texture : Texture<br/>
GlowMap : Texture<br/>
GlowColor : Color<br/>
Quadratic : Float<br/>
PointSprite : Boolean</td>
See also: <ahref="/com/jme3/gde/core/docs/jme3/beginner/hello_effects.html">Hello Effects</a></td><td>setTexture("Texture", assetManager.loadTexture(""));<br/>
Illuminated materials require a <ahref="/com/jme3/gde/core/docs/jme3/advanced/light_and_shadow.html">light source</a> added to at least one of their parent nodes! (e.g. rootNode) Illuminated materials are darker on the sides facing away from light sources. They do not automatically cast <ahref="/com/jme3/gde/core/docs/jme3/advanced/light_and_shadow.html">drop shadows</a>. They use Phong illumination model (default), or the Ward isotropic gaussian specular shader (WardIso) which looks more plastic like.
Illuminated materials require a <ahref="/com/jme3/gde/core/docs/jme3/advanced/light_and_shadow.html">light source</a> added to at least one of their parent nodes! (e.g. rootNode.) Illuminated materials are darker on the sides facing away from light sources. They use Phong illumination model (default), or the Ward isotropic gaussian specular shader (WardIso) which looks more like plastic. They do not cast <ahref="/com/jme3/gde/core/docs/jme3/advanced/light_and_shadow.html">drop shadows</a> unless you use a FilterPostProcessor.
</p>
<div><table>
<tr>
<th>Illuminated Material Definition </th><th> Usage </th><th>Parameters</th>
<th>Illuminated Material Definition </th><th> Usage </th><th>Setter, Parameter, Type</th>
</tr>
<tr>
<td> Common/MatDefs/Light/Lighting.j3md </td><td>Standard lit material with Phong Illumination. <br/>
<td> Common/MatDefs/Light/Lighting.j3md </td><td>Commonly used Material with Phong illumination. <br/>
Use this material together with DiffuseMap, SpecularMap, BumpMap (NormalMaps, ParalaxMap) textures. <br/>
Supports shininess, transparency, and plain material colors (Diffuse, Ambient, Specular colors). <br/>
See also: <ahref="/com/jme3/gde/core/docs/jme3/beginner/hello_material.html">Hello Material</a><br/>
Glowing materials require a <ahref="/com/jme3/gde/core/docs/jme3/advanced/bloom_and_glow.html">FilterPostProcessor</a>! </td><td> DiffuseMap : Texture<br/>
<th>Special Illuminated Material Definitions </th><th> Usage </th><th>Parameters</th>
<th>Special Illuminated Material Definitions </th><th> Usage </th><th>Setter, Parameter, Type</th>
</tr>
<tr>
<td>Common/MatDefs/Terrain/TerrainLighting.j3md</td><td>Same kind of multi-layered splat texture as Terrain.j3md, but with illumination and shading. <br/>
@ -177,69 +208,140 @@ For every 3 splat textures, you need one alpha map. <br/>
You can use a total of 11 texture maps in the terrain's splat texture: <br/>
Note that diffuse and normal maps all count against that. <br/>
For example, you can use a maximum of 9 diffuse textures, two of which can have normal maps; <br/>
or, five textures with both diffuse and normal maps.</td><td>Diffuse : Color <br/>
Ambient : Color <br/>
Shininess : Float <br/>
Specular : Color <br/>
SpecularMap : Texture <br/>
WardIso : Boolean <br/>
useTriPlanarMapping : Boolean <br/>
isTerrainGrid : Boolean <br/>
<strong>Texture Splat Maps</strong><br/>
DiffuseMap : Texture <br/>
DiffuseMap_0_scale : Float <br/>
NormalMap : Texture <br/>
DiffuseMap_1 : Texture <br/>
DiffuseMap_1_scale : Float <br/>
NormalMap_1 : Texture <br/>
DiffuseMap_2 : Texture <br/>
DiffuseMap_2_scale : Float <br/>
NormalMap_2 : Texture <br/>
DiffuseMap_3 : Texture <br/>
DiffuseMap_3_scale : Float <br/>
NormalMap_3 : Texture <br/>
or, five textures with both diffuse and normal maps.</td><td><strong>Texture Splat Maps</strong><br/>
<td> Common/MatDefs/Light/Reflection.j3md </td><td> Reflective glass material with environment map (CubeMap/SphereMap). See also: <objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/test/jme3test/texture/TestCubeMap.java"><paramname="text"value="<html><u>TestCubeMap.java</u></html>"><paramname="textColor"value="blue"></object></td><td> setTexture("Texture", assetManager.loadTexture("")); <br/>
setBoolean("SphereMap",true); </td>
</tr>
</table></div>
<!-- EDIT4 TABLE [8824-11115] -->
</div>
<h2><a>Testing and Debugging</a></h2>
<div>
<div><table>
<tr>
<td> Common/MatDefs/Light/Reflection.j3md </td><td> Reflective glass material with environment map (CubeMap/SphereMap). See also: <objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/test/jme3test/texture/TestCubeMap.java"><paramname="text"value="<html><u>TestCubeMap.java</u></html>"><paramname="textColor"value="blue"></object></td><td> Texture : Texture <br/>
SphereMap: Boolean </td>
<th> Material Definition </th><th> Usage </th>
</tr>
<tr>
<td> Common/MatDefs/Misc/ShowNormals.j3md </td><td> 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, or as fall-back default material. This built-in material has no parameters. </td>
</tr>
</table></div>
<!-- EDIT4 TABLE [6104-7693] -->
<!-- EDIT5 TABLE [11152-11509] -->
</div>
<h2><a>Activate Special Features</a></h2>
<div>
</div>
<h3><a>NormalMap (Bumpiness)</a></h3>
<div>
<p>
<p><div><strong>Shininess Tip:</strong> To deactivate Shininess, do not set <code>Shininess</code> to 0, but instead set the <code>Specular</code> color to <code>ColorRGBA.Black</code>!
</div></p>
A NormalMap (alos called BumpMap) describes the fine bumpy details of the Material surface that are not part of the mesh itself. E.g. cracks, pores, creases, notches.
</p>
<ol>
<li><div> Generate normals for the Mesh (not for the Geometry!) <pre>TangentBinormalGenerator.generate(mesh);</pre>
</div>
</li>
<li><div> Specify the <code>NormalMap</code> texture. (<objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://en.wikipedia.org/wiki/Bump_mapping"><paramname="text"value="<html><u>More about BumpMaps here.</u></html>"><paramname="textColor"value="blue"></object>)</div>
</li>
</ol>
</div>
<h3><a>Specular (Shininess)</a></h3>
<div>
<p>
<p><div><strong>Bumpiness Tip:</strong> Before you can use NormalMaps, you must generate normals for the mesh (not the Geometry). <code>TangentBinormalGenerator.generate(mesh);</code>
</div></p>
To activate Shininess:
</p>
<ol>
<li><div> Specify the <code>Shininess</code> intensity. <br/>
A float value between 1 (rough surface with blurry shininess) and 128 (very smooth surface with focused shininess)</div>
</li>
<li><div> Specify a Color as <code>Specular</code> value. <br/>
The ColorRGBA value of the light source, e.g. often RGBA.White.</div>
</li>
<li><div> (Optionally for some Materials) Specify a <code>SpecularMap</code> texture. <br/>
This grayscale texture outlines in detail where the DiffuseMap texture should be shiny (white) and were not (black), instead of rendering the whole material evenly shiny.</div>
</li>
</ol>
<p>
To deactivate shininess
</p>
<ul>
<li><div> Set the <code>Specular</code> color to <code>ColorRGBA.Black</code>. Do not just set <code>Shininess</code> to 0.</div>
</li>
</ul>
</div>
<h2><a>Testing and Debugging</a></h2>
<h3><a>Glow</a></h3>
<div>
<div><table>
<tr>
<th> Material Definition </th><th> Usage </th><th> Parameters </th>
</tr>
<tr>
<td> Common/MatDefs/Misc/ShowNormals.j3md </td><td> A color gradient calculated from the model's surface normals. You can use this built-in material to test models that have no material, or as fall-back default material. </td><td> – </td>
</tr>
</table></div>
<!-- EDIT5 TABLE [8058-8343] -->
<p>
To activate glow:
</p>
<ol>
<li><div> Add a <ahref="/com/jme3/gde/core/docs/jme3/advanced/bloom_and_glow.html">FilterPostProcessor</a> in your simpleInit() method.</div>
</li>
<li><div> Specify a Color as <code>Glow</code> value. <br/>
A ColorRGBA value of your choice, e.g. choose a warm or cold color for different effects.</div>
</li>
<li><div> (Optionally for some Materials) Specify a <code>GlowMap</code> texture. <br/>
This texture outlines in detail where the DiffuseMap texture glows, instead of making the whole material glow everwhere evenly.</div>
</li>
</ol>
<p>
To deactivate glow
</p>
<ul>
<li><div> Set the <code>Glow</code> color to <code>ColorRGBA.Black</code>.</div>
</li>
</ul>
</div>
<h2><a>Transparency</a></h2>
<h3><a>Transparency</a></h3>
<div>
<p>
@ -253,80 +355,83 @@ Additionally, you must specify a blendmode:
<td>mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);</td><td>Use this for normal transparency. Interpolates the background pixel with the current pixel by using the current pixel's alpha.</td><td>Hair texture, window panes, ice, glass, alpha-blended vegetation textures.</td>
<td>getAdditionalRenderState().setBlendMode(BlendMode.Alpha);</td><td>Interpolates the background pixel with the current pixel by using the current pixel's alpha.</td><td>Use this for normal every-day translucency: Frosted window panes, ice, glass, alpha-blended vegetation textures…</td>
</tr>
<tr>
<td>mat.getAdditionalRenderState().setDepthWrite(false);</td><td>Use this on materials if you have several transparent objects obscuring one another. Disables writing of the pixel's depth value to the depth buffer.</td>
<td>getAdditionalRenderState().setDepthWrite(false);</td><td>Disables writing of the pixel's depth value to the depth buffer.</td><td>Use this on Materials if you have several transparent/translucent objects obscuring one another, but you want to see through both.</td>
mat.getAdditionalRenderState().setAlphaTest(true)</td><td>Enables alpha test. Works the same way as "AlphaDiscardThreshold".</td><td>Generally used for vegetation etc.</td>
getAdditionalRenderState().setAlphaTest(true)</td><td>Enables alpha test. Works the same way as "AlphaDiscardThreshold".</td><td>Used for textures that have fully opaque pixels next to fully transparent pixels, e.g. foliage, hair, vegetation.</td>
</tr>
<tr>
<td>mat.getAdditionalRenderState().setBlendMode(BlendMode.Additive);</td><td>Additive alpha blending adds colors in a commutative way, i.e. the result does not depend on the order of transparent layers. Adds the scene's background pixel color to the current pixel color. Note that viewed in front of a white scene, these textures become fully transparent. This is useful if you have many transparent textures overlapping.</td><td>Used for particle effect textures that have a black color background. </td>
<td>getAdditionalRenderState().setBlendMode(BlendMode.Additive);</td><td>Additive alpha blending adds colors in a commutative way, i.e. the result does not depend on the order of transparent layers, since it adds the scene's background pixel color to the current pixel color. This is useful if you have lots of transparent textures overlapping and don't care about the order. <br/>
Viewed in front of a white background, Additive textures become fully transparent! </td><td>Used for particle effect textures that have a black color background. </td>
</tr>
<tr>
<td>mat.getAdditionalRenderState().setBlendMode(BlendMode.AlphaAdditive);</td><td>Same as "Additive", except first it multiplies the current pixel color by the pixel alpha.</td><td>Used for particle effects that have alpha as background. </td>
<td>getAdditionalRenderState().setBlendMode(BlendMode.AlphaAdditive);</td><td>Same as "Additive", except first it multiplies the current pixel color by the pixel alpha.</td><td>Used for particle effects that have alpha as background. </td>
</tr>
<tr>
<td>mat.getAdditionalRenderState().setBlendMode(BlendMode.Color);</td><td>Blends by color.</td><td>Generally useless.</td>
<td>getAdditionalRenderState().setBlendMode(BlendMode.Color);</td><td>Blends by color.</td><td>Generally useless.</td>
</tr>
<tr>
<td>mat.getAdditionalRenderState().setBlendMode(BlendMode.Modulate);</td><td>Multiplies the background pixel by the current pixel.</td>
<td>getAdditionalRenderState().setBlendMode(BlendMode.Modulate);</td><td>Multiplies the background pixel by the current pixel.</td><td>?</td>
</tr>
<tr>
<td>mat.getAdditionalRenderState().setBlendMode(BlendMode.ModulateX2);</td><td>Same as "Modulate", except the result is doubled.</td>
<td>getAdditionalRenderState().setBlendMode(BlendMode.ModulateX2);</td><td>Same as "Modulate", except the result is doubled.</td><td>?</td>
</tr>
<tr>
<td>mat.getAdditionalRenderState().setBlendMode(BlendMode.PremultAlpha);</td><td>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.</td><td>For use with premult alpha textures.</td>
<td>getAdditionalRenderState().setBlendMode(BlendMode.PremultAlpha);</td><td>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.</td><td>For use with Premult Alpha textures.</td>
</tr>
</table></div>
<!-- EDIT6 TABLE [8698-10778] -->
<!-- EDIT6 TABLE [13546-15768] -->
<p>
Also note the AlphaDiscardThreshold value for materials based on Lighting.j3md. The renderer does not render pixels whose transparancy is below the threshold.
<p><div>For partially transparent Materials based on Lighting.j3md, consider setting the <code>AlphaDiscardThreshold</code> value. The renderer only renders pixels above your alpha threshold, and does not render pixels below the threshold. This means, that gradients in the AlphaMap are no longer interpreted as soft translucency, but parts of the texture become either fully opaque or fully transparent. You typically activate Alpha Testing for partially transparent objects such as foliage, hair, etc.
<td>mat.getAdditionalRenderState().setWireframe(true);</td><td>Switch to showing the (textured) Material in wireframe mode</td>
<td>getAdditionalRenderState().setWireframe(true);</td><td>Switch to showing the (textured) Material in wireframe mode. For debugging or "matrix/holodeck" effect.</td><td></td>
</tr>
<tr>
<td>mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Back); </td><td>Activate back-face culling. Mesh faces that are not visible are not rendered, which saves time. Backface culling is activated by default as an optimization.</td>
<td>getAdditionalRenderState().setFaceCullMode(FaceCullMode.Back); </td><td>Activate back-face culling. Mesh faces that are not facing the camera are not rendered, which saves time. Backface culling is activated by default as a major optimization.</td><td>The backside of mesh polygons (and the inside of models) is invisible. </td>
</tr>
<tr>
<td>mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off); </td><td>No culling. All meshes are rendered even if they are out of view. Slow.</td>
<td>getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off); </td><td>Nothing is culled. Both mesh faces are rendered, even if they face away from the camera. Slow.</td><td>Sometimes used to debug custom meshes if you messed up some of the polygon sides, or for special shadow effects.</td>
</tr>
<tr>
<td>mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Front); </td><td>Activate front-face culling. Mesh faces facing the camera are not rendered.Typically not used.</td>
<td>getAdditionalRenderState().setFaceCullMode(FaceCullMode.Front); </td><td>Activate front-face culling. Mesh faces facing the camera are not rendered.</td><td>Typically not used.</td>
</tr>
<tr>
<td>mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.FrontAndBack)</td><td>Activate both back- and frontface culling. Use this as an efficient way to make an object temporarily invisible. All it's other in-game properties, collision shapes, interactions, etc remain active.</td>
<td>getAdditionalRenderState().setFaceCullMode(FaceCullMode.FrontAndBack)</td><td>Cull both backfaces and frontfaces.</td><td>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.</td>
</tr>
<tr>
<td>mat.getAdditionalRenderState().setColorWrite(false);</td><td>Disable writing the color of pixels.Use this together with setDepthWrite(true) to write pixels only to the depth buffer, for example. </td>
<td>getAdditionalRenderState().setColorWrite(false);</td><td>Disable writing the color of pixels.</td><td>Use this together with setDepthWrite(true) to write pixels only to the depth buffer, for example. </td>
</tr>
<tr>
<td>mat.getAdditionalRenderState().setPointSprite(true);</td><td>Enables point-sprite mode, so meshes with "Mode.Points" will be rendered as textured sprites. Note that gl_PointCoord must be set in the shader.Point sprites are used for hardware accelerated particle effects.</td>
<td>getAdditionalRenderState().setPointSprite(true);</td><td>Enables point-sprite mode, e.g. meshes with "Mode.Points" will be rendered as textured sprites. Note that gl_PointCoord must be set in the shader.</td><td>Point sprites are used internally for hardware accelerated particle effects.</td>
</tr>
<tr>
<td>mat.getAdditionalRenderState().setPolyOffset();</td><td>Enable polygon offset.Use this when you have meshes that have triangles really close to each over (e.g. <objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://en.wikipedia.org/wiki/Coplanarity"><paramname="text"value="<html><u>Coplanar</u></html>"><paramname="textColor"value="blue"></object>), it will shift the depth values to prevent <objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://en.wikipedia.org/wiki/Z-fighting"><paramname="text"value="<html><u>Z-fighting</u></html>"><paramname="textColor"value="blue"></object>.</td>
<td>getAdditionalRenderState().setPolyOffset();</td><td>Enable polygon offset.</td><td>Use this when you have meshes that have triangles really close to each over (e.g. <objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://en.wikipedia.org/wiki/Coplanarity"><paramname="text"value="<html><u>Coplanar</u></html>"><paramname="textColor"value="blue"></object>), it will shift the depth values to prevent <objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://en.wikipedia.org/wiki/Z-fighting"><paramname="text"value="<html><u>Z-fighting</u></html>"><paramname="textColor"value="blue"></object>.</td>
@ -444,15 +444,9 @@ Use the following methods to move physics objects.
<tr>
<td> applyForce(…) </td><td> Move (push) the object once with a certain moment, expressed as a Vector3f. Optionally, you can specify where on the object the pushing force hits. </td>
</tr>
<tr>
<td> applyContinuousForce(…) </td><td> Keep moving (pushing) the object with continuous force in one direction, expressed as a Vector3f. Optionally, you can specifiy where on the object the pushing force hits. You can <code>applyContinuousForce(false)</code> to stop the force. </td>
</tr>
<tr>
<td> applyTorque(…) </td><td> Rotate (twist) the object once around its axes, expressed as a Vector3f. </td>
</tr>
<tr>
<td> applyContinuousTorque(…) </td><td> Keep rotating (twisting) the object continuously around its axes, expressed as a Vector3f. You can <code>applyContinuousTorque(false)</code> to stop the rotation.</td>
</tr>
<tr>
<td> applyImpulse(…) </td><td> An idealised change of momentum. This is the kind of push that you would use on a pool billiard ball. </td>
</tr>
@ -466,7 +460,7 @@ Use the following methods to move physics objects.
<td>clearForces()</td><td>Cancels out all forces (force, torque) etc and stops the motion.</td>
</tr>
</table></div>
<!-- EDIT5 TABLE [13584-15257] -->
<!-- EDIT5 TABLE [13584-14809] -->
<p>
<strong>Note:</strong> It is technically possible to position PhysicsControls using setLocalTranslation(), e.g. to place them in their start position in the scene. However you must be very careful not to cause an "impossible state" where one physical object overlaps with another! Within the game, you typically use the setters shown here exclusively.
@ -501,7 +495,7 @@ removeCollideWithGroup(COLLISION_GROUP_01)</td><td>Collision Groups are integer
<td> setSleepingThreshold(float,float)</td><td>Sets the sleeping thresholds wich define when the object gets deactivated to save ressources. Low values keep the object active when it barely moves. The first value is the linear threshold and the second the angular.</td>
<li><div> com.jme3.scene.shape.Dome – A semi-sphere, e.g. SkyDome.</div>
<ul>
<li><div> For a cone, set the Dome's radialSamples>4 and planes=2. </div>
@ -28,9 +43,11 @@ The simplest type of Meshes are the built-in JME Shapes. You can create Shapes w
</li>
</ul>
</li>
</ul>
<ul>
<li><div> com.jme3.scene.shape.Torus – An single-holed torus or "donut".</div>
</li>
<li><div> com.jme3.scene.shape.PQTorus – A parameterized torus. A PQ-Torus looks like a <objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://en.wikipedia.org/wiki/Torus_knot"><paramname="text"value="<html><u>donut knotted into spirals</u></html>"><paramname="textColor"value="blue"></object>.</div>
<li><div> com.jme3.scene.shape.PQTorus – A parameterized torus. A PQ-Torus looks like a <objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://en.wikipedia.org/wiki/Torus_knot"><paramname="text"value="<html><u>donut knotted into spirals</u></html>"><paramname="textColor"value="blue"></object>.<imgsrc="nbdocs:/com/jme3/gde/core/docs/jme3/advanced/nurbs_3-d_surface.png"><imgsrc="nbdocs:/com/jme3/gde/core/docs/jme3/advanced/220px-trefoil_knot_arb.png"><imgsrc="/wiki/lib/exe/fetch.php"></div>
</li>
<li><div> com.jme3.scene.shape.Surface – A curved surface (called <objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://en.wikipedia.org/wiki/File:NURBS_3-D_surface.gif"><paramname="text"value="<html><u>NURBS</u></html>"><paramname="textColor"value="blue"></object>) described by knots, weights and control points. Compare with shape.Curve.</div>
</li>
@ -38,7 +55,7 @@ The simplest type of Meshes are the built-in JME Shapes. You can create Shapes w
</div>
<h2><a>List of Non-3D shapes</a></h2>
<h2><a>Non-3D shapes</a></h2>
<div>
<ul>
<li><div> com.jme3.scene.shape.Quad – A flat 2D rectangle (has two sides)</div>
@ -51,10 +68,11 @@ The simplest type of Meshes are the built-in JME Shapes. You can create Shapes w
</div>
<h3><a>Math versus Shape?</a></h3>
<h4><a>Math versus Shape?</a></h4>
<div>
<p>
Do not mix up these visible Shapes with similarly named classes from the maths package. Choose the right package when letting your IDE fill in the import statements!
</p>
<ul>
@ -70,7 +88,6 @@ Do not mix up these visible Shapes with similarly named classes from the maths p
<p>
These maths objects are invisible and are used for collision testing (ray casting) or to describe motion paths. They cannot be wrapped into a Geometry.
</p>
</div>
@ -80,7 +97,7 @@ These maths objects are invisible and are used for collision testing (ray castin
</div>
<h3><a>Basic Usage</a></h3>
<h4><a>Basic Usage</a></h4>
<div>
<p>
@ -99,7 +116,7 @@ To add a shape to the scene:
</div>
<h3><a>Complex Shapes</a></h3>
<h4><a>Complex Shapes</a></h4>
<div>
<p>
@ -119,11 +136,7 @@ You can compose more complex custom Geometries out of simple Shapes. Think of th
</ol>
<p>
The order is important: First arrange around origin, then transform. Otherwise, transformations are applied around the wrong center (pivot). Of course, you can attach your constellation to other pivot Nodes to create even more complex shapes (a chair, a furnished room, a house, a city, …), but again, arrange them around the origin first before you transform them.
<br/>
Note: Obviously, these composed Geometries are simpler than hand-sculpted meshes from a mesh editor.
The order is important: First arrange around origin, then transform. Otherwise, transformations are applied around the wrong center (pivot). Of course, you can attach your constellation to other pivot Nodes to create even more complex shapes (a chair, a furnished room, a house, a city, …), but again, arrange them around the origin first before you transform them. Obviously, such composed Geometries are simpler than hand-sculpted meshes from a mesh editor.
@ -11,9 +11,12 @@ This is a draft of a feature that is work in progress. If you have questions or
<h2><a>Requirements</a></h2>
<div>
</div>
<h3><a>Developer Requirements</a></h3>
<div>
<ul>
<li><div> Android device that supports OpenGL ES 2.0</div>
</li>
<li><div> Install <objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://developer.android.com/sdk/index.html"><paramname="text"value="<html><u>Android SDK 2.2</u></html>"><paramname="textColor"value="blue"></object> or better.</div>
</li>
<li><div> Install jMonkeyEngine <acronymtitle="Software Development Kit">SDK</acronym></div>
@ -34,6 +37,19 @@ This is a draft of a feature that is work in progress. If you have questions or
</div>
<h3><a>User Requirements</a></h3>
<div>
<ul>
<li><div> Android 2.2 device or better</div>
</li>
<li><div> Graphic card that supports OpenGL ES 2.0 or better</div>
</li>
<li><div><objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://jmonkeyengine.org/groups/android/forum/topic/does-my-phone-meet-the-requirements-necessary-to-run-jmonkeyengine-3/"><paramname="text"value="<html><u>Does my phone meet the requirements necessary to run jMonkeyEngine 3?</u></html>"><paramname="textColor"value="blue"></object></div>
@ -109,22 +109,37 @@ A rotating object is just a simple example. In the update loop, you typically ha
</div>
<h2><a>Init versus Update</a></h2>
<h2><a>Init - Update - Render</a></h2>
<div>
<p>
Note the contrast: The <code>simpleUpdate()</code> method runs repeatedly, while the <code>simpleInitApp()</code> method is executed only once, right at the beginning. These two are the most important methods in a SimpleApplication-derived game. From these two methods, you create other class instances (your game data) and change their properties (your game state).
Note the contrast:
</p>
<ul>
<li><div> The <code>simpleInitApp()</code> method is executed only once, right at the beginning; </div>
</li>
<li><div> The <code>simpleUpdate()</code> method runs repeatedly, during the game. </div>
</li>
<li><div> After every update, the jMonkeyEngine automatically redraws (<code>renders</code>) the screen for you!</div>
</li>
</ul>
<p>
Since rendering is automatic, initialization and updating are the two most important concepts in a SimpleApplication for you right now. These methods are where you load and create game data (once), and (repeatedly) change their properties to update the game state:
</p>
<ul>
<li><div><code>simpleInitApp()</code> is the application's "first breath".</div>
</li>
<li><div><code>simpleUpdate()</code> is the application's heartbeat.</div>
<li><div><code>simpleUpdate()</code> is the application's heartbeat. <br/>
The update time unit is called <code>ticks</code>.</div>
</li>
</ul>
<p>
Basically everything in your game happens in either one or the other method. This means that these methods grow very long over time. There are two strategies how advanced developers can spread out their init and update code over several Java classes:
<p><div>Everything in a game happens either during initialization or during the update loop. This means that these two methods grow very long over time. There are two strategies how experienced developers spread out their init and update code over several Java classes:
</p>
<ul>
<li><div> Move code blocks from the simpleInitApp() method to <ahref="/com/jme3/gde/core/docs/jme3/advanced/application_states.html">AppStates</a>.</div>
@ -134,7 +149,9 @@ Basically everything in your game happens in either one or the other method. Thi
</ul>
<p>
Keep this in mind for later when your game application grows.
Keep this in mind for later when your application grows.
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.
<form><div><inputtype="hidden"name="do"value="login"/><inputtype="hidden"name="sectok"value="b273fed70c8f61e2ac778ef448e51618"/><inputtype="submit"value="Login"class="button"title="Login"/></div></form><form><div><inputtype="hidden"name="do"value="index"/><inputtype="submit"value="Sitemap"class="button"accesskey="x"title="Sitemap [X]"/></div></form><a><inputtype="button"class="button"value="Back to top"onclick="window.scrollTo(0, 0)"title="Back to top"/></a>
<form><div><inputtype="hidden"name="do"value="login"/><inputtype="hidden"name="sectok"value="6f139d65a3f955caf3492f84be10ab4e"/><inputtype="submit"value="Login"class="button"title="Login"/></div></form><form><div><inputtype="hidden"name="do"value="index"/><inputtype="submit"value="Sitemap"class="button"accesskey="x"title="Sitemap [X]"/></div></form><a><inputtype="button"class="button"value="Back to top"onclick="window.scrollTo(0, 0)"title="Back to top"/></a>
</div>
<div></div>
</div-->
@ -348,16 +349,9 @@ You've followed a link to a topic that doesn't exist yet. If permissio
@ -60,12 +64,8 @@ The <strong>jME Context</strong> makes settings, renderer, timer, input and even
<p>
Coordinates represent a location in a coordinate system, relative to the origin (0,0,0). m. In 3D space, you need to specify three coordinate values to locate a point: x,y,z.
As opposed to a vector (which looks similar), a coordinate does not have a "direction".
Coordinates represent a location in a coordinate system. Coordinates are relative to the origin at (0,0,0). In 3D space, you need to specify three coordinate values to locate a point: X (right), Y (up), Z (towards you).
In contrast to a vector (which looks similar), a coordinate is a location, not a direction.
</p>
</div>
@ -75,8 +75,11 @@ As opposed to a vector (which looks similar), a coordinate does not have a "
<p>
The origin is the central point in the 3D world. It's at the coordinates (0,0,0).
Code sample: <code>Vector3f origin = new Vector3f( Vector3f.ZERO );</code>
The origin is the central point in the 3D world, where the three axes meet. It's at the coordinates (0,0,0).
</p>
<p>
<strong>Example:</strong><code>Vector3f origin = new Vector3f( Vector3f.ZERO );</code>
A vector has a length and a direction. It is used like an arrow pointing at a point in 3D space. A vector starts at the origin (0,0,0), and ends at the target coordinate (x,y,z). Backwards directions are expressed with negative values.
Code sample: <code>Vector3f v = new Vector3f( 17 , -4 , 0 );</code>
A vector has a length and a direction, like an arrow in 3D space. A vector starts at the origin (0,0,0), and ends at the target coordinate (x,y,z). Backwards directions are expressed with negative values.
</p>
<p>
<strong>Example:</strong><code>Vector3f v = new Vector3f( 17 , -4 , 0 );</code>
</p>
</div>
@ -131,12 +137,12 @@ When you normalize a vector, it still has the same direction, but you lose the i
</div>
<h3><a>Surface Normals</a></h3>
<h3><a>Surface Normal Vectors</a></h3>
<div>
<p>
A surface normal is a vector that is perpendicular to a plane.
A surface normal is a vector that is perpendicular (orthogonal) to a plane.
You calculate the Surface Normal by calculating the cross product.
</p>
@ -288,7 +294,13 @@ Set the Specular color to ColorRGBA.Black to switch off shininess.</div>
<p>
Textures are part of Materials. In the simplest case, an object could have just one texture, the Color Map, loaded from one image file. When you think back of old computer games you'll remember this looks quite plain.
</p>
<p>
The more information you (the game designer) provide additionally to the Color Map, the higher the degree of detail and realism. Whether you want photo-realistic rendering or "toon" rendering (Cel Shading), everything depends on the quality of your materials and texture maps. Modern 3D graphics use several layers of information to describe one material, each layer is a Texture Map.
<p><div>You have no textures? <objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://opengameart.org"><paramname="text"value="<html><u>Download free textures</u></html>"><paramname="textColor"value="blue"></object> (including texture maps) from opengameart.org.
</div></p>
</p>
</div>
@ -298,44 +310,39 @@ The more information you (the game designer) provide additionally to the Color M
</div>
<h3><a>Color Map</a></h3>
<h3><a>Color Map / Diffuse Map</a></h3>
<div>
<p>
<imgsrc="/wiki/lib/exe/fetch.php">
</p>
<ul>
<li><div> A simple image file (or a procedural texture).</div>
<li><div> A plain image file or a procedural texture that describes an object's visible surface.</div>
</li>
<li><div> The image can have alpha channels for transparency.</div>
</li>
<li><div><strong>A color map is the minimum texture you need.</strong> All other texture maps are optional improvements.</div>
<li><div><strong>A Color Map is the minimum texture.</strong> You can add texture maps as optional improvements. </div>
</li>
<li><div> Color Maps are called Diffuse Map in a Phong-illuminated Material, because the map defines the basic colors of light that are diffused by this object.</div>
</li>
</ul>
<p>
<imgsrc="/wiki/lib/exe/fetch.php">
</p>
</div>
<h3><a>Diffuse Map</a></h3>
<h3><a>Bump Map</a></h3>
<div>
<p>
Bump maps are used to describe detailed shapes that would be too hard or simply too inefficient to sculpt in a mesh editor. There are two types:
</p>
<ul>
<li><div> The Diffuse Map specifies the intensity of color.</div>
<li><div>You use Normal Maps to model tiny details such as cracks in walls, rust, skin texture, or a canvas weave ( (<objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://en.wikipedia.org/wiki/Bump_mapping"><paramname="text"value="<html><u>More on BumpMaps</u></html>"><paramname="textColor"value="blue"></object>). </div>
</li>
<li><div> Its basically the same as a Color Map but its called Diffuse Map in a lighting environment, as it defines the color the object "diffuses".</div>
<li><div>You use Height Maps to model large terrains with valleys and mountains.</div>
</li>
</ul>
</div>
<h3><a>Bump Map</a></h3>
<div>
<p>
Bump maps are used to describe detailed shapes that would be too hard or simply too inefficient to sculpt in a mesh editor. You use Normal Maps to model cracks in walls, rust, skin texture, or a canvas weave. You use Height Maps to model whole terrains with valleys and mountains.
<imgsrc="/wiki/lib/exe/fetch.php">
</p>
@ -364,9 +371,9 @@ Bump maps are used to describe detailed shapes that would be too hard or simply
<ul>
<li><div> A well-done Normal Map makes a shape more detailed – without the need to add costly polygons to the mesh. It contains shading information that makes the object appear smoother and more fine-grained.</div>
</li>
<li><div>The Normal Map is displayed looking like a false-color version of the Color Map–but it is never used for coloring, instead, each RGB value encodes transformation data. This displacement data is represented by Surface Normals of the slopes, hence the name.</div>
<li><div>When you open a Normal Map in an image editor, it looks like a false-color version of the Color Map. Normal maps however are never used for coloring, instead, each the color values encode displacement data of bumps and cracks on the surface. Displacement data is represented by the Surface Normals of the slopes, hence the name.</div>
</li>
<li><div>It's hard to draw normal maps by hand. Generally you use software tools to calculate them off 3D models.</div>
<li><div>You cannot draw normal maps by hand, professional designers use software to calculate them off high-quality 3D models. </div>
</li>
</ul>
@ -381,9 +388,9 @@ Bump maps are used to describe detailed shapes that would be too hard or simply
<ul>
<li><div> A Specular Map further improves the realism of an object's surface: It contains extra information about shininess and makes the shape appear more realistically illumated.</div>
</li>
<li><div> Start out with a gray value that corresponds to the average shininess/dullness of this material. Then add ligher grays for smoother, shinier, more reflective areas; and darker grays for duller, rougher, worn-out areas. The resulting image file looks similar to a grayscale version of the Color Map.</div>
<li><div> Start out with a copy of the Diffuse Map in a medium gray that corresponds to the average shininess/dullness of this material. Then add ligher grays for smoother, shinier, more reflective areas; and darker grays for duller, rougher, worn-out areas. The resulting image file looks similar to a grayscale version of the Diffuse Map.</div>
</li>
<li><div> You can use colors in a specular map to create certain reflective effects (iridiscence, metallic).</div>
<li><div> You can use colors in a specular map to create certain reflective effects (fake iridiscence, metallic effect).</div>
</li>
</ul>
@ -394,9 +401,11 @@ Bump maps are used to describe detailed shapes that would be too hard or simply
<p>
<imgsrc="/wiki/lib/exe/fetch.php">
This is a very simple, commonly used type of texture. When texturing a wide area (e.g. walls, floors), you don't create one huge texture, instead you tile a small texture repeatedly to fill the area.
A seamless texture is an image file that has been designed so that it can be used as tiles: The right edge matches the left edge, and the top edge matches the bottom edge. The onlooker cannot easily tell where one starts and the next one ends, thus creating an illusion of a huge texture. The downside is that the tiling becomes painfully obvious when the area is viewed from a distance. Also you cannot use it on more complex models such as characters.
Tiles are a very simple, commonly used type of texture. When texturing a wide area (e.g. walls, floors), you don't create one huge texture – instead you tile a small texture repeatedly to fill the area.
</p>
<p>
A seamless texture is an image file that has been designed so that it can be used as tiles: The right edge matches the left edge, and the top edge matches the bottom edge. The onlooker cannot easily tell where one starts and the next one ends, thus creating an illusion of a huge texture. The downside is that the tiling becomes painfully obvious when the area is viewed from a distance. Also you cannot use it on more complex models such as characters.
</p>
</div>
@ -410,7 +419,7 @@ A seamless texture is an image file that has been designed so that it can be use
</p>
<p>
Creating a texture for a cube is easy – but what about a character with a face and extremities? For more complex objects, you design the texture in the same ways as a sewing pattern: One image file contains the outline of the front, back, and side of the object, next to one another. Specific areas of the flat texture (UV coordinates) map onto certain areas of your 3D model (XYZ coordinates), hence the name UV map. Using UV Maps, models can have a different texture on each side.
Creating a texture for a cube is easy – but what about a character with a face and extremities? For more complex objects, you design the texture in the same ways as a flat sewing pattern: One image file contains the outline of the front, back, and side of the object, next to one another. Specific areas of the flat texture (UV coordinates) map onto certain areas of your 3D model (XYZ coordinates), hence the name UV map. Using UV Maps, one model can have different textures on each side.
</p>
<p>
@ -428,8 +437,11 @@ Getting the seams and mappings right is crucial: You must use a graphic tool lik
</p>
<p>
Environment Maps are used to create the impression of reflections and refractions. You create a Cube Map to represent your environment, similar to a skybox. (Sphere Maps are possible, but often look too distorted.) You give the Cube Map a set of images showing a "360° view" of the completed scene. The renderer uses this as base to texture the reflective surface.
Of course these reflections are static and not "real", e.g. the player will not see his avatar's face reflected, etc… But they cause the desired "glass/mirror/water" effect, and are fast enough to render in real usecases, it's better than nothing.
Environment Maps are used to create the impression of reflections and refractions. You create a Cube Map to represent your environment, similar to a skybox. (Sphere Maps are possible, but often look distorted.) You give the Cube Map a set of images showing a "360° view" of the completed scene. The renderer uses this as base to texture the reflective surface.
</p>
<p>
Of course the reflected environment is static and not "real", e.g. the player will not see his avatar's face reflected, etc. But EnvMaps cause the desired "glass/mirror/water" effect, and are fast enough to render in real usecases.
</p>
</div>
@ -439,7 +451,7 @@ Of course these reflections are static and not "real", e.g. the player
<p>
You provide the texture in two or three resolutions to be stored in one file (MIP = "multum in parvo" = "many in one"). Depending on how close (or far) the camera is, the engine automatically renders a more (or less) detailed texture for the object. Thus objects look smooth from close up, but don't waste resources with unspottable details when far away. Good for everything, but requires more time to create and more space to store textures.
MIP Map means that you provide one texture in two or three resolutions in one file (MIP = "multum in parvo" = "many in one"). Depending on how close (or far) the camera is, the engine automatically renders a more (or less) detailed texture for the object. Thus objects look smooth from close up, but don't waste resources with unspottable details when far away. Good for everything, but requires more time to create and more space to store textures. If you don't provide custom ones, the jMonkeyEngine creates basic MIP maps automatically as an optimization.
</p>
</div>
@ -449,7 +461,7 @@ You provide the texture in two or three resolutions to be stored in one file (MI
<p>
A procedural texture is generated from repeating one small image, plus some pseudo-random, gradient variations (Perlin noise). Procedural textures look more natural than static rectangular textures, for instance, they look less distorted on spheres. On big meshes, their repetitiveness is much less noticable than tiled seamless textures. Procedural textures are ideal for irregular large-area textures like grass, soil, rock, rust, and walls. See also:<objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://jmonkeyengine.org/wiki/doku.php/sdk:neotexture"><paramname="text"value="<html><u>jMonkeyEngine SDK NeoTexture plugin</u></html>"><paramname="textColor"value="blue"></object>
A procedural texture is generated from repeating one small image, plus some pseudo-random, gradient variations (called Perlin noise). Procedural textures look more natural than static rectangular textures, and they look less distorted on spheres. On big meshes, their repetitiveness is much less noticable than with tiled seamless textures. Procedural textures are ideal for irregular large-area textures like grass, soil, rock, rust, and walls. Use the<objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://jmonkeyengine.org/wiki/doku.php/sdk:neotexture"><paramname="text"value="<html><u>jMonkeyEngine SDK NeoTexture plugin</u></html>"><paramname="textColor"value="blue"></object> to create them.
</p>
<p>
@ -467,8 +479,11 @@ See also: <object classid="java:org.netbeans.modules.javahelp.BrowserDisplayer">
<p>
In 3D games, Skeletal Animation is used for animated characters, but in principle the skeleton approach can be extended to any 3D mesh (for example, an opening crate's hinge can be considered a joint).
Unless you animate a 3D cartoon, realism of animated characters is generally a problem: Movement can look alien-like mechanical or broken, the character appears hollow, or as if floating. Professional game designers invest a lot of effort to make characters animate in a natural way (including motion capturing).
In 3D games, Skeletal Animation is used for animated characters, but in principle the skeleton approach can be extended to any 3D mesh (for example, an opening crate's hinge can be considered a primitive joint).
</p>
<p>
Unless you animate a 3D cartoon, realism of animated characters is generally a problem: Movement can look alien-like mechanical or broken, the character appears hollow, or as if floating. Professional game designers invest a lot of effort to make characters animate in a natural way, including <objectclassid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><paramname="content"value="http://en.wikipedia.org/wiki/Motion_capture"><paramname="text"value="<html><u>motion capture</u></html>"><paramname="textColor"value="blue"></object>.