X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fscene%2Fmodel%2FCheckSceneryVisitor.cxx;h=e0149c069a5a8f6bb00298a05ffba65b1d9ae7bf;hb=5a96b283f63cfacd3a3a90a82246defb038242d3;hp=56a023680429d92d1f0765bcceeb9970bd1e3253;hpb=7e7d877874fcd67cad0152bd1a2a073e0337235f;p=simgear.git diff --git a/simgear/scene/model/CheckSceneryVisitor.cxx b/simgear/scene/model/CheckSceneryVisitor.cxx index 56a02368..e0149c06 100644 --- a/simgear/scene/model/CheckSceneryVisitor.cxx +++ b/simgear/scene/model/CheckSceneryVisitor.cxx @@ -1,4 +1,5 @@ // Copyright (C) 2008 Till Busch buti@bux.at +// Copyright (C) 2011 Mathias Froehlich // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -19,22 +20,25 @@ #endif #include +#include +#include #include #include "CheckSceneryVisitor.hxx" -#include "SGPagedLOD.hxx" #include using namespace simgear; -CheckSceneryVisitor::CheckSceneryVisitor(osgDB::DatabasePager* dbp, osg::Vec3 &position, double range) +CheckSceneryVisitor::CheckSceneryVisitor(osgDB::DatabasePager* dbp, const osg::Vec3 &position, double range, + osg::FrameStamp* framestamp) :osg::NodeVisitor(osg::NodeVisitor::NODE_VISITOR, osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN), -_loaded(true), _position(position), _range(range), _dbp(dbp) + _position(position), _range(range), _loaded(true), _matrix(osg::Matrix::identity()) { - _viewMatrices.push_back(osg::Matrix::identity()); + setDatabaseRequestHandler(dbp); + setFrameStamp(framestamp); } void CheckSceneryVisitor::apply(osg::Node& node) @@ -42,35 +46,62 @@ void CheckSceneryVisitor::apply(osg::Node& node) traverse(node); } -void CheckSceneryVisitor::apply(osg::PagedLOD& node) +void CheckSceneryVisitor::apply(osg::ProxyNode& node) { - SGPagedLOD *sgplod = dynamic_cast(&node); - if (sgplod) { - osg::Vec3 pos = sgplod->getCenter() * _viewMatrices.back(); - double dist = (pos-_position).length(); - if (dist < _range) { - if (sgplod->getNumChildren() < 1) { - // if the DatabasePager would load LODs while the splashscreen - // is there, we could just wait for the models to be loaded - // by only setting setLoaded(false) here - sgplod->forceLoad(_dbp); - setLoaded(false); - } + osg::Vec3 pos = node.getCenter() * _matrix; + double dist = (pos - _position).length(); + if (dist < _range) { + for (unsigned i = 0; i < node.getNumFileNames(); ++i) { + if (node.getFileName(i).empty()) + continue; + // Check if this is already loaded. + if (i < node.getNumChildren() && node.getChild(i)) + continue; + + // if the DatabasePager would load LODs while the splashscreen + // is there, we could just wait for the models to be loaded + // by only setting setLoaded(false) here + osg::NodePath nodePath = getNodePath(); + DatabaseRequestHandler* db = getDatabaseRequestHandler(); + const osg::FrameStamp* fs = getFrameStamp(); + db->requestNodeFile(node.getFileName(i), nodePath, 1.0 /*priority*/, fs, + node.getDatabaseRequest(i), node.getDatabaseOptions()); + setLoaded(false); } } traverse(node); } -void CheckSceneryVisitor::apply(osg::Transform &node) +void CheckSceneryVisitor::apply(osg::PagedLOD& node) { - osg::Matrix currMatrix = _viewMatrices.back(); - bool pushMatrix = node.computeLocalToWorldMatrix(currMatrix, this); + osg::Vec3 pos = node.getCenter() * _matrix; + double dist = (pos - _position).length(); + if (dist < _range) { + for (unsigned i = 0; i < node.getNumFileNames(); ++i) { + if (node.getFileName(i).empty()) + continue; + // Check if this is already loaded. + if (i < node.getNumChildren() && node.getChild(i)) + continue; - if (pushMatrix) { - _viewMatrices.push_back(currMatrix); + // if the DatabasePager would load LODs while the splashscreen + // is there, we could just wait for the models to be loaded + // by only setting setLoaded(false) here + osg::NodePath nodePath = getNodePath(); + DatabaseRequestHandler* db = getDatabaseRequestHandler(); + const osg::FrameStamp* fs = getFrameStamp(); + db->requestNodeFile(node.getFileName(i), nodePath, 1.0 /*priority*/, fs, + node.getDatabaseRequest(i), node.getDatabaseOptions()); + setLoaded(false); + } } traverse(node); - if (pushMatrix) { - _viewMatrices.pop_back(); - } +} + +void CheckSceneryVisitor::apply(osg::Transform &node) +{ + osg::Matrix matrix = _matrix; + node.computeLocalToWorldMatrix(_matrix, this); + traverse(node); + _matrix = matrix; }