osg.Switch

class osg.Switch
Represents

c++ class

Wraps

osg::Switch

Bases

osg.Group

osg.Switch is a Group node that allows switching between children. Typical uses would be for objects which might need to be rendered differently at different times, for instance a switch could be used to represent the different states of a traffic light.

-- Example of osg.Switch usage.
-- Show one of 3 images each <period> seconds.

local hud       = reactorController:getReactorByName("HeadUpDisplay") -- must be presented in the project
local timer     = reactorController:getReactorByName("timer") -- must be presented in the project
local image_1   = reactorController:getReactorByName("image_1") -- must be presented in the project
local image_2   = reactorController:getReactorByName("image_2") -- must be presented in the project
local image_3   = reactorController:getReactorByName("image_3") -- must be presented in the project
local switch    = osg.Switch()

-- NOTE: ImageReactors must be explicitly enabled for correct work
image_1:show()
image_2:show()
image_3:show()

hud:freeze()    -- lock the object to change high-level objects hierarchy
hud:removeChild(image_1)
hud:removeChild(image_2)
hud:removeChild(image_3)
hud:thaw()

-- NOTE: we do not need any freeze/thaw here to change OSG nodes' hierarchy
-- All images are visible on startup
hud.node:addChild(switch)
switch:addChild(image_1.node, true)
switch:addChild(image_2.node, true)
switch:addChild(image_3.node, true)

-- switch:setAllChildrenOff()   -- uncomment to hide all images on startup

local period        = 2.0   --seconds
local currentImage  = 0     -- first image's index is 0

timer:subscribeEvent("onAlarm", function()
    loginfo("Show image_" .. currentImage)
    switch:setSingleChildOn(currentImage)
    currentImage = (currentImage + 1) % 3
end)

timer:start(period, timer.Mode.LOOP)

return switch

Constructors:

osg.Switch()

Methods:

:addChild(osg.Node node, bool val)

Параметры
Тип результата

bool

:insertChild(unsigned index, osg.Node node)

Параметры
  • index (unsigned) –

  • node (osg.Node) –

Тип результата

bool

:insertChild(unsigned index, osg.Node node, bool val)

Параметры
  • index (unsigned) –

  • node (osg.Node) –

  • val (bool) –

Тип результата

bool

:removeChildren(unsigned pos, unsigned count)

Параметры
  • pos (unsigned) –

  • count (unsigned) –

Тип результата

bool

:setValue(unsigned index, bool val)

Параметры
  • index (unsigned) –

  • val (bool) –

:getValue(unsigned index)

Параметры

index (unsigned) –

Тип результата

bool

:setChildValue(osg.Node node, bool val)

Параметры
:getChildValue(osg.Node node)

Параметры

node (osg.Node) –

Тип результата

bool

:setAllChildrenOff()

Set all the children off (false), and set the new default child value to off (false).

Тип результата

bool

:setAllChildrenOn()

Set all the children on (true), and set the new default child value to on (true).

Тип результата

bool

:setSingleChildOn(unsigned pos)

Set a single child on, switch off all other children.

Параметры

pos (unsigned) –

Тип результата

bool