【问题标题】:How to disable surface detection in ARCore Android如何在 ARCore Android 中禁用表面检测
【发布时间】:2019-01-06 09:42:01
【问题描述】:

我正在处理一个项目,但遇到了 ARCore 问题。我在我的项目中使用了ARCore Location,我使用纬度和经度设置了对象的位置。但是当我在设备中看到它时,AR 中的对象位置会有所不同。

CompletableFuture<ViewRenderable> exampleLayout = ViewRenderable.builder()
                    .setView(this, R.layout.example_layout)
                    .build();

    // When you build a Renderable, Sceneform loads its resources in the background while returning
    // a CompletableFuture. Call thenAccept(), handle(), or check isDone() before calling get().
    CompletableFuture<ModelRenderable> andy = ModelRenderable.builder()
            .setSource(this, R.raw.andy)
            .build();


    CompletableFuture.allOf(
            exampleLayout,
            andy)
            .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 renderables", throwable);
                            return null;
                        }

                        try {
                            exampleLayoutRenderable = exampleLayout.get();
                            andyRenderable = andy.get();
                            hasFinishedLoading = true;

                        } catch (InterruptedException | ExecutionException ex) {
                            DemoUtils.displayError(this, "Unable to load renderables", ex);
                        }

                        return null;
                    });

    // Set an update listener on the Scene that will hide the loading message once a Plane is
    // detected.
    arSceneView
            .getScene()
            .setOnUpdateListener(
                    frameTime -> {
                        if (!hasFinishedLoading) {
                            return;
                        }

                        if (locationScene == null) {
                            // If our locationScene object hasn't been setup yet, this is a good time to do it
                            // We know that here, the AR components have been initiated.
                            locationScene = new LocationScene(this, this, arSceneView);

                            // Now lets create our location markers.
                            // First, a layout
                            LocationMarker layoutLocationMarker = new LocationMarker(
                                    77.398151,
                                    28.540926,
                                    getExampleView()
                            );

                            // An example "onRender" event, called every frame
                            // Updates the layout with the markers distance
                            layoutLocationMarker.setRenderEvent(new LocationNodeRender() {
                                @SuppressLint("SetTextI18n")
                                @Override
                                public void render(LocationNode node) {
                                    View eView = exampleLayoutRenderable.getView();
                                    TextView distanceTextView = eView.findViewById(R.id.textView2);
                                    distanceTextView.setText(node.getDistance() + "M");
                                }
                            });
                            // Adding the marker
                            locationScene.mLocationMarkers.add(layoutLocationMarker);

                            // Adding a simple location marker of a 3D model
                            locationScene.mLocationMarkers.add(
                                    new LocationMarker(
                                            77.398151,
                                            28.540926,
                                            getAndy()));
                        }

                        Frame frame = arSceneView.getArFrame();
                        if (frame == null) {
                            return;
                        }

                        if (frame.getCamera().getTrackingState() != TrackingState.TRACKING) {
                            return;
                        }

                        if (locationScene != null) {
                            locationScene.processFrame(frame);
                        }

                        if (loadingMessageSnackbar != null) {
                            for (Plane plane : frame.getUpdatedTrackables(Plane.class)) {
                                if (plane.getTrackingState() == TrackingState.TRACKING) {
                                    hideLoadingMessage();
                                }
                            }
                        }
                    });


    // Lastly request CAMERA & fine location permission which is required by ARCore-Location.
    ARLocationPermissionHelper.requestPermission(this);

这里的主要问题是它会根据它检测表面和放置图像,如果有任何可能禁用表面检测,那么它可以完美运行。

【问题讨论】:

    标签: android location arcore


    【解决方案1】:

    使用 EnablePlaneFinding = false 修改会话配置,然后禁用并重新启用 ARCoreSession。这将禁用飞机查找功能,但会保留现有飞机目前的状态。

    如果您不想禁用会话,您可以在会话上强制 OnEnable() 调用而不禁用它:

     var session = GameObject.Find("ARCore Device").GetComponent<ARCoreSession>(); 
    session.SessionConfig.EnablePlaneFinding = false; session.OnEnable();
    

    【讨论】:

      【解决方案2】:

      您可以使用hide() 方法在android 中隐藏平面发现。此外,通过将setEnabled() 方法设置为 false 来禁用平面渲染器。

      这样试试,

      arFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.ux_fragment);
      arFragment.getPlaneDiscoveryController().hide();
      arFragment.getPlaneDiscoveryController().setInstructionView(null);
      arFragment.getArSceneView().getPlaneRenderer().setEnabled(false);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-12-16
        • 2018-02-09
        • 2020-02-20
        • 1970-01-01
        • 2018-02-20
        • 2018-09-22
        • 2018-03-22
        • 2014-10-31
        相关资源
        最近更新 更多