vulkanscenegraph显示倾斜模型(6.5)-vsg::DatabasePager

 前言

       上章深入分析了帧循环过程中,多线程下的记录与提交机制。本章将分析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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CHPCWWHSU

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值