Files
OpenSpace/scripts/common.lua
Alexander Bock c275b2f833 Feature/cmake cleanup (#381)
* Rename OnScreenGui module to ImGui
* Support multiple external module folders (closes #31)
* Cleaning up CMake files
  * Restructure application specification
  * Add parameter for library mode to all modules
  * Add functions to handle global variable state
* Misc/remove warnings (#383)
* Increase build timeout and do a clean rebuild every commit
2017-08-14 09:38:32 -04:00

145 lines
5.5 KiB
Lua

--[[ Commonly used OpenSpace configuration functions ]]--
helper = {}
helper.renderable = {}
helper.property = {}
-- These helpers are for scheduling lua scripts
-- See class ScriptScheduler and ScheduledScript for reference
helper.scheduledScript = {}
helper.scheduledScript.reversible = {}
-- Function that sets the most common key bindings that are common to most (all?)
-- scenes
helper.setCommonKeys = function()
openspace.bindKeyLocal(
"F1",
helper.property.invert('Global Properties.ImGUI.Main.Enabled'),
"Toggles the visibility of the on-screen GUI."
)
openspace.bindKeyLocal(
"F2",
helper.property.invert("RenderEngine.PerformanceMeasurements"),
"Toogles performance measurements that shows rendering time informations."
)
openspace.bindKeyLocal(
"ESC",
"openspace.toggleShutdown()",
"Toggles the shutdown that will stop OpenSpace after a grace period. Press again to cancel the shutdown during this period."
)
openspace.bindKeyLocal(
"PRINT_SCREEN",
"openspace.setPropertyValueSingle('RenderEngine.TakeScreenshot', nil)",
"Saves the contents of the screen to a file in the working directory."
)
openspace.bindKey(
"SPACE",
"openspace.time.togglePause()",
"Starts and stops the simulation time."
)
openspace.bindKey(
"COMMA",
"openspace.setRenderer('Framebuffer');",
"Changes the currently used renderer to use the 'Framebuffer' implementation."
)
openspace.bindKey(
"PERIOD",
"openspace.setRenderer('ABuffer');",
"Changes the currently used renderer to use the 'ABuffer' implementation."
)
openspace.bindKey(
"f",
helper.property.invert('NavigationHandler.OrbitalNavigator.Friction.RotationalFriction'),
"Toggles the rotational friction of the camera. If it is disabled, the camera rotates around the focus object indefinitely."
)
openspace.bindKey(
"Shift+f",
helper.property.invert('NavigationHandler.OrbitalNavigator.Friction.ZoomFriction'),
"Toggles the zoom friction of the camera. If it is disabled, the camera rises up from or closes in towards the focus object indefinitely."
)
openspace.bindKey(
"Ctrl+f",
helper.property.invert('NavigationHandler.OrbitalNavigator.Friction.RollFriction'),
"Toggles the roll friction of the camera. If it is disabled, the camera rolls around its own axis indefinitely."
)
openspace.bindKey(
"w",
"openspace.toggleFade(3)",
"Toggles the fade to black within 3 seconds or shows the rendering after 3 seconds."
)
end
helper.setDeltaTimeKeys = function(t)
local Keys = {
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'Shift+1', 'Shift+2', 'Shift+3', 'Shift+4', 'Shift+5', 'Shift+6', 'Shift+7', 'Shift+8', 'Shift+9', 'Shift+0',
'Ctrl+1', 'Ctrl+2', 'Ctrl+3', 'Ctrl+4', 'Ctrl+5', 'Ctrl+6', 'Ctrl+7', 'Ctrl+8', 'Ctrl+9', 'Ctrl+0',
'Alt+1', 'Alt+2', 'Alt+3', 'Alt+4', 'Alt+5', 'Alt+6', 'Alt+7', 'Alt+8', 'Alt+9', 'Alt+0'
}
if #t > #Keys then
openspace.printError("Error settings delta time keys: Too many delta times (" .. #t .. ")")
return
end
for i, v in ipairs(t) do
openspace.bindKey(
Keys[i],
'openspace.time.setDeltaTime(' .. v .. ")",
'Setting the simulation speed to ' .. v .. ' seconds per realtime second'
)
end
end
-- Function that returns the string that inverts the fully qualified boolean property 'property'
helper.property.invert = function(property)
local escaped_property = "'" .. property .. "'"
return "openspace.setPropertyValue(" .. escaped_property .. ", not openspace.getPropertyValue(" .. escaped_property .. "));"
end
-- Function that returns the string that increments the 'property' by the 'value'
helper.property.increment = function(property, value)
local v = value or 1
local escaped_property = "'" .. property .. "'"
return "openspace.setPropertyValue(" .. escaped_property .. ", openspace.getPropertyValue(" .. escaped_property .. ") + " .. v .. ");"
end
-- Function that returns the string that decrements the 'property' by the 'value'
helper.property.decrement = function(property, value)
return helper.property.increment(property, -value)
end
-- Function that returns the string that enables/disables the renderable 'renderable'
helper.renderable.toggle = function(renderable)
return helper.property.invert(renderable .. ".renderable.Enabled")
end
-- Function that returns the string that sets the enabled property of <renderable> to <enabled>
helper.renderable.setEnabled = function(renderable, enabled)
return "openspace.setPropertyValue('" .. renderable .. ".renderable.Enabled', " .. (enabled and "true" or "false") .. ");";
end
-- Function that returns a lua table specifying a reversible ScheduledScript for
-- setting the enabled property of <renderable> to <enabled> at time <time>.
helper.scheduledScript.reversible.setEnabled = function(time, renderable, enabled)
return
{
Time = time,
ForwardScript = helper.renderable.setEnabled(renderable, enabled),
BackwardScript = helper.renderable.setEnabled(renderable, not enabled)
}
end
helper.scheduledScript.setEnabled = function(time, renderable, enabled)
return
{
Time = time,
ForwardScript = helper.renderable.setEnabled(renderable, enabled)
}
end