Pyrr icon indicating copy to clipboard operation
Pyrr copied to clipboard

generate_vertex_normals_ts

Open szabolcsdombi opened this issue 7 years ago • 7 comments

  • [x] Generate normals for indexed triangle strips
  • [x] Support primitive restart index
  • [ ] Tests for generating normals for triangle strips
  • [ ] Docs

szabolcsdombi avatar Aug 01 '17 08:08 szabolcsdombi

Unfortunately the winding changes for the triangles generated. Removing the invalid triangles will mess up the winding order.

Example:

index: 1 2 3 4 5 6 -1 7 8 9
triangles:
1 2 3 CCW
2 3 4 CW
4 5 6 CCW
----- primitive restart
7 8 9 CCW

Visual example:

triangles

index: 0 1 2 3 4 5 6 7 8
triangles:
(see the image above)

szabolcsdombi avatar Aug 01 '17 12:08 szabolcsdombi

You'd have to split the array into subarrays first, then call the index restructuring procedure for each of the subarrays, and then concatenate them.

Korijn avatar Aug 01 '17 14:08 Korijn

something like this: https://stackoverflow.com/a/38278327/552379

Korijn avatar Aug 02 '17 17:08 Korijn

I had no time to push it, but I have some code that can build the indices. I stopped work on this because I noticed the normals are not correct. I will have time around the weekend.

The normals depend on the number of triangles and the "area" of the triangles.

I understand the problem and I want to fix it (maybe it is not a fix but a tweak or a different solution)

I expect to have normals like this:

image

image

szabolcsdombi avatar Aug 03 '17 07:08 szabolcsdombi

You can ignore the area of the triangles to get that result. Maybe add a kwarg weighted=True to the generate_vertex_normals function?

Korijn avatar Aug 03 '17 07:08 Korijn

image

This is another example where the normals are not okey. I have an idea but I have not time right now.

szabolcsdombi avatar Aug 03 '17 08:08 szabolcsdombi

Yes I will add a kwarg for that.

szabolcsdombi avatar Aug 03 '17 08:08 szabolcsdombi