33 m_aryMeshes.RemoveAll();
36 {
Std_TraceMsg(0,
"Caught Error in desctructor of OsgMeshMgr\r\n",
"", -1,
false,
true);}
39 std::string OsgMeshMgr::FileCreateTime(std::string strFilename)
45 WIN32_FILE_ATTRIBUTE_DATA wfad;
48 GetFileAttributesEx(strFilename.c_str(), GetFileExInfoStandard, &wfad);
49 FileTimeToSystemTime(&wfad.ftLastWriteTime, &st);
51 ss << st.wMonth <<
'/' << st.wDay <<
'/' << st.wYear <<
" " << st.wHour <<
":" << st.wMinute <<
":" << st.wSecond;
54 stat(strFilename.c_str(), &attrib);
57 ts = localtime(&attrib.st_mtime);
59 ss << ts->tm_mon <<
'/' << ts->tm_wday <<
'/' << ts->tm_year <<
" " << ts->tm_hour <<
":" << ts->tm_min <<
":" << ts->tm_sec;
65 osg::Node *OsgMeshMgr::LoadMesh(std::string strFilename)
67 std::pair<std::string, osg::ref_ptr<osg::Node>> MeshPair;
70 if(!
FindMesh(strFilename, MeshPair,
false))
71 return AddMesh(strFilename);
74 std::string strCreateDate = FileCreateTime(strFilename);
78 if(strCreateDate == MeshPair.first)
79 return MeshPair.second.get();
82 ReleaseMesh(strFilename);
83 return AddMesh(strFilename);
88 osg::Node *OsgMeshMgr::AddMesh(std::string strFilename)
90 osg::ref_ptr<osg::Node> lpTempMesh = osgDB::readNodeFile(strFilename.c_str());
94 osgUtil::SmoothingVisitor sv;
95 lpTempMesh->accept(sv);
97 std::string strFileCreateTime = FileCreateTime(strFilename);
98 std::pair<std::string, osg::ref_ptr<osg::Node>> MeshPair2(strFileCreateTime, lpTempMesh);
101 return lpTempMesh.get();
108 void OsgMeshMgr::ReleaseMesh(std::string strFilename)
111 std::pair<std::string, osg::ref_ptr<osg::Node>> MeshPair;
112 if(!
FindMesh(strFilename, MeshPair,
false))
return;
114 MeshPair.second.release();
119 bool OsgMeshMgr::ContainesMesh(std::string strFilename)
121 std::pair<std::string, osg::ref_ptr<osg::Node>> MeshPair;
123 if(
FindMesh(strFilename, MeshPair,
false))
140 bool OsgMeshMgr::FindMesh(std::string strFilename, std::pair<std::string, osg::ref_ptr<osg::Node>> &MeshPair,
bool bThrowError)
142 CStdMap<std::string, std::pair<std::string, osg::ref_ptr<osg::Node>> >::iterator oPos;
145 if(oPos != m_aryMeshes.end())
147 MeshPair = oPos->second;
151 THROW_TEXT_ERROR(Osg_Err_lMeshIDNotFound, Osg_Err_strMeshNotFound,
" Mesh Filename: " + strFilename);
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
bool FindMesh(std::string strFilename, std::pair< std::string, osg::ref_ptr< osg::Node >> &MeshPair, bool bThrowError=true)
Searches for a mesh that matches the specified filename.
void Std_TraceMsg(const int iLevel, std::string strMessage, std::string strSourceFile, int iSourceLine, bool bLogToFile, bool bPrintHeader)
Traces a message to the debugger window.
Declares the vortex MeshMgr class.
std::string Std_CheckString(std::string strVal)
Converts a string to upper case and trims it.
OsgMeshMgr()
Default constructor.
virtual ~OsgMeshMgr()
Destructor.