Changeset 870 for GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE
- Timestamp:
- 05/02/06 10:26:43 (19 years ago)
- Location:
- GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityOctreeSceneManager.h
r868 r870 123 123 /** Finds object corresponding to this bounding box in the scene. 124 124 */ 125 MovableObject*FindCorrespondingObject(const AxisAlignedBox &box);125 Entity *FindCorrespondingObject(const AxisAlignedBox &box); 126 126 127 127 /** Identifies objects in the scene and gives them unique ids that … … 129 129 */ 130 130 void IdentifyObjects(GtpVisibilityPreprocessor::ObjectContainer &objects); 131 132 /** Loads / unloads pvs of the view cell to set the visibility in the scene. 133 */ 134 void applyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, const bool load); 135 136 /** updates pvs in current frame. 137 */ 138 void updatePvs(Camera *cam); 139 140 /** Sets all objects invisible. 141 */ 142 void SetObjectsVisible(const bool visible); 131 143 132 144 /// the interface to the scene hierarchy. … … 183 195 bool mViewCellsLoaded; 184 196 GtpVisibilityPreprocessor::ViewCellsManager *mViewCellsManager; 197 198 /** Used to assign Ogre meshes to view cell entries. 199 */ 200 GtpVisibilityPreprocessor::ObjectContainer mObjects; 201 202 GtpVisibilityPreprocessor::ViewCell *mOldViewCell; 203 GtpVisibilityPreprocessor::ViewCell *mCurrentViewCell; 204 205 /** If view cells are used. 206 */ 207 bool mUseViewCells; 185 208 }; 186 209 -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilityOctreeSceneManager.cpp
r868 r870 15 15 #include <OgreConfigFile.h> 16 16 #include "OgreTypeConverter.h" 17 #include "OgreMeshInstance.h" 18 #include "common.h" 17 19 18 20 // normal terrain rendering … … 42 44 mExecuteVertexProgramForAllPasses(true), 43 45 mIsHierarchicalCulling(false), 44 mViewCellsLoaded(false) 46 mViewCellsLoaded(false), 47 mCurrentViewCell(NULL), 48 mOldViewCell(NULL), 49 mUseViewCells(false) 45 50 { 46 51 mHierarchyInterface = new OctreeHierarchyInterface(this, mDestRenderSystem); … … 85 90 { 86 91 OGRE_DELETE(mHierarchyInterface); 92 CLEAR_CONTAINER(mObjects); 87 93 } 88 94 //----------------------------------------------------------------------- … … 127 133 } 128 134 // add bounding boxes of rendered objects 135 if (0) 129 136 for (BoxList::iterator it = mBoxes.begin(); it != mBoxes.end(); ++it) 130 137 { … … 145 152 { 146 153 // render the leaf nodes 147 if (((*it)->numAttachedObjects() > 0) && ((*it)->numChildren() == 0) && 148 (*it)->getAttachedObject(0)->getMovableType() == "Entity") 154 if ((*it)->numAttachedObjects() && 155 !(*it)->numChildren() && 156 ((*it)->getAttachedObject(0)->getMovableType() == "Entity") && 157 (*it)->getAttachedObject(0)->isVisible()) 149 158 { 150 159 getRenderQueue()->addRenderable((*it)); 151 std::stringstream d;152 d << "here 223 " << (*it)->getAttachedObject(0)->getWorldBoundingBox();153 Ogre::LogManager::getSingleton().logMessage(d.str());154 160 } 155 156 // addbounding boxes instead of node itself157 //(*it)->_addBoundingBoxToQueue(getRenderQueue());158 161 } 159 162 // add renderables itself … … 247 250 return; 248 251 } 252 249 253 250 254 //-- show visible scene nodes and octree bounding boxes from last frame … … 265 269 OctreeSceneManager::_findVisibleObjects(cam, onlyShadowCasters); 266 270 } 271 267 272 // only shadow casters will be rendered in shadow texture pass 268 273 if (0) mHierarchyInterface->SetOnlyShadowCasters(onlyShadowCasters); 274 275 276 //-- apply view cell pvs 277 updatePvs(cam); 269 278 } 270 279 … … 311 320 else //-- the hierarchical culling algorithm 312 321 { 313 // this is also called in TerrainSceneManager: really 314 // nexessary? 322 // this is also called in TerrainSceneManager: really necessary? 315 323 //mDestRenderSystem -> setLightingEnabled(false); 316 324 … … 498 506 if (!mViewCellsLoaded) 499 507 { 500 LoadViewCells(""); 501 mViewCellsLoaded = true; 502 } 503 504 return true; 505 } 506 508 LoadViewCells(static_cast<const char *>(val)); 509 mViewCellsLoaded = true; 510 } 511 512 return true; 513 } 514 if (key == "UseViewCells") 515 { 516 if (mViewCellsLoaded) 517 { 518 mUseViewCells = *static_cast<const bool *>(val); 519 520 if (mUseViewCells) 521 { 522 SetObjectsVisible(false); 523 mCurrentViewCell = mOldViewCell = NULL; 524 } 525 else 526 { 527 SetObjectsVisible(true); 528 } 529 } 530 531 return true; 532 } 507 533 return VisibilityOptionsManager(mVisibilityManager, mHierarchyInterface). 508 534 setOption(key, val) || OctreeSceneManager::setOption(key, val); … … 876 902 } 877 903 } 878 //----------------------------------------------------------------------- 879 MovableObject *VisibilityOctreeSceneManager::FindCorrespondingObject(const AxisAlignedBox &box) 904 905 inline static AxisAlignedBox EnlargeBox(const AxisAlignedBox &box) 906 { 907 const float eps = 1e-3f; 908 const Vector3 veps(eps, eps, eps); 909 Vector3 max = box.getMaximum(); 910 Vector3 min = box.getMinimum(); 911 912 return AxisAlignedBox(min - veps, max + veps); 913 } 914 //----------------------------------------------------------------------- 915 Entity *VisibilityOctreeSceneManager::FindCorrespondingObject(const AxisAlignedBox &box) 880 916 { 881 917 list<SceneNode *> sceneNodeList; 882 883 findNodesIn(box, sceneNodeList, NULL); 884 std::stringstream d; 885 d << "\n*******************"; 886 Ogre::LogManager::getSingleton().logMessage(d.str()); 918 AxisAlignedBox mybox = EnlargeBox(box); 919 //AxisAlignedBox dummy(Vector3(-50000, -50000, -50000), Vector3(50000, 50000, 50000)); 920 921 // get intersecting scene nodes 922 findNodesIn(mybox, sceneNodeList, NULL); 923 924 887 925 list<SceneNode *>::const_iterator sit, sit_end = sceneNodeList.end(); 888 926 889 float overlap = GtpVisibilityPreprocessor::Limits::Small; 890 891 892 d << "here23 " << box; 893 Ogre::LogManager::getSingleton().logMessage(d.str()); 894 895 MovableObject *bestFittingObj = NULL; 927 float overlap = 0;//GtpVisibilityPreprocessor::Limits::Small; 928 929 Entity *bestFittingObj = NULL; 896 930 float bestFit = overlap; 897 931 … … 908 942 while (oit.hasMoreElements()) 909 943 { 910 MovableObject *mo = oit.getNext(); 911 const AxisAlignedBox bbox = mo->getWorldBoundingBox(true); 912 913 overlap = RatioOfOverlap(OgreTypeConverter::ConvertFromOgre(box), 914 OgreTypeConverter::ConvertFromOgre(bbox)); 944 MovableObject *mo = oit.getNext(); 945 946 // we are only interested in scene entities 947 if (mo->getMovableType() != "Entity") 948 { 949 continue; 950 } 951 952 const AxisAlignedBox bbox = EnlargeBox(mo->getWorldBoundingBox()); 953 954 955 // compute measure how much aabbs overlap 956 overlap = RatioOfOverlap(OgreTypeConverter::ConvertFromOgre(mybox), 957 OgreTypeConverter::ConvertFromOgre(bbox)); 958 915 959 if (overlap > bestFit) 916 960 { 917 961 bestFit = overlap; 918 bestFittingObj = mo; 919 d << "new bestfit " << bestFit << endl;Ogre::LogManager::getSingleton().logMessage(d.str()); 920 // perfect fit => object found 962 963 bestFittingObj = static_cast<Entity *>(mo); 964 965 // perfect fit => object found, eraly exit 921 966 if (overlap >= thresh) 922 { 923 std::stringstream d2; 924 925 d2 << "!!best fit " << bestFittingObj->getWorldBoundingBox(true); 926 Ogre::LogManager::getSingleton().logMessage(d2.str()); 927 return bestFittingObj; 928 } 967 return bestFittingObj; 929 968 } 930 969 } 931 970 } 932 971 933 std::stringstream d2; 934 if (bestFittingObj) 935 { 936 d2 << "best fit " << bestFittingObj->getWorldBoundingBox(true); 937 } 938 else 939 { 940 d2 << "warning, no best fitting objects"; 941 } 942 943 Ogre::LogManager::getSingleton().logMessage(d2.str()); 972 if (0) 973 { 974 std::stringstream d; 975 if (bestFittingObj) 976 d << "best fit: " << bestFit; 977 else 978 d << "warning, objects do not fit\n" << box; 979 980 Ogre::LogManager::getSingleton().logMessage(d.str()); 981 } 944 982 945 983 return bestFittingObj; … … 948 986 void VisibilityOctreeSceneManager::LoadViewCells(string filename) 949 987 { 950 GtpVisibilityPreprocessor::ObjectContainer objects; 988 // the objects are set to invisible a prioriy 989 SetObjectsVisible(false); 990 951 991 // identify the corresponding Ogre meshes using the bounding boxes 952 IdentifyObjects( objects);992 IdentifyObjects(mObjects); 953 993 954 994 // load the view cells assigning the found objects to the pvss 955 //mViewCellsManager->LoadViewCells(filename, &objects); 995 mViewCellsManager = 996 GtpVisibilityPreprocessor::ViewCellsManager::LoadViewCells(filename, &mObjects); 997 998 std::stringstream d; 999 d << "view cells loaded" << endl; 1000 Ogre::LogManager::getSingleton().logMessage(d.str()); 956 1001 } 957 1002 //----------------------------------------------------------------------- … … 970 1015 const GtpVisibilityPreprocessor::AxisAlignedBox3 box = (*iit).second; 971 1016 const AxisAlignedBox currentBox = OgreTypeConverter::ConvertToOgre(box); 972 973 MovableObject *mo = FindCorrespondingObject(currentBox); 974 975 //objects.push_back(mi); 976 } 977 } 978 1017 1018 Entity *ent = FindCorrespondingObject(currentBox); 1019 1020 // create new mesh instance 1021 OgreMeshInstance *omi = new OgreMeshInstance(ent); 1022 omi->SetId((*iit).first); 1023 objects.push_back(omi); 1024 } 1025 } 979 1026 //------------------------------------------------------------------------- 980 void VisibilityOctreeSceneManager::loadVisibilityConfig(const String& filename) 981 { 982 /// Set up the options 1027 void VisibilityOctreeSceneManager::applyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, 1028 const bool load) 1029 { GtpVisibilityPreprocessor::Debug << "here9 " << endl; 1030 // NOTE: should not happen, rather apply view cell representing unbounded space then 1031 if (!vc) return; 1032 1033 GtpVisibilityPreprocessor::ObjectPvsMap::const_iterator oit, 1034 oit_end = vc->GetPvs().mEntries.end(); 1035 1036 //-- PVS of view cell 1037 for (oit = vc->GetPvs().mEntries.begin(); oit != oit_end; ++ oit) 1038 { 1039 if (!(*oit).first) continue; 1040 1041 OgreMeshInstance *omi = dynamic_cast<OgreMeshInstance*>((*oit).first); 1042 omi->GetMesh()->setVisible(load); 1043 GtpVisibilityPreprocessor::Debug << "here45 " << omi->GetId() << endl; 1044 } 1045 } 1046 //------------------------------------------------------------------------- 1047 void VisibilityOctreeSceneManager::SetObjectsVisible(const bool visible) 1048 { 1049 // for OGRE 1.2 1050 #ifdef OGRE12 1051 MovableObjectIterator mit = getMovableObjectIterator("Entity"); 1052 #else 1053 EntityIterator eit = getEntityIterator(); 1054 1055 // set all objects to invisible (initially); 1056 while (eit.hasMoreElements()) 1057 { 1058 Entity *ent = eit.getNext(); 1059 ent->setVisible(visible); 1060 } 1061 1062 #endif 1063 } 1064 //------------------------------------------------------------------------- 1065 void VisibilityOctreeSceneManager::loadVisibilityConfig(const String &filename) 1066 { 1067 // TODO matt 1068 // Set up the options 983 1069 ConfigFile config; 984 1070 String val; … … 1000 1086 } 1001 1087 } 1088 //------------------------------------------------------------------------- 1089 void VisibilityOctreeSceneManager::updatePvs(Camera *cam) 1090 { 1091 Ogre::LogManager::getSingleton().logMessage("here196"); 1092 if (mViewCellsLoaded && mUseViewCells) 1093 { 1094 GtpVisibilityPreprocessor::ViewCell *vc = 1095 mViewCellsManager->GetViewCell(OgreTypeConverter::ConvertFromOgre(cam->getDerivedPosition())); 1096 1097 std::stringstream d; d << "pos " << cam->getDerivedPosition() << "vc: " << vc; 1098 Ogre::LogManager::getSingleton().logMessage(d.str()); 1099 1100 // view cell changed => unload old objects and load new objects 1101 if (vc != mCurrentViewCell) 1102 { 1103 //-- unload old pvs 1104 if (mOldViewCell) 1105 { 1106 const bool load = false; 1107 1108 applyViewCellPvs(mOldViewCell, load); 1109 Ogre::LogManager::getSingleton().logMessage("here16"); 1110 } 1111 1112 mOldViewCell = mCurrentViewCell; 1113 1114 //-- load new pvs 1115 mCurrentViewCell = vc; 1116 const bool load = true; 1117 1118 applyViewCellPvs(mCurrentViewCell, load); 1119 Ogre::LogManager::getSingleton().logMessage("here106"); 1120 } 1121 } 1122 } 1123 1002 1124 } // namespace Ogre -
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreVisibilitySceneManagerDll.cpp
r657 r870 49 49 { 50 50 visEnv = new GtpVisibility::VisibilityEnvironment(); 51 visEnv->LoadEnvironment("vienna_simple.env"); 51 52 visManager = new GtpVisibility::VisibilityManager(visEnv); 52 53
Note: See TracChangeset
for help on using the changeset viewer.