Desktop VR template: /project.lua code sample - Stingray Lua API Reference
-----------------------------------------------------------------------------------
-- This implementation uses the default SimpleProject and the Project extensions are
-- used to extend the SimpleProject behavior.
-- This is the global table name used by Appkit Basic project to extend behavior
Project = Project or {}
local VRPlugin = require 'vr_tools/script/lua/vr_plugin'
local SimpleProject = require 'core/appkit/lua/simple_project'
require 'script/lua/flow_callbacks'
-- Startup options
Project.args = { stingray.Application.argv() } -- command line args
Project.settings = stingray.Application.settings() or {} -- script_data in ini
Project.level_names = {
default = Project.settings.default_level or "content/levels/vr_learning"
}
Project.is_freecam_mode = Project.settings.is_walk_mode == false or false
-- Can provide a config for the basic project, or it will use a default if not.
SimpleProject.config = {
standalone_init_level_name = Project.level_names.default,
camera_unit = "core/appkit/units/camera/camera",
camera_index = 1,
shading_environment = nil, -- Will override levels that have env set in editor.
create_free_cam_player = false, -- Project will provide its own player.
exit_standalone_with_esc_key = true,
dont_capture_mouse_at_startup = true
-- loading_screen_materials = {"core/appkit/materials/loading_screen"},
-- loading_screen_start_package = "loading_screen",
-- loading_screen_end_package = "main",
-- loading_screen_shading_env = "core/stingray_renderer/environments/midday/midday" -- Controls the shading environment used by default by the loading screen.
}
Appkit.register_plugin(VRPlugin)
function Project.on_init_complete()
VRPlugin:init_vr_system()
end
-- This optional function is called by SimpleProject after level, world and player is loaded
-- but before lua trigger level loaded node is activated.
function Project.on_level_load_pre_flow()
if not VRPlugin.is_enabled then
local player_start_pose = Appkit.PlayerUtil.get_player_start_pose(SimpleProject.world) or stingray.Matrix4x4.identity()
local start_position = stingray.Matrix4x4.translation(player_start_pose)
local start_rotation = stingray.Matrix4x4.rotation(player_start_pose)
local Player = require 'script/lua/player'
if Project.is_freecam_mode then
start_position = start_position + stingray.Vector3(0, 0, 1.6)
end
Project.player_controller = Player.spawn_player(SimpleProject.level, start_position, start_rotation, nil, Project.is_freecam_mode)
end
end
function Project.render()
-- returning true overrides appkit.render
if VRPlugin.is_enabled then
return VRPlugin:render()
end
end
return Project