前言
上章深入分析了帧循环过程中,多线程下的记录与提交机制。本章将分析vsg::DatabasePager在更新场景图过程中的作用,进一步揭露vsg中场景图管理机制,并通过分析代码,详细解释vsg中场景图管理机制中的节点添加、节点删除、节点加载过程。同时本章也作为vulkanscenegraph显示倾斜模型主体内容的最后一章。
目录
- 1 vsg::PagedLOD
- 2 vsg::DatabasePager
- 3 帧循环过程中的场景图更新机制
1 vsg::PagedLOD
vsg::PagedLOD作为VSG中的动态细节级别节点,在场景遍历过程中通过计算当前视口下子节点是否可见,从而选择或加载最优精度的子节点。

上图为vsg::PagedLOD的继承关系,其继承自vsg::Node,可作为vsg场景图中普通的节点来使用,如作为组节点vsg::Group的子节点等。
vsg::PagedLOD通过重写read和write,支持自定义序列化(如从内存写到磁盘)和反序列化(如从磁盘写到内存)。
void PagedLOD::read(Input& input)
{
Node::read(input);
input.read("bound", bound);
input.read("child.minimumScreenHeightRatio", children[0].minimumScreenHeightRatio);
input.read("child.filename", filename);
children[0].node = nullptr;
if (input.filename)
{
auto path = filePath(input.filename);
if (path)
{
filename = (path / filename).lexically_normal();
}
}
input.read("child.minimumScreenHeightRatio", children[1].minimumScreenHeightRatio);
input.read("child.node", children[1].node);
options = Options::create_if(input.options, *input.options);
}
void PagedLOD::write(Output& output) const
{
Node::write(output);
output.write("bound", bound);
output.write("child.minimumScreenHeightRatio", children[0].minimumScreenHeightRatio);
output.write("child.filename", filename);
output.write("child.minimumScreenHeightRatio", children[1].minimumScreenHeightRatio);
output.write("child.node", children[1].node);
}
其中读写涉及到的变量如下:
Path filename;
dsphere bound;
using Children = std::array<Child, 2>;
Children children;
bound(dsphere)表示节点范围,children(Children)表示子节点,数量为2,其中第一个为动态子节点,即可卸载和加载的节点,其对应的路径为filename(PATH),相比常规子节点(第二个子节点),其分辨率会更高(对应的模型更精细)。
struct Child
{
double minimumScreenHeightRatio = 0.0; // 0.0 is always visible
ref_ptr<Node> node;
};
Child结构体包含两个变量,其中minimumScreenHeightRatio用于控制子节点是否可见。
和其它节点类似,vsg::PagedLOD的访问通过vsg::Visitor或其子类实现,vsg::PagedLOD动态子节点的加载与否由vsg::RecordTraversal遍历节点过程中判断,具体实现在void RecordTrav

最低0.47元/天 解锁文章
1243

被折叠的 条评论
为什么被折叠?



