plotly / plotly.js

Open-source JavaScript charting library behind Plotly and Dash
https://plotly.com/javascript/
MIT License
16.93k stars 1.85k forks source link

Transparent faces in mesh plots overlap incorrectly #3243

Open scottsleep opened 5 years ago

scottsleep commented 5 years ago

Normally, when a face is opaque it can obscure other faces, or if the camera is rotated 180 degrees the first is now obscured by the second. This is currently not true for faces with opacity < 1. Instead it seems as if they are always layered in order of creation, so the first face in the mesh will always be on top (or beneath?) the others, no matter their relative 3D location.

The example contains 4 triangles: the two on the left are opaque while the two on the right are transparent.

plotly bug https://codepen.io/anon/pen/bQqeMg

This leads to situations where obscured objects are drawn in front. All the boxes in the image below are either behind or inside the Blue one. plotly bug2

Observed in Chrome 70.0.3538.102 and Firefox 63.0.1 (64-bit) on Win 10

etpinard commented 5 years ago

Yeah, that's essentially the mesh3d manifestation of bug https://github.com/plotly/plotly.js/issues/1267

Thank you for writing in with such clear examples.

etpinard commented 5 years ago

Related https://github.com/plotly/plotly.js/issues/3138

etpinard commented 5 years ago

Another example: https://github.com/plotly/plotly.js/issues/3410 - this for surface traces.

archmoj commented 5 years ago

I think we may need to sort triangles when there are transparent ones. There might be other solutions useful for orthographic projection {this PR}. Another idea for making surfaces transparent is surface tessellation.

archmoj commented 5 years ago

Another codepen to highlight the draw order issue still exists even with lower opacity values and separated RGB channels.

archmoj commented 5 years ago

OK. I think a patch like this commit may help. cc: https://github.com/plotly/plotly.js/issues/4111 cc: https://github.com/plotly/plotly.js/issues/1267

Please notice how one could get similar overlap colors here but not before.

Here are more examples: example 2 before after

example 3 before after

example 4 before after

archmoj commented 5 years ago

Also for scatter3d traces there is another possibility to enable depth like these: example 2 example 3 example 4

archmoj commented 5 years ago

And finally for regular point-clouds here is the algorithm that works best: Example 1 Example 2 Example 3 Example 4

cc: #4111 cc: #1267

archmoj commented 4 years ago

Also for surface plot the app at https://dash-gallery.plotly.host/dash-yield-curve/ displays
Screenshot from 2019-11-11 10-07-42

jackparmer commented 4 years ago

This issue has been tagged with NEEDS SPON$OR

A community PR for this feature would certainly be welcome, but our experience is deeper features like this are difficult to complete without the Plotly maintainers leading the effort.

What Sponsorship includes:

Please include the link to this issue when contacting us to discuss.

gvwilson commented 4 months ago

@archmoj is this currently on your pile? No worries if not - we're just trying to do some planning.

archmoj commented 4 months ago

@gvwilson yes it is. I need 2 days to possibly complete #4643 pull.