This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Precalc.gd
56 lines (49 loc) · 1.69 KB
/
Precalc.gd
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
extends Spatial
# Each bike takes 4 pixels of precalc storage per frame (one vec3 for position, one mat3x3 for translation)
const NO_BIKES: int = 5
const PRECALC_TICKS: int = 256
var image: Image = Image.new()
var bikes: Array
var tick: int = 0
func _ready():
image.create(PRECALC_TICKS, PRECALC_TICKS, false, Image.FORMAT_RGBF);
image.lock()
bikes.append(find_node("Bike1"))
bikes.append(find_node("Bike2"))
bikes.append(find_node("Bike3"))
bikes.append(find_node("Bike4"))
bikes.append(find_node("Bike5"))
func _physics_process(_delta):
if tick >= PRECALC_TICKS:
return
var width = self.image.data["width"]
var stream = StreamPeerBuffer.new()
stream.data_array = self.image.data["data"]
stream.seek(tick * 4 * 3 * width)
for i in range(bikes.size()):
var p = bikes[i].global_transform.origin
stream.put_float(-p.x) # ¯\_(ツ)_/¯
stream.put_float(p.y)
stream.put_float(p.z)
var t = bikes[i].global_transform.basis
# I have no bloody clue what I'm doing here, if the order is correct,
# if I should invert X here as well or not, but this is what looks
# the least bad.
stream.put_float(-t.x.x)
stream.put_float(-t.y.x)
stream.put_float(-t.z.x)
stream.put_float(t.x.y)
stream.put_float(t.y.y)
stream.put_float(t.z.y)
stream.put_float(t.x.z)
stream.put_float(t.y.z)
stream.put_float(t.z.z)
# For some reason you have to put it back on the image? Idk.. Godot..
self.image.data["data"] = stream.data_array
tick += 1
$ColorRect/ProgressBar.value = tick / float(PRECALC_TICKS) * 100
if tick >= PRECALC_TICKS:
var texture = ImageTexture.new()
texture.create_from_image(image, 0);
get_parent().find_node("MarchTarget").call_deferred("play", texture)
queue_free()