# How to draw trajectory as a Line?

Hello,

I need to draw a trajectory as a line, which is recorded as many consecutive points in 3D.

I found out, that Mesh can be drawn with line mode.

It seems to be useful to me.

Unfortunately I don’t know, which buffers needs to be created and set to the Mesh.

I suppose that POSITION buffer needs to be set (size== pointsCount3)//x,y and z coord,

INDEX buffer (size=:???),

COLOR buffer (size==pointsCount
4)//r,g,b,alpha

Anything else?

How does the INDEX buffer work?

Should it look like: [0,1,2,3,4,5…] or [0,1,1,2,2,3,3,…] or somewhat else?

Is there something suspicious in this code fragment? :

trajectory = new Line();

trajectory.setMode(Line.Mode.Lines);

trajectory.setBuffer(VertexBuffer.Type.Position,positions.length, positions); trajectory.setBuffer(VertexBuffer.Type.Index,indices.length, indices);

trajectory.setBuffer(VertexBuffer.Type.Color,colors.length, colors);

Thanks a lot.

Martin

Theres a tutorial that explains how custom meshes work:

But there are no details about mesh used as line(s) in my fashion…

Especialy I think the biggest problem is the INDEX buffer.

Because I set red color according to the tutorial posted by you for all vertexes but drawn trajectory is green and yellow…if I don’t bother to solve strange shape of the trajectory…this is another problem - it could be bad coords of course but the bad shape corresponds with bad color…and probably wrong indices…

Hm, alright, I don’t know exactly but I’d say its following the same logic then, only with two vertices, so the indices would be like 0,1,1,2 for 3 vertices that should make a complete line mesh.

1 Like

There is a Line mesh you can use between each point; it has a start and an end point. Ideally a LineString mesh would be more convenient to cover many points, but there isn’t one yet.

You can look at com.jme3.scene.shape.Line to see how the index is set up. It would be quite easy to extend it to have many points.

If Normen’s suggestions don’t work then we’d need to see code. And if you post code, don’t forget to use the code block.

Normen’s explanation works well.

Thanks to all.