glotzerlab / plato

Efficient visualization of particle data supporting several rendering engines.
https://plato-draw.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
12 stars 4 forks source link

Add Mesh to fresnel backend. #59

Closed bdice closed 3 years ago

bdice commented 3 years ago

Summary

This PR adds Mesh support to the fresnel backend. It converts the input arrays of vertices and indices into a (3T, 3) array of triangle vertices, where T is the number of triangles.

I also refactored fresnel's default material support so that every primitive gets a newly-constructed Material instance, rather than sharing a module-level constant. I removed the module constants plato.draw.fresnel.FresnelPrimitive.DEFAULT_MATERIAL and plato.draw.fresnel.FresnelPrimitive.SOLID_MATERIAL which is technically an API break, but I don't think any external code would have relied on these default materials.

References:

Caveats

It does not fully support the shape_colors attribute. The cases that are handled correctly are:

In the case where multiple distinct shape colors are provided and shape_color_fraction > 0, only the first shape color is used.

bdice commented 3 years ago

Demos

Built-in mesh test scene This defines shape_colors but only uses the first shape color for all replicas in the primitive. This means that the left cell is colored according to its shape color but the right cell is not (it uses the left cell's shape color). A warning shows: plato/plato/draw/fresnel/Mesh.py:30: UserWarning: Multiple shape colors were provided, but only the first provided shape color will be used for all mesh replicas in the primitive. meshes

Low-poly Stanford Bunny 3D model From https://www.thingiverse.com/thing:151081 by user johnny6, licensed CC BY-NC 4.0 This shows nonzero outline width and vertex colors. bunny_spectral

klarh commented 3 years ago

This looks great; thanks! I think the way you've implemented the per-shape color warning works fine. I'll probably merge these tomorrow.

On the topic of adding outlines to Mesh objects, do you know of anyone using them? If needed, we could probably add them without too much difficulty in other backends.

bdice commented 3 years ago

@klarh Thanks! Glad you like it. 😄

I defer to your expertise on adding outlines to other backends - I have been only adding features as needed. I guess it would not be much harder than for ConvexPolyhedra but I don’t have interest in writing the vispy shaders. If you (or someone else) is interested, I could help with pythreejs if you wanted to add support in vispy. I’d be fine with either of us tackling povray if that’s the route we choose to take.

bdice commented 3 years ago

Trying to close/open to trigger ReadTheDocs to run on this pull request.

bdice commented 3 years ago

Not sure. ReadTheDocs is running but I don't see how to make the check appear with the built docs link. I'll ignore this for now, hopefully it will work on future PRs.