arcore - 我们如何将场景形式与 ARCloud 锚点一起使用?
问题描述
每次我尝试托管锚点“ session.hostCloudAnchor(anchor); ”时,它都会显示NotTrackingException。
我们如何托管和解析从arFragment.setOnTapArPlaneListener获得的 Anchor ?
这是我使用的代码片段,
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();
}
});
解决方案
You need to check the anchor tracking state & proceed with hosting.
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)
}
}
}
Before hosting an anchor:
- Try to look at the anchor from different angles.
- Move around the anchor for at least a few seconds.
- Make sure you are not too far away from the anchor.
Refer : https://developers.google.com/ar/develop/java/cloud-anchors/cloud-anchors-developer-guide-android
推荐阅读
- react-native - React-native Stimulation 开发服务器返回响应错误码:500?
- vuejs3 - 如何使用quasar框架中的splitter组件动态切页?
- python - 如何在 python 中为打开的网页定义驱动程序
- node.js - 如何在 Nodejs 中对 zip 文件夹进行密码保护?
- discord.py - 在不和谐中制作不和谐反应角色机器人的问题
- python - 在 x_train 和 x_test 中拆分数据会产生错误:太多值无法解包预期 2
- flutter - 无状态小部件与有状态小部件性能
- javascript - 如何在我的网站中实现 Canva 扩展
- regex - 如何为 Word Find Wildcards 组合三种不同的文本模式
- gnuplot - 如何通过gnuplot绘制分组箱线图