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

how to display wireframe in threejs #143

Open
ghost opened this issue Sep 18, 2022 · 2 comments
Open

how to display wireframe in threejs #143

ghost opened this issue Sep 18, 2022 · 2 comments

Comments

@ghost
Copy link

ghost commented Sep 18, 2022

Hello
i want to display mesh with wireframe, but it seems not work, can you supply an demo material to me on how to display mesh with wireframe, thanks!

@ponchio
Copy link
Contributor

ponchio commented Sep 19, 2022

Hi,
wireframe rendering is way more complicated than it looks.

Note: do we really want to use wireframe? Nexus is split in blocks using different resolution and swaps betwenn resolutions when data arrive, when you zoom in and out or even pan. This is hardly noticeable for full triangle rendering but in wireframe it would be a constant flickering.

Unfortunately the easy threejs approch of using WireframeGeometry doesn't work, nexus renders geometry behind threejs engine (for perfomance reasons).

Most common approaches:

  1. render using gl.LINES: we need to create the line index from the triangle index (it's trivial), create an extra set of buffers holding the indexes. this is what WireframeGeometry is doing. Threejs would provide the shader.
    Main problem is that it's pretty slow especially since we don't want duplicated edges, and especially if you want to swap between wireframe and solid rendering.

  2. use barycentric coordinates:
    we add an attribute which has (0,0) (1,0) (0,1) coords for each triangle
    we need to 'unindex' the vertices (space grows 3x!) (this is trivial but has the same problems as above)
    we need a custom shader

  3. geometry shader, glPolygonMode, but we are in webgl2 and they are not available.

In summary: there are no good wireframe solutions for large models in webgl2, option 1 looks the most promising, but requires some effort.

I have made a commit where if you specify:

nexus_model.material.wireframe = true;
nexus_model.material.needsUpdate = true;

it simply replaces TRIANGLES with LINE_STRIP, you will be able to see the wireframe, but also wrong lines.
Due to the particular corto compression triangle sequence, the number of wrong line can be pretty small.

@ghost
Copy link
Author

ghost commented Sep 21, 2022

Many many thanks for the information.
As you said, after modifying according to your method, the wireframe of the mesh can be seen, but some triangles seem to be incorrect, is there any way for me to ensure the correctness of the mesh?
Best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant