Hi Folks,
I am trying to create a series of line segments using a small number of points and a larger number of segments. It seems like I should be able to specify the vertices using a vertex buffer and the connectivity using an index buffer. It appears, though, that I can specify no more indices than the number of vertices I have.
The following simple code example illustrates the issue. I have 4 vertices and want to draw 3 segments between them. I specify this by setting the index buffer to 0, 1, 2, 3, 1, 2. However, I only get segments from 0 to 1 and 2 to 3. Is there a way to get all 3 segments to show up without having to repeat vertices?
package sandbox;
import java.nio.*;
import com.jme.app.*;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Line;
import com.jme.scene.state.MaterialState;
import com.jme.util.geom.BufferUtils;
public class LineTest extends SimpleGame
{
@Override
protected void simpleInitGame()
{
Line foo = new Line("LINE");
foo.setMode(Line.SEGMENTS);
FloatBuffer vertices = BufferUtils.createVector3Buffer(4);
//4 vertices
vertices.put(new float[]{-1.0f, -1.0f, 0.0f});
vertices.put(new float[]{ 1.0f, -1.0f, 0.0f});
vertices.put(new float[]{ 1.0f, 1.0f, 0.0f});
vertices.put(new float[]{-1.0f, 1.0f, 0.0f});
IntBuffer indices = BufferUtils.createIntBuffer(6);
//3 pairs--I want 3 segments, but I only get 2
indices.put(new int[]{0, 1, 2, 3, 1, 2});
foo.setVertexBuffer(0, vertices);
foo.setIndexBuffer(indices, 0);
MaterialState ms = display.getRenderer().createMaterialState();
ms.setAmbient(ColorRGBA.red);
ms.setDiffuse(ColorRGBA.red);
foo.setRenderState(ms);
rootNode.attachChild(foo);
}
public static void main(String[] args)
{
new LineTest().start();
}
}
Thanks!