Как визуализировать представление справа от родительского узла в сцене ARCore - PullRequest
0 голосов
/ 09 октября 2018

Использование 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>

Теперь я создаю макет как 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);
                            }

После этого мне нужно визуализировать этот 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, но в устройстве Nokia X6 у меня мало места

Скриншот Google pixel 2 Google pixel 2 image

Скриншот Nokia x6 Nokia x6 screenshot

Как получить ширину и высоту визуализированного вида в метрах?

Как установить локальную позицию справа от родительского узла на основе размера визуализированного представления родительского узла

Помогите мне решить эту проблему, заранее спасибо

1 Ответ

0 голосов
/ 10 октября 2018

Я нашел решение, чтобы исправить вышеупомянутую проблему, с которой столкнулся.

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

Мы можем использовать setSizer, чтобы установить ширину и высоту для ViewRendarable

 ((ViewRenderable) renderable).setSizer(new FixedWidthViewSizer(2));
...