我们如何将Sceneform与ARCloud锚点一起使用?

时间:2018-06-19 12:33:52

标签: arcore

每次我尝试托管锚“ session.hostCloudAnchor(anchor); ”时,它都会显示 NotTrackingException

我们如何托管和解析从 arFragment.setOnTapArPlaneListener 获得的锚点?

这是我正在使用的代码的片段,

   arFragment.setOnTapArPlaneListener(
    (HitResult hitResult, Plane plane, MotionEvent motionEvent) -> {
      Camera camera = arFragment.getArSceneView().getArFrame().getCamera();
      TrackingState cameraTrackingState = camera.getTrackingState();

      if (andyRenderable == null) {
        return;
      }

      if (plane.getType() != Type.HORIZONTAL_UPWARD_FACING) {
        return;
      }

      if (cameraTrackingState == TrackingState.TRACKING && session!= null) {
        // Create the Anchor.
        anchor = hitResult.createAnchor();
        try{
        session.hostCloudAnchor(anchor);
        }
        catch (NotTrackingException e)
        {
            e.printStackTrace();

        }
        setNewAnchor(anchor);
        appAnchorState = AppAnchorState.HOSTING;
        Toast.makeText(HelloSceneformActivity.this, "Now, hosting anchor", Toast.LENGTH_SHORT)
            .show();

        AnchorNode anchorNode = new AnchorNode(anchor);
        anchorNode.setParent(arFragment.getArSceneView().getScene());

        // Create the transformable andy and add it to the anchor.
        TransformableNode andy = new TransformableNode(arFragment.getTransformationSystem());
        andy.setParent(anchorNode);
        andy.setRenderable(andyRenderable);
        andy.select();

        checkUpdatedAnchor();
      }
    });

1 个答案:

答案 0 :(得分:0)

您需要检查 anchor 跟踪状态并继续托管。

override fun onTapPlane(hitResult: HitResult, plane: Plane, motionEvent: MotionEvent?) {


        if (plane.type == Plane.Type.HORIZONTAL_UPWARD_FACING) {

            val anchor = hitResult.createAnchor()
            val anchorNode = AnchorNode(anchor)
            anchorNode.setParent(arFragment.arSceneView.scene)

            if (anchor.trackingState == TrackingState.TRACKING) {

                viewModel.hostAnchorToCloud(anchor)

            } 
        }
    }

在主持锚之前:

  • 尝试从不同角度看锚。
  • 在锚点周围移动至少几秒钟。
  • 确保您离锚点不太远。

引用:https://github.com/laravel/framework/blob/76fa2de90c438859f7c85718a98696fe7509c918/src/Illuminate/Routing/Console/stubs/controller.api.stub