Commit 5f31f3ea authored by Karol Actun's avatar Karol Actun
Browse files

added animation to video exporting

parent e42488ef
......@@ -324,9 +324,11 @@ class Visualization:
prev_pos = tile.coordinates
if tile in self._viewer.tile_offset_data:
prev_pos = self._viewer.tile_offset_data[tile][0]
self._viewer.tile_offset_data[tile] = (tile.coordinates, tile.color, prev_pos,
1.0 if tile.get_tile_status() else 0.0)
def remove_location(self, location):
"""
removes a location from the visualization.
......@@ -570,7 +572,7 @@ class Visualization:
self._viewer.set_show_info_frame(True)
self._viewer.set_enable_cursor(True)
def do_export(self, rps, width, height, codec, first_frame_idx, last_frame_idx):
def do_export(self, rps, width, height, codec, first_frame_idx, last_frame_idx, animation):
if not os.path.exists("videos") or not os.path.isdir("videos"):
os.mkdir("videos")
......@@ -589,23 +591,34 @@ class Visualization:
else:
fullpath = path[0] + path[1].replace('*', '')
writer = cv2.VideoWriter(fullpath, cv2.VideoWriter_fourcc(*codec), rps, (width, height))
if animation:
animation_steps = int(30/rps)
if animation_steps < 1:
animation_steps = 1
else:
animation_steps = 1
writer = cv2.VideoWriter(fullpath, cv2.VideoWriter_fourcc(*codec), rps*animation_steps, (width, height))
self._viewer.setDisabled(True)
# creating and opening loading window
lw = LoadingWindow("", "Exporting Video...")
lw.show()
out_of = (last_frame_idx - first_frame_idx + 1) * animation_steps
for i in range(first_frame_idx - 1, last_frame_idx):
# update loading windows text and progress bar
processing = i - first_frame_idx + 2
out_of = last_frame_idx - first_frame_idx + 1
lw.set_message("Please wait!\nExporting frame %d/%d..." % (processing, out_of))
lw.set_progress(processing, out_of)
# process events so the gui thread does respond to interactions..
self._app.processEvents()
# render and write frame
self._viewer.inject_record_data(self.recorder.records[i])
img = self._viewer.get_frame_cv(width, height)
writer.write(img)
# animate
for j in range(1, animation_steps+1):
# process events so the gui thread does respond to interactions..
self._app.processEvents()
# update loading windows text and progress bar
processing = (i - first_frame_idx + 1)*animation_steps + j
lw.set_message("Please wait!\nExporting frame %d/%d..." % (processing, out_of))
lw.set_progress(processing, out_of)
self._viewer.set_animation_percentage(j / animation_steps)
self._viewer.glDraw()
img = self._viewer.get_frame_cv(width, height)
writer.write(img)
self._viewer.inject_record_data(self.recorder.records[last_frame_idx - 1])
writer.release()
lw.close()
......
......@@ -84,13 +84,14 @@ class OGLWidget(QtOpenGL.QGLWidget):
def inject_record_data(self, record):
self.programs["particle"].update_offsets(record[0][0])
self.programs["particle"].update_colors(record[0][1])
self.programs["particle"].update_carried(record[0][2])
self.programs["particle"].update_previous_positions(record[0][2])
self.programs["particle"].update_carried(record[0][3])
self.programs["tile"].update_offsets(record[1][0])
self.programs["tile"].update_colors(record[1][1])
self.programs["tile"].update_carried(record[1][2])
self.programs["tile"].update_previous_positions(record[1][2])
self.programs["tile"].update_carried(record[1][3])
self.programs["location"].update_offsets(record[2][0])
self.programs["location"].update_colors(record[2][1])
self.glDraw()
def update_data(self):
"""
......
import copy
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QVBoxLayout, QSlider, QWidget, QHBoxLayout, QLabel, QPushButton, QLineEdit, QMainWindow, \
QComboBox
QComboBox, QCheckBox
from lib.visualization.utils import show_msg
......@@ -26,16 +26,24 @@ class Recorder:
return self._gui.isVisible()
def record_round(self):
r = [[[], [], []], [[], [], []], [[], []]]
r = [[[], [], [], []], [[], [], [], []], [[], []]]
for particle in self._world.particles:
r[0][0].append(copy.deepcopy(particle.coordinates))
r[0][1].append(copy.deepcopy(particle.color))
r[0][2].append(copy.deepcopy(particle.get_carried_status()))
if len(self.records) > 0:
r[0][2].append(copy.deepcopy(self.records[-1][0][0]))
else:
r[0][2].append(copy.deepcopy(particle.coordinates))
r[0][3].append(copy.deepcopy(particle.get_carried_status()))
for tile in self._world.tiles:
r[1][0].append(copy.deepcopy(tile.coordinates))
r[1][1].append(copy.deepcopy(tile.color))
r[1][2].append(copy.deepcopy(tile.get_tile_status()))
if len(self.records) > 0:
r[1][2].append(copy.deepcopy(self.records[-1][1][0]))
else:
r[1][2].append(copy.deepcopy(tile.coordinates))
r[1][3].append(copy.deepcopy(tile.get_tile_status()))
for location in self._world.locations:
r[2][0].append(copy.deepcopy(location.coordinates))
......@@ -124,6 +132,9 @@ class Recorder:
codec_box.addWidget(QLabel("codec:"))
codec_box.addWidget(codec_combo)
anim_checkbox = QCheckBox("export with animation")
anim_checkbox.setChecked(self._world.vis.get_animation())
export_button = QPushButton("export video")
def export_call():
......@@ -172,7 +183,7 @@ class Recorder:
window.setDisabled(True)
export_callback(input_rps, input_width, input_height,
codec_combo.itemData(codec_combo.currentIndex()), ff, ef)
codec_combo.itemData(codec_combo.currentIndex()), ff, ef, anim_checkbox.isChecked())
window.setDisabled(False)
export_button.clicked.connect(export_call)
......@@ -182,6 +193,7 @@ class Recorder:
main_layout.addLayout(fpsbox)
main_layout.addLayout(resbox)
main_layout.addLayout(codec_box)
main_layout.addWidget(anim_checkbox)
main_layout.addWidget(export_button)
window.setCentralWidget(main_widget)
return window
......
......@@ -56,7 +56,8 @@ void main(void)
}
use_world[3] += vec4(real_offset * world_scaling, 0);
float alpha = color[3];
if(carried > 0.5){
//taken
if(carried > 0.8){
use_world[0][0] = 0.5;
use_world[1][1] = 0.5;
use_world[2][2] = 0.5;
......@@ -64,6 +65,22 @@ void main(void)
use_world[3][1] += 0.2;
use_world[3][2] += 0.2;
alpha = 0.8;
}else if(carried > 0.5){ // just taken
use_world[0][0] = 1.0-0.5*animation_percentage;
use_world[1][1] = 1.0-0.5*animation_percentage;
use_world[2][2] = 1.0-0.5*animation_percentage;
use_world[3][0] += 1.0-0.8*animation_percentage;
use_world[3][1] += 1.0-0.8*animation_percentage;
use_world[3][2] += 1.0-0.8*animation_percentage;
alpha = 1.0-0.2*animation_percentage;
}else if(carried > 0.2){ // just placed
use_world[0][0] = 0.5+0.5*animation_percentage;
use_world[1][1] = 0.5+0.5*animation_percentage;
use_world[2][2] = 0.5+0.5*animation_percentage;
use_world[3][0] += 0.2+0.8*animation_percentage;
use_world[3][1] += 0.2+-0.8*animation_percentage;
use_world[3][2] += 0.2+-0.8*animation_percentage;
alpha = 0.8+0.2*animation_percentage;
}
v_color = vec4(diffuseReflection, alpha);
......
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