【发布时间】:2021-11-27 05:12:48
【问题描述】:
我正在开展一个项目,人们可以将 cmets 留在 AR 中的特定位置。为了测试这一点,我试图让它显示一些测试消息。
public void getStarted(Anchor anchor){
ArrayList<String> comments = new ArrayList<String>();
comments.add("Have a nice day");
for (String x : comments) {
if (closeEnough()) {
ViewRenderable.builder()
.setView(x, )
.build()
.thenAccept(renderable -> placeComment(anchor, renderable, comments));
}
}
}
我能够对其进行测试,但当您尝试放置测试视图时它会崩溃。调用 .build() 时它会崩溃。您对解决此问题有什么建议吗?
我将添加前面的函数。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (checkSystemSupport(this)) {
Button button = (Button) findViewById(R.id.button);
arCam = (ArFragment) getSupportFragmentManager().findFragmentById(R.id.arCameraArea);
arCam.setOnTapArPlaneListener((hitResult, plane, motionEvent) -> {
Anchor anchor = hitResult.createAnchor();
getStarted((anchor));
});
}
}
以及放置和编辑文本的那个。
private void placeComment(Anchor anchor, @NonNull ViewRenderable renderable, String comments) {
TextView t = renderable.getView().findViewById(R.id.post);
t.setText(comments);
AnchorNode anchorNode = new AnchorNode(anchor);
anchorNode.setParent(arCam.getArSceneView().getScene());
TransformableNode model = new TransformableNode(arCam.getTransformationSystem());
model.setParent(anchorNode);
model.setRenderable(renderable);
model.select();
}
【问题讨论】:
标签: android android-studio augmented-reality arcore