如何在ARCore场景形式中的父节点右侧渲染视图

时间:2018-10-09 10:34:16

标签: android arcore sceneform

使用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设备上效果很好,但在诺基亚x6设备上空间越来越小

Google pixel 2屏幕截图 Google pixel 2 image

诺基亚x6屏幕截图 Nokia x6 screenshot

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

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

请先帮助我解决此问题

1 个答案:

答案 0 :(得分:2)

我找到了解决上述问题的解决方案。

import cv2
import numpy as np

img_bgr = cv2.imread("/home/anmol/Downloads/tWuTW.jpg")
img_hsv = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2HSV_FULL)

# Filter out low saturation values, which means gray-scale pixels(majorly in background)
bgd_mask = cv2.inRange(img_hsv, np.array([0, 0, 0]), np.array([255, 30, 255]))

# Get a mask for pitch black pixel values
black_pixels_mask = cv2.inRange(img_bgr, np.array([0, 0, 0]), np.array([70, 70, 70]))

# Get the mask for extreme white pixels.
white_pixels_mask = cv2.inRange(img_bgr, np.array([230, 230, 230]), np.array([255, 255, 255]))

final_mask = cv2.max(bgd_mask, black_pixels_mask)
final_mask = cv2.min(final_mask, ~white_pixels_mask)
final_mask = ~final_mask

final_mask = cv2.erode(final_mask, np.ones((3, 3), dtype=np.uint8))
final_mask = cv2.dilate(final_mask, np.ones((5, 5), dtype=np.uint8))

# Now you can finally find contours.
im, contours, hierarchy = cv2.findContours(final_mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

final_contours = []
for contour in contours:
    area = cv2.contourArea(contour)
    if area > 2000:
        final_contours.append(contour)


for i in xrange(len(final_contours)):
    img_bgr = cv2.drawContours(img_bgr, final_contours, i, np.array([50, 250, 50]), 4)


debug_img = img_bgr
debug_img = cv2.resize(debug_img, None, fx=0.3, fy=0.3)
cv2.imwrite("./out.png", debug_img)

我们可以使用setSizer为 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)); 设置宽度和高度

ViewRendarable