To keep things simple, the chosen object is the Earth. It can be replaced with any other solar system body.
The first script (for Celestia 1.6) also works with DSOs.
The toggle visibility function is associated to the 'shift + T' keys. It can be replaced with any other non-virtual key.
The first script also works with a 'Ctrl + letter' combination. E.g., just use ["C-t"] for 'Ctrl + T'.
For some reason, some letters can't be used in the Windows version, though.
The first script is for use with Celestia 1.6. It uses the object:setvisible() method.
Code: Select all
-- Title: Toggle object visibility - Celestia 1.6
obj = celestia:find("Sol/Earth") -- Edit this line to define another object
obj_rad = obj:radius()
function toggleObjVisibility()
obj:setvisible(not obj:visible())
if obj:visible() then
celestia:print(obj:localname().." visible")
else
celestia:print(obj:localname().." invisible")
end
end
keyhandlers =
{
T = toggleObjVisibility -- Edit this line to define another key
}
function handlekey(k)
handler = keyhandlers[k.char]
if handler ~= nil then
handler()
return true
else
return false
end
end
celestia:registereventhandler("key", handlekey)
The second script is for use with Celestia 1.5. Since the setvisible function was not implemented yet, the object:setradius() function is used to reduce the object to an invisibly small size, and then to give it back its real size.
Code: Select all
-- Title: Toggle object visibility - Celestia 1.5
obj = celestia:find("Sol/Earth") -- Edit this line to define another object
obj_rad = obj:radius()
obj_visible = true
function toggleObjVisibility()
obj_visible = not(obj_visible)
if obj_visible then
obj:setradius(obj_rad)
celestia:print(obj:localname().." visible")
else
obj:setradius(1e-5)
celestia:print(obj:localname().." invisible")
end
end
keyhandlers =
{
T = toggleObjVisibility -- Edit this line to define another key
}
function handlekey(k)
handler = keyhandlers[k.char]
if handler ~= nil then
handler()
return true
else
return false
end
end
celestia:registereventhandler("key", handlekey)
Eventually, a more complex example of script that toggles several layers can be found here:
viewtopic.php?f=9&t=12702