new.py 1.34 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 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)

 def redraw(self, x, y, r, g, b):
  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)

  N = 4000000
  data = np.c_[x,y]
  data2 = np.c_[r,g,b]

  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)