Skip to content
Alexander Bock edited this page Mar 22, 2021 · 1 revision

Useful Lua scripts

Set the camera position to the last location of a session recording

Caveat: Only ASCII format is supported; last line in the recording has to be a 'camera' keyframe; an existing tmptmp.osrectxt file will be silently overwritten

function setPosition(file)
    local c = ''
    for line in io.lines(file) do
        if line ~= '' then c = line end
    end
    if c:sub(1, 6) ~= 'camera' then openspace.printError('Last line not camera') end
    local i = 0
    local s = ''
    for w in c:gmatch('[^%s]+') do
        if i == 1 or i == 2 then s = s .. '0.0 ' else s = s .. w .. ' ' end
        i = i + 1
    end
    s = s:sub(1, #s - 1)
    local d = io.open(openspace.absPath("${RECORDINGS}/tmptmp.osrectxt"), "w")
    d:write('OpenSpace_record/playback01.00A\n' .. s .. '\n')
    d:close()
    openspace.sessionRecording.startPlayback('tmptmp.osrectxt')
end

Usage: setPosition("A:/OpenSpace/user/recordings/test.osrectxt")

Clone this wiki locally