Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vertex normal for triangle strip #64

Closed
szabolcsdombi opened this issue Jul 20, 2017 · 5 comments
Closed

Vertex normal for triangle strip #64

szabolcsdombi opened this issue Jul 20, 2017 · 5 comments

Comments

@szabolcsdombi
Copy link
Collaborator

I was wondering if I could generate vertex normals for triangle strips.
Currently generate_vertex_normals works fine for indexed triangles but I would like to use this feature on triangle strips.

image

Generating normals for triangle strips may require support for Primitive Restart Index

Here is an example of a surface using triangle strips and primitive restart index.

for i in range(0, 32):
    for j in range(0, 32):
        vertices.append((i / 32, j / 32, height))

for i in range(0, 32 - 1):
    for j in range(0, 32):
        indices.append(i * 32 + j)
        indices.append((i + 1) * 32 + j)
    indices.append(-1)

I could make a PR to implement this feature.

Do we need support for this in Pyrr?

@Korijn
Copy link
Collaborator

Korijn commented Aug 1, 2017

You could reconstruct a TRIANGLES style index with some vectorized numpy code and reuse the generate_vertex_normals function as-is.

@szabolcsdombi
Copy link
Collaborator Author

Thanks!

Can you please check #66 if the solution is efficient? Is there a better way to do this using numpy?

@Korijn
Copy link
Collaborator

Korijn commented Aug 1, 2017

  • Adding a unit test would definitely help understanding your scenario.
  • Is -1 your primitive restart index value?

I think this should work:

zipped = np.array([indices[:-2], indices[1:-1], indices[2:]])
modified_index = zipped[:, ~np.any(zipped == -1, axis=0)].T

@szabolcsdombi
Copy link
Collaborator Author

Thanks!

The primitive restart index will be a parameter. But the default will be -1.

@Korijn
Copy link
Collaborator

Korijn commented Aug 1, 2017

The numpy version should be faster, particularly for very large indices.

@szabolcsdombi szabolcsdombi closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants