What does Mesh.PRIMITIVE_TRIANGLE_STRIP and how it works?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By abelgutierrez99

I already know how to use Mesh.PRIMITIVE_TRIANGLES, but I don’t know what Mesh.PRIMITIVE_TRIANGLE_STRIP does and how to use it.

The documentation is very poor: Render array as triangle strips

:bust_in_silhouette: Reply From: Ninfur

In a triangle strip, vertices are shared between triangles. As opposed to an un-indexed triangle list, where each triangle must be specified with 3 vertices each.

For example, lets say you want to create a rectangle from 4 vertices, A, B, C and D. Using an un-indexed triangle list (i.e. PRIMITIVE_TRIANGLES) you would have to specify the 3 vertices for each of the two triangles like this: ABC and CBD (apparently you are not allowed to write C-B-D)

But using a triangle strip (i.e. PRIMITIVE_TRIANGLE_STRIP), you only need to specify the 4 vertices that form the two triangles like this: ABCD

Wikipedia has some more in-depth explanation.

The main benefit is that triangle strips are more memory efficient. Speed-wise there should’nt be much of a different.

If you are intrested in trying triangle strips, just be aware that some collision (specifically trimesh collision) could be trickier to achieve.

So let’s say I use ABCDE, so it takes ABC for the first triangle and then drops the first point and adds the next, that is BCD (order may change to make this triangle face the same direccion as the first), and then CDE.

In my case, I want to build a hexagon:

# Vertices position
#   4
#  / \
# 3   5
# | 0 |
# 2   6
#  \ /
#   1

I would say 0123456, but since 0 is dropped first, it doesn’t work. I could try 1203456, but 0 is dropped later. So I guess I can’t create a hexagon with PRIMITIVE_TRIANGLES.

As conclusion I would say that you can’t use PRIMITIVE_TRIANGLE_STRIP if a vertex is shared between all the triangles.

Edit: see comment below

abelgutierrez99 | 2022-11-02 10:34

I answer my own comment, sorry. You must rethink the problem. I have to divide the hexagon in different triangles than in the PRIMITIVE_TRIANGLES case, 126354 works!

abelgutierrez99 | 2022-11-02 10:41

Another comment, if I use a convex collision shape, it works fine. With a trimesh shape, the behavior is not right.

abelgutierrez99 | 2022-11-02 10:51