Primitive restart

I’d like to make a custom mesh out of multiple triangle fans. Normally in opengl, I’d use glPrimitiveRestartIndex to mark when one fan ends and another begins, but I can’t figure out how to do this in jME. Is it possible? If not directly, is there a way to get at the opengl context jME is using?


I don’t think using the context directly is the answer. You can set the mesh mode to Mesh.Mode.TriangleFan however, and should be able to accomplish what you want with that

Yes, that’s easy enough, but when I give the indexes of the fan, how do I tell the mesh to end one fan, and start another?

edit: actually idk

To better clarify what I’m looking for…

Let’s say you’ve got a few separate pentagons you want to make - each with a central point in the middle. We’ll use the central points as the start point for each fan. So the first would go (0,1,2,3,4,5). Then the next pentagon has a central point index of 6, so it’s index array would be (6,7,8,9,10,11). If these were two separate meshes, no problem. But it’s one mesh, so all the indexes get lumped into one array which would be (0,1,2,3,4,5,6,7,8,9,10,11) - how is opengl supposed to know when to start a new fan?

Normally, you define glPrimitiveRestartIndex to something ridiculously high - 65535 or something, and insert that into your array. opengl sees this and starts a new fan. So now we’d have (0,1,2,3,4,5,65535,6,7,8,9,10,11). I can do this myself in lwjgl, but I don’t know how to make our friendly jmonkey let me do the same thing.

Here’s a page that explains it better:

Or can one geometry hold multiple meshes?

Are you trying to make some kind of batching?
JME does not support what you need, at least that’s not built in.
But we have a fair amount of batching solutions. Maybe if you explain what you’re aiming at, we could guide you to a painless solution.

I’ve got a number of different polygons of varying point count all attached to each other, which I would like to represent as triangle fans, all in one mesh.

jME uses lwjgl under the hood, right? Because I can do what I want in straight lwjgl, so I’m surprised I can’t figure out how to do it now. How are other people making objects of any complexity? Is everyone using straight triangles - or do most people load pre-made objects as assets? (Something I can’t do in this case since the mesh is to be generated in-game).

I think most people just use triangles or in the extreme cases triangle strips. Pretty sure triangle fans are not supported in JME for what you want. I guess it would complicate the API for relatively little gain in most cases.

Edit: I guess with a restart index the API change wouldn’t be too onerous if you choose to go with nehon’s option 3. Still, I agree with him that you should consider option 2 first. I think you could do a pentagon with a triangle strip with only 5 more index values (presuming you are jumping to another pentagon).

@rich.helvey said: jME uses lwjgl under the hood, right?
Not only. LWJGL is our main renderer for desktop, but there is a JOGL renderer in the work. Also for android we have an openglES renderer that use android gl wrapper.

triangle fans are very seldom used with JME, usually, people use models made in a modeling tool like blender or max.
Some users make custom meshes but based on triangle yes, see this doc if you want to give it a try

We don’t recommend using direct calls to the rendering layer, but for triangle fans and what you want to do it may be necessary.
You have several options :
1- make direct LWJGL calls and put aside the compatibility to others renderers (that might be acceptable depending on your needs). Also there is a good chance that you have to modify some of the engine classes.
2- Rethink the problem taking into account the tools offered by JME (what do you want to do in in your game from a functional point of view, not a technical one)
3- Go beyond all this and modify the engine so that what you want to do is possible with JME with a proper API and without making direct calls to the rendering layer. And possibly contribute it back (we’d be grateful).

Now I would go 2 first, then consider 1 or 3 (depending of the implication you want to have) only if 2 really fails.

OK, thanks for all the answers. Not what I wanted to hear, of course, but I think I’ll live. :slight_smile: I’m converting over to using straight triangles now, just have to reformat how the data is handed off to the engine a bit.

I’m curious about the suggestion to use triangle strips however, since it seems like I’d have the same problem, or is it assumed that there’d only be one really long strip per mesh?

In the case of a triangle strip, you can make degenerate triangles to move from one strip to the next… and they basically cost nothing except the extra slots in the index buffer.

Hmmm… I wonder if strips would be easier to convert to. I might have to try that.

Ok, thanks again.

@rich.helvey said: Hmmm... I wonder if strips would be easier to convert to. I might have to try that.

Ok, thanks again.

I think it’s probably the same trouble either way. Your existing index buffer needs to be drastically changed either way.