-
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
Add InstancedMeshVisual
for faster and easier rendering of repeated meshes
#2461
Conversation
I got shading to work too! A bit hacky, but it shows that the changes needed are actually pretty small. |
Almost everything thaty works with meshes works here as well! I added some shortcuts to the exampel to test the functionality. The only exception is the |
Ahah we're so close to that! |
@brisvag if you fix the merge conflicts is this ready for re-review and merge? |
Ok, fixed some warnings in the example as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good. I had a couple (mostly documentation) things I'd like updated, but otherwise I think this is pretty close to merging.
vispy/visuals/instanced_mesh.py
Outdated
class InstancedMeshVisual(MeshVisual): | ||
"""Instanced Mesh visual. | ||
|
||
Mostly identical to MeshVisual, but additionally takes arrays of | ||
of positions and transforms (optionally colors) to create multiple | ||
instances of the mesh. | ||
|
||
Parameters | ||
---------- | ||
vertices : array-like | None | ||
The vertices. | ||
faces : array-like | None | ||
The faces. | ||
vertex_colors : array-like | None | ||
Colors to use for each vertex. | ||
face_colors : array-like | None | ||
Colors to use for each face. | ||
color : instance of Color or ColorArray | ||
The color to use. | ||
vertex_values : array-like | None | ||
The values to use for each vertex (for colormapping). | ||
meshdata : instance of MeshData | None | ||
The meshdata. | ||
shading : str | None | ||
Shading to use. This uses the | ||
:class:`~vispy.visuals.filters.mesh.ShadingFilter` | ||
filter introduced in VisPy 0.7. This class provides additional | ||
features that are available when the filter is attached manually. | ||
See 'examples/basics/scene/mesh_shading.py' for an example. | ||
mode : str | ||
The drawing mode. | ||
**kwargs : dict | ||
Keyword arguments to pass to `Visual`. | ||
|
||
Notes | ||
----- | ||
Additional functionality is available through filters. Mesh-specific | ||
filters can be found in the :mod:`vispy.visuals.filters.mesh` module. | ||
|
||
This class emits a `data_updated` event when the mesh data is updated. This | ||
is used for example by filters for synchronization. | ||
|
||
Examples | ||
-------- | ||
Create a primitive shape from a helper function: | ||
|
||
>>> from vispy.geometry import create_sphere | ||
>>> meshdata = create_sphere() | ||
>>> mesh = MeshVisual(meshdata=meshdata) | ||
|
||
Create a custom shape: | ||
|
||
>>> # A rectangle made out of two triangles. | ||
>>> vertices = [(0, 0, 0), (1, 0, 1), (1, 1, 1), (0, 1, 0)] | ||
>>> faces = [(0, 1, 2), (0, 2, 3)] | ||
>>> mesh = MeshVisual(vertices=vertices, faces=faces) | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update this docstring with the new keyword arguments and any usage examples that you think make sense (remove the existing ones that were copied from MeshVisual).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh a link to a site describing instanced rendering would be really nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best example is the one in the gallery I think... Not sure if it's worth putting a big one in here. I don't really have a good link for instance rendering. I found this one maybe, but it's still a bit heavy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah maybe just a nice high-level human-readable description of what instanced rendering is would be nice. I'm basically imagining someone coming to VisPy and knowing very little about OpenGL, buffers, textures, or even only a little bit about what makes up a mesh and they question the difference between these two Visuals and why they should choose one over the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just realizing now, sorry, can we add at least one test to prove that the visual actually works beyond just the example?
Co-authored-by: David Hoese <david.hoese@ssec.wisc.edu>
Co-authored-by: David Hoese <david.hoese@ssec.wisc.edu>
InstancedMeshVisual
for faster and easier rendering of repeated meshes
Definitely... however, do you know how to test |
I think when you create the TestingCanvas or whatever you can specify a backend including a |
@brisvag Ok so I found one instance where it is just called under the Canvas context manager: vispy/vispy/gloo/tests/test_wrappers.py Lines 152 to 153 in ef98259
But there is no indication that this resets on I also found: vispy/vispy/gloo/gl/tests/test_names.py Lines 72 to 82 in 2380f80
where the module includes a teardown: vispy/vispy/gloo/gl/tests/test_names.py Lines 11 to 12 in 2380f80
So maybe a setup_module and teardown_module would be the clearest option? |
Ok website seems good to go now. |
I need to fix a few things that popped up when working on tests; will update you soon! |
…o feature/instanced-mesh
The website failure I've fixed in #2472 and will merge it shortly. |
Followup from #2460: I implemented a full visual that inherits most of its logic from
MeshVisual
!There are a few hacky workarounds, but overall the patching required is minimal.
ShadingFilter
unfortunately doesn't work as intended, I think because the light direction is computed on the non-rotated mesh... Probably possible to work around that too.Otherwise, looks great, and should also work with textures and per-face colors (though I haven't tried that yet).
instanced_mesh_visual.mp4