Skip to content

Conversation

@almarklein
Copy link
Collaborator

@almarklein almarklein commented Nov 28, 2025

Closes #487, closes #917, ref #959

  • Add MeshGraphgic
  • Add plot.add_mesh() and plot.add_surface().
  • Add light to a scene by default.
  • Add examples.
  • Support for 2D colormaps.
  • This relies more on PyGfx colormap mechanics. I am not sure why fastplotlib 'renders' its own colormap into vertex colors for lines and scatter.

Possible upstream (pygfx) improvements:

  • Support for clim everywhere where a map is supported.
  • Possibility to set map as a numpy array?

@almarklein almarklein marked this pull request as ready for review November 28, 2025 11:00
@almarklein
Copy link
Collaborator Author

I cannot find the new screenshots. Do I need to whitelist the new examples/mesh dir somewhere?

@github-actions
Copy link

github-actions bot commented Nov 28, 2025

📚 Docs preview built and uploaded! https://www.fastplotlib.org/ver/mesh

@kushalkolar
Copy link
Member

kushalkolar commented Nov 28, 2025

Good start!

_graphic_methods_mixin.py is meant to be auto-generated, so we should make a SurfaceGraphic that probably just subclasses MeshGraphic.

Working on figuring out how to make the surface data dynamically settable so we can have a data @property. I think all the properties should be mutable like the other graphics where it make sense.

For general mesh:

  • positions
  • indices
  • mapcoords
  • cmap
  • colors

For surface:

  • data (which under the hood computes positions, indices, mapcoords)
  • cmap
  • colors

Seems like the normals have to be re-computed if using phong material when positions change. No difference with basic. Edit: Can just set the material.map again. Is there a flag for this we can set?

Anyways, I think we can make the basic material mode as the default and also allow phong and slice. Nah phong default seems best for most functions.

Are morph targets useful for this? Or just setting the position directly is the way to go?

I'm not sure if any of the existing "2D" selectors are useful here, in the future we could make a "cube selector", maybe based on the pygfx gizmo example using an expandable cube that can be used to select the triangles inside the cube?

Other than that that #545 might be useful here when it's available, and we could also make a selector that just allows selecting faces on a mesh (I think pygfx has an example for this, but we could maybe make a easy way to Cntrl + Click to build a selection?). Anyways not a priority for now, just thoughts.

@kushalkolar
Copy link
Member

I'm going to add a few commits to this branch based on #953 (comment)

Comment on lines 120 to 121
self.scene.add(pygfx.AmbientLight())
self.scene.add(self._camera.add(pygfx.DirectionalLight()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these can be settable properties of the PlotArea

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmm ... Having an ambient light and one directional light on the camera is a sweet default that makes sure phong-shaded meshes look good. A user that wants custom lights will probably want to add more lights to the scene, and control on which objects they are attached. That would be tricky to expose as a prop, I think?

FWIW these lights add negligible overhead for objects that don't use lights.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's useful to have easy access to them though, and if a new camera is set on the PlotArea it needs to get the directional light. This is what I mean:

https://github.com/fastplotlib/fastplotlib/pull/953/files#diff-2a0f782c81512ab17081f35fd6cac201fafd429eded696cb76981946bc6baaecR120-R294

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. Nice fix!

@kushalkolar
Copy link
Member

I cannot find the new screenshots. Do I need to whitelist the new examples/mesh dir somewhere?

example dirs for tests are listed here:

# examples live in themed sub-folders
example_globs = [
"image/*.py",
"image_volume/*.py",
"image_widget/*.py",
"heatmap/*.py",
"scatter/*.py",
"line/*.py",
"line_collection/*.py",
"vectors/*.py"
"gridplot/*.py",
"window_layouts/*.py",
"events/*.py",
"selection_tools/*.py",
"misc/*.py",
"guis/*.py",
]

Did you automate finding them in pygfx?

Similarly for docs that dir needs a readme, making these changes in #954

@kushalkolar
Copy link
Member

kushalkolar commented Dec 2, 2025

This relies more on PyGfx colormap mechanics. I am not sure why fastplotlib 'renders' its own colormap into vertex colors for lines and scatter.

pygfx.cm.create_colormap() didn't exist when we implemented lines and scatter, is this what you mean?

Edit: I see LineMaterial.map which can be a TextureMap. Is it possible to apply what we call a "cmap transform" as well, for instance in this example it samples from the colormap using the y-values of a sine function: https://www.fastplotlib.org/ver/dev/_gallery/line/line_cmap.html#sphx-glr-gallery-line-line-cmap-py

But this can be arbitrary, we often use it to indicate things like velocity along a 2d trajectory.

I cannot find the new screenshots. Do I need to whitelist the new examples/mesh dir somewhere?

a comma was also missing, added it , slipped by in the vectors PR

* mesh with gfeatures

* surface graphic works

* update, add PolygonGraphic, works

* black

* for docs and test screenshots

* black

* polygon data updating works

* update

* black

* more examples

* update add_graphic mixin

* code review changes

* fix

* better polygon example
@kushalkolar kushalkolar mentioned this pull request Dec 3, 2025
4 tasks
@almarklein
Copy link
Collaborator Author

almarklein commented Dec 3, 2025

pygfx.cm.create_colormap() didn't exist when we implemented lines and scatter, is this what you mean?

Edit: I see LineMaterial.map which can be a TextureMap. Is it possible to apply what we call a "cmap transform" as well, for instance in this example it samples from the colormap using the y-values of a sine function: https://www.fastplotlib.org/ver/dev/_gallery/line/line_cmap.html#sphx-glr-gallery-line-line-cmap-py

Ah, create_colormap() not existing at the time explains it. Though it would be nice if fpl could simply leverage Pygfx's colormap support, by setting geometry.texcoords and material.map.

If I understand correctly, the current line's geometrytexcoords are simply the vertex indices, and map_transform is used to map that to real values. So in fact, the current map_transform is the mapcoords. Which is good news, I guess, because it means moving to pygfx doing the colormapping should be relatively easy (in a different pr).

edit: easy as in not that complex. Still quite a bit of work, I imagine.

@kushalkolar
Copy link
Member

If I understand correctly, the current line's geometrytexcoords are simply the vertex indices, and map_transform is used to map that to real values. So in fact, the current map_transform is the mapcoords. Which is good news, I guess, because it means moving to pygfx doing the colormapping should be relatively easy (in a different pr).

Yes! Thanks I understand it better now :)

@kushalkolar
Copy link
Member

@almarklein I think this is done 🥳 . Let me know what you think

@almarklein
Copy link
Collaborator Author

I was getting ready to update the buffer resizing logic for the poly data, but saw you already fixed that too. Awesome! Ready from my end then! 👍

@kushalkolar kushalkolar merged commit db49c62 into main Dec 4, 2025
36 checks passed
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

Successfully merging this pull request may close these issues.

Mesh based graphics 2D polygon graphics

3 participants