Mesh Indices Confusion

The block of Java below is suppose to be able to construct a “2d” mesh that is made up of a grid of right angles. The algorithm simply creates a bottom row of vertices and then on the second row of vertices, starts constructing the indices as it goes along. When I print out the indices and vertices to the console, everything looks good to me. Is there anyone that can take a look at this and tell me what I am missing with regards to creating the custom mesh?

Thanks for any help!


[java]package mygame;

import com.jme3.scene.Mesh;

import com.jme3.scene.VertexBuffer.Type;

import com.jme3.util.BufferUtils;



  • @author chenz


    public class SimpleGrid extends Mesh {

    SimpleGrid(int width, int height) {

    int[] index = new int[width * height * 6];

    // Change width and height with respect to the verticies (not squares.)

    width += 1;

    height += 1;

    float[] vertex = new float[width * height * 3];

    // Setup the verticies left to right, bottom to top

    int i = 0;

    for (int y = 0; y < height; ++y) {

    for (int x = 0; x < width; ++x) {

    width3)+(x3)+0] = (float)x;

    vertex[(ywidth3)+(x3)+1] = (float)y;

    width3)+(x3)+2] = 1.0f;

    if (x > 0 && y > 0) {

    /* if we’re not on first column or first row,
  • we can construct triangle indicies.


    index = (y-1)*width+x-1; i++;

    index = (y-1)*width+x-0; i++;

    index = (y-0)*width+x-0; i++;

    index = (y-0)*width+x-0; i++;

    index = (y-0)*width+x-1; i++;

    index = (y-1)*width+x-1; i++;




    // Setting buffers

    this.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertex));

    this.setBuffer(Type.Index, 1, BufferUtils.createIntBuffer(index));





    Here is the bad output:

Yup… screwed up my array index math. All good now (and updated code in post since I can’t delete topic.)