I am producing images with matplotlib
from python or julia but want to use them in a game. I do not want to produce an animation but want a fast pipeline to be able from a game engine such as Unity
to be able to 'call a python script to produce a plot/figure and use it within the game engine'. I can call the command line for the script to execute which can write the figure to disk as a png for example, that can then be loaded from Unity but that process is not fast. Not requiring animation speed but low latency to not be perceptible. Is there a more direct route to pass the image contents of the figure to a game engine like Unity? Can it be put on a 'socket' or maybe streamed to a buffer that can be read by another process so that maybe the saving times are reduced?
Asked
Active
Viewed 435 times
1

Vass
- 2,682
- 13
- 41
- 60
-
3You can write to a buffer instead of saving to disk. But that would require the buffer to be accessible to the game engine so both processes would need to use the same python kernel I suppose. I wouldn't expect too much of a speed gain though, as saving to disk would probably only be a small portion of the time it takes to generate the figure. – ImportanceOfBeingErnest Oct 28 '19 at 18:43
1 Answers
1
No. The latency is from converting conventional image data into an engine texture at runtime, which occurs on the main thread and is also slow. You can read more here.
Nonetheless, to answer your specific question, you cannot easily call matplotlib
from a C# runtime. You can try compiling a C++ matplotlib
header but it will not work well.
Take a look at Plotting with C# for lower-latency native solutions. There are probably libraries that reproduce enough of the matplotlib
syntax for your needs.

DoctorPangloss
- 2,994
- 1
- 18
- 22
-
it looks like a native solution is the only reliable way forward? The plotting frameworks do not seem to be as sophisticated as matplotlib from an initial inspection but seem to offer most of the key components as you say. would you say that 'oxyplot' (https://oxyplot.readthedocs.io/en/latest/) which is mentioned in your links is the best avenue to pursue ? – Vass Oct 29 '19 at 15:36
-
1like I wrote OxyPlot will not eliminate latency, it's from texture loading, take a look at that thread to understand the problem – DoctorPangloss Oct 29 '19 at 18:41