AnimatLab  2
Test
OsgUserDataVisitor.cpp
1 #include "StdAfx.h"
2 
3 #include "OsgMovableItem.h"
4 #include "OsgBody.h"
5 #include "OsgRigidBody.h"
6 #include "OsgJoint.h"
7 #include "OsgStructure.h"
8 #include "OsgUserDataVisitor.h"
9 #include "OsgUserData.h"
10 #include "OsgDragger.h"
11 #include "OsgMouseSpring.h"
12 #include "OsgSimulator.h"
13 
14 namespace OsgAnimatSim
15 {
16  namespace Visualization
17  {
18 
19 OsgUserDataVisitor::OsgUserDataVisitor(OsgMovableItem *lpItem) : osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN )
20 {
21  m_lpItem = lpItem;
22  //Force the osg user data visitor to visit all the nodes even if the node itself is set to not visit.
23  //Fixes a problem where frozen nodes were set as static in osg, so they were not getting their user data set.
24  setNodeMaskOverride(0xFFFFFFFF);
25 }
26 
27 OsgUserDataVisitor::~OsgUserDataVisitor(void)
28 {
29  m_lpItem = NULL;
30 }
31 
32 void OsgUserDataVisitor::apply(osg::Geode &osgGeode)
33 {
34  int iCount = osgGeode.getNumDrawables();
35 
36  for(int iIdx=0; iIdx<iCount; iIdx++)
37  {
38  osg::Drawable *lpDraw = osgGeode.getDrawable(iIdx);
39  if(lpDraw)
40  {
41  AnimatBase *lpAB = dynamic_cast<AnimatBase *>(m_lpItem);
42  if(lpAB)
43  lpDraw->setName(lpAB->Name() + "_Drawable");
44  lpDraw->setUserData(new OsgUserData(m_lpItem));
45  }
46  }
47 }
48 
49 
50  }// end Visualization
51 }// end OsgAnimatSim
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
Declares the vortex structure class.