Commit b1f86f1f authored by Jan Kremer's avatar Jan Kremer
Browse files

First tests

parent 00216749
import unreal_engine as ue
# EPixelFormat defines the various pixel formats for a texture/image, we will use RGBA with 8bit per channel
from unreal_engine.enums import EPixelFormat
import matplotlib
# set the Agg renderer as we do not need any toolkit
matplotlib.use('Agg')
import matplotlib.pyplot as plt
# set texture/plot dimensions and dpi, ensure dpi is a float !
width = 1024
height = 1024
dpi = 72.0
# create a new figure with the specified sizes
fig = plt.figure(1)
fig.set_dpi(dpi)
fig.set_figwidth(width/dpi)
fig.set_figheight(height/dpi)
# plot a simple graph with a label on the y axis
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
# draw the graph (in memory)
fig.canvas.draw()
# create a texture in memory (will be saved later)
texture = ue.create_transient_texture(width, height, EPixelFormat.PF_R8G8B8A8)
# copy pixels from matplotlib canvas to the texture as RGBA
texture.texture_set_data(fig.canvas.buffer_rgba())
# save the texture
texture.save_package('/Game/GraphTexture')
# open its editor
ue.open_editor_for_asset(texture)
\ No newline at end of file
import unreal_engine as ue
from unreal_engine.enums import EPixelFormat
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
class PlotComponent:
def begin_play(self):
width = 1024
height = 1024
dpi = 72.0
self.texture = ue.create_transient_texture(width, height, EPixelFormat.PF_R8G8B8A8)
# self.uobject.get_owner().StaticMeshComponent.getMaterial(0).set_material_texture_parameter('Graph', self.texture)
# self.uobject.get_owner().StaticMeshComponent.createDynamicMaterialInstance()
# matinst = self.uobject.get_owner().StaticMeshComponent.CreateAndSetMaterialInstanceDynamic(0)
# matinst.set_material_texture_parameter('Graph', self.texture)
self.fig = plt.figure(1)
self.fig.set_dpi(dpi)
self.fig.set_figwidth(width/dpi)
self.fig.set_figheight(height/dpi)
self.uobject.get_owner().bind_event('OnGraphDataUpdated', self.update_graph)
def update_graph(self, platform):
# clear the current plot data
plt.clf()
# draw a pie chart
plt.pie([5, 7, 12], colors=['r', 'g', 'b'], labels=['RedCube', 'GreenCube', 'BlueCube'], shadow=True)
self.fig.canvas.draw()
self.texture.texture_set_data(self.fig.canvas.buffer_rgba())
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment