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