Files
OpenSpace/data/assets/examples/statemachine.asset
T
Andreas Engberg 0fc9265837 Feature/assetvalidation (#3396)
# To run the script
Make sure to install the latest Python API version `openspace-api 0.1.2`
The script is located in `OpenSpace/support/assetvalidation`, the main script takes a few command line arguments

`--dir` - specify the OpenSpace directory 
`--filter` - optionally supply a regex string to filter which assets to validate
`--verbose` - flag to print debug info to log and also console (default off), if off only warnings and errors are logged
`--start` - flag to start OpenSpace as a subprocess (default on) if this is off it assumes OpenSpace is already running, useful if you want to run OpenSpace via Visual Studio for example. 
`--at` - specify an index to start at a specific asset

run eg: 
`python main.py --dir="C:/User/Desktop/OpenSpace" --filter="examples" --verbose=True --start=False --at=35`
2024-10-10 15:55:53 +02:00

88 lines
2.2 KiB
Lua

-- Create a state machine with a few different states. The state machine can be controlled through
-- the scripting commands from the state machine module.
asset.require("scene/solarsystem/planets/earth/earth")
asset.require("scene/digitaluniverse/constellations")
local function targetNode(nodeIdentifier)
return [[
openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.RetargetAnchor", nil)
openspace.setPropertyValueSingle(
"NavigationHandler.OrbitalNavigator.Anchor",
"]] .. nodeIdentifier .. [["
)
openspace.setPropertyValueSingle("NavigationHandler.OrbitalNavigator.Aim", "")
]]
end
local States = {
{
Identifier = "Constellations",
Enter = [[
openspace.setPropertyValueSingle("Scene.Constellations.Renderable.Opacity", 1.0, 1.0)
]],
Exit = [[
openspace.setPropertyValueSingle("Scene.Constellations.Renderable.Opacity", 0.0, 1.0)
]]
},
{
Identifier = "Earth",
Enter = [[openspace.setPropertyValueSingle("Scene.EarthLabel.Renderable.Enabled", true)]],
Exit = [[openspace.setPropertyValueSingle("Scene.EarthLabel.Renderable.Enabled", false)]]
},
{
Identifier = "Moon"
}
}
local Transitions = {
{
From = "Earth",
To = "Moon",
Action = targetNode("Moon")
},
{
From = "Moon",
To = "Earth",
Action = targetNode("Earth")
},
{
From = "Earth",
To = "Constellations"
},
{
From = "Constellations",
To = "Earth"
},
{
From = "Moon",
To = "Constellations",
Action = targetNode("Earth")
},
{
From = "Constellations",
To = "Moon",
Action = targetNode("Moon")
}
}
asset.onInitialize(function()
-- Setup (could be done in the profile)
openspace.setPropertyValueSingle("Scene.Constellations.Renderable.Enabled", true)
openspace.setPropertyValueSingle("Scene.Constellations.Renderable.Opacity", 0.0)
openspace.statemachine.createStateMachine(States, Transitions, "Earth")
end)
asset.meta = {
Name = "State Machine",
Description = [[Example of how to create a state machine in OpenSpace, where each
state and transition between states may trigger different behaviors.]],
Author = "OpenSpace Team",
URL = "http://openspaceproject.com",
License = "MIT license"
}