|
发表于 2015-6-2 17:14:37
|
显示全部楼层
本帖最后由 anlingbin 于 2015-6-2 17:15 编辑
你可以试试这样有没有效果,
namespace
{
Threading::ReadWriteMutex _pgmMutex;
typedef std::map<long, osg:bserver_ptr<osg::Node>> PgcnRegistry;
PgcnRegistry _pgcnRegistry;
}
struct ReaderWriterPagedModel : public osgDB::ReaderWriter
{
ReaderWriterPagedModel()
{
supportsExtension( "pgm", "osg PagedLOD Child Node Loader" );
}
ReadResult readNode(const std::string& uri, const Options* options) const
{
if (!acceptsExtension(osgDB::getLowerCaseFileExtension(uri)))
return ReadResult::FILE_NOT_HANDLED;
long id;
sscanf_s(uri.c_str(), "%d.%*s", &id);
osg::ref_ptr<osg::Node> node = getNode(id);
if (node.valid()) {
return ReadResult(node.get());
}
return ReadResult::ERROR_IN_READING_FILE;
}
static std::string makeURI(long uid)
{
std::stringstream buf;
buf << uid << ".pgm";
return buf.str();
}
static long registerNode(osg::Node* node)
{
Threading::ScopedWriteLock lock(_pgmMutex);
long key = (long)node;
_pgcnRegistry[key] = node;
//OE_TEST << LC << "Registered FMG " << key << std::endl;
return key;
}
static void unregisterNode(osg::Node* node)
{
Threading::ScopedWriteLock lock(_pgmMutex);
long key = (long)node;
_pgcnRegistry.erase(key);
//OE_TEST << LC << "UNregistered FMG " << uid << std::endl;
}
static osg::Node* getNode(long id)
{
Threading::ScopedReadLock lock(_pgmMutex);
PgcnRegistry::const_iterator i = _pgcnRegistry.find(id);
return i != _pgcnRegistry.end() ? i->second.get() : 0L;
}
};
REGISTER_OSGPLUGIN(pgm, ReaderWriterPagedModel);
添加模型时:
long key = ReaderWriterPagedModel::registerNode(_pIVENode );
_pPagedLod->setFileName(0, ReaderWriterPagedModel::makeURI(key));
_pPagedLod->setRange(0, dMinVisualDistance, dMaxVisualDistance); |
|