mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-08 22:38:42 -05:00
merge with master
This commit is contained in:
105
data/assets/actions/toggle_trail.asset
Normal file
105
data/assets/actions/toggle_trail.asset
Normal file
@@ -0,0 +1,105 @@
|
||||
local toggle_trail = {
|
||||
Identifier = "os.toggle_trail",
|
||||
Name = "Toggle Trail",
|
||||
Command = [[
|
||||
local node
|
||||
if is_declared("args") then
|
||||
node = args.Node
|
||||
else
|
||||
node = openspace.navigation.getNavigationState().Anchor
|
||||
end
|
||||
|
||||
local trail
|
||||
if openspace.hasSceneGraphNode(node .. "Trail") then
|
||||
trail = node .. "Trail"
|
||||
elseif openspace.hasSceneGraphNode(node .. "_trail") then
|
||||
trail = node .. "_trail"
|
||||
else
|
||||
-- No trail found, so nothing more to do here
|
||||
return
|
||||
end
|
||||
|
||||
local visibility
|
||||
if is_declared("args") then
|
||||
if args.Transition == "Approaching" then
|
||||
visibility = false
|
||||
elseif args.Transition == "Exiting" then
|
||||
visibility = true
|
||||
else
|
||||
return
|
||||
end
|
||||
else
|
||||
visibility = not openspace.getPropertyValue("Scene." .. trail .. ".Renderable.Enabled")
|
||||
end
|
||||
|
||||
openspace.setPropertyValueSingle("Scene." .. trail .. ".Renderable.Enabled", visibility)
|
||||
]],
|
||||
Documentation = [[Toggles the visibility of the associated trail of a scene graph node.
|
||||
This action takes optional arguments to 1) determine which trail to hide (as the
|
||||
'Node') and 2) the transition direction (as 'After' and 'Before').]],
|
||||
GuiPath = "/Trails",
|
||||
IsLocal = true
|
||||
}
|
||||
asset.export("toggle_trail", toggle_trail.Identifier)
|
||||
|
||||
local hide_trail = {
|
||||
Identifier = "os.hide_trail",
|
||||
Name = "Hide Trail",
|
||||
Command = [[
|
||||
local node
|
||||
if is_declared("args") then
|
||||
node = args.Node
|
||||
else
|
||||
node = openspace.navigation.getNavigationState().Anchor
|
||||
end
|
||||
|
||||
if openspace.hasSceneGraphNode(node .. "Trail") then
|
||||
openspace.setPropertyValue("Scene." .. node .. "Trail.Renderable.Enabled", false)
|
||||
elseif openspace.hasSceneGraphNode(node .. "_trail") then
|
||||
openspace.setPropertyValue("Scene." .. node .. "_trail.Renderable.Enabled", false)
|
||||
end
|
||||
]],
|
||||
Documentation = [[Hides the associated trail of a scene graph node. This action takes an
|
||||
optional argument to determine whose trail to hide. If no argument is provided, the
|
||||
current focus node is used instead]],
|
||||
GuiPath = "/Trails",
|
||||
IsLocal = true
|
||||
}
|
||||
asset.export("hide_trail", hide_trail.Identifier)
|
||||
|
||||
local show_trail = {
|
||||
Identifier = "os.show_trail",
|
||||
Name = "Show Trail",
|
||||
Command = [[
|
||||
local node
|
||||
if is_declared("args") then
|
||||
node = args.Node
|
||||
else
|
||||
node = openspace.navigation.getNavigationState().Anchor
|
||||
end
|
||||
|
||||
if openspace.hasSceneGraphNode(node .. "Trail") then
|
||||
openspace.setPropertyValue("Scene." .. node .. "Trail.Renderable.Enabled", true)
|
||||
elseif openspace.hasSceneGraphNode(node .. "_trail") then
|
||||
openspace.setPropertyValue("Scene." .. node .. "_trail.Renderable.Enabled", true)
|
||||
end
|
||||
]],
|
||||
Documentation = [[Shows the associated trail of a scene graph node. This action takes an
|
||||
optional argument to determine whose trail to hide. If no argument is provided, the
|
||||
current focus node is used instead]],
|
||||
GuiPath = "/Trails",
|
||||
IsLocal = true
|
||||
}
|
||||
asset.export("show_trail", show_trail.Identifier)
|
||||
|
||||
asset.onInitialize(function()
|
||||
openspace.action.registerAction(toggle_trail)
|
||||
openspace.action.registerAction(show_trail)
|
||||
openspace.action.registerAction(hide_trail)
|
||||
end)
|
||||
|
||||
asset.onDeinitialize(function()
|
||||
openspace.action.removeAction(toggle_trail.Identifier)
|
||||
openspace.action.removeAction(show_trail.Identifier)
|
||||
openspace.action.removeAction(hide_trail.Identifier)
|
||||
end)
|
||||
27
data/assets/events/toggle_trail.asset
Normal file
27
data/assets/events/toggle_trail.asset
Normal file
@@ -0,0 +1,27 @@
|
||||
local action = asset.require('actions/toggle_trail')
|
||||
|
||||
asset.onInitialize(function()
|
||||
openspace.event.registerEventAction(
|
||||
"CameraFocusTransition",
|
||||
action.show_trail,
|
||||
{ Transition = "Exiting" }
|
||||
);
|
||||
openspace.event.registerEventAction(
|
||||
"CameraFocusTransition",
|
||||
action.hide_trail,
|
||||
{ Transition = "Approaching" }
|
||||
);
|
||||
end)
|
||||
|
||||
asset.onDeinitialize(function()
|
||||
openspace.event.unregisterEventAction(
|
||||
"CameraFocusTransition",
|
||||
action.show_trail,
|
||||
{ Transition = "Exiting" }
|
||||
);
|
||||
openspace.event.unregisterEventAction(
|
||||
"CameraFocusTransition",
|
||||
action.hide_trail,
|
||||
{ Transition = "Approaching" }
|
||||
);
|
||||
end)
|
||||
68
data/assets/examples/approachevents.asset
Normal file
68
data/assets/examples/approachevents.asset
Normal file
@@ -0,0 +1,68 @@
|
||||
local assetHelper = asset.require('util/asset_helper')
|
||||
local sunTransforms = asset.require('scene/solarsystem/sun/transforms')
|
||||
local transforms = asset.require('scene/solarsystem/planets/earth/transforms')
|
||||
|
||||
local generic_action = {
|
||||
Identifier = "os.example.generic",
|
||||
Name = "Generic Example",
|
||||
Command = [[
|
||||
openspace.printInfo("Node: " .. args.Node)
|
||||
openspace.printInfo("Transition: " .. args.Transition)
|
||||
]],
|
||||
Documentation = "Prints the argument information for camera transitions to the log",
|
||||
GuiPath = "/Examples/Events",
|
||||
IsLocal = true
|
||||
}
|
||||
|
||||
local model = asset.syncedResource({
|
||||
Name = "Animated Box",
|
||||
Type = "HttpSynchronization",
|
||||
Identifier = "animated_box",
|
||||
Version = 1
|
||||
})
|
||||
|
||||
local obj = {
|
||||
Identifier = "ExampleEventModel",
|
||||
Parent = transforms.EarthCenter.Identifier,
|
||||
Transform = {
|
||||
Translation = {
|
||||
Type = "StaticTranslation",
|
||||
Position = { 0.0, 11E7, 0.0 }
|
||||
}
|
||||
},
|
||||
Renderable = {
|
||||
Type = "RenderableModel",
|
||||
GeometryFile = model .. "/BoxAnimated.glb",
|
||||
ModelScale = 1.0,
|
||||
LightSources = {
|
||||
{
|
||||
Type = "SceneGraphLightSource",
|
||||
Identifier = "Sun",
|
||||
Node = sunTransforms.SolarSystemBarycenter.Identifier,
|
||||
Intensity = 1.0
|
||||
}
|
||||
},
|
||||
PerformShading = true,
|
||||
DisableFaceCulling = true
|
||||
},
|
||||
InteractionSphere = 1000.0,
|
||||
OnApproach = { "os.example.generic" },
|
||||
OnReach = { "os.example.generic" },
|
||||
OnRecede = { "os.example.generic" },
|
||||
OnExit = { "os.example.generic" },
|
||||
GUI = {
|
||||
Name = "Example Event Model",
|
||||
Path = "/Example",
|
||||
Description = "",
|
||||
}
|
||||
}
|
||||
|
||||
asset.onInitialize(function()
|
||||
openspace.action.registerAction(generic_action)
|
||||
openspace.addSceneGraphNode(obj)
|
||||
end)
|
||||
|
||||
asset.onDeinitialize(function()
|
||||
openspace.removeSceneGraphNode(obj.Identifier)
|
||||
openspace.action.removeAction(generic_action.Identifier)
|
||||
end)
|
||||
Reference in New Issue
Block a user