-
Notifications
You must be signed in to change notification settings - Fork 2
/
rai.py
92 lines (73 loc) · 2.78 KB
/
rai.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import bpy
import bmesh
import numpy as np
import sys, os
import re
import time
dirname = os.path.dirname(os.path.realpath(__file__))
sys.path.append(dirname)
from src.Utils import *
from src.Camera import *
from src.RaiLoader import *
from src.RaiAnim import *
from src.RenderEngine import *
time_start_script = time.process_time()
########################################################
# CUSTOM SETTINGS
########################################################
Nsegments = 1 #display N segments. -1: display all segments
NkeyframeSteps = 10 #use every n-th keyframe, interpolate inbetween
renderAnimation = False
renderImage = True
doZoom=False
doZoomOut=False
tPaddingEnd = 200 #number of frames to append after algorithms converged
tZoomStart = 100
tZoomOutDuration = 25
tRotationStart = 50
cameraLocation = Vector((-6,-12,+5))
cameraFocusPoint = Vector((0,0,0))
###############################################################################
## Mobile robots
###############################################################################
folder = "data/animations/mobile/"
cameraLocation = Vector((-6,-12,+5))
# folder = "data/anim/pandas/10/"
# cameraLocation = Vector((-3,-6,+2))
lightLocation = 0.3*(cameraLocation-cameraFocusPoint)+Vector((0,0,+5))
# addLightSourceSun(lightLocation)
addLightSourcePoint(lightLocation)
filename = os.path.basename(os.path.dirname(folder))
########################################################
# Load collada file and preprocess the objects
########################################################
rai = RaiLoader(folder)
rai.generateKeyframesFromAnim(Nsegments, NkeyframeSteps)
setBackgroundColor((.7,.7,.7))
###############################################################################
## CAMERA
###############################################################################
bpy.context.scene.frame_end += tPaddingEnd
tend = bpy.context.scene.frame_end
camera = Camera(cameraLocation, cameraFocusPoint)
if doZoom:
camera.zoomIn(tZoomStart, tZoomStart+50)
if doZoomOut:
camera.zoomOut(tZoomStart+50+50, tZoomStart+50+50+tZoomOutDuration)
camera.rotate(tRotationStart, tend)
## set view to camera
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
area.spaces[0].region_3d.view_perspective = 'CAMERA'
break
###############################################################################
## RENDERING
###############################################################################
render = RenderEngine(folder)
if renderImage:
render.LastFrameToPNG(filename = dirname+"/output/"+filename+'.png')
if renderAnimation:
render.ToMP4(dirname+"/output/"+filename+".mp4")
elapsed_time = time.process_time() - time_start_script
print("TIME for RENDERING: %f (in s), %f (in m), %f (in h)"%\
(elapsed_time,elapsed_time/60,elapsed_time/60/60))