Created
August 4, 2022 12:20
-
-
Save gwaldron/91b58f43b6cf9cd87b3fb33c9ccd9fac to your computer and use it in GitHub Desktop.
Turn a model into a paged lod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <osg/ArgumentParser> | |
#include <osg/PagedLOD> | |
#include <osgDB/ReadFile> | |
#include <osgDB/WriteFile> | |
#include <iostream> | |
int | |
main(int argc, char** argv) | |
{ | |
osg::ArgumentParser arguments(&argc,argv); | |
// load your model: | |
auto node = osgDB::readRefNodeFile(argv[1]); | |
if (node.valid()) | |
{ | |
// bounds of the model: | |
auto bs = node->getBound(); | |
// make a PLOD with the model's bounding sphere: | |
osg::ref_ptr<osg::PagedLOD> plod = new osg::PagedLOD(); | |
plod->setCenter(bs.center()); | |
plod->setRadius(bs.radius()); | |
// model to load on demand: | |
plod->setFileName(0, argv[1]); | |
// set up the LOD parameters: | |
#ifdef USE_DISTANCE_BASED_LODS | |
plod->setRangeMode(osg::LOD::DISTANCE_FROM_EYE_POINT); | |
plod->setRange(0, 0.0f, bs.radius() * 3.0f); | |
#else | |
plod->setRangeMode(osg::LOD::PIXEL_SIZE_ON_SCREEN); | |
plod->setRange(0, 25.0f, FLT_MAX); | |
#endif | |
// dump out the osgt file. | |
osgDB::writeNodeFile(*plod.get(), "out.osgt"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment