Skip to content

Commit 7ccaa91

Browse files
author
Roberto De Ioris
committed
added graph_texture.py
1 parent f7924f6 commit 7ccaa91

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

110 KB
Loading
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import unreal_engine as ue
2+
# EPixelFormat defines the various pixel formats for a texture/image, we will use RGBA with 8bit per channel
3+
from unreal_engine.enums import EPixelFormat
4+
5+
import matplotlib
6+
# set the Agg renderer as we do not need any toolkit
7+
matplotlib.use('Agg')
8+
9+
import matplotlib.pyplot as plt
10+
11+
# set texture/plot dimensions and dpi, ensure dpi is a float !
12+
width = 1024
13+
height = 1024
14+
dpi = 72.0
15+
16+
# create a new figure with the specified sizes
17+
fig = plt.figure(1)
18+
fig.set_dpi(dpi)
19+
fig.set_figwidth(width/dpi)
20+
fig.set_figheight(height/dpi)
21+
22+
# plot a simple graph with a label on the y axis
23+
plt.plot([1, 2, 3, 4])
24+
plt.ylabel('some numbers')
25+
26+
# draw the graph (in memory)
27+
fig.canvas.draw()
28+
29+
# create a texture in memory (will be saved later)
30+
texture = ue.create_transient_texture(width, height, EPixelFormat.PF_R8G8B8A8)
31+
# copy pixels from matplotlib canvas to the texture as RGBA
32+
texture.texture_set_data(fig.canvas.buffer_rgba())
33+
34+
# save the texture
35+
texture.save_package('/Game/FirstGraphTexture')
36+
37+
# open its editor
38+
ue.open_editor_for_asset(texture)
59.7 KB
Loading

0 commit comments

Comments
 (0)