| [8637] | 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #include <osg/Node> |
|---|
| 20 | #include <osg/Geometry> |
|---|
| 21 | #include <osg/Notify> |
|---|
| [8657] | 22 | #include <osg/Texture1D> |
|---|
| [8637] | 23 | #include <osg/Texture2D> |
|---|
| [8657] | 24 | #include <osg/Texture3D> |
|---|
| 25 | #include <osg/TextureRectangle> |
|---|
| [8637] | 26 | #include <osg/ImageSequence> |
|---|
| 27 | #include <osg/Geode> |
|---|
| 28 | |
|---|
| 29 | #include <osgDB/Registry> |
|---|
| 30 | #include <osgDB/ReadFile> |
|---|
| [8657] | 31 | #include <osgDB/WriteFile> |
|---|
| [13143] | 32 | #include <osgDB/FileNameUtils> |
|---|
| 33 | #include <osgDB/FileUtils> |
|---|
| [8637] | 34 | |
|---|
| [13143] | 35 | |
|---|
| [8637] | 36 | #include <osgViewer/Viewer> |
|---|
| [8916] | 37 | #include <osgViewer/ViewerEventHandlers> |
|---|
| [8637] | 38 | |
|---|
| 39 | #include <iostream> |
|---|
| 40 | |
|---|
| [8753] | 41 | |
|---|
| [13143] | 42 | static osgDB::DirectoryContents getSuitableFiles(osg::ArgumentParser& arguments) |
|---|
| 43 | { |
|---|
| 44 | osgDB::DirectoryContents files; |
|---|
| 45 | for(int i=1; i<arguments.argc(); ++i) |
|---|
| 46 | { |
|---|
| 47 | if (osgDB::fileType(arguments[i]) == osgDB::DIRECTORY) |
|---|
| 48 | { |
|---|
| 49 | const std::string& directory = arguments[i]; |
|---|
| 50 | osgDB::DirectoryContents dc = osgDB::getSortedDirectoryContents(directory); |
|---|
| 51 | |
|---|
| 52 | for(osgDB::DirectoryContents::iterator itr = dc.begin(); itr != dc.end(); ++itr) |
|---|
| 53 | { |
|---|
| 54 | std::string full_file_name = directory + "/" + (*itr); |
|---|
| 55 | std::string ext = osgDB::getLowerCaseFileExtension(full_file_name); |
|---|
| 56 | if ((ext == "jpg") || (ext == "png") || (ext == "gif") || (ext == "rgb") || (ext == "dds") ) |
|---|
| 57 | { |
|---|
| 58 | files.push_back(full_file_name); |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | else { |
|---|
| 63 | files.push_back(arguments[i]); |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | return files; |
|---|
| 67 | } |
|---|
| [8753] | 68 | |
|---|
| 69 | |
|---|
| [8637] | 70 | |
|---|
| [8647] | 71 | |
|---|
| [8637] | 72 | |
|---|
| 73 | |
|---|
| [8841] | 74 | osg::StateSet* createState(osg::ArgumentParser& arguments) |
|---|
| [8637] | 75 | { |
|---|
| [8657] | 76 | osg::ref_ptr<osg::ImageSequence> imageSequence = new osg::ImageSequence; |
|---|
| [8918] | 77 | |
|---|
| 78 | bool preLoad = true; |
|---|
| 79 | |
|---|
| 80 | while (arguments.read("--page-and-discard")) |
|---|
| 81 | { |
|---|
| 82 | imageSequence->setMode(osg::ImageSequence::PAGE_AND_DISCARD_USED_IMAGES); |
|---|
| 83 | preLoad = false; |
|---|
| 84 | } |
|---|
| [8835] | 85 | |
|---|
| [8918] | 86 | while (arguments.read("--page-and-retain")) |
|---|
| 87 | { |
|---|
| 88 | imageSequence->setMode(osg::ImageSequence::PAGE_AND_RETAIN_IMAGES); |
|---|
| 89 | preLoad = false; |
|---|
| 90 | } |
|---|
| 91 | |
|---|
| 92 | while (arguments.read("--preload")) |
|---|
| 93 | { |
|---|
| 94 | imageSequence->setMode(osg::ImageSequence::PRE_LOAD_ALL_IMAGES); |
|---|
| 95 | preLoad = true; |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | double length = -1.0; |
|---|
| 99 | while (arguments.read("--length",length)) {} |
|---|
| 100 | |
|---|
| [13085] | 101 | double fps = 30.0; |
|---|
| 102 | while (arguments.read("--fps",fps)) {} |
|---|
| 103 | |
|---|
| [13143] | 104 | osgDB::DirectoryContents files = getSuitableFiles(arguments); |
|---|
| 105 | if (!files.empty()) |
|---|
| [8841] | 106 | { |
|---|
| [13143] | 107 | for(osgDB::DirectoryContents::iterator itr = files.begin(); |
|---|
| 108 | itr != files.end(); |
|---|
| 109 | ++itr) |
|---|
| [8841] | 110 | { |
|---|
| [13143] | 111 | const std::string& filename = *itr; |
|---|
| [8918] | 112 | if (preLoad) |
|---|
| [8841] | 113 | { |
|---|
| [13143] | 114 | osg::ref_ptr<osg::Image> image = osgDB::readImageFile(filename); |
|---|
| [8918] | 115 | if (image.valid()) |
|---|
| 116 | { |
|---|
| 117 | imageSequence->addImage(image.get()); |
|---|
| 118 | } |
|---|
| [8841] | 119 | } |
|---|
| [8918] | 120 | else |
|---|
| 121 | { |
|---|
| [13143] | 122 | imageSequence->addImageFile(filename); |
|---|
| [8918] | 123 | } |
|---|
| [13143] | 124 | |
|---|
| [8841] | 125 | } |
|---|
| [8918] | 126 | |
|---|
| 127 | if (length>0.0) |
|---|
| 128 | { |
|---|
| 129 | imageSequence->setLength(length); |
|---|
| 130 | } |
|---|
| 131 | else |
|---|
| 132 | { |
|---|
| [13191] | 133 | unsigned int maxNum = imageSequence->getNumImageData(); |
|---|
| [13085] | 134 | imageSequence->setLength(double(maxNum)*(1.0/fps)); |
|---|
| [8918] | 135 | } |
|---|
| [8841] | 136 | } |
|---|
| 137 | else |
|---|
| 138 | { |
|---|
| [8918] | 139 | if (length>0.0) |
|---|
| 140 | { |
|---|
| 141 | imageSequence->setLength(length); |
|---|
| 142 | } |
|---|
| 143 | else |
|---|
| 144 | { |
|---|
| 145 | imageSequence->setLength(4.0); |
|---|
| 146 | } |
|---|
| [8841] | 147 | imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posx.png")); |
|---|
| 148 | imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negx.png")); |
|---|
| 149 | imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posy.png")); |
|---|
| 150 | imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negy.png")); |
|---|
| 151 | imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/posz.png")); |
|---|
| 152 | imageSequence->addImage(osgDB::readImageFile("Cubemap_axis/negz.png")); |
|---|
| 153 | } |
|---|
| 154 | |
|---|
| [8835] | 155 | |
|---|
| 156 | imageSequence->play(); |
|---|
| [8657] | 157 | |
|---|
| 158 | #if 1 |
|---|
| [8637] | 159 | osg::Texture2D* texture = new osg::Texture2D; |
|---|
| [8657] | 160 | texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); |
|---|
| 161 | texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); |
|---|
| 162 | texture->setWrap(osg::Texture::WRAP_R,osg::Texture::REPEAT); |
|---|
| [8637] | 163 | texture->setResizeNonPowerOfTwoHint(false); |
|---|
| 164 | texture->setImage(imageSequence.get()); |
|---|
| [8642] | 165 | |
|---|
| [8657] | 166 | #else |
|---|
| 167 | osg::TextureRectangle* texture = new osg::TextureRectangle; |
|---|
| 168 | texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); |
|---|
| 169 | texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR); |
|---|
| 170 | texture->setWrap(osg::Texture::WRAP_R,osg::Texture::REPEAT); |
|---|
| 171 | texture->setImage(imageSequence.get()); |
|---|
| 172 | |
|---|
| 173 | #endif |
|---|
| [8637] | 174 | |
|---|
| 175 | |
|---|
| 176 | osg::StateSet* stateset = new osg::StateSet; |
|---|
| [8642] | 177 | |
|---|
| [8637] | 178 | stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); |
|---|
| 179 | |
|---|
| 180 | return stateset; |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| [8841] | 183 | osg::Node* createModel(osg::ArgumentParser& arguments) |
|---|
| [8637] | 184 | { |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | osg::Geode* geode = new osg::Geode; |
|---|
| 188 | geode->addDrawable(osg::createTexturedQuadGeometry(osg::Vec3(0.0f,0.0f,0.0), osg::Vec3(1.0f,0.0f,0.0), osg::Vec3(0.0f,0.0f,1.0f))); |
|---|
| 189 | |
|---|
| [8841] | 190 | geode->setStateSet(createState(arguments)); |
|---|
| [8637] | 191 | |
|---|
| 192 | return geode; |
|---|
| 193 | |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | |
|---|
| [8753] | 197 | osg::ImageStream* s_imageStream = 0; |
|---|
| 198 | class MovieEventHandler : public osgGA::GUIEventHandler |
|---|
| 199 | { |
|---|
| 200 | public: |
|---|
| 201 | |
|---|
| [9395] | 202 | MovieEventHandler():_playToggle(true),_trackMouse(false) {} |
|---|
| [8753] | 203 | |
|---|
| 204 | void setMouseTracking(bool track) { _trackMouse = track; } |
|---|
| 205 | bool getMouseTracking() const { return _trackMouse; } |
|---|
| 206 | |
|---|
| 207 | void set(osg::Node* node); |
|---|
| 208 | |
|---|
| [13158] | 209 | void setTrackMouse(bool tm) |
|---|
| 210 | { |
|---|
| 211 | if (tm==_trackMouse) return; |
|---|
| 212 | |
|---|
| 213 | _trackMouse = tm; |
|---|
| 214 | |
|---|
| 215 | std::cout << "tracking mouse: " << (_trackMouse ? "ON" : "OFF") << std::endl; |
|---|
| 216 | |
|---|
| 217 | for(ImageStreamList::iterator itr=_imageStreamList.begin(); |
|---|
| 218 | itr!=_imageStreamList.end(); |
|---|
| 219 | ++itr) |
|---|
| 220 | { |
|---|
| 221 | if ((*itr)->getStatus()==osg::ImageStream::PLAYING) |
|---|
| 222 | { |
|---|
| 223 | (*itr)->pause(); |
|---|
| 224 | } |
|---|
| 225 | else |
|---|
| 226 | { |
|---|
| 227 | (*itr)->play(); |
|---|
| 228 | } |
|---|
| 229 | } |
|---|
| 230 | |
|---|
| 231 | } |
|---|
| 232 | |
|---|
| 233 | bool getTrackMouse() const { return _trackMouse; } |
|---|
| 234 | |
|---|
| [8753] | 235 | virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv); |
|---|
| 236 | |
|---|
| 237 | virtual void getUsage(osg::ApplicationUsage& usage) const; |
|---|
| 238 | |
|---|
| 239 | typedef std::vector< osg::observer_ptr<osg::ImageStream> > ImageStreamList; |
|---|
| [13143] | 240 | |
|---|
| 241 | struct ImageStreamPlaybackSpeedData { |
|---|
| 242 | double fps; |
|---|
| 243 | unsigned char* lastData; |
|---|
| 244 | double timeStamp, lastOutput; |
|---|
| 245 | |
|---|
| 246 | ImageStreamPlaybackSpeedData() : fps(0), lastData(NULL), timeStamp(0), lastOutput(0) {} |
|---|
| 247 | |
|---|
| 248 | }; |
|---|
| 249 | |
|---|
| 250 | typedef std::vector< ImageStreamPlaybackSpeedData > ImageStreamPlayBackSpeedList; |
|---|
| [8753] | 251 | |
|---|
| 252 | protected: |
|---|
| 253 | |
|---|
| 254 | virtual ~MovieEventHandler() {} |
|---|
| 255 | |
|---|
| 256 | class FindImageStreamsVisitor : public osg::NodeVisitor |
|---|
| 257 | { |
|---|
| 258 | public: |
|---|
| 259 | FindImageStreamsVisitor(ImageStreamList& imageStreamList): |
|---|
| 260 | _imageStreamList(imageStreamList) {} |
|---|
| 261 | |
|---|
| 262 | virtual void apply(osg::Geode& geode) |
|---|
| 263 | { |
|---|
| 264 | apply(geode.getStateSet()); |
|---|
| 265 | |
|---|
| 266 | for(unsigned int i=0;i<geode.getNumDrawables();++i) |
|---|
| 267 | { |
|---|
| 268 | apply(geode.getDrawable(i)->getStateSet()); |
|---|
| 269 | } |
|---|
| 270 | |
|---|
| 271 | traverse(geode); |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | virtual void apply(osg::Node& node) |
|---|
| 275 | { |
|---|
| 276 | apply(node.getStateSet()); |
|---|
| 277 | traverse(node); |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | inline void apply(osg::StateSet* stateset) |
|---|
| 281 | { |
|---|
| 282 | if (!stateset) return; |
|---|
| 283 | |
|---|
| 284 | osg::StateAttribute* attr = stateset->getTextureAttribute(0,osg::StateAttribute::TEXTURE); |
|---|
| 285 | if (attr) |
|---|
| 286 | { |
|---|
| 287 | osg::Texture2D* texture2D = dynamic_cast<osg::Texture2D*>(attr); |
|---|
| 288 | if (texture2D) apply(dynamic_cast<osg::ImageStream*>(texture2D->getImage())); |
|---|
| 289 | |
|---|
| 290 | osg::TextureRectangle* textureRec = dynamic_cast<osg::TextureRectangle*>(attr); |
|---|
| 291 | if (textureRec) apply(dynamic_cast<osg::ImageStream*>(textureRec->getImage())); |
|---|
| 292 | } |
|---|
| 293 | } |
|---|
| 294 | |
|---|
| 295 | inline void apply(osg::ImageStream* imagestream) |
|---|
| 296 | { |
|---|
| 297 | if (imagestream) |
|---|
| 298 | { |
|---|
| 299 | _imageStreamList.push_back(imagestream); |
|---|
| 300 | s_imageStream = imagestream; |
|---|
| 301 | } |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | ImageStreamList& _imageStreamList; |
|---|
| [9637] | 305 | |
|---|
| 306 | protected: |
|---|
| 307 | |
|---|
| 308 | FindImageStreamsVisitor& operator = (const FindImageStreamsVisitor&) { return *this; } |
|---|
| [8753] | 309 | }; |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | bool _playToggle; |
|---|
| 313 | bool _trackMouse; |
|---|
| 314 | ImageStreamList _imageStreamList; |
|---|
| [13143] | 315 | ImageStreamPlayBackSpeedList _imageStreamPlayBackSpeedList; |
|---|
| [8753] | 316 | |
|---|
| 317 | }; |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | void MovieEventHandler::set(osg::Node* node) |
|---|
| 322 | { |
|---|
| 323 | _imageStreamList.clear(); |
|---|
| 324 | if (node) |
|---|
| 325 | { |
|---|
| 326 | FindImageStreamsVisitor fisv(_imageStreamList); |
|---|
| 327 | node->accept(fisv); |
|---|
| 328 | } |
|---|
| [13143] | 329 | _imageStreamPlayBackSpeedList.resize(_imageStreamList.size()); |
|---|
| [8753] | 330 | } |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv) |
|---|
| 334 | { |
|---|
| 335 | switch(ea.getEventType()) |
|---|
| 336 | { |
|---|
| [13143] | 337 | case(osgGA::GUIEventAdapter::FRAME): |
|---|
| 338 | { |
|---|
| 339 | double t = ea.getTime(); |
|---|
| 340 | bool printed(false); |
|---|
| 341 | |
|---|
| 342 | ImageStreamPlayBackSpeedList::iterator fps_itr = _imageStreamPlayBackSpeedList.begin(); |
|---|
| 343 | for(ImageStreamList::iterator itr=_imageStreamList.begin(); |
|---|
| 344 | itr!=_imageStreamList.end(); |
|---|
| 345 | ++itr, ++fps_itr) |
|---|
| 346 | { |
|---|
| 347 | if (((*itr)->getStatus()==osg::ImageStream::PLAYING) && ((*itr)->data() != (*fps_itr).lastData)) |
|---|
| 348 | { |
|---|
| 349 | ImageStreamPlaybackSpeedData& data(*fps_itr); |
|---|
| 350 | double dt = (data.timeStamp > 0) ? t - data.timeStamp : 1/60.0; |
|---|
| 351 | data.lastData = (*itr)->data(); |
|---|
| 352 | data.fps = (*fps_itr).fps * 0.8 + 0.2 * (1/dt); |
|---|
| 353 | data.timeStamp = t; |
|---|
| 354 | |
|---|
| 355 | if (t-data.lastOutput > 1) |
|---|
| 356 | { |
|---|
| 357 | std::cout << data.fps << " "; |
|---|
| 358 | data.lastOutput = t; |
|---|
| 359 | printed = true; |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | } |
|---|
| 363 | } |
|---|
| 364 | if (printed) |
|---|
| 365 | std::cout << std::endl; |
|---|
| 366 | } |
|---|
| 367 | break; |
|---|
| 368 | case(osgGA::GUIEventAdapter::MOVE): |
|---|
| 369 | { |
|---|
| 370 | if (_trackMouse) |
|---|
| 371 | { |
|---|
| 372 | for(ImageStreamList::iterator itr=_imageStreamList.begin(); |
|---|
| 373 | itr!=_imageStreamList.end(); |
|---|
| 374 | ++itr) |
|---|
| 375 | { |
|---|
| 376 | double dt = (*itr)->getLength() * ((1.0+ea.getXnormalized()) / 2.0); |
|---|
| 377 | (*itr)->seek(dt); |
|---|
| 378 | std::cout << "seeking to " << dt << " length: " <<(*itr)->getLength() << std::endl; |
|---|
| 379 | } |
|---|
| 380 | } |
|---|
| 381 | return false; |
|---|
| 382 | } |
|---|
| 383 | |
|---|
| [8753] | 384 | case(osgGA::GUIEventAdapter::KEYDOWN): |
|---|
| 385 | { |
|---|
| 386 | if (ea.getKey()=='p') |
|---|
| 387 | { |
|---|
| 388 | for(ImageStreamList::iterator itr=_imageStreamList.begin(); |
|---|
| 389 | itr!=_imageStreamList.end(); |
|---|
| 390 | ++itr) |
|---|
| 391 | { |
|---|
| 392 | if ((*itr)->getStatus()==osg::ImageStream::PLAYING) |
|---|
| 393 | { |
|---|
| 394 | |
|---|
| 395 | std::cout<<"Pause"<<std::endl; |
|---|
| 396 | (*itr)->pause(); |
|---|
| 397 | } |
|---|
| 398 | else |
|---|
| 399 | { |
|---|
| 400 | |
|---|
| 401 | std::cout<<"Play"<<std::endl; |
|---|
| 402 | (*itr)->play(); |
|---|
| 403 | } |
|---|
| 404 | } |
|---|
| 405 | return true; |
|---|
| 406 | } |
|---|
| 407 | else if (ea.getKey()=='r') |
|---|
| 408 | { |
|---|
| 409 | for(ImageStreamList::iterator itr=_imageStreamList.begin(); |
|---|
| 410 | itr!=_imageStreamList.end(); |
|---|
| 411 | ++itr) |
|---|
| 412 | { |
|---|
| 413 | std::cout<<"Restart"<<std::endl; |
|---|
| 414 | (*itr)->rewind(); |
|---|
| 415 | } |
|---|
| 416 | return true; |
|---|
| 417 | } |
|---|
| 418 | else if (ea.getKey()=='L') |
|---|
| 419 | { |
|---|
| 420 | for(ImageStreamList::iterator itr=_imageStreamList.begin(); |
|---|
| 421 | itr!=_imageStreamList.end(); |
|---|
| 422 | ++itr) |
|---|
| 423 | { |
|---|
| 424 | if ( (*itr)->getLoopingMode() == osg::ImageStream::LOOPING) |
|---|
| 425 | { |
|---|
| 426 | std::cout<<"Toggle Looping Off"<<std::endl; |
|---|
| 427 | (*itr)->setLoopingMode( osg::ImageStream::NO_LOOPING ); |
|---|
| 428 | } |
|---|
| 429 | else |
|---|
| 430 | { |
|---|
| 431 | std::cout<<"Toggle Looping On"<<std::endl; |
|---|
| 432 | (*itr)->setLoopingMode( osg::ImageStream::LOOPING ); |
|---|
| 433 | } |
|---|
| 434 | } |
|---|
| 435 | return true; |
|---|
| 436 | } |
|---|
| [13143] | 437 | else if (ea.getKey() == 'i') |
|---|
| 438 | { |
|---|
| [13158] | 439 | setTrackMouse(!_trackMouse); |
|---|
| [13143] | 440 | |
|---|
| 441 | |
|---|
| 442 | } |
|---|
| [8753] | 443 | return false; |
|---|
| 444 | } |
|---|
| 445 | |
|---|
| 446 | default: |
|---|
| 447 | return false; |
|---|
| 448 | } |
|---|
| [13143] | 449 | |
|---|
| 450 | return false; |
|---|
| [8753] | 451 | } |
|---|
| 452 | |
|---|
| 453 | void MovieEventHandler::getUsage(osg::ApplicationUsage& usage) const |
|---|
| 454 | { |
|---|
| [13143] | 455 | usage.addKeyboardMouseBinding("i","toggle interactive mode, scrub via mouse-move"); |
|---|
| [8753] | 456 | usage.addKeyboardMouseBinding("p","Play/Pause movie"); |
|---|
| 457 | usage.addKeyboardMouseBinding("r","Restart movie"); |
|---|
| 458 | usage.addKeyboardMouseBinding("l","Toggle looping of movie"); |
|---|
| 459 | } |
|---|
| 460 | |
|---|
| 461 | |
|---|
| 462 | |
|---|
| 463 | |
|---|
| [8657] | 464 | int main(int argc, char **argv) |
|---|
| [8637] | 465 | { |
|---|
| [8657] | 466 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 467 | |
|---|
| [8637] | 468 | |
|---|
| [8657] | 469 | osgViewer::Viewer viewer(arguments); |
|---|
| [8637] | 470 | |
|---|
| [8841] | 471 | std::string filename; |
|---|
| 472 | arguments.read("-o",filename); |
|---|
| 473 | |
|---|
| [8637] | 474 | |
|---|
| [8841] | 475 | viewer.setSceneData(createModel(arguments)); |
|---|
| [8637] | 476 | |
|---|
| [8753] | 477 | |
|---|
| 478 | MovieEventHandler* meh = new MovieEventHandler(); |
|---|
| 479 | meh->set( viewer.getSceneData() ); |
|---|
| [13158] | 480 | |
|---|
| 481 | if (arguments.read("--track-mouse")) meh->setTrackMouse(true); |
|---|
| 482 | |
|---|
| [8753] | 483 | viewer.addEventHandler( meh ); |
|---|
| 484 | |
|---|
| [8916] | 485 | viewer.addEventHandler( new osgViewer::StatsHandler()); |
|---|
| [8753] | 486 | |
|---|
| [8841] | 487 | if (!filename.empty()) |
|---|
| [8660] | 488 | { |
|---|
| 489 | osgDB::writeNodeFile(*viewer.getSceneData(),filename); |
|---|
| 490 | } |
|---|
| [8657] | 491 | |
|---|
| [8637] | 492 | return viewer.run(); |
|---|
| 493 | } |
|---|