每次我尝试托管锚“ 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();
}
});
答案 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)
}
}
}
在主持锚之前: