如何解决Android Sceneform 使用垂直平面检测墙
想要检测垂直平面并将物体放在墙上,但它没有发生并且水平平面工作但没有垂直平面甚至检测不到。
{
ArFragment wallFragment;
public Session mArSession;
public Config mArConfig;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_wall);
wallFragment = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.wallfrag);
mArSession = wallFragment.getArSceneView().getSession();
try {
setupPlaneFinder(mArSession);
} catch (UnavailableSdkTooOldException e) {
e.printStackTrace();
} catch (UnavailableDeviceNotCompatibleException e) {
e.printStackTrace();
} catch (UnavailableArcoreNotInstalledException e) {
e.printStackTrace();
} catch (UnavailableApkTooOldException e) {
e.printStackTrace();
}
wallFragment.setOnTapArPlaneListener(
(HitResult hitResult,Plane plane,MotionEvent motionEvent) -> {
Anchor anchor = hitResult.createAnchor();
ModelRenderable.builder()
.setSource(wallFragment.getContext(),RenderableSource
.builder().
setSource(this,Uri.parse("file:///android_asset/chair.glb"),RenderableSource.SourceType.GLB)
.setScale(0.75f)
.setRecenterMode(RenderableSource.RecenterMode.ROOT)
.build())
.build()
.thenAccept(modelRenderable -> addNodeToScene(wallFragment,anchor,modelRenderable,plane))
.exceptionally(throwable -> {
Toast.makeText(wallFragment.getContext(),"Error:" + throwable.getMessage(),Toast.LENGTH_LONG).show();
return null;
}
);
});
}
private void addNodeToScene(ArFragment wallFragment,Anchor anchor,ModelRenderable modelRenderable,Plane plane) {
AnchorNode anchorNode = new AnchorNode(anchor);
TransformableNode node = new TransformableNode(wallFragment.getTransformationSystem());
node.setRenderable(modelRenderable);
node.setParent(anchorNode);
Config config = wallFragment.getArSceneView().getSession().getConfig();
config.setPlaneFindingMode(Config.PlaneFindingMode.HORIZONTAL_AND_VERTICAL);
wallFragment.getArSceneView().getSession().configure(config);
wallFragment.getArSceneView().getScene().addChild(anchorNode);
node.select();
}
@Override
protected void onResume() {
super.onResume();
try {
setupPlaneFinder(mArSession);
} catch (UnavailableSdkTooOldException e) {
e.printStackTrace();
} catch (UnavailableDeviceNotCompatibleException e) {
e.printStackTrace();
} catch (UnavailableArcoreNotInstalledException e) {
e.printStackTrace();
} catch (UnavailableApkTooOldException e) {
e.printStackTrace();
}
}
private void setupPlaneFinder(Session mArSession) throws UnavailableSdkTooOldException,UnavailableDeviceNotCompatibleException,UnavailableArcoreNotInstalledException,UnavailableApkTooOldException {
if (mArSession == null)
mArSession = new Session(this);
mArConfig = new Config(mArSession);
mArConfig.setPlaneFindingMode(Config.PlaneFindingMode.);
mArConfig.setUpdateMode(Config.UpdateMode.LATEST_CAMERA_IMAGE);
mArSession.configure(mArConfig);
wallFragment.getArSceneView().setupSession(mArSession);
}
}
请帮我解决这个问题,我不知道在哪里创建会话以及它的垂直配置。主要是寻找墙壁检测和放置物体或将图像放置在平面上的结果。
已经尝试了所有方法,但 google docs 也没有提供那么多信息。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。