Get triangle id from Blender


Is there a way of seeing the id of my mesh’s triangle which would correspond to the same triangle in jMonkey?

For example, how can I find out the id of the selected triangle in the screenshot?

It’s either impossible or extremely difficult bordering on impossible.

You might take a step back and explain why you need this as perhaps there is a different way to do what you want to to. Even iterating over all of the positions would be easy in comparison to trying to get some kind of triangle index to line up.

What I want to do is make set of hitboxes and and ragdoll collision shapes all rolled into one. If I knew how to get triangle ids, I could set, say 10th triangle to be part of the head hitbox, and so a ray that goes through the 10th triangle would count as a headshot.

Make editor for your game. You can click and find ID by yourself then you can write it to file.

I have a couple of questions/observations about what you’re trying to accomplish.

(1) Why do you want to combine the hitboxes and ragdoll shapes? Those are two very different needs, and it seems to me that trying to double up two unrelated pieces of functionality like that is likely to cause you lots of headaches, both to get it working initially and to maintain it later.

(2) Why is the specific triangle that a ray hits important? It’s much easier to identify a geometry than it is to identify a triangle within that geometry. From your question, I’m guessing that your hitboxes are related to FPS functionality. In that case, I think it would be a lot easier for your system to keep a head hitbox, arm hitboxes, torso hitboxes, etc. Then to determine a hit, all you have to do is cast a ray through your scene and find the first hitbox that the ray collided with. If it hit a head hitbox, it’s a headshot. The trouble with identifying triangles, in addition to what @pspeed said, is that you have to do a whole lot of “book keeping” to determine which triangle belonged to which hitbox. You’ll probably have to do a lot more work to correctly identify targets using your triangle system than just attaching the hitboxes to the characters. If you need more information than one hitbox per body part gives (i.e., did the shot come from the front or from behind), then use multiple hitboxes per “target” - i.e., head front, head back, torso front, torso back. If you’re trying to do this to save memory, my guess is that you’ll use more memory and processor time keeping track of triangles and identifying which one got hit than the memory and processor time involved in using the much simpler hitbox system I described above.

1 Like

Or if the data explosion doesn’t really concern you then just go all in and use a second texture layer or something. Even a second set of texture coordinates might work. There is really no such thing as “triangle attributes” so you’ll likely have to tag vertexes no matter what you do anyway.

Edit: that is still kind of meant to encourage you to take a different approach. As @danielp suggests, there are way more efficient ways to track hit boxes.

1 Like

Perhaps I should just make seperate hitboxes to be attached to the limbs. But then could I use their collision shapes to replace default ragdoll collision shapes?

Lets look at this logically. The player got hit. So you know who the player is. Which means you know how big the player is. So you can detect the height of the hit by simple subtraction and determine whether it was the head, body or legs. You could do the same for limbs on the x plane. It will have corner cases, but is by far the simplest solution.

I don’t think this is that good of a sollution because one hitbox may be in front of another, i. e. , a hand hitbox in front of a chest hitbox. I think I’ll just make seperate hitboxes and attach those to their limbs.

That way you would add a Z Coordinate. You can actually just define some Boxes with 4 edge points and then use some trival math for “is hitpoint within box”

Why do you want to use the hitboxes as collision shapes for ragdoll physics? These are two very different areas of functionality, and I find it doubtful that this will give you the best result (or maybe even a good result).

If I could combine hitboxes and collision shapes into one mesh, I’d have to do less work for the same goal which is to make a combined hitbox and ragdoll collision shape systems. So there are a bunch of hitboxes attached to their respective limbs and upon character’s death the shape of those hitboxes could be used as a collision shape for the same limb of the ragdoll, i. e., the head hitbox becomes the collision shape for the head in ragdoll mode.

I think that if you try to do this you’ll find that it will take you more work to get acceptable results for both your ragdoll and your hit calculation than if you keep the two separate at the Jme level. The hitboxes are easy - just make your shapes and attach them to the character’s bones. Ragdolls, however, complicate things - even if you have no need for per-joint constraints, the collision shapes for a ragdoll that looks right probably conflict with the shapes of the boxes that give good hit results. For example, to make sure that you always get correct hits near joints the boxes probably need to come very close to each other at the joint (and may overlap during animation) or you could “shoot” a joint and have the shot pass between the hitboxes. Your ragdoll, however, will probably require significant space between the collision shapes to get a good result.

At the end of the day I think you’ll find that keeping two logically distinct systems separate will cost you much less work and will give you much better results than trying to combine them like this. There’s even an experimental control referenced in the Javadoc that will automatically generate ragdoll collision shapes given a ragdoll preset and an animated model - see com.jme3.bullet.control.KinematicRagdollControl.