[1919] | 1 | #include "OgreOdePrecompiledHeaders.h" |
---|
| 2 | #include "OgreOdeTriangleMeshDataManager.h" |
---|
| 3 | |
---|
[1923] | 4 | #include "OgreOdeTriangleMeshData.h" |
---|
| 5 | |
---|
[1919] | 6 | using namespace Ogre; |
---|
| 7 | using namespace OgreOde; |
---|
| 8 | |
---|
| 9 | namespace Ogre |
---|
| 10 | { |
---|
| 11 | template<> TriangleMeshDataManager *Ogre::Singleton<TriangleMeshDataManager>::ms_Singleton = 0; |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | namespace OgreOde |
---|
| 15 | { |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | //----------------------------------------------------------------------- |
---|
| 19 | TriangleMeshDataManager::TriangleMeshDataManager() |
---|
| 20 | { |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | //----------------------------------------------------------------------- |
---|
| 24 | TriangleMeshDataManager::~TriangleMeshDataManager() |
---|
| 25 | { |
---|
| 26 | //mTriangleMeshDataMap.clear(); |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | //----------------------------------------------------------------------- |
---|
| 30 | TriangleMeshDataManager *TriangleMeshDataManager::getSingletonPtr () |
---|
| 31 | { |
---|
| 32 | return ms_Singleton; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | //----------------------------------------------------------------------- |
---|
| 36 | TriangleMeshDataManager &TriangleMeshDataManager::getSingleton () |
---|
| 37 | { |
---|
| 38 | assert (ms_Singleton); |
---|
| 39 | return (*ms_Singleton); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | //----------------------------------------------------------------------- |
---|
| 44 | void TriangleMeshDataManager::addTriangleMeshData(const String& name, TriangleMeshDataPtr shape, Vector3 scale) |
---|
| 45 | { |
---|
| 46 | |
---|
| 47 | mTriangleMeshDataMap[name][scale] = shape; |
---|
| 48 | |
---|
| 49 | // reduce count so when Ode::Geometry changes its dataPtr or is deleted we arn't |
---|
| 50 | // left with this one on a referance count of 1 |
---|
| 51 | unsigned int* count = shape.useCountPointer(); |
---|
| 52 | (*count)--; |
---|
| 53 | |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | //----------------------------------------------------------------------- |
---|
| 58 | void TriangleMeshDataManager::removeTriangleMeshData(const String& name, Vector3 scale) |
---|
| 59 | { |
---|
| 60 | |
---|
| 61 | TriangleMeshDataPtrMap::iterator itr = mTriangleMeshDataMap.find(name); |
---|
| 62 | if(itr != mTriangleMeshDataMap.end()) |
---|
| 63 | { |
---|
| 64 | |
---|
| 65 | std::map<Ogre::Vector3, TriangleMeshDataPtr, vectorLess>::iterator itr2; |
---|
| 66 | |
---|
| 67 | itr2 = itr->second.find(scale); |
---|
| 68 | |
---|
| 69 | if ( itr2 != itr->second.end() ) |
---|
| 70 | { |
---|
| 71 | //printf ("no TriangleMeshData for scale so erase it\n"); |
---|
| 72 | itr->second.erase(itr2); |
---|
| 73 | itr2->second.setNull(); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | if (itr->second.size() == 0) |
---|
| 77 | { |
---|
| 78 | //printf ("have no TriangleMeshData for this mesh so erase it from map\n"); |
---|
| 79 | mTriangleMeshDataMap.erase(itr); |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | /** looks for mesh name then size or returns a NULL TriangleMeshDataPtr |
---|
| 87 | */ |
---|
| 88 | //----------------------------------------------------------------------- |
---|
| 89 | TriangleMeshDataPtr TriangleMeshDataManager::getTriangleMeshData(const String& name, Vector3 scale) |
---|
| 90 | { |
---|
| 91 | |
---|
| 92 | TriangleMeshDataPtrMap::iterator itr = mTriangleMeshDataMap.find(name); |
---|
| 93 | if(itr != mTriangleMeshDataMap.end()) |
---|
| 94 | { |
---|
| 95 | std::map<Ogre::Vector3, TriangleMeshDataPtr, vectorLess>::iterator itr2; |
---|
| 96 | |
---|
| 97 | itr2 = itr->second.find(scale); |
---|
| 98 | |
---|
| 99 | if ( itr2 != itr->second.end() ) |
---|
| 100 | { |
---|
| 101 | return itr2->second; |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | //printf ("TriangleMeshDataManager::getTriangleMeshData not found\n"); |
---|
| 106 | |
---|
| 107 | return NULL; |
---|
| 108 | |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | } |
---|