-
Notifications
You must be signed in to change notification settings - Fork 616
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
Possibility to have 2D gridLines in 3D and limit its area #2311
Comments
As you've discovered, this feature/functionality does not exist. The GridLinesVisual was developed specifically for 2D and would have to be updated to work in 3D. This will likely require a contribution from someone outside the core vispy maintainer group as I don't think we have the time for this work right now. ...but the current version looks pretty cool 😜 |
Hi, |
@mars0001 I'm not sure what you'll need to fix this, but I'm hoping that starting from the main GridLinesVisual will be enough (at least as a start): https://github.com/vispy/vispy/blob/main/vispy/visuals/gridlines.py This visual is based on the ImageVisual (https://github.com/vispy/vispy/blob/main/vispy/visuals/image.py) which is just displaying a 2D image on the Canvas. The GridLinesVisual cheats by overriding some of the functions used by the ImageVisual to make it get an endless amount of "image data" (the lines of the grid). You can see in the little shader code that is in the gridlines module that it is only given a 2-element vector location:
So I guess if you had a modified version of this GLSL (OpenGL Shader Language) implementation to "know" that the grid should only stretch so far, then the logic in the GridLinesVisual's This is all just a guess, but I'm hoping this is all that's needed. |
I don't think I suggested in my previous comments, but one thing that could be done for people wanting this is to use the LineVisual with a series of line segments (or a series of connected vertices where you're smart about switching directions). Thanks @singal95 for the suggestion. Your solution makes me think that maybe something like the ClipperFilter could be used: https://github.com/vispy/vispy/blob/main/vispy/visuals/filters/clipper.py I'm not sure what the parameters would have to be, but if you then did |
Thanks for the tips @djhoese, I tried the |
What was the result? |
Hi, I think the biggest struggle is due to how GridLines are being implemented. With 3D projection such as turntable camera it will create artefacts as observed in your first screenshot, workaround proposed @singal95 wouldn't solve the issue but instead discard vertices based on screen pos. One way would be either to reimplement how GridLinesVisual are being done (there's plenty of shader/explanation on the web on how to) or I found another way based on current implementation. If you set the method as "subdivide" instead of "impostor" inside the gridlines visual it would create only a "portion" of the grid you could then rework and add configurable size inside the visual to allows the shader to limit grid drawing to the world coordinates you are expecting to. I provided here an example with simply a quick test code for substituting impostor method to subdivide: Be aware that's it's not a final solution and not compatible with 2D without further refinement since the grid in 2D would also being affected. |
Hey,
I was wondering if there was a possibility to limit the size and dimensions of the gridlines drawn in 3D.
In pyqtgraph there was a possbility to limit the size
gridplt = gl.GLGridItem(size=pg.Vector(15, 15, 0))
in vispy I use following, but I don't seem to find if it is possible at all to limit the size. Also to limit it to be a 2D grid in 3D plot.
plotGrid = scene.visuals.GridLines(scale=(1, 1), color="white", parent=view.scene)
Thanks in advance!
The text was updated successfully, but these errors were encountered: