Как исправить "AR_ERROR_NOT_TRACKING" создание якоря - PullRequest
0 голосов
/ 19 апреля 2019

Я пытаюсь разместить изображение маркера с заданными координатами вместо использования hitReuslt, однако, когда выполняется session.createAnchor, приложение вылетает из-за ошибки:

status.cc:156 ArStatusErrorSpace::AR_ERROR_NOT_TRACKING: Cannot create anchors while the camera is not tracking.

и эта ошибка также:

Unable to start activity ComponentInfo{ar.navi/ar.navi.TestActivity}: com.google.ar.core.exceptions.NotTrackingException

ниже мой код:

    private ArFragment fragment;
    private Session mSession;
    private ModelRenderable markerRenderable;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (!checkIsSupportedDeviceOrFinish(this)){
            return;
        }
        setContentView(R.layout.activity_navigation);

        fragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.sceneform_fragment);

        if (mSession == null){
            try {
                mSession = new Session(this);
                fragment.getArSceneView().setupSession(mSession);
            } catch (UnavailableArcoreNotInstalledException e) {
                e.printStackTrace();
            } catch (UnavailableApkTooOldException e) {
                e.printStackTrace();
            } catch (UnavailableSdkTooOldException e) {
                e.printStackTrace();
            } catch (UnavailableDeviceNotCompatibleException e) {
                e.printStackTrace();
            }
        }

        // 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().
        ModelRenderable.builder()
                .setSource(this, Uri.parse("marker.sfb"))
                .build()
                .thenAccept(renderable -> markerRenderable = renderable)
                .exceptionally(
                        throwable -> {
                            Toast toast =
                                    Toast.makeText(this, "Unable to load andy renderable", Toast.LENGTH_LONG);
                            toast.setGravity(Gravity.CENTER, 0, 0);
                            toast.show();
                            return null;
                        });

        Session session = fragment.getArSceneView().getSession();
        //Pose pose = Pose.makeTranslation((float)deviceLocation.getLatitude(), (float)deviceLocation.getLatitude(), 0);

        if (session != null){
            try{
                session.resume();
            } catch (CameraNotAvailableException e){
                e.printStackTrace();
            }
            float[] position = { 0, 0, (float)-0.75};       // 75 cm away from camera
            float[] rotation = { 0, 0, 0, 1 };
            //createAnchor always crashes the app and saying camera is not trakcing
            Anchor anchor = session.createAnchor(new Pose(position, rotation));
            AnchorNode anchorNode = new AnchorNode(anchor);
            anchorNode.setRenderable(markerRenderable);
            anchorNode.setParent(fragment.getArSceneView().getScene());
        }
    }

Я выполнил отладку и выяснил, что session.createAnchor - это та часть, где происходит сбой приложения и он не работает, кто-нибудь может указать, что я сделал неправильно?

...