|
@@ -5,7 +5,11 @@
|
|
|
<p>
|
|
|
<img src="/wiki/lib/exe/fetch.php">
|
|
|
Use the Mesh class to create custom shapes that go beyond Quad, Box, Cylinder, and Sphere, even procedural shapes are possible. Thank you to KayTrance for providing the sample code!
|
|
|
-In this tutorial, we (re)create a very simple rectangular mesh, and we have a look at different ways of coloring it. A flat rectangle may not look useful because it's exactly the same as a <code>com.jme3.scene.shape.Quad</code>. We choose this simple example in order to show you how to build any shape out of triangles ??? without the distractions of more complex shapes.
|
|
|
+</p>
|
|
|
+
|
|
|
+<p>
|
|
|
+<strong>Note:</strong> In this tutorial, we (re)create a very simple rectangular mesh (a quad), and we have a look at different ways of coloring it. Coding a custom quad may not be very useful because it's exactly the same as the built-in <code>com.jme3.scene.shape.Quad</code>. We chose a simple quad to teach you how to build any shape out of triangles, without the distractions of more complex shapes.
|
|
|
+
|
|
|
</p>
|
|
|
<ul>
|
|
|
<li><div> Full code sample: <object classid="java:org.netbeans.modules.javahelp.BrowserDisplayer"><param name="content" value="http://jmonkeyengine.googlecode.com/svn/branches/stable-alpha4/engine/src/test/jme3test/model/shape/TestCustomMesh.java"><param name="text" value="<html><u>TestCustomMesh.java</u></html>"><param name="textColor" value="blue"></object></div>
|
|
@@ -13,43 +17,68 @@ In this tutorial, we (re)create a very simple rectangular mesh, and we have a lo
|
|
|
</ul>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT1 SECTION "Custom Mesh Shapes" [1-811] -->
|
|
|
+<!-- EDIT1 SECTION "Custom Mesh Shapes" [1-834] -->
|
|
|
<h2><a>Polygon Meshes</a></h2>
|
|
|
<div>
|
|
|
|
|
|
<p>
|
|
|
-Polygon meshes are made up of triangles. The corners of the triangles are vertices. So, when ever you create a new shape, you break it down into triangles.
|
|
|
-Let's look at a cube. A cube is made up of 6 rectangles. Each rectangle can be broken down into two triangles. This means you need 12 triangles to create a cube mesh. You also need to know the 8 corner coordinates (vertices). The trick is that you have to specify the vertices in a certain order: Each triangle separately, counter-clockwise.
|
|
|
-Sounds worse than it is ??? here is an example:
|
|
|
|
|
|
+Polygon <a href="/com/jme3/gde/docs/jme3/advanced/mesh.html">mesh</a>es are made up of triangles. The corners of the triangles are called vertices. When ever you create any new shape, you break it down into triangles.
|
|
|
+</p>
|
|
|
+
|
|
|
+<p>
|
|
|
+<strong>Example:</strong> Let's look at a cube. A cube is made up of 6 rectangles. Each rectangle can be broken down into two triangles. This means you need 12 triangles to describe a cube mesh. Therefor you must provide the coordinates of the triangles' 8 corners (called vertices).
|
|
|
+</p>
|
|
|
+
|
|
|
+<p>
|
|
|
+The important thing is that you have to specify the vertices of each triangle in the right order: Each triangle separately, counter-clockwise.
|
|
|
+</p>
|
|
|
+
|
|
|
+<p>
|
|
|
+Sounds harder than it is ??? let's create a simple custom mesh, a quad.
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT2 SECTION "Polygon Meshes" [812-1383] -->
|
|
|
+<!-- EDIT2 SECTION "Polygon Meshes" [835-1518] -->
|
|
|
<h2><a>Creating a Quad Mesh</a></h2>
|
|
|
<div>
|
|
|
|
|
|
<p>
|
|
|
-Okay, we want to create a Quad. A quad has four vertices, and is made up of two triangles.
|
|
|
-The base class for creating meshes is <code>com.jme3.scene.Mesh</code>.
|
|
|
|
|
|
+In this tutorial we want to create a 3x3 Quad. The quad has four vertices, and is made up of two triangles. In our example, we decide that the bottom left corner is at 0/0/0 and the top right is at 3/3/0.
|
|
|
</p>
|
|
|
-<pre>Mesh mesh = new Mesh();</pre>
|
|
|
+<pre>0,3,0--3,3,0
|
|
|
+| \ |
|
|
|
+| \ |
|
|
|
+| \ |
|
|
|
+| \ |
|
|
|
+| \|
|
|
|
+0,0,0--3,0,0</pre>
|
|
|
+
|
|
|
+</div>
|
|
|
+<!-- EDIT3 SECTION "Creating a Quad Mesh" [1519-1864] -->
|
|
|
+<h3><a>The Mesh Object</a></h3>
|
|
|
+<div>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
-If you create your own Mesh-based class, replace <code>mesh</code> by <code>this</code> in the following examples:
|
|
|
+The base class for creating meshes is <code>com.jme3.scene.Mesh</code>.
|
|
|
|
|
|
</p>
|
|
|
-<pre>public class MyMesh extends Mesh { }</pre>
|
|
|
+<pre>Mesh mesh = new Mesh();</pre>
|
|
|
+
|
|
|
+<p>
|
|
|
+Tip: If you create your own Mesh-based class (<code>public class MyMesh extends Mesh { }</code>), replace the variable <code>mesh</code> by <code>this</code> in the following examples.
|
|
|
+</p>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT3 SECTION "Creating a Quad Mesh" [1384-1766] -->
|
|
|
-<h3><a>Vertices</a></h3>
|
|
|
+<!-- EDIT4 SECTION "The Mesh Object" [1865-2157] -->
|
|
|
+<h3><a>Vertex Coordinates</a></h3>
|
|
|
<div>
|
|
|
|
|
|
<p>
|
|
|
-To define your own shape, determine its vertex positions in space. Store them in an array using com.jme3.math.Vector3f. For a Quad, we need four vertices: Bottom left, bottom right, top left, top right. We name the array <code>vertices[]</code>.
|
|
|
+
|
|
|
+To define your own shape, determine the shape's <strong>vertex coordinates</strong> in 3D space. Store the list of corner positions in an <code>com.jme3.math.Vector3f</code> array. For a Quad, we need four vertices: Bottom left, bottom right, top left, top right. We name the array <code>vertices[]</code>.
|
|
|
|
|
|
</p>
|
|
|
<pre>Vector3f [] vertices = new Vector3f[4];
|
|
@@ -59,12 +88,12 @@ vertices[2] = new Vector3f(0,3,0);
|
|
|
vertices[3] = new Vector3f(3,3,0);</pre>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT4 SECTION "Vertices" [1767-2222] -->
|
|
|
+<!-- EDIT5 SECTION "Vertex Coordinates" [2158-2664] -->
|
|
|
<h3><a>Texture Coordinates</a></h3>
|
|
|
<div>
|
|
|
|
|
|
<p>
|
|
|
-Next, define the Quad's 2D texture coordinates for each vertex, in the same order: Bottom left, bottom right, top left, top right. We name this array <code>texCoord[]</code>
|
|
|
+Next, we define the Quad's 2D <strong>texture coordinates</strong> for each vertex, in the same order as the vertices: Bottom left, bottom right, top left, top right. We name this Vector2f array <code>texCoord[]</code>
|
|
|
|
|
|
</p>
|
|
|
<pre>Vector2f[] texCoord = new Vector2f[4];
|
|
@@ -73,17 +102,33 @@ texCoord[1] = new Vector2f(1,0);
|
|
|
texCoord[2] = new Vector2f(0,1);
|
|
|
texCoord[3] = new Vector2f(1,1);</pre>
|
|
|
|
|
|
+<p>
|
|
|
+
|
|
|
+This syntax means, when you apply a texture to this mesh, the texture will fill the quad from corner to corner at 100% percent size. Especially when you stitch together a larger mesh, you use this to tell the renderer whether, and how exactly, you want to cover the whole mesh. E.g. if you use .5f or 2f as texture coordinates instead of 1f, textures will be stretched or shrunk accordingly.
|
|
|
+</p>
|
|
|
+
|
|
|
</div>
|
|
|
-<!-- EDIT5 SECTION "Texture Coordinates" [2223-2608] -->
|
|
|
+<!-- EDIT6 SECTION "Texture Coordinates" [2665-3475] -->
|
|
|
<h3><a>Connecting the Dots</a></h3>
|
|
|
<div>
|
|
|
|
|
|
<p>
|
|
|
-Next we turn the unrelated coordinates into triangles ??? We define the order in which the mesh is constructed. Think of these indexes as coming in groups of three. Each group of indexes describes one triangle. Note that you must specify the vertices counter-clockwise!
|
|
|
+Next we turn these unrelated coordinates into <strong>triangles</strong>: We define the order in which each triangle is constructed. Think of these indexes as coming in groups of three. Each group of indexes describes one triangle. If the corners are identical, you can (and should!) reuse an index for several triangles.
|
|
|
+</p>
|
|
|
+
|
|
|
+<p>
|
|
|
+Remember that you must specify the vertices counter-clockwise.
|
|
|
|
|
|
</p>
|
|
|
<pre>int [] indexes = { 2,0,1, 1,3,2 };</pre>
|
|
|
+
|
|
|
+<p>
|
|
|
+
|
|
|
+This syntax means:
|
|
|
+</p>
|
|
|
<ul>
|
|
|
+<li><div> The indices 0,1,2,3 stand for the four vertices that you specified for the quad in <code>vertices[]</code>.</div>
|
|
|
+</li>
|
|
|
<li><div> The 2,0,1 triangle starts at top left, continues bottom left, and ends at bottom right.</div>
|
|
|
</li>
|
|
|
<li><div> The 1,3,2 triangle start at bottom right, continues top right, and ends at top left.</div>
|
|
@@ -94,18 +139,28 @@ Next we turn the unrelated coordinates into triangles ??? We define the order in
|
|
|
| \ |
|
|
|
0--1\1</pre>
|
|
|
|
|
|
+<p>
|
|
|
+
|
|
|
+If the shape is more complex, it has more triangles, and therefor also more vertices/indices. Just continue expanding the list by adding groups of three indices for each triangle. (For example a three-triangle "house" shape has 5 vertices/indices and you'd specify three groups: <code>int [] indexes = { 2,0,1, 1,3,2, 2,3,4 };</code>.)
|
|
|
+</p>
|
|
|
+
|
|
|
+<p>
|
|
|
+<p><div>If you get the order wrong (clockwise) for some of the triangles, then these triangles face backwards. If the <a href="/com/jme3/gde/docs/jme3/advanced/spatial.html">Spatial</a>'s material uses the default <code>FaceCullMode.Back</code> (see "face culling"), the broken triangles appear as holes in the rendered mesh. You need to identify and fix them in your code.
|
|
|
+</div></p>
|
|
|
+</p>
|
|
|
+
|
|
|
</div>
|
|
|
-<!-- EDIT6 SECTION "Connecting the Dots" [2609-3204] -->
|
|
|
+<!-- EDIT7 SECTION "Connecting the Dots" [3476-4947] -->
|
|
|
<h3><a>Setting the Mesh Buffer</a></h3>
|
|
|
<div>
|
|
|
|
|
|
<p>
|
|
|
-The Mesh data is stored in a buffer.
|
|
|
+You store the Mesh data in a buffer.
|
|
|
</p>
|
|
|
<ol>
|
|
|
<li><div> Using <code>com.jme3.util.BufferUtils</code>, we create three buffers for the three types of information we have:</div>
|
|
|
<ul>
|
|
|
-<li><div> vertex positions,</div>
|
|
|
+<li><div> vertex coordinates,</div>
|
|
|
</li>
|
|
|
<li><div> texture coordinates,</div>
|
|
|
</li>
|
|
@@ -113,11 +168,11 @@ The Mesh data is stored in a buffer.
|
|
|
</li>
|
|
|
</ul>
|
|
|
</li>
|
|
|
-<li><div> We assign the data to the appropriate type of buffer inside the mesh object. The three buffer types are taken from an enum in <code>com.jme3.scene.VertexBuffer.Type</code>.</div>
|
|
|
+<li><div> We assign the data to the appropriate type of buffer inside the <code>Mesh</code> object. The three buffer types (<code>Position</code>, <code>TextCoord</code>, <code>Index</code>) are taken from an enum in <code>com.jme3.scene.VertexBuffer.Type</code>.</div>
|
|
|
</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 3 ints representing 3 vertices in a triangle.</div>
|
|
|
+<li><div> The integer 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 3 ints representing 3 vertices in a triangle.</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> To render the mesh in the scene, we need to pre-calculate the bounding volume of our new mesh: Call the <code>updateBound()</code> method on it.</div>
|
|
|
</li>
|
|
|
</ol>
|
|
|
<pre>mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
|
|
@@ -128,20 +183,20 @@ mesh.updateBound();</pre>
|
|
|
<p>
|
|
|
|
|
|
Our Mesh is ready! Now we want to see it.
|
|
|
-
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT7 SECTION "Setting the Mesh Buffer" [3205-4320] -->
|
|
|
+<!-- EDIT8 SECTION "Setting the Mesh Buffer" [4948-6071] -->
|
|
|
<h2><a>Using the Mesh in a Scene</a></h2>
|
|
|
<div>
|
|
|
|
|
|
<p>
|
|
|
-We create a <code>com.jme3.scene.Geometry</code>, apply a simple color material to it, and attach it to the rootNode to make it appear in the scene.
|
|
|
+We create a <code>com.jme3.scene.Geometry</code> from our <code>mesh</code>, apply a simple color material to it, and attach it to the rootNode to make it appear in the scene.
|
|
|
|
|
|
</p>
|
|
|
-<pre>Geometry geo = new Geometry("OurMesh", mesh);
|
|
|
-Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
|
|
+<pre>Geometry geo = new Geometry("OurMesh", mesh); // using our custom mesh object
|
|
|
+Material mat = new Material(assetManager,
|
|
|
+ "Common/MatDefs/Misc/Unshaded.j3md");
|
|
|
mat.setColor("Color", ColorRGBA.Blue);
|
|
|
geo.setMaterial(mat);
|
|
|
rootNode.attachChild(geo);</pre>
|
|
@@ -149,43 +204,50 @@ rootNode.attachChild(geo);</pre>
|
|
|
<p>
|
|
|
|
|
|
Ta-daa!
|
|
|
-
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT8 SECTION "Using the Mesh in a Scene" [4321-4740] -->
|
|
|
+<!-- EDIT9 SECTION "Using the Mesh in a Scene" [6072-6547] -->
|
|
|
<h2><a>Dynamic Meshes</a></h2>
|
|
|
<div>
|
|
|
|
|
|
<p>
|
|
|
-If modifying a mesh dynamically in a way which would change the model's bounds then you need to call updateModelBound() on the Geometry object containing the mesh after calling updateBounds() on the mesh object. There is a warning on updateModelBounds about not usually needing to use it but that can be ignored in this special case.
|
|
|
+
|
|
|
+If you are modifying a mesh dynamically in a way which changes the model's bounds, you need to update it:
|
|
|
+</p>
|
|
|
+<ol>
|
|
|
+<li><div> Call <code>updateBounds()</code> on the mesh object, and then </div>
|
|
|
+</li>
|
|
|
+<li><div> call <code>updateModelBound()</code> on the Geometry object containing the mesh. </div>
|
|
|
+</li>
|
|
|
+</ol>
|
|
|
+
|
|
|
+<p>
|
|
|
+The updateModelBounds() method warns you about not usually needing to use it, but that can be ignored in this special case.
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT9 SECTION "Dynamic Meshes" [4741-5102] -->
|
|
|
+<!-- EDIT10 SECTION "Dynamic Meshes" [6548-6942] -->
|
|
|
<h2><a>Optional Mesh Features</a></h2>
|
|
|
<div>
|
|
|
|
|
|
<p>
|
|
|
There are more vertex buffers in a Mesh than the three shown above. For an overview, see also <a href="/com/jme3/gde/docs/jme3/advanced/mesh.html">mesh</a>.
|
|
|
-
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT10 SECTION "Optional Mesh Features" [5103-5241] -->
|
|
|
+<!-- EDIT11 SECTION "Optional Mesh Features" [6943-7082] -->
|
|
|
<h3><a>Example: Vertex Colors</a></h3>
|
|
|
<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. You can use the same mesh <code>mesh</code> object that you defined above.
|
|
|
-
|
|
|
+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. For this demo, you can use the same mesh <code>mesh</code> object that you defined above.
|
|
|
</p>
|
|
|
-<pre>Geometry geo = new Geometry ("ColoredMesh", mesh);
|
|
|
+<pre>Geometry geo = new Geometry ("ColoredMesh", mesh); // using the custom mesh
|
|
|
Material matVC = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
|
|
|
matVC.setBoolean("VertexColor", true);</pre>
|
|
|
|
|
|
<p>
|
|
|
-
|
|
|
You create a float array color buffer:
|
|
|
</p>
|
|
|
<ul>
|
|
@@ -209,10 +271,11 @@ You create a float array color buffer:
|
|
|
</ul>
|
|
|
|
|
|
<p>
|
|
|
-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.
|
|
|
|
|
|
+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++){
|
|
|
+<pre>// note: the red and green values are arbitray in this example
|
|
|
+for(int i = 0; i < 4; i++){
|
|
|
// Red value (is increased by .2 on each next vertex here)
|
|
|
colorArray[colorIndex++]= 0.1f+(.2f*i);
|
|
|
// Green value (is reduced by .2 on each next vertex)
|
|
@@ -224,7 +287,6 @@ Loop over the colorArray buffer to quickly set some RGBA value for each vertex.
|
|
|
}</pre>
|
|
|
|
|
|
<p>
|
|
|
-
|
|
|
Next, set the color buffer. An RGBA color value contains four float components, thus the parameter <code>4</code>.
|
|
|
|
|
|
</p>
|
|
@@ -233,36 +295,38 @@ geo.setMaterial(matVC);</pre>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
-Now you see a gradient color extending from each vertex.
|
|
|
-
|
|
|
+When you run this code, you see a gradient color extending from each vertex.
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT11 SECTION "Example: Vertex Colors" [5242-7391] -->
|
|
|
-<h3><a>Example: Shaded Mesh with Normals</a></h3>
|
|
|
+<!-- EDIT12 SECTION "Example: Vertex Colors" [7083-9361] -->
|
|
|
+<h3><a>Example: Using Meshes With Lighting.j3md</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.)
|
|
|
|
|
|
+The previous examples used the mesh together with the <code>Unshaded.j3md</code> material. If you want to use the mesh with a Phong illuminated material (such as <code>Lighting.j3md</code>), the mesh must include information about its Normals. (Normal Vectors 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};
|
|
|
mesh.setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals));</pre>
|
|
|
|
|
|
<p>
|
|
|
+You need to specify as many normals as the polygon has vertices. For a flat quad, the four normals point in the same direction. In this case, the direction is the Z unit vector (0,0,1), this means our quad is facing the camera.
|
|
|
+</p>
|
|
|
|
|
|
-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>
|
|
|
+If the mesh is more complex or rounded, calculate cross products of neighbouring vertices to identify normal vectors!
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT12 SECTION "Example: Shaded Mesh with Normals" [7392-8163] -->
|
|
|
+<!-- EDIT13 SECTION "Example: Using Meshes With Lighting.j3md" [9362-10288] -->
|
|
|
<h3><a>Example: Point Mode</a></h3>
|
|
|
<div>
|
|
|
|
|
|
<p>
|
|
|
-Alternatively, you can show the vertices as colored points instead of coloring the faces.
|
|
|
|
|
|
+Additionally to coloring the faces as just described, you can hide the faces and show only the vertices as colored corner points.
|
|
|
</p>
|
|
|
<pre>Geometry coloredMesh = new Geometry ("ColoredMesh", cMesh);
|
|
|
...
|
|
@@ -277,39 +341,46 @@ rootNode.attachChild(geo);</pre>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
-This will result in a 10 px dot being rendered for each of the four vertices. The dot has the vertex color you specified above. The Quad's faces are not rendered at all. This can be used for a special debugging or editing mode.
|
|
|
+This will result in a 10 px dot being rendered for each of the four vertices. The dot has the vertex color you specified above. The Quad's faces are not rendered at all in this mode. You can use this to visualize a special debugging or editing mode in your game.
|
|
|
</p>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT13 SECTION "Example: Point Mode" [8164-8819] -->
|
|
|
+<!-- EDIT14 SECTION "Example: Point Mode" [10289-11022] -->
|
|
|
<h2><a>Debugging Tip: Culling</a></h2>
|
|
|
<div>
|
|
|
|
|
|
<p>
|
|
|
|
|
|
-By default, jME3 optimizes a mesh by culling (not drawing) its backfaces. It determines which side the front or backface of a mesh is by the order of the vertices: The frontface is the one where the vertices are specified counter-clockwise.
|
|
|
+By default, jME3 optimizes a mesh by "backface culling", this means not drawing the inside. It determines the side of a triangle by the order of the vertices: The frontface is the face where the vertices are specified counter-clockwise.
|
|
|
</p>
|
|
|
|
|
|
<p>
|
|
|
-This means for you that your custom mesh is invisible when seen from "behind" or from the inside. This may not be a problem, often this is even intended because it's faster. The player will not look at the inside of most things anyway. For example, if your custom mesh is a closed polyhedron, or a flat wallpaper-like object, then rendering the backfaces (the inside of the pillar, the back of the painting, etc) would indeed be a waste of resources.
|
|
|
+This means for you that, by default, your custom mesh is invisible when seen from "behind" or from the inside. This may not be a problem, typically this is even intended, because it's faster. The player will not look at the inside of most things anyway. For example, if your custom mesh is a closed polyhedron, or a flat wallpaper-like object, then rendering the backfaces (the inside of the pillar, the back of the painting, etc) would indeed be a waste of resources.
|
|
|
</p>
|
|
|
|
|
|
<p>
|
|
|
-In case however that your usecase requires the backfaces to be visible, you have two options:
|
|
|
+In case however that your usecase requires the backfaces be visible, you have two options:
|
|
|
</p>
|
|
|
<ul>
|
|
|
-<li><div> If you have a very simple scene, you can just deactivate backface culling for this one mesh's material. <br/>
|
|
|
-<code>mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);</code></div>
|
|
|
+<li><div> If you have a very simple scene, you can simply deactivate backface culling for this one mesh's material. <pre>mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);</pre>
|
|
|
+</div>
|
|
|
</li>
|
|
|
-<li><div> The recommended solution is to specify each triangle twice, the second time with the opposite order of vertices. The second, reversed triangle is a second frontface that replaces the culled backface. <br/>
|
|
|
-<code>int[] indexes = { 2,0,1, 1,3,2, 2,3,1, 1,0,2 }; </code></div>
|
|
|
+<li><div> Another solution for truly double-sided meshes is to specify each triangle twice, the second time with the opposite order of vertices. The second (reversed) triangle is a second frontface that covers up the culled backface. <pre>int[] indexes = { 2,0,1, 1,3,2, 2,3,1, 1,0,2 };</pre>
|
|
|
+</div>
|
|
|
</li>
|
|
|
</ul>
|
|
|
+<hr />
|
|
|
|
|
|
<p>
|
|
|
+See also:
|
|
|
|
|
|
-See also: <a href="/com/jme3/gde/docs/jme3/advanced/spatial.html">Spatial</a> ??? contains more info about how to debug custom meshes (that do not render as expected) by changing the default culling behaviour.
|
|
|
</p>
|
|
|
+<ul>
|
|
|
+<li><div> <a href="/com/jme3/gde/docs/jme3/advanced/spatial.html">Spatial</a> ??? contains more info about how to debug custom meshes (that do not render as expected) by changing the default culling behaviour.</div>
|
|
|
+</li>
|
|
|
+<li><div> <a href="/com/jme3/gde/docs/jme3/advanced/mesh.html">Mesh</a> ??? more details about advanced Mesh properties</div>
|
|
|
+</li>
|
|
|
+</ul>
|
|
|
<div><span>
|
|
|
<a href="/wiki/doku.php/tag:spatial?do=showtag&tag=tag%3Aspatial">spatial</a>,
|
|
|
<a href="/wiki/doku.php/tag:node?do=showtag&tag=tag%3Anode">node</a>,
|
|
@@ -319,5 +390,5 @@ See also: <a href="/com/jme3/gde/docs/jme3/advanced/spatial.html">Spatial</a> ??
|
|
|
</span></div>
|
|
|
|
|
|
</div>
|
|
|
-<!-- EDIT14 SECTION "Debugging Tip: Culling" [8820-] -->
|
|
|
-<p><em><a href="http://jmonkeyengine.org/wiki/doku.php/jme3:advanced:custom_meshes?do=export_xhtmlbody">view online version</a></em></p>
|
|
|
+<!-- EDIT15 SECTION "Debugging Tip: Culling" [11023-] -->
|
|
|
+<p><em><a href="http://hub.jmonkeyengine.org/wiki/doku.php/jme3:advanced:custom_meshes?do=export_xhtmlbody">view online version</a></em></p>
|