osg.NodeVisitor

class osg.NodeVisitor
Represents

c++ class

Wraps

osg::NodeVisitor

Bases

osg.Object

Visitor for type safe operations on osg.Nodes. Based on GOF’s Visitor pattern. The osg.NodeVisitor is useful for developing type safe operations to nodes in the scene graph (as per Visitor pattern), and adds to this support for optional scene graph traversal to allow operations to be applied to whole scenes at once. The Visitor pattern uses a technique of double dispatch as a mechanism to call the appropriate osg.NodeVisitor.apply() method of the osg.NodeVisitor. To use this feature one must use the osg.Node.accept(NodeVisitor)() which is extended in each osg.Node subclass, rather than the NodeVisitor apply directly. So use root:accept(myVisitor) instead of myVisitor:apply(root). The later method will bypass the double dispatch and the appropriate NodeVisitor:apply(..) method will not be called. There are a number of methods with signature like setApply<NodeType>Cb (e.g. osg.NodeVisitor.setApplyDrawableCb() for osg.Drawable). These methods set callbacks which are called during traversal for corresbonding Node’s type only.

-- Example of osg.NodeVisitor usage.
-- Show complete subgraph of Scene object.
-- See results in the console (script will be evaluated Immediately during project startup).

local scene = reactorController:getReactorByName("Scene") -- must be presented in the project

local depth = 0
local nv = osg.NodeVisitor(osg.NodeVisitor.TRAVERSE_ALL_CHILDREN)
nv:setNodeMaskOverride(0xffffffff)
nv:setApplyNodeCb(function(aNode)
    local prefix = ""
    for i = 0, depth do prefix = prefix .. "  " end

    loginfo(string.format("%s'%s' (%s.%s)", prefix, aNode:getName(), aNode:libraryName(), aNode:className()))

    depth = depth + 1
    nv:traverse(aNode)
    depth = depth - 1
end)

loginfo("******* Complete subgraph of Scene object *******")
scene.node:accept(nv)
loginfo("*************************************************")

Constructors:

osg.NodeVisitor(osg.NodeVisitor.TraversalMode tm)

Параметры

tm (osg.NodeVisitor.TraversalMode) –

osg.NodeVisitor(osg.NodeVisitor.VisitorType type, osg.NodeVisitor.TraversalMode tm)

Параметры

Methods:

:asNodeVisitor()

Convert this into a osg.NodeVisitor pointer if Object is a osg.NodeVisitor, otherwise return 0. Equivalent to C++ dynamic_cast<NodeVisitor*>(this).

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

osg.NodeVisitor

:asCullStack()

Convert this into a osg.CullStack pointer if Object is a osg.CullStack, otherwise return 0. Equivalent to C++ dynamic_cast<osg::CullStack*>(this).

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

osg.CullStack

:reset()

Method to call to reset visitor. Useful if your visitor accumulates state during a traversal, and you plan to reuse the visitor. To flush that state for the next traversal: call reset() prior to each traversal.

:setVisitorType(osg.NodeVisitor.VisitorType type)

Set the VisitorType, used to distinguish different visitors during traversal of the scene, typically used in the osg.Node.traverse() method to select which behaviour to use for different types of traversal/visitors.

Параметры

type (osg.NodeVisitor.VisitorType) –

:getVisitorType()

Get the VisitorType of this osg.NodeVisitor.

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

osg.NodeVisitor.VisitorType

:setTraversalNumber(unsigned fn)

Set the traversal number. Typically used to denote the frame count.

Параметры

fn (unsigned) –

:getTraversalNumber()

Get the traversal number. Typically used to denote the frame count.

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

unsigned

:setFrameStamp(osg.FrameStamp fs)

Set the FrameStamp that this traversal is associated with.

Параметры

fs (osg.FrameStamp) –

:setTraversalMask(unsigned mask)

Set the TraversalMask of this osg.NodeVisitor. The TraversalMask is used by the osg.NodeVisitor.validNodeMask() method to determine whether to operate on a node and its subgraph. osg.NodeVisitor.validNodeMask() is called automatically in the osg.Node.accept() method before any call to osg.NodeVisitor.apply(), apply() is only ever called if validNodeMask returns true. Note, if NodeVisitor::_traversalMask is 0 then all operations will be switched off for all nodes. Whereas setting both _traversalMask and _nodeMaskOverride to 0xffffffff will allow a visitor to work on all nodes regardless of their own Node::_nodeMask state.

Параметры

mask (unsigned) –

:getTraversalMask()

Get the TraversalMask.

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

unsigned

:getNodeMaskOverride()

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

unsigned

:setNodeMaskOverride(unsigned mask)

Set the NodeMaskOverride mask. Used in osg.NodeVisitor.validNodeMask() to determine whether to operate on a node or its subgraph, by OR’ing NodeVisitor::_nodeMaskOverride with the Node’s own Node::_nodeMask. Typically used to force on nodes which may have been switched off by their own Node::_nodeMask.

Параметры

mask (unsigned) –

:validNodeMask(osg.Node node)

Method to called by osg.Node and its subclass“ osg.Node.accept() method, if the result is true it is used to cull operations of nodes and their subgraphs. Return true if the result of a bit wise and of the NodeVisitor::_traversalMask with the bit or between NodeVistor::_nodeMaskOverride and the Node::_nodeMask. Default values for _traversalMask is 0xffffffff, _nodeMaskOverride is 0x0, and Node::_nodeMask is 0xffffffff.

Параметры

node (osg.Node) –

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

bool

:setTraversalMode(osg.NodeVisitor.TraversalMode mode)

Set the traversal mode for osg.Node.traverse() to use when deciding which children of a node to traverse. If a osg.NodeVisitor has been attached via setTraverseVisitor() and the new mode is not osg.NodeVisitor.TRAVERSE_VISITOR from then the attached visitor is detached. Default mode is osg.NodeVisitor.TRAVERSE_NONE.

Параметры

mode (osg.NodeVisitor.TraversalMode) –

:getTraversalMode()

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

osg.NodeVisitor.TraversalMode

:traverse(osg.Node node)

Method for handling traversal of a nodes. If you intend to use the osg.NodeVisitor for actively traversing the scene graph then make sure the accept() methods call this method unless they handle traversal directly.

Параметры

node (osg.Node) –

:pushOntoNodePath(osg.Node node)

Параметры

node (osg.Node) –

:popFromNodePath()

:getNodePath()

Get the osg.NodePath from the top most node applied down to the current osg.Node being visited.

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

osg.NodePath

:getEyePoint()

Get the eye point in local coordinates. Note, not all NodeVisitor implement this method, it is mainly cull visitors which will implement.

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

osg.Vec3

:getViewPoint()

Get the view point in local coordinates. Note, not all NodeVisitor implement this method, it is mainly cull visitors which will implement.

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

osg.Vec3

:getDistanceToEyePoint(osg.Vec3 pos, bool useLODScale)

Get the distance from a point to the eye point, distance value in local coordinate system. Note, not all NodeVisitor implement this method, it is mainly cull visitors which will implement. If the osg.NodeVisitor.getDistanceToEyePoint() is not implemented then a default value of 0.0 is returned.

Параметры
  • pos (osg.Vec3) –

  • useLODScale (bool) –

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

double

:getDistanceFromEyePoint(osg.Vec3 pos, bool useLODScale)

Get the distance of a point from the eye point, distance value in the eye coordinate system. Note, not all NodeVisitor implement this method, it is mainly cull visitors which will implement. If the osg.NodeVisitor.getDistanceFromEyePoint() is not implemented then a default value of 0.0 is returned.

Параметры
  • pos (osg.Vec3) –

  • useLODScale (bool) –

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

double

:getDistanceToViewPoint(osg.Vec3 pos, bool useLODScale)

Get the distance from a point to the view point, distance value in local coordinate system. Note, not all NodeVisitor implement this method, it is mainly cull visitors which will implement. If the osg.NodeVisitor.getDistanceToViewPoint() is not implemented then a default value of 0.0 is returned.

Параметры
  • pos (osg.Vec3) –

  • useLODScale (bool) –

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

double

:setApplyDrawableCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyGeometryCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyNodeCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyGeodeCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyBillboardCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyGroupCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyProxyNodeCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyProjectionCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyCoordinateSystemNodeCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyClipNodeCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyTexGenNodeCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyLightSourceCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyTransformCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyCameraCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyCameraViewCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyMatrixTransformCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyPositionAttitudeTransformCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyAutoTransformCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplySwitchCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplySequenceCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyLODCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyPagedLODCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyClearNodeCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyOccluderNodeCb(luafunction__ cb)

Параметры

cb (luafunction) –

:setApplyOcclusionQueryNodeCb(luafunction__ cb)

Параметры

cb (luafunction) –