当前位置: 首页 > 知识库问答 >
问题:

如何在ARCore sceneform中渲染父节点右侧的视图

施永宁
2023-03-14

使用ViewRenderable渲染布局文件。我为布局文件指定了固定的宽度和高度

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="500dp"
    android:layout_height="50dp"
    android:background="@android:color/transparent">
// Add design
</android.support.constraint.ConstraintLayout>

现在,我将建筑布局设置为可视可渲染

 // Build a renderable from a 2D View.
        CompletableFuture<ViewRenderable> meterOne =
                ViewRenderable.builder().setView(this, R.layout.meter).build();

     CompletableFuture.allOf(circle,
                meterOne, meterTwo)
                .handle(
                        (notUsed, throwable) -> {
                            // When you build a Renderable, Sceneform loads its resources in the background while
                            // returning a CompletableFuture. Call handle(), thenAccept(), or check isDone()
                            // before calling get().

                            if (throwable != null) {
                                DemoUtils.displayError(this, "Unable to load renderable", throwable);
                                return null;
                            }

                            try {
 Meters.add(meterOne.get());
 } catch (InterruptedException | ExecutionException ex) {
                                DemoUtils.displayError(this, "Unable to load renderable", ex);
                            }

之后,我需要渲染这个ViewRenderable对象到节点

        Node sunVisual = new Node();
        sunVisual.setParent(sun);
        sunVisual.setRenderable(Meters.get(0)); // View
        sunVisual.setLocalScale(new Vector3(0.5f, 0.5f, 0.5f));

现在我需要在sunVisual节点的右侧添加另一个节点

            Node node = new Node();
            node.setParent(sunVisual );
            node.setRenderable(Meters.get(1));
            node.setLocalPosition(new Vector3(2.0f, 0.0f, 0.0f)); 

这段代码在google pixel 2设备上运行良好,但我在诺基亚x6设备上的空间很小

如何以米为单位获取渲染视图的宽度和高度?

如何根据父节点呈现的视图大小设置父节点右侧的本地位置

请帮助我解决此问题,提前感谢

共有1个答案

吕树
2023-03-14

我找到了解决我所面临的上述问题的方法。

    Node node = new Node();
    node.setParent(parent);
    Renderable renderable = Meters.get(i);
    renderable.setShadowReceiver(false);
    renderable.setShadowCaster(false);
 ((ViewRenderable) renderable).setSizer(new FixedWidthViewSizer(2));
    node.setRenderable(renderable);
    node.setLocalPosition(new Vector3(2.0f, 0.0f, 0.0f));

我们可以使用setSzer为ViewRendarable设置宽度和高度

 ((ViewRenderable) renderable).setSizer(new FixedWidthViewSizer(2));
 类似资料:
  • 节点类 成员变量 变量 类型 名称 备注 id number 标识 无 name string 名称 无 position Object 位置 结构为 {x:0,y:0,z:0} scale Object 缩放比例 结构为 {x:0,y:0} 分别标识x方向和y方向上的缩放系数 rotation Object 旋转 结构为 {x:0,y:0,z:0} 绕x,y,z轴逆时针旋转 vertexColo

  • 加载页面时 <div id="root"></div> 这样的占位空节点在 js bundle 未生效前表现为白屏。网速差 js bundle 加载慢时,白屏时间增长会造成不好的体验。 节点快照可将 HTML 容器填充为用户上一次访问时对应的内容,极速展示页面内容,提升首屏加载速度。 第一步:在工程配置 build.json 中的 build-plugin-rax-pwa 添加 snapshot

  • 我最近开始学习数据结构和算法。我正在创建一个二叉树,它只在树的左侧添加节点。我如何创建这样一种方式,即它应该在根节点的两侧添加节点,并如下所示: 以下是我编写的代码: 主要类别:

  • 渲染某个变量 假定我们定义了一个变量:  <script> export default { data () { return { my_value: '默认值', } }, } </script> 我们就可以这样来显示它:  <div>{{my_value}}</div> 方法的声明和调用 声明一个方法: show_my_value <script> ex

  • Elements(节点)是React apps中最简单的构建块。 一个Elmeent定义了你将在屏幕上看到什幺内容,如: const element = <h1>Hello,world</h1>; 不像浏览器中的DOM节点,React elements其实就是一个普通的对象,你可以很容易的创建它,然后由React DOM来保持element和DOM的更新同步! 注意 一种使人困惑的观念就是

  • Blade 内部内置了一个非常简单的模板渲染引擎,如果你有一些简单的页面需要渲染可以试试它(生产环境不适用)。 渲染一个模板需要遵守一条准则: 所有的模板文件都存储在 resources/templates 目录下 你可以调用 Response 方法的 render 方法渲染或者返回一个 String 类型的视图路径。 @GetRoute("/index") public void renderI