diff --git a/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/300px-surface_normal.png b/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/300px-surface_normal.png new file mode 100644 index 000000000..3723ad341 Binary files /dev/null and b/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/300px-surface_normal.png differ diff --git a/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/advanced/220px-trefoil_knot_arb.png b/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/advanced/220px-trefoil_knot_arb.png new file mode 100644 index 000000000..8974e487e Binary files /dev/null and b/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/advanced/220px-trefoil_knot_arb.png differ diff --git a/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/advanced/collision_and_intersection.html b/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/advanced/collision_and_intersection.html index 38f8068c7..900144f9e 100644 --- a/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/advanced/collision_and_intersection.html +++ b/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/advanced/collision_and_intersection.html @@ -4,45 +4,20 @@
-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 physical interactions (where physical objects collide, push and bump off one another), and also to non-physical intersections in 3D space. This article is about the non-physical (mathematical) collisions.
-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 mouse picking 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.
-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. +Example: 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.
-- -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. -
-- -Note: Physical objects have their own "bounding volumes" called CollisionShapes. -
- -@@ -73,7 +48,7 @@ Note that jME counts all collisions, this means a ray intersecting a bo
A CollisionResult object contains information about the second party of the collision event.
@@ -100,7 +75,7 @@ A CollisionResult object contains information about the second party of the coll
-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 Collidable
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.
-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. +
+ ++Supported types: +
-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. +
-Learn how to implement Mouse Picking here. + +For example you can use Bounding Volumes on custom meshes, or complex non-physical shapes. +
+mesh.setBound(new BoundingSphere()); +q.updateBound();
-com.jme3.collision.bih.BIHNode -com.jme3.scene.CollisionData +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).
-+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. +
++ +
+Learn the details of how to implement Mouse Picking here. +
++TODO:
+com.jme3.scene.Mesh
.
-Mesh m = new Mesh();+
Mesh mesh = new Mesh();+ +
+
+If you create your own Mesh-based class, replace mesh
by this
in the following examples:
+
+
public class MyMesh extends Mesh { }@@ -110,13 +117,13 @@ The Mesh data is stored in a buffer.
m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices)); -m.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord)); -m.setBuffer(Type.Index, 1, BufferUtils.createIntBuffer(indexes)); -m.updateBound();+
mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices)); +mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord)); +mesh.setBuffer(Type.Index, 1, BufferUtils.createIntBuffer(indexes)); +mesh.updateBound();
@@ -133,11 +140,11 @@ Our Mesh is ready! Now we want to see it.
We create a com.jme3.scene.Geometry
, apply a simple color material to it, and attach it to the rootNode to make it appear in the scene.
Geometry geom = new Geometry("OurMesh", m); -Material mat = new Material(assetManager, "Common/MatDefs/Misc/SolidColor.j3md"); +Geometry geo = new Geometry("OurMesh", mesh); +Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"); mat.setColor("Color", ColorRGBA.Blue); -geom.setMaterial(mat); -rootNode.attachChild(geom);+geo.setMaterial(mat); +rootNode.attachChild(geo);
@@ -161,21 +168,20 @@ There are more vertex buffers in a Mesh than the three shown above. For an overv
-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 m
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 mesh
object that you defined above.
Geometry coloredMesh = new Geometry ("ColoredMesh", m); -Material matVC = new Material(assetManager, "Common/MatDefs/Misc/VertexColor.j3md");+
Geometry geo = new Geometry ("ColoredMesh", mesh); +Material matVC = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
-We create a float array color buffer. +You create a float array color buffer:
int colorIndex = 0;+
int colorIndex = 0;
-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. Note that the color values in this example 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 meaningful values for the color buffer depending on which color you want your mesh to have.
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 parameter4
. -m.setBuffer(Type.Color, 4, colorArray); -coloredMesh.setMaterial(matVC);+mesh.setBuffer(Type.Color, 4, colorArray); +geo.setMaterial(matVC);@@ -223,6 +229,24 @@ Now you see a gradient color extending from each vertex.
+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.) + +
+float[] normals = new float[12]; +normals = new float[]{0,0,1, 0,0,1, 0,0,1, 0,0,1}; +mesh.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals));+ +
+ +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. +
+ +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); points.setMaterial(mat); rootNode.attachChild(points); -rootNode.attachChild(coloredMesh);+rootNode.attachChild(geo);
diff --git a/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/advanced/materials_overview.html b/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/advanced/materials_overview.html index ec0bf2f81..952b446ea 100644 --- a/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/advanced/materials_overview.html +++ b/sdk/jme3-core/javahelp/com/jme3/gde/core/docs/jme3/advanced/materials_overview.html @@ -4,60 +4,91 @@
-Geometries have Materials (.j3m), Materials are based on material definitions (.j3md). You can write .j3m files in a text editor, or use the jMonkeyEngine SDK to generate 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.
-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 texture maps 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.) +
+ ++You can write .j3m files in a text editor, or use the jMonkeyEngine SDK to create .j3m files for you. (Advanced users can also create custom Material Definitions.) +
+ ++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 texture maps are to be able to use textured materials.
-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. Spatial myGeometry = assetManager.loadModel("Models/Teapot/Teapot.j3o");
Material mat = new Material(assetManager, // Create new material and + "Common/MatDefs/Misc/Unshaded.j3md"); // specify .j3md file path. +mat.setColor("Color", ColorRGBA.Blue); // Set one or more parameters. +myGeometry.setMaterial(mat); // Use material on Geometry.
-Most parameters are not mandatory, even if they are not explicitly marked optional. For example, it is okay to specify solely the DiffuseMap
and NormalMap
when using Lighting.j3md
, 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.
+or
myGeometry.setMaterial( (Material)assetManager.loadAsset( "myMaterial.j3m") );
-
Unshaded.j3md
, and then Lighting.j3md
. DiffuseMap
and NormalMap
when using Lighting.j3md
, 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.
+
+
++
Unshaded.j3md
, then look into Lighting.j3md
. +jMonkeyEngine supports illuminated and unshaded Material Definitions. +
+-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.
Basic Material Definition | Usage | Parameter : Type | +Basic Material Definition | Usage | Parameter |
---|---|---|---|---|---|
Common/MatDefs/Misc/Unshaded.j3md | Standard, non-illuminated Materials. Use this for simple coloring, simple texturing, simple glow, simple transparency. -See also: Hello Material | ColorMap : Texture -LightMap : Texture -Color : Color -VertexColor : Boolean -SeparateTexCoord : Boolean -GlowMap : Texture -GlowColor: Color |
+ Common/MatDefs/Misc/Unshaded.j3md | Standard, non-illuminated Materials. +Use this for simple coloring and texturing, glow, and transparency. +See also: Hello Material | Texture Maps +setTexture("ColorMap", assetManager.loadTexture("")); + setBoolean("SeparateTexCoord",true); +setTexture("LightMap", assetManager.loadTexture("")); +Colors +setColor("Color", ColorRGBA.White); +setBoolean("VertexColor",true); +Glow +setTexture("GlowMap", assetManager.loadTexture("")); +setColor("GlowColor", ColorRGBA.White); |
Other useful, but less commonly used material definitions: @@ -65,23 +96,23 @@ Other useful, but less commonly used material definitions:
Special Material Definitions | Usage | Parameter : Type | +Special Material Definitions | Usage | Setter, Parameter, Type |
---|---|---|---|---|---|
Common/MatDefs/Misc/Sky.j3md | A solid skyblue, or use with a custom SkyDome texture. -See also: Sky | Texture : TextureCubeMap -SphereMap : Boolean -NormalScale : Vector3 |
+See also: Sky setTexture("TextureCubeMap", assetManager.loadTexture("")); + setBoolean("SphereMap",true); +setVector3("NormalScale", new Vector3f(0,0,0)); |
||
Common/MatDefs/Terrain/Terrain.j3md | Splat textures for e.g. terrains. -See also: Hello Terrain | Texture1 : Texture (red) -Texture1Scale : Float -Texture2 : Texture (green) -Texture2Scale : Float -Texture3 : Texture (blue) -Texture3Scale : Float -Alpha : Texture |
+See also: Hello Terrain setTexture("Texture1", assetManager.loadTexture("")); (red) + setFloat("Texture1Scale",1f); + setTexture("Texture2", assetManager.loadTexture("")); (green) + setFloat("Texture2Scale",1f); +setTexture("Texture3", assetManager.loadTexture("")); (blue) + setFloat("Texture3Scale",1f); +setTexture("Alpha", assetManager.loadTexture("")); |
||
Common/MatDefs/Terrain/HeightBasedTerrain.j3md | A multi-layered texture for terrains. @@ -93,31 +124,31 @@ Texture regions can overlap. For example: Specify a seafloor texture for the lowest areas, a sandy texture for the beaches, a grassy texure for inland areas, -and a rocky texture for mountain tops. | terrainSize : Float -region1ColorMap : Texture2D -region2ColorMap : Texture2D -region3ColorMap : Texture2D -region4ColorMap : Texture2D -region1 : Vector3 -region2 : Vector3 -region3 : Vector3 -region4 : Vector3 +and a rocky texture for mountain tops. | setFloat("terrainSize",512f); +setTexture("region1ColorMap", assetManager.loadTexture("")); +setTexture("region2ColorMap", assetManager.loadTexture("")); +setTexture("region3ColorMap", assetManager.loadTexture("")); +setTexture("region4ColorMap", assetManager.loadTexture("")); +setVector3("region1", new Vector3f(0,0,0)); + setVector3("region2", new Vector3f(0,0,0)); + setVector3("region3", new Vector3f(0,0,0)); + setVector3("region4", new Vector3f(0,0,0)); Settings for steep areas: -slopeColorMap : Texture2D -slopeTileFactor : Float |
+setTexture("slopeColorMap", assetManager.loadTexture("")); ||
Common/MatDefs/Misc/Particle.j3md | Used with texture masks for particle effects, or for point sprites. The Quadratic value scales the particle for perspective view (). Does support an optional colored glow effect. -See also: Hello Effects | Texture : Texture -GlowMap : Texture -GlowColor : Color -Quadratic : Float -PointSprite : Boolean |
+See also: Hello Effects setTexture("Texture", assetManager.loadTexture("")); +setTexture("GlowMap", assetManager.loadTexture("")); +setColor("GlowColor", ColorRGBA.White); + setFloat("Quadratic",1f); + setBoolean("PointSprite",true); |
-Illuminated materials require a light source 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 drop shadows. They use Phong illumination model (default), or the Ward isotropic gaussian specular shader (WardIso) which looks more plastic like. +Illuminated materials require a light source 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 drop shadows unless you use a FilterPostProcessor.
Illuminated Material Definition | Usage | Parameters | +Illuminated Material Definition | Usage | Setter, Parameter, Type |
---|---|---|---|---|---|
Common/MatDefs/Light/Lighting.j3md | Standard lit material with Phong Illumination. + | Common/MatDefs/Light/Lighting.j3md | Commonly used Material with Phong illumination. Use this material together with DiffuseMap, SpecularMap, BumpMap (NormalMaps, ParalaxMap) textures. Supports shininess, transparency, and plain material colors (Diffuse, Ambient, Specular colors). -See also: Hello Material - Glowing materials require a FilterPostProcessor! | DiffuseMap : Texture -UseAlpha1) : Boolean -NormalMap : Texture -LATC2) : Boolean -SpecularMap : Texture -Shininess : Float [1-128] -ParallaxMap : Texture -AlphaMap : Texture -AlphaDiscardThreshold: Float -ColorRamp : Texture -Glow (optional) -GlowMap : Texture -GlowColor : Color -Performance and quality (optional) -VertexLighting : Boolean -UseVertexColor : Boolean -LowQuality : Boolean -HighQuality : Boolean -Material Colors (optional) -UseMaterialColors : Boolean -Diffuse : Color - Ambient : Color -Specular : Color -Tangent shading (optional): -VTangent : Boolean -Minnaert3) : Boolean -WardIso4) : Boolean |
+See also: Hello Material Texture Maps +setTexture("DiffuseMap", assetManager.loadTexture("")); +setBoolean("UseAlpha",true);1) +setTexture("NormalMap", assetManager.loadTexture("")); +setBoolean("LATC",true); 2) +setTexture("SpecularMap", assetManager.loadTexture("")); + setFloat("Shininess",64f); +setTexture("ParallaxMap", assetManager.loadTexture("")); +setTexture("AlphaMap", assetManager.loadTexture("")); + setFloat("AlphaDiscardThreshold",1f); +setTexture("ColorRamp", assetManager.loadTexture("")); +Glow +setTexture("GlowMap", assetManager.loadTexture("")); +setColor("GlowColor", ColorRGBA.White); +Performance and quality +setBoolean("VertexLighting",true); + setBoolean("UseVertexColor",true); + setBoolean("LowQuality",true); + setBoolean("HighQuality",true); +Material Colors + setBoolean("UseMaterialColors",true); +setColor("Diffuse", ColorRGBA.White); + setColor("Ambient", ColorRGBA.White); +setColor("Specular", ColorRGBA.White); +Tangent shading: + setBoolean("VTangent",true); + setBoolean("Minnaert",true);3) +setBoolean("WardIso",true);4) |
Special Illuminated Material Definitions | Usage | Parameters | +Special Illuminated Material Definitions | Usage | Setter, Parameter, Type |
---|---|---|---|---|---|
Common/MatDefs/Terrain/TerrainLighting.j3md | Same kind of multi-layered splat texture as Terrain.j3md, but with illumination and shading. @@ -177,69 +208,140 @@ For every 3 splat textures, you need one alpha map. You can use a total of 11 texture maps in the terrain's splat texture: Note that diffuse and normal maps all count against that. For example, you can use a maximum of 9 diffuse textures, two of which can have normal maps; -or, five textures with both diffuse and normal maps. | Diffuse : Color -Ambient : Color -Shininess : Float -Specular : Color -SpecularMap : Texture -WardIso : Boolean -useTriPlanarMapping : Boolean -isTerrainGrid : Boolean -Texture Splat Maps -DiffuseMap : Texture -DiffuseMap_0_scale : Float -NormalMap : Texture -DiffuseMap_1 : Texture -DiffuseMap_1_scale : Float -NormalMap_1 : Texture -DiffuseMap_2 : Texture -DiffuseMap_2_scale : Float -NormalMap_2 : Texture -DiffuseMap_3 : Texture -DiffuseMap_3_scale : Float -NormalMap_3 : Texture +or, five textures with both diffuse and normal maps. | Texture Splat Maps + setTexture("DiffuseMap", assetManager.loadTexture("")); + setFloat("DiffuseMap_0_scale",1f); +setTexture("NormalMap", assetManager.loadTexture("")); +setTexture("DiffuseMap_1", assetManager.loadTexture("")); + setFloat("DiffuseMap_1_scale",1f); +setTexture("NormalMap_1", assetManager.loadTexture("")); +setTexture("DiffuseMap_2", assetManager.loadTexture("")); + setFloat("DiffuseMap_2_scale",1f); +setTexture("NormalMap_2", assetManager.loadTexture("")); +setTexture("DiffuseMap_3", assetManager.loadTexture("")); + setFloat("DiffuseMap_3_scale",1f); +setTexture("NormalMap_3", assetManager.loadTexture("")); etc, up to 11. Alpha Maps -AlphaMap : Texture -AlphaMap_1 : Texture -AlphaMap_2 : Texture +setTexture("AlphaMap", assetManager.loadTexture("")); +setTexture("AlphaMap_1", assetManager.loadTexture("")); +setTexture("AlphaMap_2", assetManager.loadTexture("")); Glowing -GlowMap : Texture -GlowColor : Color |
+setTexture("GlowMap", assetManager.loadTexture("")); ||
Common/MatDefs/Light/Reflection.j3md | Reflective glass material with environment map (CubeMap/SphereMap). See also: | setTexture("Texture", assetManager.loadTexture("")); + setBoolean("SphereMap",true); |
Common/MatDefs/Light/Reflection.j3md | Reflective glass material with environment map (CubeMap/SphereMap). See also: | Texture : Texture -SphereMap: Boolean |
+ Material Definition | Usage | +
---|---|---|---|---|
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, or as fall-back default material. This built-in material has no parameters. |
-
Shininess
to 0, but instead set the Specular
color to ColorRGBA.Black
!
-TangentBinormalGenerator.generate(mesh);+
NormalMap
texture. ()-
TangentBinormalGenerator.generate(mesh);
-Shininess
intensity. Specular
value. SpecularMap
texture. + +To deactivate shininess +
+Specular
color to ColorRGBA.Black
. Do not just set Shininess
to 0.Material Definition | Usage | Parameters | -
---|---|---|
Common/MatDefs/Misc/ShowNormals.j3md | 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. | – | -
+ +To activate glow: +
+Glow
value. GlowMap
texture. + +To deactivate glow +
+Glow
color to ColorRGBA.Black
.@@ -253,80 +355,83 @@ Additionally, you must specify a blendmode:
Option | Usage | Example | +Material option | Usage | Example |
---|---|---|---|---|---|
mat.getAdditionalRenderState().setBlendMode(BlendMode.Off); | Opaque | + | getAdditionalRenderState().setBlendMode(BlendMode.Off); | Opaque | |
mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); | Use this for normal transparency. Interpolates the background pixel with the current pixel by using the current pixel's alpha. | Hair texture, window panes, ice, glass, alpha-blended vegetation textures. | +getAdditionalRenderState().setBlendMode(BlendMode.Alpha); | Interpolates the background pixel with the current pixel by using the current pixel's alpha. | Use this for normal every-day translucency: Frosted window panes, ice, glass, alpha-blended vegetation textures… |
mat.getAdditionalRenderState().setDepthWrite(false); | 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. | +getAdditionalRenderState().setDepthWrite(false); | Disables writing of the pixel's depth value to the depth buffer. | Use this on Materials if you have several transparent/translucent objects obscuring one another, but you want to see through both. | |
mat.getAdditionalRenderState().setAlphaFallOff(0.5f); -mat.getAdditionalRenderState().setAlphaTest(true) | Enables alpha test. Works the same way as "AlphaDiscardThreshold". | Generally used for vegetation etc. | +getAdditionalRenderState().setAlphaFallOff(0.5f); +getAdditionalRenderState().setAlphaTest(true) | Enables alpha test. Works the same way as "AlphaDiscardThreshold". | Used for textures that have fully opaque pixels next to fully transparent pixels, e.g. foliage, hair, vegetation. |
mat.getAdditionalRenderState().setBlendMode(BlendMode.Additive); | 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. | Used for particle effect textures that have a black color background. | +getAdditionalRenderState().setBlendMode(BlendMode.Additive); | 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. +Viewed in front of a white background, Additive textures become fully transparent! | Used for particle effect textures that have a black color background. |
mat.getAdditionalRenderState().setBlendMode(BlendMode.AlphaAdditive); | Same as "Additive", except first it multiplies the current pixel color by the pixel alpha. | Used for particle effects that have alpha as background. | +getAdditionalRenderState().setBlendMode(BlendMode.AlphaAdditive); | Same as "Additive", except first it multiplies the current pixel color by the pixel alpha. | Used for particle effects that have alpha as background. |
mat.getAdditionalRenderState().setBlendMode(BlendMode.Color); | Blends by color. | Generally useless. | +getAdditionalRenderState().setBlendMode(BlendMode.Color); | Blends by color. | Generally useless. |
mat.getAdditionalRenderState().setBlendMode(BlendMode.Modulate); | Multiplies the background pixel by the current pixel. | +getAdditionalRenderState().setBlendMode(BlendMode.Modulate); | Multiplies the background pixel by the current pixel. | ? | |
mat.getAdditionalRenderState().setBlendMode(BlendMode.ModulateX2); | Same as "Modulate", except the result is doubled. | +getAdditionalRenderState().setBlendMode(BlendMode.ModulateX2); | Same as "Modulate", except the result is doubled. | ? | |
mat.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. | +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. |
-Also note the AlphaDiscardThreshold value for materials based on Lighting.j3md. The renderer does not render pixels whose transparancy is below the threshold. +
AlphaDiscardThreshold
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.
+
+Material Option | Usage | +Material Option | Usage | Example |
---|---|---|---|---|
mat.getAdditionalRenderState().setWireframe(true); | Switch to showing the (textured) Material in wireframe mode | +getAdditionalRenderState().setWireframe(true); | Switch to showing the (textured) Material in wireframe mode. For debugging or "matrix/holodeck" effect. | |
mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Back); | 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. | +getAdditionalRenderState().setFaceCullMode(FaceCullMode.Back); | 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. | The backside of mesh polygons (and the inside of models) is invisible. |
mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off); | No culling. All meshes are rendered even if they are out of view. Slow. | +getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off); | Nothing is culled. Both mesh faces are rendered, even if they face away from the camera. Slow. | Sometimes used to debug custom meshes if you messed up some of the polygon sides, or for special shadow effects. |
mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Front); | Activate front-face culling. Mesh faces facing the camera are not rendered. Typically not used. | +getAdditionalRenderState().setFaceCullMode(FaceCullMode.Front); | Activate front-face culling. Mesh faces facing the camera are not rendered. | Typically not used. |
mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.FrontAndBack) | 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. | +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. |
mat.getAdditionalRenderState().setColorWrite(false); | Disable writing the color of pixels. Use this together with setDepthWrite(true) to write pixels only to the depth buffer, for example. | +getAdditionalRenderState().setColorWrite(false); | Disable writing the color of pixels. | Use this together with setDepthWrite(true) to write pixels only to the depth buffer, for example. |
mat.getAdditionalRenderState().setPointSprite(true); | 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. | +getAdditionalRenderState().setPointSprite(true); | 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. | Point sprites are used internally for hardware accelerated particle effects. |
mat.getAdditionalRenderState().setPolyOffset(); | Enable polygon offset. Use this when you have meshes that have triangles really close to each over (e.g. ), it will shift the depth values to prevent . | +getAdditionalRenderState().setPolyOffset(); | Enable polygon offset. | Use this when you have meshes that have triangles really close to each over (e.g. ), it will shift the depth values to prevent . |
applyContinuousForce(false)
to stop the force. applyContinuousTorque(false)
to stop the rotation.Note: 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)
The simplest type of Meshes are the built-in JME Shapes. You can create Shapes without using the AssetManager. -
-+ + + +
+ + + +
++ 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!
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. -
@@ -99,7 +116,7 @@ To add a shape to the scene:
@@ -119,11 +136,7 @@ You can compose more complex custom Geometries out of simple Shapes. Think of th
-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.
-
-
-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.
-Note the contrast: The simpleUpdate()
method runs repeatedly, while the simpleInitApp()
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:
+
simpleInitApp()
method is executed only once, right at the beginning; simpleUpdate()
method runs repeatedly, during the game. renders
) the screen for you!+ +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:
simpleInitApp()
is the application's "first breath".simpleUpdate()
is the application's heartbeat.simpleUpdate()
is the application's heartbeat. ticks
.-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: + +
-Keep this in mind for later when your game application grows. +Keep this in mind for later when your application grows. + +
+You can batch all Geometries in a scene (or a subnode) that remains static. + +
jme3tools.optimize.GeometryBatchFactory.optimize(rootNode);+
+ +Batching means that all Geometries with the same Material are combined into one mesh. This optimization only has an effect if you use only few (roughly up to 32) Materials total. The pay-off is that batching takes extra time when the game is initialized. + +
++ +
+-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.
-The origin is the central point in the 3D world. It's at the coordinates (0,0,0).
-Code sample: Vector3f origin = new Vector3f( Vector3f.ZERO );
+The origin is the central point in the 3D world, where the three axes meet. It's at the coordinates (0,0,0).
+
+Example: Vector3f origin = new Vector3f( Vector3f.ZERO );
Vector3f origin = new Vector3f( Vector3f.ZERO );
-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: Vector3f v = new Vector3f( 17 , -4 , 0 );
+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.
+
+Example: Vector3f v = new Vector3f( 17 , -4 , 0 );
- -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.
@@ -288,7 +294,13 @@ Set the Specular color to ColorRGBA.Black to switch off shininess.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. +
+ +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. +
- - -
-+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: +
-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.
@@ -362,11 +369,11 @@ Bump maps are used to describe detailed shapes that would be too hard or simply-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. +
++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.
-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.
@@ -428,8 +437,11 @@ Getting the seams and mappings right is crucial: You must use a graphic tool lik
-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. +
+ ++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.
@@ -439,7 +451,7 @@ Of course these reflections are static and not "real", e.g. the player-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.
@@ -449,7 +461,7 @@ You provide the texture in two or three resolutions to be stored in one file (MI-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: +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 to create them.
@@ -467,8 +479,11 @@ See also: