Problems with connecting the vertices of custom mesh

Hi.
I want to create a custom 3d mesh procedurally. I made two different approaches, just for the debugging. The first one works fine, but it is only for debugging purposes and I cant and must not use in the final source code. The second doesnt work as intended, and I cant understand why. Here is the explanation:

The first method makes a triangle in every iteration by evaluating its vertices, immediately makes a mesh from it by putting the 3 vertices into an index buffer, makes geometry from it and finally renders it. By the end of all the iterations, we will practically have X number of triangle-shaped geometries which forms the final mesh.

The second method generated all the triangles, puts all the indices in an index buffer (in the order of generation), and after all the iterations we create a mesh based on this buffer and render it.

The problem here is, if we assume that we have generated vertices (0,1,2,3,4,5…) in this order, then I want the triangles to be (0,1,2), (3,4,5), (6,7,8) which works in the first method, but in the second method I get triangles (0,1,2), (1,2,3), (2,3,4), (3,4,5)…even if I define the index buffer as (0,1,2, 3,4,5, 6,7,8, …).

ps: yes, I have read the custom mesh tutorial many times, but it doesnt help :frowning:

I don’t have a solution but I suggest you attach your code and/or the mesh file to make it a lot more possible to help you.

I can assure you that if your vertex buffer is really setup right and your index buffer is really setup right then it will work.

This statement: " I get triangles (0,1,2), (1,2,3), (2,3,4), (3,4,5)…even if I define the index buffer as (0,1,2, 3,4,5, 6,7,8, ……)." is wrong. You’ve made an assumption somewhere else that is incorrect. If your index buffer is 0,1,2,3,4,5 then your triangles are (0,1,2), (3,4,5), etc.

Ok, so if in my vertex buffer i have: 0,1,2,3,4,5,6,7,8… and in my index buffer I have 0,1,2,3,4,5,6,7,8… then with this code:
[java]
for(int i=0; i<getTriangleCount(); i++){
Triangle t = new Triangle();
getTriangle(i,t);
FileFactory.writeToFile(“index.txt”, t.get1().toString()+"\n"+t.get2().toString()+"\n"+t.get3().toString()+"\n");
}
[/java]

I should get output: 0,1,2,3,4,5,6,7… right? Because I get the mentioned 0,1,2,1,2,3,2,3,4…

I can’t see how you set your vertex buffers up so I can’t say.

[java]
for(int j=0; j<n/2; j++) {
beta = -PI;
for(int i=0; i<n; i++) {

			if(j != (n/2)-1){
			//Triangle 1
			p = EvaluateVertex(phi, beta);
			vertexList.add(p);
			normalsList.add(p.normalize());
			p = EvaluateVertex(phi+dP, beta);
			vertexList.add(p);
			normalsList.add(p.normalize());
			p = EvaluateVertex(phi+dP, beta+dB);
			vertexList.add(p);
			normalsList.add(p.normalize());
			}
			
			if(j != 0) {
			//Triangle 2
			p = EvaluateVertex(phi, beta);
			vertexList.add(p);
			normalsList.add(p.normalize());
			p = EvaluateVertex(phi+dP, beta+dB);
			vertexList.add(p);
			normalsList.add(p.normalize());
			p = EvaluateVertex(phi, beta+dB);
			vertexList.add(p);
			normalsList.add(p.normalize());
			}
			
			beta += dB;
		}
		phi += dP;
	}
	vertices = new Vector3f[vertexList.size()];
	vertices = vertexList.toArray(vertices);
	normals = new Vector3f[normalsList.size()];
	normals = normalsList.toArray(normals);
	
	int[] indices = new int[vertices.length];
	for(int i=0; i&lt;vertices.length; i++) {
		indices[i] = i;
	}
	
	setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
	setBuffer(Type.Normal, 3, BufferUtils.createFloatBuffer(normals));
	setBuffer(Type.Index, 3, BufferUtils.createIntBuffer(indices));
	updateBound();

[/java]

Referring to my first post, when I used the first method to render (separate geometries for the triangles and render them separately with separate buffers which consists of 3 vetrices), it worked fine. With this method, when I print the triangles, it shows an order of 0,1,2, 1,2,3, 2,3,4, 3,4,5… of the vertices.

Ok, If someone is still interested, I have found the problem. Earlier in my code I definded: setMode(Mesh.Mode.TriangleStrip);
This was the problem,it seems that this line overrides the index buffer. Im a happy monkey now :smiley:

Yes, triangle strips dont use index buffers at all.