| 302 | | |
| 303 | | if (readDatabasesInPagingThread) |
| 304 | | { |
| 305 | | // load the models using a paging thread and use the incremental compile operation to |
| 306 | | // manage the compilation of GL objects without breaking frame. |
| 307 | | |
| 308 | | unsigned int modelIndex = 0; |
| 309 | | |
| 310 | | osg::ref_ptr<osg::OperationThread> databasePagingThread; |
| 311 | | osg::ref_ptr<DatabasePagingOperation> databasePagingOperation; |
| 312 | | |
| 313 | | databasePagingThread = new osg::OperationThread; |
| 314 | | databasePagingThread->startThread(); |
| 315 | | |
| 316 | | databasePagingOperation = new DatabasePagingOperation( |
| 317 | | fileNames[modelIndex++], |
| 318 | | sceneGraphProcessor.get(), |
| 319 | | incrementalCompile.get()); |
| 320 | | |
| 321 | | databasePagingThread->add(databasePagingOperation.get()); |
| 322 | | |
| 323 | | osg::ref_ptr<osg::Group> group = new osg::Group; |
| 324 | | viewer.setSceneData(group); |
| 325 | | |
| 326 | | viewer.realize(); |
| 327 | | |
| 328 | | double timeOfLastMerge = viewer.getFrameStamp()->getReferenceTime(); |
| 329 | | |
| 330 | | while(!viewer.done()) |
| 331 | | { |
| 332 | | viewer.frame(); |
| 333 | | |
| 334 | | double currentTime = viewer.getFrameStamp()->getReferenceTime(); |
| 335 | | |
| 336 | | if (!databasePagingOperation && |
| 337 | | modelIndex<fileNames.size() && |
| 338 | | (currentTime-timeOfLastMerge)>timeBetweenMerges) |
| 339 | | { |
| 340 | | databasePagingOperation = new DatabasePagingOperation( |
| 341 | | fileNames[modelIndex++], |
| 342 | | sceneGraphProcessor.get(), |
| 343 | | incrementalCompile.get()); |
| 344 | | |
| 345 | | databasePagingThread->add(databasePagingOperation.get()); |
| 346 | | } |
| 347 | | |
| 348 | | if (databasePagingOperation.get() && databasePagingOperation->_modelReadyToMerge) |
| 349 | | { |
| 350 | | timeOfLastMerge = currentTime; |
| 351 | | |
| 352 | | group->removeChildren(0,group->getNumChildren()); |
| 353 | | |
| 354 | | group->addChild(databasePagingOperation->_loadedModel.get()); |
| 355 | | |
| 356 | | viewer.home(); |
| 357 | | |
| 358 | | // we no longer need the paging operation as it's done it's job. |
| 359 | | databasePagingOperation = 0; |
| 360 | | |
| 361 | | viewer.home(); |
| 362 | | } |
| 363 | | } |
| 364 | | |
| 365 | | } |
| 366 | | else |
| 367 | | { |
| 368 | | // load the models directly and then just use the IncrementalCompileOperation to |
| 369 | | // compile the GL objects for us. |
| 370 | | typedef std::vector< osg::ref_ptr<osg::Node> > Models; |
| 371 | | Models models; |
| 372 | | unsigned int modelIndex = 0; |
| 373 | | |
| 374 | | for(FileNames::iterator itr = fileNames.begin(); |
| 375 | | itr != fileNames.end(); |
| 376 | | ++itr) |
| 377 | | { |
| 378 | | // not an option so assume string is a filename. |
| 379 | | osg::ref_ptr<osg::Node> node = osgDB::readNodeFile( *itr ); |
| 380 | | if(node.valid()) |
| 381 | | { |
| 382 | | if (node->getName().empty()) node->setName( *itr ); |
| 383 | | |
| 384 | | node = sceneGraphProcessor->process(node.get()); |
| 385 | | |
| 386 | | models.push_back(node.get()); |
| 387 | | } |
| 388 | | } |
| 389 | | |
| 390 | | osg::ref_ptr<osg::Group> group = new osg::Group; |
| 391 | | group->addChild(models[modelIndex++].get()); |
| 392 | | |
| 393 | | viewer.setSceneData(group); |
| 394 | | |
| 395 | | viewer.realize(); |
| 396 | | |
| 397 | | double timeOfLastMerge = viewer.getFrameStamp()->getReferenceTime(); |
| 398 | | |
| 399 | | osg::ref_ptr<CustomCompileCompletedCallback> compileCompletedCallback; |
| 400 | | |
| 401 | | while(!viewer.done()) |
| 402 | | { |
| 403 | | viewer.frame(); |
| 404 | | |
| 405 | | double currentTime = viewer.getFrameStamp()->getReferenceTime(); |
| 406 | | |
| 407 | | if (!compileCompletedCallback && |
| 408 | | modelIndex<fileNames.size() && |
| 409 | | (currentTime-timeOfLastMerge)>timeBetweenMerges) |
| 410 | | { |
| 411 | | OSG_NOTICE<<"Compiling model "<<modelIndex<<" at "<<currentTime<<std::endl; |
| 412 | | |
| 413 | | osg::ref_ptr<osgUtil::IncrementalCompileOperation::CompileSet> compileSet = |
| 414 | | new osgUtil::IncrementalCompileOperation::CompileSet(models[modelIndex].get()); |
| 415 | | |
| 416 | | compileCompletedCallback = new CustomCompileCompletedCallback; |
| 417 | | |
| 418 | | compileSet->_compileCompletedCallback = compileCompletedCallback; |
| 419 | | |
| 420 | | incrementalCompile->add(compileSet.get()); |
| 421 | | } |
| 422 | | |
| 423 | | if (compileCompletedCallback.valid() && compileCompletedCallback->completed) |
| 424 | | { |
| 425 | | OSG_NOTICE<<"Merging model "<<modelIndex<<" at "<<currentTime<<std::endl; |
| 426 | | |
| 427 | | timeOfLastMerge = currentTime; |
| 428 | | |
| 429 | | group->removeChildren(0,group->getNumChildren()); |
| 430 | | |
| 431 | | group->addChild(models[modelIndex++].get()); |
| 432 | | |
| 433 | | compileCompletedCallback = 0; |
| 434 | | |
| 435 | | viewer.home(); |
| 436 | | } |
| | 297 | // load the models using a paging thread and use the incremental compile operation to |
| | 298 | // manage the compilation of GL objects without breaking frame. |
| | 299 | |
| | 300 | unsigned int modelIndex = 0; |
| | 301 | |
| | 302 | osg::ref_ptr<osg::OperationThread> databasePagingThread; |
| | 303 | osg::ref_ptr<DatabasePagingOperation> databasePagingOperation; |
| | 304 | |
| | 305 | databasePagingThread = new osg::OperationThread; |
| | 306 | databasePagingThread->startThread(); |
| | 307 | |
| | 308 | std::string filename = fileNames[modelIndex++]; |
| | 309 | std::string outputFilename = outputPostfix.empty() ? std::string() : filename+outputPostfix; |
| | 310 | |
| | 311 | databasePagingOperation = new DatabasePagingOperation( |
| | 312 | filename, |
| | 313 | outputFilename, |
| | 314 | sceneGraphProcessor.get(), |
| | 315 | incrementalCompile.get()); |
| | 316 | |
| | 317 | databasePagingThread->add(databasePagingOperation.get()); |
| | 318 | |
| | 319 | osg::ref_ptr<osg::Group> group = new osg::Group; |
| | 320 | viewer.setSceneData(group); |
| | 321 | |
| | 322 | viewer.realize(); |
| | 323 | |
| | 324 | double timeOfLastMerge = viewer.getFrameStamp()->getReferenceTime(); |
| | 325 | |
| | 326 | while(!viewer.done()) |
| | 327 | { |
| | 328 | viewer.frame(); |
| | 329 | |
| | 330 | double currentTime = viewer.getFrameStamp()->getReferenceTime(); |
| | 331 | |
| | 332 | if (!databasePagingOperation && |
| | 333 | modelIndex<fileNames.size() && |
| | 334 | (currentTime-timeOfLastMerge)>timeBetweenMerges) |
| | 335 | { |
| | 336 | std::string filename = fileNames[modelIndex++]; |
| | 337 | std::string outputFilename = outputPostfix.empty() ? std::string() : filename+outputPostfix; |
| | 338 | |
| | 339 | databasePagingOperation = new DatabasePagingOperation( |
| | 340 | filename, |
| | 341 | outputFilename, |
| | 342 | sceneGraphProcessor.get(), |
| | 343 | incrementalCompile.get()); |
| | 344 | |
| | 345 | databasePagingThread->add(databasePagingOperation.get()); |
| | 346 | } |
| | 347 | |
| | 348 | if (databasePagingOperation.get() && databasePagingOperation->_modelReadyToMerge) |
| | 349 | { |
| | 350 | timeOfLastMerge = currentTime; |
| | 351 | |
| | 352 | group->removeChildren(0,group->getNumChildren()); |
| | 353 | |
| | 354 | group->addChild(databasePagingOperation->_loadedModel.get()); |
| | 355 | |
| | 356 | viewer.home(); |
| | 357 | |
| | 358 | // we no longer need the paging operation as it's done it's job. |
| | 359 | databasePagingOperation = 0; |
| | 360 | |
| | 361 | viewer.home(); |