Skip to content

Commit

Permalink
Changed interface to LODGenerator to handle the
Browse files Browse the repository at this point in the history
case where the input is a single geometry/geode
without any parents.
  • Loading branch information
jasonbeverage committed May 13, 2024
1 parent a9e75d3 commit c319a7e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/applications/osgearth_lod/osgearth_lod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ main(int argc, char** argv)
osg::ref_ptr<osg::Node> root = osgDB::readRefNodeFiles(args);

LODGenerator generator;
generator.generateLODs(root.get(), options);
osg::ref_ptr< osg::Node> result = generator.generateLODs(root.get(), options);

osgDB::writeNodeFile(*root, outFilename);
osgDB::writeNodeFile(*result, outFilename);
return 0;
}
2 changes: 1 addition & 1 deletion src/osgEarth/LODGenerator
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace osgEarth
bool aggressive;
};

void generateLODs(osg::Node* node, const std::vector<LODOptions>& options);
osg::Node* generateLODs(osg::Node* node, const std::vector<LODOptions>& options);
};


Expand Down
17 changes: 15 additions & 2 deletions src/osgEarth/LODGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ osg::LOD* createLODFromGeometry(osg::Geometry* originalGeometry, const std::vect
}


void LODGenerator::generateLODs(osg::Node* node, const std::vector<LODOptions>& options)
osg::Node* LODGenerator::generateLODs(osg::Node* node, const std::vector<LODOptions>& options)
{
FindNodesVisitor<osg::Geometry> nv;
node->accept(nv);
Expand All @@ -113,15 +113,28 @@ void LODGenerator::generateLODs(osg::Node* node, const std::vector<LODOptions>&
if (geode)
{
lod->setStateSet(geode->getStateSet());
geode->getParent(0)->replaceChild(geode, lod);
if (geode->getNumParents() == 0)
{
return lod;
}
else
{
geode->getParent(0)->replaceChild(geode, lod);
}
}
else
{
parent->replaceChild(geom, lod);
}
}
else
{
return lod;
}
}
}

return node;
}

#endif // OSGEARTH_HAVE_MESH_OPTIMIZER

0 comments on commit c319a7e

Please sign in to comment.