How to render a View to the right of parent node in ARCore sceneform
Asked Answered
V

1

5

Using ViewRenderable I am rendering layout file. I gave fixed width and height for the layout file

<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>

Now I am building layout as ViewRenderable

 // 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);
                            }

After that I need to render this ViewRenderable Object into the node

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

Now I need to add another node to the right of sunVisual node

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

This code works well on google pixel 2 devices but I am getting small space in nokia x6 device

Google pixel 2 screenshotGoogle pixel 2 image

Nokia x6 screenshotNokia x6 screenshot

How to get the rendered view width and height in meter?

How to set local position to the right of parent node based on the parent node rendered view size

Help me to fix this issue thanks in advance

Verlinevermeer answered 9/10, 2018 at 10:34 Comment(0)
V
6

I found solution to fix the above mentioned issue that I faced.

    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));

We can use setSizer to set width and height for ViewRendarable

 ((ViewRenderable) renderable).setSizer(new FixedWidthViewSizer(2));
Verlinevermeer answered 10/10, 2018 at 11:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.