我正在尝试使用给定的坐标放置标记图像,而不是使用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是使应用程序崩溃且无法正常工作的部分,有人可以指出我做错了什么吗?