- Timestamp:
- 08/10/06 17:08:57 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/src/OgreKdTree.cpp
r1192 r1195 307 307 mMaxDepth(maxdepth), 308 308 mBuildMethod(bm), 309 mHiLiteLevel( HILITE_OFF),309 mHiLiteLevel(0), 310 310 mShowAllBoxes(false), 311 311 mShowNodes(true), … … 335 335 void KdTree::init() 336 336 { 337 // init visualization materials 338 MaterialPtr mphi = MaterialManager::getSingleton().getByName("KdTree/BoxHiLite"); 339 if (mphi.isNull()) 337 MaterialPtr mat; 338 TextureUnitState *tex; 339 340 // init visualization materials (unlit solid green/yellow) 341 mat = MaterialManager::getSingleton().getByName("KdTree/BoxHiLite"); 342 if (mat.isNull()) 340 343 { 341 344 ColourValue green(0, 1, 0); 342 mphi = MaterialManager::getSingleton().create("KdTree/BoxHiLite", "General"); 343 mphi->setAmbient(green); 344 mphi->setDiffuse(green); 345 mphi->setLightingEnabled(true); 346 mphi->getTechnique(0)->getPass(0)->removeAllTextureUnitStates(); 347 } 348 349 MaterialPtr mpviz = MaterialManager::getSingleton().getByName("KdTree/BoxViz"); 350 if (mpviz.isNull()) 345 mat = MaterialManager::getSingleton().create("KdTree/BoxHiLite", "General"); 346 //mat->setAmbient(green); 347 //mat->setDiffuse(green); 348 mat->setLightingEnabled(false); 349 tex = mat->getTechnique(0)->getPass(0)->createTextureUnitState(); 350 tex->setColourOperationEx(LBX_SOURCE2, LBS_CURRENT, LBS_MANUAL, green, green); 351 } 352 353 mat = MaterialManager::getSingleton().getByName("KdTree/BoxViz"); 354 if (mat.isNull()) 351 355 { 352 356 ColourValue yellow(1, 1, 0); 353 mpviz = MaterialManager::getSingleton().create("KdTree/BoxViz", "General"); 354 mpviz->setAmbient(yellow); 355 mpviz->setDiffuse(yellow); 356 mpviz->setLightingEnabled(true); 357 mpviz->getTechnique(0)->getPass(0)->removeAllTextureUnitStates(); 357 mat = MaterialManager::getSingleton().create("KdTree/BoxViz", "General"); 358 //mat->setAmbient(yellow); 359 //mat->setDiffuse(yellow); 360 mat->setLightingEnabled(false); 361 tex = mat->getTechnique(0)->getPass(0)->createTextureUnitState(); 362 tex->setColourOperationEx(LBX_SOURCE2, LBS_CURRENT, LBS_MANUAL, yellow, yellow); 358 363 } 359 364 … … 1180 1185 1181 1186 //------------------------------------------------------------------------- 1182 void KdTree::queueVisibleObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes) 1187 void KdTree::queueVisibleObjects(Camera* cam, RenderQueue* queue, bool onlyShadowCasters, 1188 bool showBoxes, KdTree::NodeList& visibleNodes) 1183 1189 { 1184 1190 if (mKdRoot) 1185 1191 recQueueVisibleObjects(mKdRoot, Root::getSingleton().getCurrentFrameNumber(), 1186 cam, queue, onlyShadowCasters, showBoxes );1192 cam, queue, onlyShadowCasters, showBoxes, visibleNodes); 1187 1193 } 1188 1194 1189 1195 //------------------------------------------------------------------------- 1190 1196 void KdTree::recQueueVisibleObjects(KdTree::Node * node, unsigned long currentFrame, 1191 Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes )1197 Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes, KdTree::NodeList& visibleNodes) 1192 1198 { 1193 1199 // test visibility 1194 1200 if (cam->isVisible(node->mAABB)) 1195 1201 { 1196 #if 0 1202 visibleNodes.push_back(node); 1203 1197 1204 node->queueVisibleObjects(currentFrame, cam, queue, onlyShadowCasters, showBoxes); 1198 1205 1199 1206 if (node->getLeftChild()) 1200 recQueueVisibleObjects(node->getLeftChild(), currentFrame, cam, queue, onlyShadowCasters, showBoxes); 1207 recQueueVisibleObjects(node->getLeftChild(), currentFrame, 1208 cam, queue, onlyShadowCasters, showBoxes, visibleNodes); 1201 1209 if (node->getRightChild()) 1202 recQueueVisibleObjects(node->getRightChild(), currentFrame, cam, queue, onlyShadowCasters, showBoxes); 1203 #else 1204 #ifdef KDTREE_DEBUG 1205 WireBoundingBox * wbb = 0; 1206 if (showBoxes) 1207 wbb = node->getWireBoundingBox(); 1208 #endif 1209 1210 if (node->isLeaf()) 1211 { 1212 KdTree::Leaf * leaf = KDLEAFPTR_CAST(node); 1213 KdRenderableList::iterator it = leaf->mKdRenderables.begin(); 1214 KdRenderableList::iterator end = leaf->mKdRenderables.end(); 1215 while (it != end) 1216 { 1217 if (!(*it)->isQueued(currentFrame, cam)) 1218 { 1219 (*it)->queueObjects(cam, queue, onlyShadowCasters); 1220 } 1221 it++; 1222 } 1223 #ifdef KDTREE_DEBUG 1224 if (wbb) 1225 queue->addRenderable(wbb); 1226 #else 1227 if (showBoxes) 1228 queue->addRenderable(leaf->getWireBoundingBox()); 1229 #endif 1230 } 1231 else 1232 { 1233 KdTree::Branch * branch = KDBRANCHPTR_CAST(node); 1234 #ifdef KDTREE_DEBUG 1235 if (wbb) 1236 queue->addRenderable(wbb); 1237 #else 1238 if (showBoxes) 1239 queue->addRenderable(branch->getWireBoundingBox()); 1240 #endif 1241 1242 if (branch->mLeft) 1243 recQueueVisibleObjects(branch->mLeft, currentFrame, cam, queue, onlyShadowCasters, showBoxes); 1244 if (branch->mRight) 1245 recQueueVisibleObjects(branch->mRight, currentFrame, cam, queue, onlyShadowCasters, showBoxes); 1246 } 1247 #endif 1248 } 1249 } 1210 recQueueVisibleObjects(node->getRightChild(), currentFrame, 1211 cam, queue, onlyShadowCasters, showBoxes, visibleNodes); 1212 } 1213 } 1214 1215 ////------------------------------------------------------------------------- 1216 //void KdTree::findVisibleNodes(NodeList& visibleNodes, Camera * cam) 1217 //{ 1218 // if (mKdRoot) 1219 // recFindVisibleNodes(mKdRoot, visibleNodes, cam); 1220 //} 1221 1222 ////------------------------------------------------------------------------- 1223 //void KdTree::recFindVisibleNodes(KdTree::Node * node, NodeList& visibleNodes, Camera * cam) 1224 //{ 1225 // // test visibility 1226 // if (cam->isVisible(node->mAABB)) 1227 // { 1228 // visibleNodes.push_back(node); 1229 1230 // if (node->getLeftChild()) 1231 // recFindVisibleNodes(node->getLeftChild(), visibleNodes, cam); 1232 // if (node->getRightChild()) 1233 // recFindVisibleNodes(node->getRightChild(), visibleNodes, cam); 1234 // } 1235 //} 1250 1236 1251 1237 /************************************************************************/ … … 1356 1342 } 1357 1343 1344 //------------------------------------------------------------------------- 1358 1345 void KdTree::Leaf::queueVisibleObjects(unsigned long currentFrame, 1359 1346 Camera* cam, RenderQueue* queue, bool onlyShadowCasters, bool showBoxes) … … 1376 1363 1377 1364 //------------------------------------------------------------------------- 1365 void KdTree::Leaf::getGeometryList(GtpVisibility::GeometryVector *geometryList) 1366 { 1367 KdRenderableList::iterator it = mKdRenderables.begin(); 1368 KdRenderableList::iterator end = mKdRenderables.end(); 1369 while (it != end) 1370 { 1371 (*it)->getGeometryList(geometryList); 1372 it++; 1373 } 1374 } 1375 1376 //------------------------------------------------------------------------- 1378 1377 // update the world aabb based on the contained geometry 1379 1378 void KdTree::Leaf::_updateBounds(bool recurse)
Note: See TracChangeset
for help on using the changeset viewer.