new.py 1.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
# pylint: disable=invalid-name, no-member, unused-argument

import numpy as np
import datetime
import unreal_engine as ue
from unreal_engine.enums import EPixelFormat
from vispy import app, gloo

class Plot:

 def begin_play(self):
  self.uobject.get_owner().bind_event('OnRedraw', self.redraw)

14
 def redraw(self, x, y, c):
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
  width=1024
  height=1024
  canvas = app.Canvas(size=(width, height))

  vertex = """
  #version 150 compatibility
  attribute vec2 a_position;
  attribute vec3 a_color;
  out vec4 color;
  void main(void)
  {
  gl_Position = vec4(a_position, 0.0, 1.0);
  color = vec4(a_color, 1.0);
  }
  """

  fragment = """
  #version 150 compatibility
  in vec4 color;
  void main()
  {
  gl_FragColor = color;
  }
  """

  program = gloo.Program(vert=vertex, frag=fragment)

42 43
  data = np.c_[x[0:100000],y[0:100000]]
  data2 = np.c_[c]
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

  program['a_color'] = data2.astype('float32')
  program['a_position'] = data.astype('float32')

  @canvas.connect
  def on_draw(event):			
   gloo.set_clear_color((1.0, 1.0, 1.0, 1.0))
   gloo.clear()

   program.draw(mode='points')

  array = canvas.render().tobytes()
  self.texture = ue.create_transient_texture(width, height, EPixelFormat.PF_R8G8B8A8)
  self.texture.texture_set_data(array)
  self.uobject.get_owner().StaticMeshComponent.OverrideMaterials[0].set_material_texture_parameter('Graph', self.texture)